From: Lars Op den Kamp Date: Fri, 25 Nov 2011 09:59:54 +0000 (+0100) Subject: cec: moved part of the TryLogicalAddress() logic to CCECBusDevice X-Git-Tag: upstream/2.2.0~1^2~44^2~107 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=93fff5c18f5e39ffbee143b4d01e89cc02d6fd99;p=deb_libcec.git cec: moved part of the TryLogicalAddress() logic to CCECBusDevice --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index cf64053..782b611 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 3037501..5b5ba4b 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -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); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 20fe43b..ecefaa7 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -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); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index d7f4e27..2f45dd9 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -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);