X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FCECCommandHandler.h;h=2943ba39b3a17059491bc098a3414a3be18c8182;hb=24dd566c2a75900a5add19d9b5965ab04f7d6fd4;hp=a1b1f96fb90e2c16ff5c57f711d6af7703d8028a;hpb=80726797815c6dd13604818f41511cf3ffa139ee;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index a1b1f96..2943ba3 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,83 @@ 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); + for (std::map::iterator it = m_waitingFor.begin(); it != m_waitingFor.end(); it++) + { + it->second->Broadcast(); + delete it->second; + } + 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: @@ -136,12 +214,8 @@ namespace CEC int32_t m_iTransmitWait; int8_t m_iTransmitRetries; bool m_bHandlerInited; - cec_opcode m_expectedResponse; - cec_opcode m_lastCommandSent; bool m_bOPTSendDeckStatusUpdateOnActiveSource; cec_vendor_id m_vendorId; - PLATFORM::CMutex m_receiveMutex; - PLATFORM::CCondition m_condition; - volatile bool m_bRcvSignal; + CWaitForResponse *m_waitForResponse; }; };