cec: perform the cec bus scan in another thread
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 23:06:37 +0000 (00:06 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 23:06:37 +0000 (00:06 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index 0b834bf545fb8eee2387c9f3f130ddff9d1dc98b..b8d6d2bfb357b46538794e699449eeccd7327659 100644 (file)
@@ -53,7 +53,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm
     m_strDeviceName(strDeviceName),
     m_communication(serComm),
     m_controller(controller),
-    m_bMonitor(false)
+    m_bMonitor(false),
+    m_busScan(NULL)
 {
   m_logicalAddresses.Clear();
   m_logicalAddresses.Set(iLogicalAddress);
@@ -107,8 +108,15 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm
 
 CCECProcessor::~CCECProcessor(void)
 {
+  if (m_busScan)
+  {
+    m_busScan->StopThread();
+    delete m_busScan;
+  }
+
   m_startCondition.Broadcast();
   StopThread();
+
   m_communication = NULL;
   m_controller = NULL;
   for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
@@ -136,7 +144,8 @@ bool CCECProcessor::Start(void)
     if (SetAckMask(m_logicalAddresses.AckMask()) &&
         SetHDMIPort(m_iHDMIPort, true))
     {
-      ScanCECBus();
+      m_busScan = new CCECBusScan(this);
+      m_busScan->CreateThread(true);
       return true;
     }
   }
@@ -383,24 +392,6 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort, bool bForce /* = false */)
   return bReturn;
 }
 
-void CCECProcessor::ScanCECBus(void)
-{
-  CCECBusDevice *device(NULL);
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
-  {
-    device = m_busDevices[iPtr];
-    if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
-    {
-      device->GetPhysicalAddress();
-      Sleep(5);
-      device->GetCecVersion();
-      Sleep(5);
-      device->GetVendorId();
-      Sleep(5);
-    }
-  }
-}
-
 bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress)
 {
   for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
@@ -855,3 +846,27 @@ bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait
 {
   return m_busDevices[iDestination]->SendKeyRelease(bWait);
 }
+
+void *CCECBusScan::Process(void)
+{
+  CCECBusDevice *device(NULL);
+  for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++)
+  {
+    device = m_processor->m_busDevices[iPtr];
+    if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+    {
+      if (!IsStopped())
+        device->GetPhysicalAddress();
+      Sleep(5);
+
+      if (!IsStopped())
+        device->GetCecVersion();
+      Sleep(5);
+
+      if (!IsStopped())
+        device->GetVendorId();
+      Sleep(5);
+    }
+  }
+  return NULL;
+}
index c6e7b75e611b64075e3a876e036151c0a77f0f60..8e5349accccc86f97b3f51e98d985b0e6ee27787 100644 (file)
@@ -134,5 +134,17 @@ namespace CEC
       bool                   m_bMonitor;
       CecBuffer<cec_command> m_commandBuffer;
       cec_keypress           m_previousKey;
+      CThread *              m_busScan;
+  };
+
+  class CCECBusScan : public CThread
+  {
+  public:
+    CCECBusScan(CCECProcessor *processor) { m_processor = processor; }
+    virtual ~CCECBusScan(void) {}
+    virtual void *Process(void);
+
+  private:
+    CCECProcessor *m_processor;
   };
 };