+bool CCECBusDevice::TryLogicalAddress(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "trying logical address '%s'", GetLogicalAddressName());
+
+ m_processor->SetAckMask(0);
+ if (!TransmitPoll(m_iLogicalAddress))
+ {
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "using logical address '%s'", GetLogicalAddressName());
+ SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
+
+ return true;
+ }
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address '%s' already taken", GetLogicalAddressName());
+ SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT);
+ return false;
+}
+
+void CCECBusDevice::ResetDeviceStatus(void)
+{
+ CLockObject lock(m_mutex);
+ SetPowerStatus (CEC_POWER_STATUS_UNKNOWN);
+ SetVendorId (CEC_VENDOR_UNKNOWN);
+ SetMenuState (CEC_MENU_STATE_ACTIVATED);
+ SetCecVersion (CEC_VERSION_UNKNOWN);
+ SetStreamPath (0);
+ SetOSDName (ToString(m_iLogicalAddress));
+ SetInactiveSource();
+ m_iLastActive = 0;
+}
+
+void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
+{
+ {
+ CLockObject lock(m_mutex);
+ 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));
+ ResetDeviceStatus();
+ 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));
+ SetPowerStatus (CEC_POWER_STATUS_ON);
+ SetVendorId (CEC_VENDOR_UNKNOWN);
+ SetMenuState (CEC_MENU_STATE_ACTIVATED);
+ SetCecVersion (CEC_VERSION_1_3A);
+ SetStreamPath (0);
+ SetInactiveSource();
+ m_iLastActive = 0;
+ 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));
+ ResetDeviceStatus();
+ m_deviceStatus = newStatus;
+ }
+ break;
+ }
+ }
+
+ if (newStatus == CEC_DEVICE_STATUS_PRESENT)
+ RequestVendorId(false);
+}
+
+void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
+{
+ CLockObject lock(m_mutex);
+ if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
+ m_iPhysicalAddress = iNewAddress;
+ }
+}
+
+void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
+{
+ CLockObject lock(m_mutex);
+ if (iNewAddress > 0)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress);
+ m_iStreamPath = iNewAddress;
+
+ // suppress polls when searching for a device
+ CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress, false, true);
+ if (device)
+ {
+ // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
+ device->SetActiveSource();
+ }
+ else
+ {
+ // try to find the device with the old address, and mark it as inactive when found
+ device = m_processor->GetDeviceByPhysicalAddress(iOldAddress, false, true);
+ if (device)
+ device->SetInactiveSource();
+ }
+
+ if (iNewAddress > 0)
+ {
+ lock.Unlock();
+ SetPowerStatus(CEC_POWER_STATUS_ON);
+ }
+ }
+}
+
+void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)