+ MarkBusy();
+ LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
+ bReturn = m_handler->TransmitPoll(m_iLogicalAddress, destination);
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
+
+ CLockObject lock(m_mutex);
+ if (bReturn)
+ {
+ m_iLastActive = GetTimeMs();
+ destDevice->m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
+ }
+ else
+ destDevice->m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
+
+ MarkReady();
+ return bReturn;
+}
+
+void CCECBusDevice::HandlePoll(const cec_logical_address destination)
+{
+ if (destination >= 0 && destination < CECDEVICE_BROADCAST)
+ {
+ CCECBusDevice *device = m_processor->GetDevice(destination);
+ if (device)
+ device->HandlePollFrom(m_iLogicalAddress);
+ }
+}
+
+void CCECBusDevice::HandlePollFrom(const cec_logical_address initiator)
+{
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator), initiator, ToString(m_iLogicalAddress), m_iLogicalAddress);
+ m_bAwaitingReceiveFailed = true;
+}
+
+bool CCECBusDevice::HandleReceiveFailed(void)
+{
+ bool bReturn = m_bAwaitingReceiveFailed;
+ m_bAwaitingReceiveFailed = false;
+ return bReturn;
+}
+
+cec_menu_state CCECBusDevice::GetMenuState(const cec_logical_address UNUSED(initiator))
+{
+ CLockObject lock(m_mutex);
+ return m_menuState;
+}
+
+void CCECBusDevice::SetMenuState(const cec_menu_state state)
+{
+ CLockObject lock(m_mutex);
+ if (m_menuState != state)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
+ m_menuState = state;
+ }
+}
+
+bool CCECBusDevice::TransmitMenuState(const cec_logical_address dest)
+{
+ cec_menu_state menuState;
+ {
+ CLockObject lock(m_mutex);
+ LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
+ menuState = m_menuState;
+ }
+
+ MarkBusy();
+ bool bReturn = m_handler->TransmitMenuState(m_iLogicalAddress, dest, menuState);
+ MarkReady();
+ return bReturn;
+}
+
+bool CCECBusDevice::ActivateSource(void)
+{
+ MarkAsActiveSource();
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "activating source '%s'", ToString(m_iLogicalAddress));
+ MarkBusy();
+ bool bReturn = m_handler->ActivateSource();
+ MarkReady();
+ return bReturn;
+}
+
+bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse /* = true */)
+{
+ bool bReturn(false);
+
+ if (IsHandledByLibCEC())
+ {
+ MarkBusy();
+ LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< requesting active source");
+
+ bReturn = m_handler->TransmitRequestActiveSource(m_iLogicalAddress, bWaitForResponse);
+ MarkReady();
+ }
+ return bReturn;
+}
+
+void CCECBusDevice::MarkAsActiveSource(void)
+{
+ CLockObject lock(m_mutex);
+ if (!m_bActiveSource)
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress);
+ else
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress);
+
+ CECDEVICEVEC devices;
+ m_processor->GetDevices()->Get(devices);
+ for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
+ if ((*it)->GetLogicalAddress() != m_iLogicalAddress)
+ (*it)->MarkAsInactiveSource();
+
+ m_bActiveSource = true;
+ SetPowerStatus(CEC_POWER_STATUS_ON);
+}
+
+void CCECBusDevice::MarkAsInactiveSource(void)
+{
+ {
+ CLockObject lock(m_mutex);
+ if (m_bActiveSource)
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress);
+ m_bActiveSource = false;
+ }