cec: fixed possible crash when command handler were switched while it was being used
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
index bc302aa8092bad94ee81de56682d9a48b130130a..c9fd65d3a544a762ed0060ff2db1c810f77f82d9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the libCEC(R) library.
  *
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
  * libCEC(R) is an original work, containing original code.
  *
  * libCEC(R) is a trademark of Pulse-Eight Limited.
@@ -34,8 +34,6 @@
 #include "../devices/CECBusDevice.h"
 #include "../devices/CECPlaybackDevice.h"
 #include "../CECProcessor.h"
-#include "../platform/timeutils.h"
-#include "../platform/threads.h"
 
 using namespace CEC;
 
@@ -50,15 +48,15 @@ using namespace CEC;
 
 CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
     CCECCommandHandler(busDevice),
-    m_bAwaitingReceiveFailed(false),
     m_bSLEnabled(false),
     m_bPowerStateReset(false)
 {
+  m_vendorId = CEC_VENDOR_LG;
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
 
   /* imitate LG devices */
-  if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
-    primary->SetVendorId(CEC_VENDOR_LG, false);
+  if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
+    primary->SetVendorId(CEC_VENDOR_LG);
   SetLGDeckStatus();
 
   /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */
@@ -72,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)
@@ -105,6 +85,14 @@ bool CSLCommandHandler::InitHandler(void)
   return true;
 }
 
+bool CSLCommandHandler::ActivateSource(void)
+{
+  CCECBusDevice *primary = m_processor->GetPrimaryDevice();
+  primary->SetActiveSource();
+  primary->TransmitActiveSource();
+  return true;
+}
+
 bool CSLCommandHandler::HandleActiveSource(const cec_command &command)
 {
   if (command.parameters.size == 2)
@@ -132,7 +120,7 @@ bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command)
 
 bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
 {
-  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)