cec: fixed 'unsupported command' marking in CCECBusDevice
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index 59dcb4662d40ba9d813973e8713546a04325f242..a0d612ed5daa8178740a58475d2ff8b415da3170 100644 (file)
@@ -117,11 +117,20 @@ bool CCECBusDevice::PowerOn(void)
   GetVendorId(); // ensure that we got the vendor id, because the implementations vary per vendor
 
   MarkBusy();
-  CLibCEC::AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
-  if (m_handler->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress))
+  cec_power_status currentStatus = GetPowerStatus(false);
+  if (currentStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON &&
+    currentStatus != CEC_POWER_STATUS_ON)
   {
-    SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
-    bReturn = true;
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+    if (m_handler->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress))
+    {
+      SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
+      bReturn = true;
+    }
+  }
+  else
+  {
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(currentStatus));
   }
 
   MarkReady();
@@ -141,12 +150,12 @@ bool CCECBusDevice::Standby(void)
 //@{
 cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
     bRequestUpdate = bIsPresent &&
-                       (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN);
+        (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN);
   }
 
   if (bRequestUpdate)
@@ -160,7 +169,8 @@ bool CCECBusDevice::RequestCecVersion(void)
 {
   bool bReturn(false);
 
-  if (!MyLogicalAddressContains(m_iLogicalAddress))
+  if (!MyLogicalAddressContains(m_iLogicalAddress) &&
+      !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION))
   {
     MarkBusy();
     CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
@@ -178,7 +188,7 @@ const char* CCECBusDevice::GetLogicalAddressName(void) const
 
 cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
@@ -226,7 +236,7 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
 
 CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
@@ -259,7 +269,7 @@ bool CCECBusDevice::RequestOSDName(void)
 
 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
@@ -290,7 +300,7 @@ bool CCECBusDevice::RequestPhysicalAddress(void)
 
 cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
@@ -325,7 +335,7 @@ bool CCECBusDevice::RequestPowerStatus(void)
 
 cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */)
 {
-       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
+  bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
@@ -534,6 +544,8 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
   switch (newStatus)
   {
   case CEC_DEVICE_STATUS_UNKNOWN:
+    if (m_deviceStatus != newStatus)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'unknown'", ToString(m_iLogicalAddress));
     m_iStreamPath      = 0;
     m_powerStatus      = CEC_POWER_STATUS_UNKNOWN;
     m_vendor           = CEC_VENDOR_UNKNOWN;
@@ -544,6 +556,8 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
     m_deviceStatus     = newStatus;
     break;
   case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
+    if (m_deviceStatus != newStatus)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'handled by libCEC'", ToString(m_iLogicalAddress));
     m_iStreamPath      = 0;
     m_powerStatus      = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON;
     m_vendor           = CEC_VENDOR_UNKNOWN;
@@ -554,7 +568,13 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
     m_deviceStatus     = newStatus;
     break;
   case CEC_DEVICE_STATUS_PRESENT:
+    if (m_deviceStatus != newStatus)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'present'", ToString(m_iLogicalAddress));
+    m_deviceStatus = newStatus;
+    break;
   case CEC_DEVICE_STATUS_NOT_PRESENT:
+    if (m_deviceStatus != newStatus)
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'not present'", ToString(m_iLogicalAddress));
     m_deviceStatus = newStatus;
     break;
   }
@@ -792,7 +812,7 @@ bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
 {
   bool bReturn(false);
-  if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING))
+  if (!m_processor->m_busDevices[dest]->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING))
   {
     CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
     MarkBusy();
@@ -914,11 +934,15 @@ bool CCECBusDevice::TransmitKeyRelease(bool bWait /* = true */)
 
 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode) const
 {
-  return m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end();
+  bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end());
+  if (bUnsupported)
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
+  return bUnsupported;
 }
 
 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode)
 {
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
   m_unsupportedFeatures.insert(opcode);
 }