cec: request the active source if it's unknown in CCECProcessor::GetActiveSource()
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 26 Apr 2012 12:08:16 +0000 (14:08 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 26 Apr 2012 12:10:05 +0000 (14:10 +0200)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/testclient/main.cpp

index 0e85dab388264f9317ebcaac2fc6b10f75aafcb4..a1603e8243a26b92cbed4d2080639eaa044fdf28 100644 (file)
@@ -911,7 +911,7 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
   return CEC_POWER_STATUS_UNKNOWN;
 }
 
-cec_logical_address CCECProcessor::GetActiveSource(void)
+cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */)
 {
   for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
   {
@@ -919,6 +919,15 @@ cec_logical_address CCECProcessor::GetActiveSource(void)
       return (cec_logical_address)iPtr;
   }
 
+  if (bRequestActiveSource && m_configuration.logicalAddresses.primary != CECDEVICE_UNKNOWN)
+  {
+    CCECBusDevice *primary = m_busDevices[m_configuration.logicalAddresses.primary];
+    if (primary)
+      primary->RequestActiveSource();
+
+    return GetActiveSource(false);
+  }
+
   return CECDEVICE_UNKNOWN;
 }
 
index acefd8b0a4840c1c1eab17ae8f51917853f00af9..9b7a6e3cd463c44a93e6822087b2ed824c5c44a4 100644 (file)
@@ -127,7 +127,7 @@ namespace CEC
       bool                  IsPresentDeviceType(cec_device_type type);
       uint16_t              GetPhysicalAddress(void) const;
       uint64_t              GetLastTransmission(void) const { return m_iLastTransmission; }
-      cec_logical_address   GetActiveSource(void);
+      cec_logical_address   GetActiveSource(bool bRequestActiveSource = true);
       bool                  IsActiveSource(cec_logical_address iAddress);
       bool                  IsInitialised(void);
       bool                  SetStreamPath(uint16_t iPhysicalAddress);
index 757204cb3ed31ed3b3fb4aae727e2c8c295ac68c..0cd28d56ae0aa47fe6bc0c7b0b5327d18f50dc16 100644 (file)
@@ -170,6 +170,21 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
   return m_cecVersion;
 }
 
+bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse /* = true */)
+{
+  bool bReturn(false);
+
+  if (MyLogicalAddressContains(m_iLogicalAddress))
+  {
+    MarkBusy();
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting active source");
+
+    bReturn = m_handler->TransmitRequestActiveSource(GetMyLogicalAddress(), bWaitForResponse);
+    MarkReady();
+  }
+  return bReturn;
+}
+
 bool CCECBusDevice::RequestCecVersion(bool bWaitForResponse /* = true */)
 {
   bool bReturn(false);
index f6e0d82d5cae176215e6da88d8fc05776e0e105e..f5868c124ce651febc87dd6d3a537b864c919786 100644 (file)
@@ -111,6 +111,8 @@ namespace CEC
     bool ReplaceHandler(bool bActivateSource = true);
     virtual bool TransmitPendingActiveSourceCommands(void);
 
+    virtual bool RequestActiveSource(bool bWaitForResponse = true);
+
   protected:
     void ResetDeviceStatus(void);
     void CheckVendorIdRequested(void);
index 5fa83ed80cdff3e6e34182f4afc49397567b4b44..82110bcec58bd667a32b89b9b6c65e5297b1d831 100644 (file)
@@ -773,6 +773,14 @@ bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, c
   return Transmit(command);
 }
 
+bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */)
+{
+  cec_command command;
+  cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE);
+
+  return Transmit(command, !bWaitForResponse);
+}
+
 bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
index 8a0182805290d25f543520798b7bb7d036608453..be1f6436ad8f64636c346c9a20a7966bdf13d0be 100644 (file)
@@ -132,6 +132,7 @@ namespace CEC
     virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
     virtual bool TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination);
     virtual bool TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination);
+    virtual bool TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse = true);
     virtual bool TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
     virtual bool TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
     virtual bool TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true);
index fe5d6476051d03f704745df5ce8c5549f035f70d..cb5903bcc8e7a9184acedf4be7a1fa1cb4ba45cf 100644 (file)
@@ -848,7 +848,7 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string & UNU
     }
 
     cec_logical_address activeSource = parser->GetActiveSource();
-    strLog.AppendFormat("currently active source: %s (%X)", parser->ToString(activeSource), (int)activeSource);
+    strLog.AppendFormat("currently active source: %s (%d)", parser->ToString(activeSource), (int)activeSource);
 
     PrintToStdOut(strLog);
     return true;