cec: added bWait parameter to volume change methods.
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index d1cfdf005f75f4c3c2fb11a8e2ce7617918280a4..9debd5d9423cd3ad0fd47fc35400674c997b2278 100644 (file)
@@ -138,15 +138,19 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   case CEC_OPCODE_SET_OSD_NAME:
     HandleSetOSDName(command);
     break;
+  case CEC_OPCODE_IMAGE_VIEW_ON:
+    HandleImageViewOn(command);
+    break;
+  case CEC_OPCODE_TEXT_VIEW_ON:
+    HandleTextViewOn(command);
+    break;
   default:
     UnhandledCommand(command);
     bHandled = false;
     break;
   }
 
-  if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
-    m_busDevice->GetProcessor()->AddCommand(command);
-
+  m_busDevice->GetProcessor()->AddCommand(command);
   return bHandled;
 }
 
@@ -283,6 +287,24 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
   return false;
 }
 
+bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
+{
+  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  {
+    CCECBusDevice *device = GetDevice(command.destination);
+    if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+      return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
+  }
+
+  return false;
+}
+
+bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
+{
+  m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
+  return true;
+}
+
 bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
 {
   if (m_busDevice->MyLogicalAddressContains(command.destination))
@@ -317,11 +339,7 @@ bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
   if (command.parameters.size == 3)
   {
     uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-    cec_device_type type = (cec_device_type)command.parameters[2];
-
-    CCECBusDevice *device = GetDevice(command.initiator);
-    if (device && device->GetType() == type)
-      device->SetPhysicalAddress(iNewAddress);
+    SetPhysicalAddress(command.initiator, iNewAddress);
   }
   return true;
 }
@@ -369,13 +387,7 @@ bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
   if (command.parameters.size == 2)
   {
     uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-
-    CCECBusDevice *device = GetDevice(command.initiator);
-    if (device)
-    {
-      device->SetStreamPath(iNewAddress);
-      return true;
-    }
+    m_busDevice->GetProcessor()->SetStreamPath(iNewAddress);
   }
 
   return false;
@@ -475,16 +487,10 @@ bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command)
   return false;
 }
 
-bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
+bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
-  {
-    CCECBusDevice *device = GetDevice(command.destination);
-    if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
-      return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
-  }
-
-  return false;
+  m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
+  return true;
 }
 
 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
@@ -583,6 +589,22 @@ void CCECCommandHandler::SetVendorId(const cec_command &command)
     device->SetVendorId(iVendorId);
 }
 
+void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress)
+{
+  if (!m_busDevice->MyLogicalAddressContains(iAddress))
+  {
+    bool bOurAddress(m_busDevice->GetProcessor()->GetPhysicalAddress() == iNewAddress);
+    GetDevice(iAddress)->SetPhysicalAddress(iNewAddress);
+    if (bOurAddress)
+    {
+      /* another device reported the same physical address as ours
+       * since we don't have physical address detection yet, we'll just use the
+       * given address, increased by 0x100 for now */
+      m_busDevice->GetProcessor()->SetPhysicalAddress(iNewAddress + 0x100);
+    }
+  }
+}
+
 const char *CCECCommandHandler::ToString(const cec_menu_state state)
 {
   switch (state)