cec: cleanups in ActivateSource() and CSLCommandHandler
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 9535a21a746e7c1713c6b7b6646b36165c708f6f..ebd17729f4e0355f3ad77ab8f2a30a3a85f70188 100644 (file)
@@ -47,7 +47,26 @@ using namespace CEC;
 using namespace std;
 using namespace PLATFORM;
 
-CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress /* = 0 */) :
+CCECProcessor::CCECProcessor(CLibCEC *controller, const libcec_configuration *configuration) :
+    m_bInitialised(false),
+    m_iPhysicalAddress(configuration->iPhysicalAddress),
+    m_iHDMIPort(configuration->iHDMIPort),
+    m_iBaseDevice(configuration->baseDevice),
+    m_strDeviceName(configuration->strDeviceName),
+    m_types(configuration->deviceTypes),
+    m_communication(NULL),
+    m_controller(controller),
+    m_bMonitor(false),
+    m_iStandardLineTimeout(3),
+    m_iRetryLineTimeout(3),
+    m_iLastTransmission(0),
+    m_clientVersion(configuration->clientVersion)
+{
+  m_logicalAddresses.Clear();
+  CreateBusDevices();
+}
+
+CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress, cec_client_version clientVersion) :
     m_bInitialised(false),
     m_iPhysicalAddress(iPhysicalAddress),
     m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
@@ -59,9 +78,15 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
     m_bMonitor(false),
     m_iStandardLineTimeout(3),
     m_iRetryLineTimeout(3),
-    m_iLastTransmission(0)
+    m_iLastTransmission(0),
+    m_clientVersion(clientVersion)
 {
   m_logicalAddresses.Clear();
+  CreateBusDevices();
+}
+
+void CCECProcessor::CreateBusDevices(void)
+{
   for (int iPtr = 0; iPtr < 16; iPtr++)
   {
     switch(iPtr)
@@ -149,7 +174,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
   }
 
   if (bReturn)
-    CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", m_communication->GetFirmwareVersion());
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString(m_clientVersion));
 
   return bReturn;
 }
@@ -186,10 +211,10 @@ bool CCECProcessor::Initialise(void)
 
   /* get the vendor id from the TV, so we are using the correct handler */
   m_busDevices[CECDEVICE_TV]->RequestVendorId();
-  ReplaceHandlers();
 
   if (m_iPhysicalAddress != 0)
   {
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_iPhysicalAddress);
     m_busDevices[m_logicalAddresses.primary]->m_iPhysicalAddress = m_iPhysicalAddress;
     if ((bReturn = m_busDevices[m_logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
       CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_iPhysicalAddress);
@@ -381,7 +406,6 @@ bool CCECProcessor::FindLogicalAddresses(void)
 
 void CCECProcessor::ReplaceHandlers(void)
 {
-  CLockObject lock(m_mutex);
   if (!IsInitialised())
     return;
   for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
@@ -435,22 +459,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
 
   m_busDevices[addr]->SetActiveSource();
   if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
-  {
-    bReturn = m_busDevices[addr]->TransmitActiveSource();
-
-    if (bReturn)
-    {
-      m_busDevices[addr]->SetMenuState(CEC_MENU_STATE_ACTIVATED);
-      m_busDevices[addr]->TransmitMenuState(CECDEVICE_TV);
-    }
-
-    if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
-        m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
-        m_busDevices[addr]->GetHandler()->SendDeckStatusUpdateOnActiveSource())
-    {
-      bReturn = ((CCECPlaybackDevice *)m_busDevices[addr])->TransmitDeckStatus(CECDEVICE_TV);
-    }
-  }
+    bReturn = m_busDevices[addr]->ActivateSource();
 
   return bReturn;
 }
@@ -1261,6 +1270,19 @@ const char *CCECProcessor::ToString(const cec_vendor_id vendor)
   }
 }
 
+const char *CCECProcessor::ToString(const cec_client_version version)
+{
+  switch (version)
+  {
+  case CEC_CLIENT_VERSION_PRE_1_5:
+    return "pre-1.5";
+  case CEC_CLIENT_VERSION_1_5_0:
+    return "1.5.0";
+  default:
+    return "Unknown";
+  }
+}
+
 void *CCECBusScan::Process(void)
 {
   CCECBusDevice *device(NULL);
@@ -1331,3 +1353,23 @@ bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress)
   // stream path changes are sent by the TV
   return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress);
 }
+
+bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
+{
+  configuration->iPhysicalAddress = m_iPhysicalAddress;
+  configuration->iHDMIPort = m_iHDMIPort;
+  configuration->baseDevice = m_iBaseDevice;
+  snprintf(configuration->strDeviceName, 13, "%s", m_strDeviceName.c_str());
+  configuration->deviceTypes = m_types;
+  return true;
+}
+
+bool CCECProcessor::CanPersistConfiguration(void)
+{
+  return m_communication->GetFirmwareVersion() >= 2;
+}
+
+bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
+{
+  return m_communication->PersistConfiguration(configuration);
+}