cec: moved SetVendorId(const cec_datapacket &packet) to CCECCommandHandler
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index 665d7fdc893bccc5591887908c80c8d909be3b77..a7ec1ec98e5e596d84132999c71dcc26289975e2 100644 (file)
@@ -42,6 +42,7 @@ using namespace CEC;
 
 CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
   m_iPhysicalAddress(iPhysicalAddress),
+  m_iStreamPath(0),
   m_iLogicalAddress(iLogicalAddress),
   m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
   m_processor(processor),
@@ -87,7 +88,8 @@ void CCECBusDevice::PollVendorId(void)
   CLockObject lock(&m_mutex);
   if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
       m_vendor.vendor == CEC_VENDOR_UNKNOWN &&
-      GetTimeMs() - m_iLastActive > 5000)
+      GetTimeMs() - m_iLastActive > 5000 &&
+      !m_processor->IsMonitoring())
   {
     m_iLastActive = GetTimeMs();
 
@@ -254,7 +256,7 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
   }
 }
 
-void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
+void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
 {
   if (iNewAddress > 0)
   {
@@ -266,30 +268,27 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddres
   }
 }
 
-void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
+void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
 {
-  if (m_powerStatus != powerStatus)
+  if (iNewAddress > 0)
   {
     CStdString strLog;
-    strLog.Format("device %d power status changed from %2x to %2x", m_iLogicalAddress, m_powerStatus, powerStatus);
-    m_processor->AddLog(CEC_LOG_DEBUG, strLog);
-    m_powerStatus = powerStatus;
+    strLog.Format(">> %i stream path from %04x to %04x", m_iLogicalAddress, iOldAddress, iNewAddress);
+    AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+    m_iStreamPath = iNewAddress;
   }
 }
 
-void CCECBusDevice::SetVendorId(const cec_datapacket &data)
+void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
 {
-  if (data.size < 3)
+  if (m_powerStatus != powerStatus)
   {
-    AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
-    return;
+    CStdString strLog;
+    strLog.Format("device %d power status changed from %2x to %2x", m_iLogicalAddress, m_powerStatus, powerStatus);
+    m_processor->AddLog(CEC_LOG_DEBUG, strLog);
+    m_powerStatus = powerStatus;
   }
-
-  uint64_t iVendorId = ((uint64_t)data[0] << 3) +
-                       ((uint64_t)data[1] << 2) +
-                        (uint64_t)data[2];
-
-  SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0);
 }
 
 void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 */)
@@ -340,7 +339,7 @@ void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0
 bool CCECBusDevice::TransmitActiveSource(void)
 {
   CStdString strLog;
-  strLog.Format("<< %x -> broadcast: active source", m_iLogicalAddress);
+  strLog.Format("<< %x -> broadcast: active source (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
   AddLog(CEC_LOG_NOTICE, strLog);
 
   cec_command command;
@@ -354,7 +353,7 @@ bool CCECBusDevice::TransmitActiveSource(void)
 bool CCECBusDevice::TransmitActiveView(void)
 {
   CStdString strLog;
-  strLog.Format("<< %x -> broadcast: active view", m_iLogicalAddress);
+  strLog.Format("<< %x -> broadcast: active view (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
   AddLog(CEC_LOG_NOTICE, strLog);
 
   cec_command command;
@@ -403,7 +402,7 @@ bool CCECBusDevice::TransmitDeckStatus(cec_logical_address dest)
   strLog.Format("<< %x -> %x: deck status feature abort", m_iLogicalAddress, dest);
   AddLog(CEC_LOG_NOTICE, strLog);
 
-  m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+  m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DECK_STATUS);
   return false;
 }
 
@@ -481,7 +480,7 @@ bool CCECBusDevice::TransmitPhysicalAddress(void)
   cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
   command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
   command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
-  command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE));
+  command.parameters.push_back((uint8_t) (m_type));
 
   return m_processor->Transmit(command);
 }