cec: per-client monitoring mode (which is just a call to (Un)RegisterClient()
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 14 May 2012 09:12:14 +0000 (11:12 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 14 May 2012 09:12:14 +0000 (11:12 +0200)
src/lib/CECClient.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index 93b9916db352fcf6404a52fec45fb19b9dc633af..6df9dbab4288f6898fa1316b3fbf38697a22da2d 100644 (file)
@@ -1170,7 +1170,17 @@ bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress)
 
 bool CCECClient::SwitchMonitoring(bool bEnable)
 {
-  return m_processor ? m_processor->SwitchMonitoring(bEnable) : false;
+  LIB_CEC->AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
+
+  if (m_processor)
+  {
+    if (bEnable)
+      return m_processor->UnregisterClient(this);
+    else
+      return m_processor->RegisterClient(this);
+  }
+
+  return false;
 }
 
 bool CCECClient::PollDevice(const cec_logical_address iAddress)
index d9981b9368d37e8d53c86510bca6fb5a1337eaf4..7c2e08a0ac537ef7c3dca64513058c15c5698f47 100644 (file)
@@ -56,8 +56,6 @@ CCECProcessor::CCECProcessor(CLibCEC *libcec) :
     m_bInitialised(false),
     m_communication(NULL),
     m_libcec(libcec),
-    m_bMonitor(false),
-    m_iPreviousAckMask(0),
     m_iStandardLineTimeout(3),
     m_iRetryLineTimeout(3),
     m_iLastTransmission(0)
@@ -120,8 +118,6 @@ void CCECProcessor::ResetMembers(void)
   }
 
   // reset the other members to the initial state
-  m_bMonitor = false;
-  m_iPreviousAckMask = 0;
   m_iStandardLineTimeout = 3;
   m_iRetryLineTimeout = 3;
   m_iLastTransmission = 0;
@@ -302,26 +298,6 @@ void CCECProcessor::LogOutput(const cec_command &data)
   m_libcec->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
 }
 
-bool CCECProcessor::SwitchMonitoring(bool bEnable)
-{
-  m_libcec->AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
-
-  {
-    CLockObject lock(m_mutex);
-    // switch to monitoring mode, which will stop processing of incoming messages
-    m_bMonitor = bEnable;
-    // and store the current ackmask
-    m_iPreviousAckMask = m_communication->GetAckMask();
-  }
-
-  // set the mask to 0 when enabling monitor mode
-  if (bEnable)
-    return SetAckMask(0);
-  // and restore the previous mask otherwise
-  else
-    return SetAckMask(m_iPreviousAckMask);
-}
-
 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
 {
   // try to find the primary device
@@ -461,15 +437,11 @@ void CCECProcessor::ProcessCommand(const cec_command &command)
     dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
   m_libcec->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
 
-  // if we're not in monitor mode
-  if (!m_bMonitor)
-  {
-    // find the initiator
-    CCECBusDevice *device = m_busDevices->At(command.initiator);
-    // and "handle" the command
-    if (device)
-      device->HandleCommand(command);
-  }
+  // find the initiator
+  CCECBusDevice *device = m_busDevices->At(command.initiator);
+
+  if (device)
+    device->HandleCommand(command);
 }
 
 bool CCECProcessor::IsPresentDevice(cec_logical_address address)
@@ -725,10 +697,10 @@ bool CCECProcessor::RegisterClient(CCECClient *client)
   return bReturn;
 }
 
-void CCECProcessor::UnregisterClient(CCECClient *client)
+bool CCECProcessor::UnregisterClient(CCECClient *client)
 {
   if (!client)
-    return;
+    return false;
 
   if (client->IsRegistered())
     m_libcec->AddLog(CEC_LOG_NOTICE, "unregistering client: %s", client->GetConnectionInfo().c_str());
@@ -755,7 +727,7 @@ void CCECProcessor::UnregisterClient(CCECClient *client)
   }
 
   // set the new ackmask
-  SetAckMask(GetLogicalAddresses().AckMask());
+  return SetAckMask(GetLogicalAddresses().AckMask());
 }
 
 void CCECProcessor::UnregisterClients(void)
index e859ab0506917edd0b8923f48fff2b5c6f11e73a..5f496d2631558506045e645ecf450e4ba37c5995 100644 (file)
@@ -64,14 +64,13 @@ namespace CEC
       void Close(void);
 
       bool RegisterClient(CCECClient *client);
-      void UnregisterClient(CCECClient *client);
+      bool UnregisterClient(CCECClient *client);
       void UnregisterClients(void);
       CCECClient *GetPrimaryClient(void);
       CCECClient *GetClient(const cec_logical_address address);
 
       bool                  OnCommandReceived(const cec_command &command);
 
-      bool                  IsMonitoring(void) const { return m_bMonitor; }
       CCECBusDevice *       GetDevice(cec_logical_address address) const;
       CCECAudioSystem *     GetAudioSystem(void) const;
       CCECPlaybackDevice *  GetPlaybackDevice(cec_logical_address address) const;
@@ -99,7 +98,6 @@ namespace CEC
 
       bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
       bool ActivateSource(uint16_t iStreamPath);
-      bool SwitchMonitoring(bool bEnable);
       bool PollDevice(cec_logical_address iAddress);
       void SetStandardLineTimeout(uint8_t iTimeout);
       uint8_t GetStandardLineTimeout(void);
@@ -148,8 +146,6 @@ namespace CEC
       PLATFORM::CMutex                            m_mutex;
       IAdapterCommunication *                     m_communication;
       CLibCEC*                                    m_libcec;
-      bool                                        m_bMonitor;
-      uint16_t                                    m_iPreviousAckMask;
       uint8_t                                     m_iStandardLineTimeout;
       uint8_t                                     m_iRetryLineTimeout;
       uint64_t                                    m_iLastTransmission;