+ m_handler->MarkBusy();
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ bReturn = m_handler->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress);
+ m_handler->MarkReady();
+ }
+ return bReturn;
+}
+
+cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */)
+{
+ bool bRequestUpdate(false);
+ {
+ CLockObject lock(m_mutex);
+ bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+ (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN));
+ }
+
+ if (bRequestUpdate)
+ RequestVendorId();
+
+ CLockObject lock(m_mutex);
+ return m_vendor;
+}
+
+bool CCECBusDevice::RequestVendorId(void)
+{
+ bool bReturn(false);
+
+ if (!MyLogicalAddressContains(m_iLogicalAddress))
+ {
+ m_handler->MarkBusy();
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ bReturn = m_handler->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress);
+ m_handler->MarkReady();
+
+ ReplaceHandler(true);
+ }
+ return bReturn;
+}
+
+const char *CCECBusDevice::GetVendorName(bool bUpdate /* = false */)
+{
+ return ToString(GetVendorId(bUpdate));
+}
+
+bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
+{
+ return m_processor->HasLogicalAddress(address);
+}
+
+bool CCECBusDevice::NeedsPoll(void)
+{
+ bool bSendPoll(false);
+ switch (m_iLogicalAddress)
+ {
+ case CECDEVICE_PLAYBACKDEVICE3:
+ if (m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE2]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_PLAYBACKDEVICE2:
+ if (m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE1]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_RECORDINGDEVICE3:
+ if (m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE2]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_RECORDINGDEVICE2:
+ if (m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE1]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_TUNER4:
+ if (m_processor->m_busDevices[CECDEVICE_TUNER3]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_TUNER3:
+ if (m_processor->m_busDevices[CECDEVICE_TUNER2]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_TUNER2:
+ if (m_processor->m_busDevices[CECDEVICE_TUNER1]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ bSendPoll = true;
+ break;
+ case CECDEVICE_AUDIOSYSTEM:
+ case CECDEVICE_PLAYBACKDEVICE1:
+ case CECDEVICE_RECORDINGDEVICE1:
+ case CECDEVICE_TUNER1:
+ case CECDEVICE_TV:
+ bSendPoll = true;
+ break;
+ default:
+ break;
+ }
+
+ return bSendPoll;
+}
+
+cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */)
+{
+ CLockObject lock(m_mutex);
+ if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC &&
+ (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll))
+ {
+ lock.Unlock();
+ bool bPollAcked(false);
+ if (bForcePoll || NeedsPoll())
+ bPollAcked = m_processor->PollDevice(m_iLogicalAddress);
+
+ lock.Lock();
+ m_deviceStatus = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT;
+ }
+
+ return m_deviceStatus;
+}
+
+//@}
+
+/** @name Setters */
+//@{
+void CCECBusDevice::SetCecVersion(const cec_version newVersion)
+{
+ m_cecVersion = newVersion;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
+}
+
+void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
+{
+ CLockObject lock(m_mutex);
+ if (language.device == m_iLogicalAddress)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
+ m_menuLanguage = language;
+ }
+}
+
+void CCECBusDevice::SetOSDName(CStdString strName)
+{
+ CLockObject lock(m_mutex);
+ if (m_strDeviceName != strName)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str());
+ m_strDeviceName = strName;
+ }
+}
+
+void CCECBusDevice::SetMenuState(const cec_menu_state state)
+{
+ CLockObject lock(m_mutex);
+ if (m_menuState != state)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
+ m_menuState = state;
+ }
+}
+
+void CCECBusDevice::SetInactiveSource(void)
+{
+ {
+ CLockObject lock(m_mutex);
+ m_bActiveSource = false;
+ }
+
+ if (MyLogicalAddressContains(m_iLogicalAddress))
+ SetPowerStatus(CEC_POWER_STATUS_STANDBY);
+}
+
+void CCECBusDevice::SetActiveSource(void)
+{
+ CLockObject lock(m_mutex);
+ if (!m_bActiveSource)
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress);
+
+ for (int iPtr = 0; iPtr < 16; iPtr++)
+ if (iPtr != m_iLogicalAddress)
+ m_processor->m_busDevices[iPtr]->SetInactiveSource();
+
+ m_bActiveSource = true;
+ m_powerStatus = CEC_POWER_STATUS_ON;
+}
+
+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::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_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_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);
+ 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;
+
+ if (iNewAddress > 0)