cec: add GetDevicePhysicalAddress()/cec_get_device_physical_address()
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 84b9bafcbc451ba5e4881cd80f2e66107d5234bd..46e3419d484c38ddc2a8aea86b9cd99c5157ed92 100644 (file)
@@ -118,14 +118,6 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
 CCECProcessor::~CCECProcessor(void)
 {
   m_bStarted = false;
-  StopThread(false);
-
-  if (m_busScan)
-  {
-    m_busScan->StopThread();
-    delete m_busScan;
-  }
-
   m_startCondition.Broadcast();
   StopThread();
 
@@ -268,7 +260,9 @@ void *CCECProcessor::Process(void)
   }
   else
   {
-    m_busDevices[m_logicalAddresses.primary]->TransmitPhysicalAddress();
+    m_busDevices[CECDEVICE_TV]->GetVendorId();
+    m_busDevices[m_logicalAddresses.primary]->TransmitVendorID(CECDEVICE_TV, false);
+
     CLockObject lock(&m_mutex);
     m_bStarted = true;
     m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
@@ -302,6 +296,13 @@ void *CCECProcessor::Process(void)
     m_controller->CheckKeypressTimeout();
   }
 
+  if (m_busScan)
+  {
+    m_busScan->StopThread();
+    delete m_busScan;
+    m_busScan = NULL;
+  }
+
   if (m_communication)
     m_communication->Close();
 
@@ -329,8 +330,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
     }
   }
 
-  bReturn = m_busDevices[CECDEVICE_TV]->PowerOn() &&
-      m_busDevices[addr]->TransmitActiveSource() &&
+  bReturn = m_busDevices[addr]->TransmitActiveSource() &&
       SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false));
 
   if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
@@ -354,11 +354,6 @@ void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
   m_iRetryLineTimeout = iTimeout;
 }
 
-bool CCECProcessor::SetActiveSource(cec_logical_address iAddress)
-{
-  return SetStreamPath(m_busDevices[iAddress]->GetPhysicalAddress(false));
-}
-
 bool CCECProcessor::SetActiveView(void)
 {
   return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
@@ -525,7 +520,11 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
   {
     for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
       if (m_logicalAddresses[iPtr])
+      {
+        m_busDevices[iPtr]->SetInactiveDevice();
         m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
+        m_busDevices[iPtr]->TransmitPhysicalAddress();
+      }
     return SetActiveView();
   }
   return false;
@@ -541,7 +540,7 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable)
     CLockObject lock(&m_mutex);
     m_bMonitor = bEnable;
 
-    if (bEnable)
+    if (!bEnable)
     {
       if (!m_busScan)
       {
@@ -671,6 +670,13 @@ uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
   return false;
 }
 
+uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
+{
+  if (m_busDevices[iAddress])
+    return m_busDevices[iAddress]->GetPhysicalAddress(false);
+  return false;
+}
+
 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
 {
   if (m_busDevices[iAddress])
@@ -1298,9 +1304,15 @@ const char *CCECProcessor::ToString(const cec_vendor_id vendor)
 void *CCECBusScan::Process(void)
 {
   CCECBusDevice *device(NULL);
+  uint8_t iCounter(0);
 
   while (!IsStopped())
   {
+    if (++iCounter < 30)
+    {
+      Sleep(1000);
+      continue;
+    }
     for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
     {
       device = m_processor->m_busDevices[iPtr];