cec: retry 'activate source' every 10 seconds if it failed
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 376cfc42bfb5a5d6b21a18e617908b212a8c6e46..3627c4e38a1e5421f4fb8fc93730a30d34b13f39 100644 (file)
@@ -37,6 +37,7 @@
 #include "../CECClient.h"
 #include "../CECProcessor.h"
 #include "../LibCEC.h"
+#include "../CECTypeUtils.h"
 #include "../platform/util/util.h"
 
 using namespace CEC;
@@ -44,7 +45,7 @@ using namespace std;
 using namespace PLATFORM;
 
 #define LIB_CEC     m_busDevice->GetProcessor()->GetLib()
-#define ToString(p) LIB_CEC->ToString(p)
+#define ToString(p) CCECTypeUtils::ToString(p)
 
 CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
     m_busDevice(busDevice),
@@ -55,7 +56,8 @@ CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
     m_bHandlerInited(false),
     m_bOPTSendDeckStatusUpdateOnActiveSource(false),
     m_vendorId(CEC_VENDOR_UNKNOWN),
-    m_waitForResponse(new CWaitForResponse)
+    m_waitForResponse(new CWaitForResponse),
+    m_bActiveSourcePending(false)
 {
 }
 
@@ -1055,16 +1057,27 @@ bool CCECCommandHandler::ActivateSource(void)
   if (m_busDevice->IsActiveSource() &&
     m_busDevice->IsHandledByLibCEC())
   {
+    {
+      CLockObject lock(m_mutex);
+      m_bActiveSourcePending = false;
+    }
+
     m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON);
     m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED);
 
-    m_busDevice->TransmitImageViewOn();
-    m_busDevice->TransmitActiveSource();
-    m_busDevice->TransmitMenuState(CECDEVICE_TV);
+    if (!m_busDevice->TransmitImageViewOn() ||
+        !m_busDevice->TransmitActiveSource() ||
+        !m_busDevice->TransmitMenuState(CECDEVICE_TV))
+    {
+      CLockObject lock(m_mutex);
+      m_bActiveSourcePending = true;
+      return false;
+    }
 
     CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice();
     if (playbackDevice && SendDeckStatusUpdateOnActiveSource())
       playbackDevice->TransmitDeckStatus(CECDEVICE_TV);
+
     m_bHandlerInited = true;
   }
   return true;
@@ -1074,3 +1087,9 @@ void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
 {
   m_waitForResponse->Received(opcode);
 }
+
+bool CCECCommandHandler::ActiveSourcePending(void)
+{
+  CLockObject lock(m_mutex);
+  return m_bActiveSourcePending;
+}