cec: don't poll for a vendor ID in monitoring mode
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 94348676b94600b020b27405667ddf7468140a98..33644d8709d3972bb0ed6082f04ede397428ac0e 100644 (file)
@@ -96,6 +96,12 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
     case CEC_OPCODE_GIVE_AUDIO_STATUS:
       HandleGiveAudioStatus(command);
       break;
+    case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
+      HandleGiveSystemAudioModeStatus(command);
+      break;
+    case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
+      HandleSetSystemAudioModeRequest(command);
+      break;
     default:
       UnhandledCommand(command);
       m_busDevice->GetProcessor()->AddCommand(command);
@@ -282,7 +288,7 @@ bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
 
     CCECBusDevice *device = GetDevice(command.initiator);
     if (device)
-      device->SetPhysicalAddress(iNewAddress, iOldAddress);
+      device->SetStreamPath(iNewAddress, iOldAddress);
   }
   return true;
 }
@@ -313,17 +319,33 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
     CStdString strLog;
     strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr);
     m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
-    if (streamaddr == m_busDevice->GetMyPhysicalAddress())
-    {
-      CCECBusDevice *device = GetDevice(command.destination);
-      if (device)
-        return device->TransmitActiveSource();
-      return false;
-    }
+    CCECBusDevice *device = GetDeviceByPhysicalAddress(streamaddr);
+    if (device)
+      return device->TransmitActiveSource();
+  }
+  return true;
+}
+
+bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
+{
+  if (command.parameters.size >= 1)
+  {
+    CCECBusDevice *device = GetDevice(command.destination);
+    if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+      return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
   }
   return true;
 }
 
+bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
+{
+  CCECBusDevice *device = GetDevice(command.destination);
+  if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+    return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
+
+  return false;
+}
+
 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 {
   if (command.parameters.size > 0)
@@ -364,3 +386,19 @@ CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
 
   return device;
 }
+
+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;
+}