cec: fixed possible crash when command handler were switched while it was being used
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Feb 2012 23:46:06 +0000 (00:46 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Feb 2012 23:46:06 +0000 (00:46 +0100)
src/lib/adapter/USBCECAdapterCommunication.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/lib/implementations/SLCommandHandler.cpp
src/lib/implementations/SLCommandHandler.h

index a97ded88707d1622f88be2c46e11d71352f7395d..01bf303b45f9a65b16601dd9be9f03aa3b46775c 100644 (file)
@@ -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))
index 3577518a95305bb7fa0574968d95e696841f3465..2aa29c1d31c2f09818a4833ab100280f2c71ece5 100644 (file)
@@ -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;
 }
 
 //@}
index 0415ad19e08817287b7829b4d5784f46c1c52a88..79ae987b654b1a72399cd0a2dd08b521bea8b3ce 100644 (file)
@@ -139,5 +139,6 @@ namespace CEC
     std::set<cec_opcode>  m_unsupportedFeatures;
     PLATFORM::CMutex      m_mutex;
     PLATFORM::CMutex      m_handlerMutex;
+    bool                  m_bAwaitingReceiveFailed;
   };
 };
index 27e80094cd27555de2a3f2858a41a80192397158..7be147d8ab49f1775b10b87538bb8d361cc7bcb2 100644 (file)
@@ -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;
index 32c0d5462881033d352def1ea402e6de233819bc..409591be7c95b4e37d4d01eb18250eb5a56da857 100644 (file)
@@ -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; }
index 647b0539edc3bb13bdfbb4cbe84958231f0352a6..c9fd65d3a544a762ed0060ff2db1c810f77f82d9 100644 (file)
@@ -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)
index 4095b0e700a62262ddebf94d9415c7692b071c43..dae426605758b1e03b7f42535db9be55b588dae9 100644 (file)
@@ -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;
   };