m_processor(m_busDevice->GetProcessor()),
m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT),
m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT),
- m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES)
+ m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES),
+ m_bHandlerInited(false),
+ m_iUseCounter(0)
{
}
CCECCommandHandler::~CCECCommandHandler(void)
{
+ CLockObject lock(&m_processor->m_transmitMutex);
+ CLockObject receiveLock(&m_receiveMutex);
m_condition.Broadcast();
}
{
bool bHandled(true), bHandlerChanged(false);
+ MarkBusy();
CStdString strLog;
strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode);
m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
m_condition.Signal();
}
+ MarkReady();
return bHandled;
}
{
m_processor->m_busDevices[command.initiator]->SetUnsupportedFeature((cec_opcode)command.parameters[0]);
}
+ return true;
}
bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
return true;
}
-bool CCECCommandHandler::TransmitPowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
{
cec_command command;
cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON);
bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* = true */)
{
+ bool bReturn(false);
command.transmit_timeout = m_iTransmitTimeout;
- CLockObject writeLock(&m_processor->m_transmitMutex);
- CLockObject receiveLock(&m_receiveMutex);
- if (m_processor->Transmit(command))
{
- if (bExpectResponse)
- return m_condition.Wait(&m_receiveMutex, m_iTransmitWait);
- return true;
+ CLockObject writeLock(&m_processor->m_transmitMutex);
+ CLockObject receiveLock(&m_receiveMutex);
+ ++m_iUseCounter;
+ if (m_processor->Transmit(command))
+ {
+ bReturn = bExpectResponse ?
+ m_condition.Wait(&m_receiveMutex, m_iTransmitWait) :
+ true;
+ }
+ --m_iUseCounter;
}
- return false;
+ return bReturn;
}
bool CCECCommandHandler::InitHandler(void)
primary->SetPowerStatus(CEC_POWER_STATUS_ON);
primary->SetMenuState(CEC_MENU_STATE_ACTIVATED);
- m_processor->SetActiveSource();
- primary->TransmitMenuState(m_busDevice->GetLogicalAddress());
+ if (m_processor->GetPrimaryDevice()->GetPhysicalAddress(false) != 0xffff)
+ {
+ m_processor->SetActiveSource();
+ primary->TransmitMenuState(m_busDevice->GetLogicalAddress());
+ m_bHandlerInited = true;
+ }
}
return true;
}
+
+void CCECCommandHandler::MarkBusy(void)
+{
+ CLockObject receiveLock(&m_receiveMutex);
+ ++m_iUseCounter;
+}
+
+bool CCECCommandHandler::MarkReady(void)
+{
+ CLockObject receiveLock(&m_receiveMutex);
+ return m_iUseCounter > 0 ? (--m_iUseCounter == 0) : true;
+}
+
+bool CCECCommandHandler::InUse(void)
+{
+ CLockObject receiveLock(&m_receiveMutex);
+ return m_iUseCounter > 0;
+}