mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
cscore: Add connection strategy to sources (#1252)
By default, sources automatically manage their connection based on whether any sinks are connected. This change allows the user to keep a connection open or force it closed regardless of the number of connected sinks.
This commit is contained in:
@@ -41,6 +41,15 @@ class SourceImpl : public PropertyContainer {
|
||||
void SetDescription(const wpi::Twine& description);
|
||||
wpi::StringRef GetDescription(wpi::SmallVectorImpl<char>& buf) const;
|
||||
|
||||
void SetConnectionStrategy(CS_ConnectionStrategy strategy) {
|
||||
m_strategy = static_cast<int>(strategy);
|
||||
}
|
||||
bool IsEnabled() const {
|
||||
return m_strategy == CS_CONNECTION_KEEP_OPEN ||
|
||||
(m_strategy == CS_CONNECTION_AUTO_MANAGE && m_numSinksEnabled > 0);
|
||||
}
|
||||
|
||||
// User-visible connection status
|
||||
void SetConnected(bool connected);
|
||||
bool IsConnected() const { return m_connected; }
|
||||
|
||||
@@ -130,7 +139,6 @@ class SourceImpl : public PropertyContainer {
|
||||
virtual void NumSinksEnabledChanged() = 0;
|
||||
|
||||
std::atomic_int m_numSinks{0};
|
||||
std::atomic_int m_numSinksEnabled{0};
|
||||
|
||||
protected:
|
||||
// Cached video modes (protected with m_mutex)
|
||||
@@ -146,6 +154,9 @@ class SourceImpl : public PropertyContainer {
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
|
||||
std::atomic_int m_strategy{CS_CONNECTION_AUTO_MANAGE};
|
||||
std::atomic_int m_numSinksEnabled{0};
|
||||
|
||||
wpi::mutex m_frameMutex;
|
||||
wpi::condition_variable m_frameCv;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user