cec: moved part of the TryLogicalAddress() logic to CCECBusDevice
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 09:59:54 +0000 (10:59 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 10:00:41 +0000 (11:00 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index cf6405370b1dce2390d7c1b0ba7fc4a843598c24..782b611647520f6d8f04da001c28e0c704557d1d 100644 (file)
@@ -139,27 +139,14 @@ bool CCECProcessor::Start(void)
 
 bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int iIndex)
 {
-  const char *strLabel = CCECCommandHandler::ToString(address);
-  CStdString strLog;
-  strLog.Format("trying logical address '%s'", strLabel);
-  AddLog(CEC_LOG_DEBUG, strLog);
-
-  SetAckMask(0x1 << address);
-  if (!m_busDevices[address]->TransmitPoll(address))
+  if (m_busDevices[address]->TryLogicalAddress())
   {
-    strLog.Format("using logical address '%s'", strLabel);
-    AddLog(CEC_LOG_NOTICE, strLog);
-
     /* only set our OSD name and active source for the primary device */
     if (m_logicalAddresses.IsEmpty())
     {
       m_busDevices[address]->m_strDeviceName = m_strDeviceName;
       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_deviceStatus = CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC;
-
     m_logicalAddresses.Set(address);
 
     // TODO
@@ -168,8 +155,6 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int
     return true;
   }
 
-  strLog.Format("logical address '%s' already taken", strLabel);
-  AddLog(CEC_LOG_DEBUG, strLog);
   return false;
 }
 
index 303750180c7dcb1fa924794ac09f836ec51f2d37..5b5ba4ba1b09276eaf1379c8b22ea9dd5bb31bd7 100644 (file)
@@ -92,6 +92,7 @@ namespace CEC
       virtual void AddLog(cec_log_level level, const CStdString &strMessage);
 
       virtual bool FindLogicalAddresses(void);
+      virtual bool SetAckMask(uint16_t iMask);
 
       CCECBusDevice *m_busDevices[16];
 
@@ -102,7 +103,6 @@ namespace CEC
       bool FindLogicalAddressPlaybackDevice(unsigned int iIndex);
       bool FindLogicalAddressAudioSystem(unsigned int iIndex);
 
-      bool SetAckMask(uint16_t iMask);
       void LogOutput(const cec_command &data);
       bool WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout = 1000);
       bool ParseMessage(const CCECAdapterMessage &msg);
index 20fe43b33179b2bf9fd23d3a669ff9a1c50df339..ecefaa72501b68dcab78e62b37d870413c341608 100644 (file)
@@ -322,6 +322,62 @@ void CCECBusDevice::SetActiveDevice(void)
   m_powerStatus   = CEC_POWER_STATUS_ON;
 }
 
+bool CCECBusDevice::TryLogicalAddress(void)
+{
+  CStdString strLog;
+  strLog.Format("trying logical address '%s'", GetLogicalAddressName());
+  AddLog(CEC_LOG_DEBUG, strLog);
+
+  m_processor->SetAckMask(0x1 << m_iLogicalAddress);
+  if (!TransmitPoll(m_iLogicalAddress))
+  {
+    strLog.Format("using logical address '%s'", GetLogicalAddressName());
+    AddLog(CEC_LOG_NOTICE, strLog);
+    SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
+
+    return true;
+  }
+
+  strLog.Format("logical address '%s' already taken", GetLogicalAddressName());
+  AddLog(CEC_LOG_DEBUG, strLog);
+  SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT);
+  return false;
+}
+
+void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
+{
+  CLockObject lock(&m_mutex);
+  switch (newStatus)
+  {
+  case CEC_DEVICE_STATUS_UNKNOWN:
+    m_iStreamPath      = 0;
+    m_powerStatus      = CEC_POWER_STATUS_UNKNOWN;
+    m_vendor           = CEC_VENDOR_UNKNOWN;
+    m_menuState        = CEC_MENU_STATE_ACTIVATED;
+    m_bActiveSource    = false;
+    m_iLastCommandSent = 0;
+    m_iLastActive      = 0;
+    m_cecVersion       = CEC_VERSION_UNKNOWN;
+    m_deviceStatus     = newStatus;
+    break;
+  case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
+    m_iStreamPath      = 0;
+    m_powerStatus      = CEC_POWER_STATUS_ON;
+    m_vendor           = CEC_VENDOR_UNKNOWN;
+    m_menuState        = CEC_MENU_STATE_ACTIVATED;
+    m_bActiveSource    = false;
+    m_iLastCommandSent = 0;
+    m_iLastActive      = 0;
+    m_cecVersion       = CEC_VERSION_1_3A;
+    m_deviceStatus     = newStatus;
+    break;
+  case CEC_DEVICE_STATUS_PRESENT:
+  case CEC_DEVICE_STATUS_NOT_PRESENT:
+    m_deviceStatus = newStatus;
+    break;
+  }
+}
+
 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
 {
   CLockObject lock(&m_mutex);
index d7f4e27460b4b2f1cc8e4c14e1f386bafef49c1b..2f45dd9d3ed6a6170c2530d23cea6415774ceb82 100644 (file)
@@ -74,7 +74,9 @@ namespace CEC
 
     virtual void SetInactiveDevice(void);
     virtual void SetActiveDevice(void);
+    virtual bool TryLogicalAddress(void);
 
+    virtual void SetDeviceStatus(const cec_bus_device_status newStatus);
     virtual void SetPhysicalAddress(uint16_t iNewAddress);
     virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = 0);
     virtual void SetCecVersion(const cec_version newVersion);