cec: changed - libcec_configuration.bAutodetectAddress is now read-only, and will...
[deb_libcec.git] / src / lib / CECClient.cpp
index 013a7656209dc7ca9b76004291ba6a3f0f85c015..ae0b9f6e0c7408c5a73758c43db5d37cfc5cc08a 100644 (file)
@@ -33,6 +33,7 @@
 #include "CECClient.h"
 #include "CECProcessor.h"
 #include "LibCEC.h"
+#include "CECTypeUtils.h"
 #include "devices/CECPlaybackDevice.h"
 #include "devices/CECAudioSystem.h"
 #include "devices/CECTV.h"
@@ -41,7 +42,7 @@ using namespace CEC;
 using namespace PLATFORM;
 
 #define LIB_CEC     m_processor->GetLib()
-#define ToString(x) LIB_CEC->ToString(x)
+#define ToString(x) CCECTypeUtils::ToString(x)
 
 CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &configuration) :
     m_processor(processor),
@@ -194,15 +195,19 @@ void CCECClient::ResetPhysicalAddress(void)
 
 void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration)
 {
-  // try to autodetect the address
   bool bPASet(false);
-  if (m_processor->CECInitialised() && configuration.bAutodetectAddress == 1)
-    bPASet = AutodetectPhysicalAddress();
 
-  // try to use physical address setting
+  // override the physical address from configuration.iPhysicalAddress if it's set
   if (!bPASet && CLibCEC::IsValidPhysicalAddress(configuration.iPhysicalAddress))
     bPASet = SetPhysicalAddress(configuration.iPhysicalAddress);
 
+  // try to autodetect the address
+  if (!bPASet && m_processor->CECInitialised())
+  {
+    bPASet = AutodetectPhysicalAddress();
+    m_configuration.bAutodetectAddress = bPASet ? 1 : 0;
+  }
+
   // use the base device + hdmi port settings
   if (!bPASet)
     bPASet = SetHDMIPort(configuration.baseDevice, configuration.iHDMIPort);
@@ -678,21 +683,19 @@ uint8_t CCECClient::SendMuteAudio(void)
 
 bool CCECClient::SendKeypress(const cec_logical_address iDestination, const cec_user_control_code key, bool bWait /* = true */)
 {
-  CCECBusDevice *device = GetPrimaryDevice();
   CCECBusDevice *dest = m_processor->GetDevice(iDestination);
 
-  return device && dest ?
-      device->TransmitKeypress(GetPrimaryLogicalAdddress(), key, bWait) :
+  return dest ?
+      dest->TransmitKeypress(GetPrimaryLogicalAdddress(), key, bWait) :
       false;
 }
 
 bool CCECClient::SendKeyRelease(const cec_logical_address iDestination, bool bWait /* = true */)
 {
-  CCECBusDevice *device = GetPrimaryDevice();
   CCECBusDevice *dest = m_processor->GetDevice(iDestination);
 
-  return device && dest ?
-      device->TransmitKeyRelease(GetPrimaryLogicalAdddress(), bWait) :
+  return dest ?
+      dest->TransmitKeyRelease(GetPrimaryLogicalAdddress(), bWait) :
       false;
 }
 
@@ -741,6 +744,13 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration)
     memcpy(configuration.strDeviceLanguage, m_configuration.strDeviceLanguage, 3);
     configuration.iFirmwareBuildDate      = m_configuration.iFirmwareBuildDate;
   }
+
+  // client version 1.6.3
+  if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_3)
+  {
+    configuration.bMonitorOnly            = m_configuration.bMonitorOnly;
+  }
+
   return true;
 }
 
@@ -792,6 +802,12 @@ bool CCECClient::SetConfiguration(const libcec_configuration &configuration)
       memcpy(m_configuration.strDeviceLanguage, configuration.strDeviceLanguage, 3);
     }
 
+    // client version 1.6.3
+    if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_3)
+    {
+      m_configuration.bMonitorOnly = configuration.bMonitorOnly;
+    }
+
     // ensure that there is at least 1 device type set
     if (m_configuration.deviceTypes.IsEmpty())
       m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
@@ -1175,7 +1191,10 @@ bool CCECClient::SwitchMonitoring(bool bEnable)
     if (bEnable)
       return m_processor->UnregisterClient(this);
     else
+    {
+      m_configuration.bMonitorOnly = false;
       return m_processor->RegisterClient(this);
+    }
   }
 
   return false;