cec: handle CEC_OPCODE_ACTIVE_SOURCE
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index c92908c8c3459436f930e093bdbe45cc79e03706..e9b0a79c2b86910dd1b5ab2a9a5b0c409deed68d 100644 (file)
@@ -33,6 +33,7 @@
 #include "CECCommandHandler.h"
 #include "../devices/CECBusDevice.h"
 #include "../devices/CECAudioSystem.h"
+#include "../devices/CECPlaybackDevice.h"
 #include "../CECProcessor.h"
 
 using namespace CEC;
@@ -63,6 +64,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
       break;
     case CEC_OPCODE_SET_MENU_LANGUAGE:
       HandleSetMenuLanguage(command);
+      /* pass to listeners */
       m_busDevice->GetProcessor()->AddCommand(command);
       break;
     case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
@@ -109,6 +111,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
       break;
     default:
       UnhandledCommand(command);
+      /* pass to listeners */
       m_busDevice->GetProcessor()->AddCommand(command);
       bHandled = false;
       break;
@@ -121,6 +124,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
     {
     case CEC_OPCODE_SET_MENU_LANGUAGE:
       HandleSetMenuLanguage(command);
+      /* pass to listeners */
       m_busDevice->GetProcessor()->AddCommand(command);
       break;
     case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
@@ -128,11 +132,9 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
       break;
     case CEC_OPCODE_SET_STREAM_PATH:
       HandleSetStreamPath(command);
-      m_busDevice->GetProcessor()->AddCommand(command);
       break;
     case CEC_OPCODE_ROUTING_CHANGE:
       HandleRoutingChange(command);
-      m_busDevice->GetProcessor()->AddCommand(command);
       break;
     case CEC_OPCODE_DEVICE_VENDOR_ID:
       HandleDeviceVendorId(command);
@@ -140,8 +142,19 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
     case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
       HandleDeviceVendorCommandWithId(command);
      break;
+    case CEC_OPCODE_STANDBY:
+      HandleStandby(command);
+      /* pass to listeners */
+      m_busDevice->GetProcessor()->AddCommand(command);
+     break;
+    case CEC_OPCODE_ACTIVE_SOURCE:
+      HandleActiveSource(command);
+      /* pass to listeners */
+      m_busDevice->GetProcessor()->AddCommand(command);
+      break;
     default:
       UnhandledCommand(command);
+      /* pass to listeners */
       m_busDevice->GetProcessor()->AddCommand(command);
       bHandled = false;
       break;
@@ -158,6 +171,17 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   return bHandled;
 }
 
+bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
+{
+  if (command.parameters.size == 2)
+  {
+    uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
+    return m_busDevice->GetProcessor()->SetStreamPath(iAddress);
+  }
+
+  return true;
+}
+
 bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
 {
   if (command.parameters.size == 1)
@@ -203,8 +227,8 @@ bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
 {
   CCECBusDevice *device = GetDevice(command.destination);
-  if (device)
-    return device->TransmitDeckStatus(command.initiator);
+  if (device && device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
+    return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
 
   return false;
 }
@@ -337,6 +361,14 @@ bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &comm
   return true;
 }
 
+bool CCECCommandHandler::HandleStandby(const cec_command &command)
+{
+  CCECBusDevice *device = GetDevice(command.initiator);
+  if (device)
+    device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
+  return true;
+}
+
 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
 {
   CCECBusDevice *device = GetDevice(command.destination);
@@ -406,18 +438,7 @@ CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
 
 CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
 {
-  CCECBusDevice *device = NULL;
-
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
-  {
-    if (m_busDevice->GetProcessor()->m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
-    {
-      device = m_busDevice->GetProcessor()->m_busDevices[iPtr];
-      break;
-    }
-  }
-
-  return device;
+  return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
 }
 
 void CCECCommandHandler::SetVendorId(const cec_command &command)
@@ -478,6 +499,45 @@ const char *CCECCommandHandler::ToString(const cec_logical_address address)
   }
 }
 
+const char *CCECCommandHandler::ToString(const cec_deck_info status)
+{
+  switch (status)
+  {
+  case CEC_DECK_INFO_PLAY:
+    return "play";
+  case CEC_DECK_INFO_RECORD:
+    return "record";
+  case CEC_DECK_INFO_PLAY_REVERSE:
+    return "play reverse";
+  case CEC_DECK_INFO_STILL:
+    return "still";
+  case CEC_DECK_INFO_SLOW:
+    return "slow";
+  case CEC_DECK_INFO_SLOW_REVERSE:
+    return "slow reverse";
+  case CEC_DECK_INFO_FAST_FORWARD:
+    return "fast forward";
+  case CEC_DECK_INFO_FAST_REVERSE:
+    return "fast reverse";
+  case CEC_DECK_INFO_NO_MEDIA:
+    return "no media";
+  case CEC_DECK_INFO_STOP:
+    return "stop";
+  case CEC_DECK_INFO_SKIP_FORWARD_WIND:
+    return "info skip forward wind";
+  case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
+    return "info skip reverse rewind";
+  case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
+    return "info index search forward";
+  case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
+    return "info index search reverse";
+  case CEC_DECK_INFO_OTHER_STATUS:
+    return "other";
+  default:
+    return "unknown";
+  }
+}
+
 const char *CCECCommandHandler::ToString(const cec_opcode opcode)
 {
   switch (opcode)