cec: added bWait parameter to volume change methods.
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index c273784462963e1ad2dbf1b1fd4701fdc0fc65fb..9debd5d9423cd3ad0fd47fc35400674c997b2278 100644 (file)
@@ -129,14 +129,28 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
     HandleReportPhysicalAddress(command);
     break;
+  case CEC_OPCODE_REPORT_AUDIO_STATUS:
+    HandleReportAudioStatus(command);
+    break;
+  case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
+    HandleSystemAudioStatus(command);
+    break;
+  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);
-    if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
-      m_busDevice->GetProcessor()->AddCommand(command);
     bHandled = false;
     break;
   }
 
+  m_busDevice->GetProcessor()->AddCommand(command);
   return bHandled;
 }
 
@@ -144,8 +158,6 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
 {
   if (command.parameters.size == 2)
   {
-    m_busDevice->GetProcessor()->AddCommand(command);
-
     uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
     return m_busDevice->GetProcessor()->SetStreamPath(iAddress);
   }
@@ -158,8 +170,6 @@ bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
   CCECBusDevice *device = GetDevice(command.destination);
   if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
   {
-    m_busDevice->GetProcessor()->AddCommand(command);
-
     ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
     return true;
   }
@@ -277,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))
@@ -287,24 +315,31 @@ bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
       if (device)
         return device->TransmitMenuState(command.initiator);
     }
-    else
+  }
+
+  return false;
+}
+
+bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command)
+{
+  if (command.parameters.size == 1)
+  {
+    CCECBusDevice *device = GetDevice(command.initiator);
+    if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
     {
-      m_busDevice->GetProcessor()->AddCommand(command);
+      ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]);
+      return true;
     }
   }
-
   return false;
 }
 
 bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
 {
-  if (command.parameters.size == 2)
+  if (command.parameters.size == 3)
   {
     uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-
-    CCECBusDevice *device = GetDevice(command.initiator);
-    if (device)
-      device->SetPhysicalAddress(iNewAddress);
+    SetPhysicalAddress(command.initiator, iNewAddress);
   }
   return true;
 }
@@ -352,11 +387,10 @@ 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->SetPhysicalAddress(iNewAddress);
+    m_busDevice->GetProcessor()->SetStreamPath(iNewAddress);
   }
+
+  return false;
 }
 
 bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
@@ -372,12 +406,31 @@ bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
         language.language[iPtr] = command.parameters[iPtr];
       language.language[3] = 0;
       device->SetMenuLanguage(language);
+      return true;
+    }
+  }
+  return false;
+}
+
+bool CCECCommandHandler::HandleSetOSDName(const cec_command &command)
+{
+  if (command.parameters.size > 0)
+  {
+    CCECBusDevice *device = GetDevice(command.initiator);
+    if (device)
+    {
+      char buf[1024];
+      for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
+        buf[iPtr] = (char)command.parameters[iPtr];
+      buf[command.parameters.size] = 0;
+
+      CStdString strName(buf);
+      device->SetOSDName(strName);
 
-      if (m_busDevice->MyLogicalAddressContains(command.destination))
-        m_busDevice->GetProcessor()->AddCommand(command);
+      return true;
     }
   }
-  return true;
+  return false;
 }
 
 bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
@@ -398,9 +451,8 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
             device->TransmitMenuState(command.initiator);
       }
     }
-    return false;
   }
-  return true;
+  return false;
 }
 
 bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
@@ -420,23 +472,27 @@ bool CCECCommandHandler::HandleStandby(const cec_command &command)
   if (device)
     device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
 
-  m_busDevice->GetProcessor()->AddCommand(command);
-
   return true;
 }
 
-bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
+bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  CCECBusDevice *device = GetDevice(command.initiator);
+  if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
   {
-    CCECBusDevice *device = GetDevice(command.destination);
-    if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
-      return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
+    ((CCECAudioSystem *)device)->SetSystemAudioMode(command);
+    return true;
   }
 
   return false;
 }
 
+bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
+{
+  m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
+  return true;
+}
+
 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 {
   if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
@@ -458,9 +514,10 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
       }
 
       m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
+      return true;
     }
   }
-  return true;
+  return false;
 }
 
 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
@@ -532,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)