From: Lars Op den Kamp Date: Thu, 2 Aug 2012 16:57:53 +0000 (+0200) Subject: p8: don't disable controlled mode when switching to monitoring mode X-Git-Tag: upstream/2.2.0~1^2~19^2^2~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cc0a29772b1a007b1b3760bcfb11750a801f844b;p=deb_libcec.git p8: don't disable controlled mode when switching to monitoring mode --- diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index b6c0812..e7ac955 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -1249,13 +1249,9 @@ bool CCECClient::SwitchMonitoring(bool bEnable) if (m_processor) { - if (bEnable) - return m_processor->UnregisterClient(this); - else - { - m_configuration.bMonitorOnly = false; - return m_processor->RegisterClient(this); - } + m_processor->SwitchMonitoring(bEnable); + m_configuration.bMonitorOnly = bEnable; + return bEnable ? true: m_processor->RegisterClient(this); } return false; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 6461ca9..88795e9 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -62,7 +62,8 @@ CCECProcessor::CCECProcessor(CLibCEC *libcec) : m_libcec(libcec), m_iStandardLineTimeout(3), m_iRetryLineTimeout(3), - m_iLastTransmission(0) + m_iLastTransmission(0), + m_bMonitor(true) { m_busDevices = new CCECDeviceMap(this); } @@ -800,7 +801,7 @@ bool CCECProcessor::UnregisterClient(CCECClient *client) if (SetLogicalAddresses(addresses)) { // no more clients left, disable controlled mode - if (addresses.IsEmpty()) + if (addresses.IsEmpty() && !m_bMonitor) m_communication->SetControlledMode(false); return true; @@ -873,3 +874,13 @@ bool CCECProcessor::IsRunningLatestFirmware(void) m_communication->IsRunningLatestFirmware() : true; } + +void CCECProcessor::SwitchMonitoring(bool bSwitchTo) +{ + { + CLockObject lock(m_mutex); + m_bMonitor = bSwitchTo; + } + if (bSwitchTo) + UnregisterClients(); +} diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 5aa532b..dc8e9f5 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -127,7 +127,9 @@ namespace CEC bool TryLogicalAddress(cec_logical_address address, cec_version libCECSpecVersion = CEC_VERSION_1_4); bool IsRunningLatestFirmware(void); - private: + void SwitchMonitoring(bool bSwitchTo); + + private: bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true); void SetCECInitialised(bool bSetTo = true); @@ -152,5 +154,6 @@ namespace CEC CCECInputBuffer m_inBuffer; CCECDeviceMap * m_busDevices; std::map m_clients; + bool m_bMonitor; }; };