From: Lars Op den Kamp Date: Wed, 26 Oct 2011 23:32:31 +0000 (+0200) Subject: cec: poll for a vendor id when an active device is detected on a logical addres,... X-Git-Tag: upstream/2.2.0~1^2~211 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0ab58650411d2de14fbe707e7c01ea407655bd15;p=deb_libcec.git cec: poll for a vendor id when an active device is detected on a logical addres, the vendor id is unknown and it's been inactive for 5 seconds. --- diff --git a/src/lib/CECBusDevice.cpp b/src/lib/CECBusDevice.cpp index 9eb2ed6..b3d338f 100644 --- a/src/lib/CECBusDevice.cpp +++ b/src/lib/CECBusDevice.cpp @@ -35,6 +35,7 @@ #include "implementations/ANCommandHandler.h" #include "implementations/CECCommandHandler.h" #include "implementations/SLCommandHandler.h" +#include "platform/timeutils.h" using namespace CEC; @@ -43,7 +44,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi m_iLogicalAddress(iLogicalAddress), m_processor(processor), m_iVendorId(0), - m_iVendorClass(0) + m_iVendorClass(CEC_VENDOR_UNKNOWN), + m_iLastActive(0) { m_handler = new CCECCommandHandler(this); } @@ -70,35 +72,61 @@ void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) void CCECBusDevice::SetVendorId(uint16_t iVendorId, uint8_t iVendorClass /* = 0 */) { - delete m_handler; m_iVendorId = iVendorId; m_iVendorClass = iVendorClass; switch (iVendorId) { case CEC_VENDOR_SAMSUNG: - m_handler = new CANCommandHandler(this); + if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG) + { + delete m_handler; + m_handler = new CANCommandHandler(this); + } break; case CEC_VENDOR_LG: - m_handler = new CSLCommandHandler(this); + if (m_handler->GetVendorId() != CEC_VENDOR_LG) + { + delete m_handler; + m_handler = new CSLCommandHandler(this); + } break; default: - m_handler = new CCECCommandHandler(this); + if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN) + { + delete m_handler; + m_handler = new CCECCommandHandler(this); + } break; } CStdString strLog; - strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, CECVendorIdToString(iVendorId), iVendorId, iVendorClass); + strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass()); m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); } bool CCECBusDevice::HandleCommand(const cec_command &command) { CLockObject lock(&m_mutex); + m_iLastActive = GetTimeMs(); m_handler->HandleCommand(command); return true; } +void CCECBusDevice::PollVendorId(void) +{ + CLockObject lock(&m_mutex); + if (m_iLastActive > 0 && m_iVendorId == CEC_VENDOR_UNKNOWN && + GetTimeMs() - m_iLastActive > 5000) + { + m_iLastActive = GetTimeMs(); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), GetLogicalAddress(), CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); + m_processor->Transmit(command, false); + } +} + const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId) { switch (iVendorId) diff --git a/src/lib/CECBusDevice.h b/src/lib/CECBusDevice.h index fc42556..613c766 100644 --- a/src/lib/CECBusDevice.h +++ b/src/lib/CECBusDevice.h @@ -53,12 +53,20 @@ namespace CEC virtual uint16_t GetMyPhysicalAddress(void) const; virtual void SetVendorId(uint16_t iVendorId, uint8_t iVendorClass = 0); + virtual const char *GetVendorName(void) const { return CECVendorIdToString(m_iVendorId); } + virtual uint64_t GetVendorId(void) const { return m_iVendorId; } + virtual uint8_t GetVendorClass(void) const { return m_iVendorClass; } + + virtual uint64_t GetLastActive(void) const { return m_iLastActive; } + virtual bool HandleCommand(const cec_command &command); virtual void AddLog(cec_log_level level, const CStdString &strMessage); virtual CCECProcessor *GetProcessor() const { return m_processor; } virtual CCECCommandHandler *GetHandler(void) const { return m_handler; }; + virtual void PollVendorId(void); + static const char *CECVendorIdToString(const uint64_t iVendorId); protected: @@ -68,6 +76,7 @@ namespace CEC CCECCommandHandler *m_handler; uint64_t m_iVendorId; uint8_t m_iVendorClass; + uint64_t m_iLastActive; CMutex m_mutex; }; }; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index e9caaf0..648ec20 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -114,6 +114,9 @@ void *CCECProcessor::Process(void) m_controller->CheckKeypressTimeout(); + for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) + m_busDevices[iDevicePtr]->PollVendorId(); + if (!IsStopped()) Sleep(5); } diff --git a/src/lib/implementations/ANCommandHandler.h b/src/lib/implementations/ANCommandHandler.h index d1729aa..0207a63 100644 --- a/src/lib/implementations/ANCommandHandler.h +++ b/src/lib/implementations/ANCommandHandler.h @@ -43,6 +43,8 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); + virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_SAMSUNG; }; + protected: virtual bool HandleVendorRemoteButtonDown(const cec_command &command); }; diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 7129b40..7bb0fc2 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -44,6 +44,7 @@ namespace CEC virtual ~CCECCommandHandler(void) {}; virtual bool HandleCommand(const cec_command &command); + virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }; protected: bool HandleDeviceVendorCommandWithId(const cec_command &command); diff --git a/src/lib/implementations/SLCommandHandler.h b/src/lib/implementations/SLCommandHandler.h index e5edac5..76a9970 100644 --- a/src/lib/implementations/SLCommandHandler.h +++ b/src/lib/implementations/SLCommandHandler.h @@ -40,5 +40,6 @@ namespace CEC public: CSLCommandHandler(CCECBusDevice *busDevice); virtual ~CSLCommandHandler(void) {}; + virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_LG; }; }; };