From 7c63a480cbe63c5c6725b9558ae21acbe427ccc2 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Tue, 29 Nov 2011 00:06:37 +0100 Subject: [PATCH] cec: perform the cec bus scan in another thread --- src/lib/CECProcessor.cpp | 55 +++++++++++++++++++++++++--------------- src/lib/CECProcessor.h | 12 +++++++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 0b834bf..b8d6d2b 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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; +} diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index c6e7b75..8e5349a 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -134,5 +134,17 @@ namespace CEC bool m_bMonitor; CecBuffer 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; }; }; -- 2.34.1