p8: don't disable controlled mode when switching to monitoring mode
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Aug 2012 16:57:53 +0000 (18:57 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Aug 2012 17:03:55 +0000 (19:03 +0200)
src/lib/CECClient.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index b6c0812d2cbb1de4c37ab17b44fc2be7b44db83e..e7ac9556349601af73230fbc73904c918ed8777d 100644 (file)
@@ -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;
index 6461ca9b2bd1da66f2e134f3d465ed868aa609af..88795e92b9dde65123abe66f6b4de546371b9759 100644 (file)
@@ -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();
+}
index 5aa532b07a2db66e51986ee6f042ce100e8afd94..dc8e9f557d1c476b6a16029a11239fc3f380b56a 100644 (file)
@@ -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<cec_logical_address, CCECClient *> m_clients;
+      bool                                        m_bMonitor;
   };
 };