+bool CCECBusDevice::ActivateSource(uint64_t iDelay /* = 0 */)
+{
+ MarkAsActiveSource();
+ MarkBusy();
+ bool bReturn(true);
+ if (iDelay == 0)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending active source message for '%s'", ToString(m_iLogicalAddress));
+ bReturn = m_handler->ActivateSource();
+ }
+ else
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "scheduling active source message for '%s'", ToString(m_iLogicalAddress));
+ m_handler->ScheduleActivateSource(iDelay);
+ }
+ 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)
+{
+ bool bWasActivated(false);
+
+ // set the power status to powered on
+ SetPowerStatus(CEC_POWER_STATUS_ON);
+
+ // mark this device as active source
+ {
+ CLockObject lock(m_mutex);
+ if (!m_bActiveSource)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress);
+ bWasActivated = true;
+ }
+ else
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%x) was already marked as active source", GetLogicalAddressName(), m_iLogicalAddress);
+
+ m_bActiveSource = true;
+ }
+
+ // mark other devices as inactive sources
+ CECDEVICEVEC devices;
+ m_processor->GetDevices()->Get(devices);
+ for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
+ if ((*it)->GetLogicalAddress() != m_iLogicalAddress)
+ (*it)->MarkAsInactiveSource();
+
+ if (bWasActivated)
+ {
+ CCECClient *client = GetClient();
+ if (client)
+ client->SourceActivated(m_iLogicalAddress);
+ }
+}
+
+void CCECBusDevice::MarkAsInactiveSource(void)
+{
+ bool bWasDeactivated(false);
+ {
+ CLockObject lock(m_mutex);
+ if (m_bActiveSource)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress);
+ bWasDeactivated = true;
+ }
+ m_bActiveSource = false;
+ }
+
+ if (bWasDeactivated)
+ {
+ CCECClient *client = GetClient();
+ if (client)
+ client->SourceDeactivated(m_iLogicalAddress);
+ }