cec: check if the processor thread is marked as initialised, not if the thread is...
[deb_libcec.git] / src / lib / CECProcessor.cpp
index d9981b9368d37e8d53c86510bca6fb5a1337eaf4..e90d5cb59038a62f8917bbb8cab61f52e24bc43e 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)
@@ -88,9 +86,6 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = CEC_SERIA
     }
   }
 
-  // mark as initialised
-  SetCECInitialised(true);
-
   return true;
 }
 
@@ -120,8 +115,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;
@@ -160,6 +153,9 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
 
   m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened");
 
+  // mark as initialised
+  SetCECInitialised(true);
+
   return bReturn;
 }
 
@@ -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)
@@ -643,8 +615,11 @@ CCECTuner *CCECProcessor::GetTuner(cec_logical_address address) const
 
 bool CCECProcessor::RegisterClient(CCECClient *client)
 {
-  if (!client || !IsRunning())
+  if (!client || !CECInitialised())
+  {
+    m_libcec->AddLog(CEC_LOG_ERROR, "failed to register a new CEC client: CEC processor is not initialised");
     return false;
+  }
 
   // unregister the client first if it's already been marked as registered
   if (client->IsRegistered())
@@ -725,10 +700,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 +730,7 @@ void CCECProcessor::UnregisterClient(CCECClient *client)
   }
 
   // set the new ackmask
-  SetAckMask(GetLogicalAddresses().AckMask());
+  return SetAckMask(GetLogicalAddresses().AckMask());
 }
 
 void CCECProcessor::UnregisterClients(void)