From: Lars Op den Kamp Date: Thu, 2 Feb 2012 23:46:06 +0000 (+0100) Subject: cec: fixed possible crash when command handler were switched while it was being used X-Git-Tag: upstream/2.2.0~1^2~36^2~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ef5836621411aa39169f9c8c2fc8a7f3038dbb15;p=deb_libcec.git cec: fixed possible crash when command handler were switched while it was being used --- diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index a97ded8..01bf303 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -247,7 +247,7 @@ bool CUSBCECAdapterCommunication::Write(CCECAdapterMessage *data) CLockObject lock(data->mutex); data->state = ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT; m_outBuffer.Push(data); - data->condition.Wait(data->mutex, data->transmit_timeout); + data->condition.Wait(data->mutex); if ((data->expectControllerAck && data->state != ADAPTER_MESSAGE_STATE_SENT_ACKED) || (!data->expectControllerAck && data->state != ADAPTER_MESSAGE_STATE_SENT)) diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 3577518..2aa29c1 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -834,16 +834,19 @@ bool CCECBusDevice::ActivateSource(void) return m_handler->ActivateSource(); } -void CCECBusDevice::HandlePoll(cec_logical_address destination) +void CCECBusDevice::HandlePoll(cec_logical_address iDestination) { - CLockObject lock(m_handlerMutex); - m_handler->HandlePoll(m_iLogicalAddress, destination); + CLockObject lock(m_mutex); + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(m_iLogicalAddress), m_iLogicalAddress, ToString(iDestination), iDestination); + m_bAwaitingReceiveFailed = true; } bool CCECBusDevice::HandleReceiveFailed(void) { CLockObject lock(m_handlerMutex); - return m_handler->HandleReceiveFailed(); + bool bReturn = m_bAwaitingReceiveFailed; + m_bAwaitingReceiveFailed = false; + return bReturn; } //@} diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 0415ad1..79ae987 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -139,5 +139,6 @@ namespace CEC std::set m_unsupportedFeatures; PLATFORM::CMutex m_mutex; PLATFORM::CMutex m_handlerMutex; + bool m_bAwaitingReceiveFailed; }; }; diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 27e8009..7be147d 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -714,17 +714,6 @@ void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16 } } -void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) -{ - CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", m_processor->ToString(iInitiator), iInitiator, m_processor->ToString(iDestination), iDestination); -} - -bool CCECCommandHandler::HandleReceiveFailed(void) -{ - /* default = error */ - return true; -} - bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) { cec_command command; diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 32c0d54..409591b 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -50,8 +50,6 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); virtual cec_vendor_id GetVendorId(void) { return m_vendorId; }; virtual void SetVendorId(cec_vendor_id vendorId) { m_vendorId = vendorId; } - virtual void HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination); - virtual bool HandleReceiveFailed(void); static bool HasSpecificHandler(cec_vendor_id vendorId) { return vendorId == CEC_VENDOR_LG || vendorId == CEC_VENDOR_SAMSUNG || vendorId == CEC_VENDOR_PANASONIC;} virtual bool InitHandler(void) { return true; } diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 647b053..c9fd65d 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -48,7 +48,6 @@ using namespace CEC; CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : CCECCommandHandler(busDevice), - m_bAwaitingReceiveFailed(false), m_bSLEnabled(false), m_bPowerStateReset(false) { @@ -56,7 +55,7 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : CCECBusDevice *primary = m_processor->GetPrimaryDevice(); /* imitate LG devices */ - if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) + if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) primary->SetVendorId(CEC_VENDOR_LG); SetLGDeckStatus(); @@ -71,24 +70,6 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : m_busDevice->SetMenuLanguage(lang); } - -void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) -{ - CCECCommandHandler::HandlePoll(iInitiator, iDestination); - m_bAwaitingReceiveFailed = true; -} - -bool CSLCommandHandler::HandleReceiveFailed(void) -{ - if (m_bAwaitingReceiveFailed) - { - m_bAwaitingReceiveFailed = false; - return false; - } - - return true; -} - bool CSLCommandHandler::InitHandler(void) { if (m_bHandlerInited) diff --git a/src/lib/implementations/SLCommandHandler.h b/src/lib/implementations/SLCommandHandler.h index 4095b0e..dae4266 100644 --- a/src/lib/implementations/SLCommandHandler.h +++ b/src/lib/implementations/SLCommandHandler.h @@ -41,9 +41,6 @@ namespace CEC CSLCommandHandler(CCECBusDevice *busDevice); virtual ~CSLCommandHandler(void) {}; - virtual void HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination); - virtual bool HandleReceiveFailed(void); - virtual bool InitHandler(void); virtual bool ActivateSource(void); @@ -64,7 +61,6 @@ namespace CEC virtual void SetLGDeckStatus(void); - bool m_bAwaitingReceiveFailed; bool m_bSLEnabled; bool m_bPowerStateReset; };