From: Lars Op den Kamp Date: Thu, 2 Feb 2012 20:06:21 +0000 (+0100) Subject: cec: don't replace handlers when not initialised, or the primary device's logical... X-Git-Tag: upstream/2.2.0~1^2~36^2~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0cfdeb5a137651058e393d70c18523f77c10b5a6;p=deb_libcec.git cec: don't replace handlers when not initialised, or the primary device's logical addres isn't known yet, which can lead to crashes. don't call handlers directly in CCECProcessor without holding a lock on them --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 20b63bd..c63bc57 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -162,6 +162,12 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint return bReturn; } +bool CCECProcessor::IsInitialised(void) +{ + CLockObject lock(m_mutex); + return m_bInitialised; +} + void CCECProcessor::SetInitialised(bool bSetTo /* = true */) { CLockObject lock(m_mutex); @@ -377,6 +383,8 @@ bool CCECProcessor::FindLogicalAddresses(void) void CCECProcessor::ReplaceHandlers(void) { + if (!IsInitialised()) + return; for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++) m_busDevices[iPtr]->ReplaceHandler(m_bInitialised); } @@ -1315,10 +1323,10 @@ bool CCECProcessor::PingAdapter(void) void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination) { - m_busDevices[initiator]->GetHandler()->HandlePoll(initiator, destination); + m_busDevices[initiator]->HandlePoll(destination); } bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator) { - return !m_busDevices[initiator]->GetHandler()->HandleReceiveFailed(); + return !m_busDevices[initiator]->HandleReceiveFailed(); } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 3e98cc0..0d2446a 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -76,7 +76,7 @@ namespace CEC virtual uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } virtual cec_logical_address GetActiveSource(void); virtual bool IsActiveSource(cec_logical_address iAddress); - virtual bool IsInitialised(void) const { return m_bInitialised; } + virtual bool IsInitialised(void); virtual bool SetActiveView(void); virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 61af701..3577518 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -834,4 +834,16 @@ bool CCECBusDevice::ActivateSource(void) return m_handler->ActivateSource(); } +void CCECBusDevice::HandlePoll(cec_logical_address destination) +{ + CLockObject lock(m_handlerMutex); + m_handler->HandlePoll(m_iLogicalAddress, destination); +} + +bool CCECBusDevice::HandleReceiveFailed(void) +{ + CLockObject lock(m_handlerMutex); + return m_handler->HandleReceiveFailed(); +} + //@} diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index df7bd96..0415ad1 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -76,6 +76,8 @@ namespace CEC virtual bool IsActiveSource(void) const { return m_bActiveSource; } virtual bool IsUnsupportedFeature(cec_opcode opcode) const; virtual void SetUnsupportedFeature(cec_opcode opcode); + virtual void HandlePoll(cec_logical_address initiator); + virtual bool HandleReceiveFailed(void); virtual void SetInactiveSource(void); virtual void SetActiveSource(void);