X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FCECCommandHandler.h;h=4cfb81fbd1510d932777b4e9a10c17554ce3aa3a;hb=be54289b785d3318dd644223cacb9f281f3e2d3d;hp=ad65063ef1f8945dff985a03c701e715522d4309;hpb=1344fd1a7e86aa1bbc8b1e78eed6be8cd59c4b3b;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index ad65063..4cfb81f 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -33,6 +33,7 @@ #include "../../../include/cectypes.h" #include +#include #include "../platform/threads/mutex.h" #include "../platform/util/StdString.h" @@ -41,6 +42,78 @@ namespace CEC class CCECProcessor; class CCECBusDevice; + class CResponse + { + public: + CResponse(cec_opcode opcode) : + m_opcode(opcode){} + ~CResponse(void) + { + Broadcast(); + } + + bool Wait(uint32_t iTimeout) + { + return m_event.Wait(iTimeout); + } + + void Broadcast(void) + { + m_event.Broadcast(); + } + + private: + cec_opcode m_opcode; + PLATFORM::CEvent m_event; + }; + + class CWaitForResponse + { + public: + CWaitForResponse(void) {} + ~CWaitForResponse(void) + { + PLATFORM::CLockObject lock(m_mutex); + m_waitingFor.clear(); + } + + bool Wait(cec_opcode opcode, uint32_t iTimeout = 2000) + { + CResponse *response = GetEvent(opcode); + return response ? response->Wait(iTimeout) : false; + } + + void Received(cec_opcode opcode) + { + CResponse *response = GetEvent(opcode); + if (response) + response->Broadcast(); + } + + private: + CResponse *GetEvent(cec_opcode opcode) + { + CResponse *retVal(NULL); + { + PLATFORM::CLockObject lock(m_mutex); + std::map::iterator it = m_waitingFor.find(opcode); + if (it != m_waitingFor.end()) + { + retVal = it->second; + } + else + { + retVal = new CResponse(opcode); + m_waitingFor[opcode] = retVal; + } + return retVal; + } + } + + PLATFORM::CMutex m_mutex; + std::map m_waitingFor; + }; + class CCECCommandHandler { public: @@ -56,6 +129,7 @@ namespace CEC virtual bool ActivateSource(void); virtual uint8_t GetTransmitRetries(void) const { return m_iTransmitRetries; } + virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination); @@ -135,11 +209,8 @@ namespace CEC int32_t m_iTransmitWait; int8_t m_iTransmitRetries; bool m_bHandlerInited; - cec_opcode m_expectedResponse; bool m_bOPTSendDeckStatusUpdateOnActiveSource; cec_vendor_id m_vendorId; - PLATFORM::CMutex m_receiveMutex; - PLATFORM::CCondition m_condition; - volatile bool m_bRcvSignal; + CWaitForResponse *m_waitForResponse; }; };