cec: added GetDevicePowerStatus()/cec_get_device_power_status()
[deb_libcec.git] / src / lib / CECProcessor.cpp
index d5ee321ce90954fa485cd33a978dd610c55f003a..38eb5cdce7cd55631c2e44f7ef7487ae344b1e2a 100644 (file)
@@ -54,6 +54,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm
 
 CCECProcessor::~CCECProcessor(void)
 {
+  m_startCondition.Broadcast();
   StopThread();
   m_communication = NULL;
   m_controller = NULL;
@@ -63,6 +64,7 @@ CCECProcessor::~CCECProcessor(void)
 
 bool CCECProcessor::Start(void)
 {
+  CLockObject lock(&m_mutex);
   if (!m_communication || !m_communication->IsOpen())
   {
     m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
@@ -76,7 +78,14 @@ bool CCECProcessor::Start(void)
   }
 
   if (CreateThread())
+  {
+    if (!m_startCondition.Wait(&m_mutex))
+    {
+      m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+      return false;
+    }
     return true;
+  }
   else
     m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
 
@@ -85,7 +94,11 @@ bool CCECProcessor::Start(void)
 
 void *CCECProcessor::Process(void)
 {
-  m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+  {
+    CLockObject lock(&m_mutex);
+    m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+    m_startCondition.Signal();
+  }
 
   cec_command           command;
   CCECAdapterMessage    msg;
@@ -189,6 +202,27 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable)
     return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
 }
 
+cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
+{
+  return m_busDevices[iAddress]->GetCecVersion();
+}
+
+bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
+{
+  *language = m_busDevices[iAddress]->GetMenuLanguage();
+  return (strcmp(language->language, "???"));
+}
+
+uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
+{
+  return m_busDevices[iAddress]->GetVendorId();
+}
+
+cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
+{
+  return m_busDevices[iAddress]->GetPowerStatus();
+}
+
 bool CCECProcessor::Transmit(const cec_command &data)
 {
   bool bReturn(false);
@@ -210,17 +244,17 @@ bool CCECProcessor::Transmit(const cec_command &data)
         return bReturn;
       }
     }
-  }
 
-  if (data.ack_timeout > 0)
-  {
-    bool bError(false);
-    if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false)
-      m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
-  }
-  else
-  {
-    bReturn = true;
+    if (data.ack_timeout > 0)
+    {
+      bool bError(false);
+      if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false)
+        m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
+    }
+    else
+    {
+      bReturn = true;
+    }
   }
 
   return bReturn;