cec: check whether the initiator is valid in CCECProcessor::ParseCommand(). fixes...
[deb_libcec.git] / src / lib / CECProcessor.cpp
index dce52acdde66b35c7df84bd7407b570980960e81..cc8d86eb471e844345b8c4c0276536072ba4db63 100644 (file)
@@ -157,7 +157,8 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int
       m_busDevices[address]->m_bActiveSource = true;
     }
     m_busDevices[address]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
-    m_busDevices[address]->m_cecVersion = CEC_VERSION_1_3A;
+    m_busDevices[address]->m_cecVersion =  CEC_VERSION_1_3A;
+
     m_logicalAddresses.set(address);
 
     // TODO
@@ -319,6 +320,38 @@ bool CCECProcessor::SetActiveView(void)
   return SetActiveSource();
 }
 
+bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
+{
+  bool bReturn(false);
+
+  CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+  if (device)
+  {
+    ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
+    if (bSendUpdate)
+      ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+    bReturn = true;
+  }
+
+  return bReturn;
+}
+
+bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
+{
+  bool bReturn(false);
+
+  CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+  if (device)
+  {
+    ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
+    if (bSendUpdate)
+      ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+    bReturn = true;
+  }
+
+  return bReturn;
+}
+
 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
 {
   bool bReturn(false);
@@ -332,10 +365,7 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
     device->m_bActiveSource = true;
     device->m_powerStatus   = CEC_POWER_STATUS_ON;
 
-    if (m_logicalAddresses.isset(device->m_iLogicalAddress))
-      bReturn = device->TransmitActiveSource();
-    else
-      bReturn = true;
+    bReturn = true;
   }
 
   return bReturn;
@@ -378,6 +408,20 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
   return true;
 }
 
+bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
+{
+  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (m_logicalAddresses[iPtr])
+      m_busDevices[iPtr]->SetMenuState(state);
+  }
+
+  if (bSendUpdate)
+    m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
+
+  return true;
+}
+
 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
 {
   if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
@@ -408,7 +452,6 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
   return false;
 }
 
-
 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
 {
   CCECBusDevice *device = NULL;
@@ -425,6 +468,22 @@ CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddre
   return device;
 }
 
+CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
+{
+  CCECBusDevice *device = NULL;
+
+  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (m_busDevices[iPtr]->m_type == type)
+    {
+      device = m_busDevices[iPtr];
+      break;
+    }
+  }
+
+  return device;
+}
+
 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
 {
   return m_busDevices[iAddress]->GetCecVersion();
@@ -600,7 +659,7 @@ void CCECProcessor::ParseCommand(cec_command &command)
     dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
   m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
 
-  if (!m_bMonitor)
+  if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator < CECDEVICE_BROADCAST)
     m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
 }