}
// don't continue if the connection isn't opened
- if (!m_processor->IsRunning() && !bForce)
+ if (!m_processor->CECInitialised() && !bForce)
return true;
// get the PA of the base device
{
// try to autodetect the address
bool bPASet(false);
- if (m_processor->IsRunning() && configuration.bAutodetectAddress == 1)
+ if (m_processor->CECInitialised() && configuration.bAutodetectAddress == 1)
bPASet = AutodetectPhysicalAddress();
// try to use physical address setting
}
// persist the new configuration
- if (m_processor->IsRunning())
+ if (m_processor->CECInitialised())
m_processor->PersistConfiguration(m_configuration);
// set the physical address for each device
CCECBusDevice *device = *devices.begin();
// and activate it
- if (!m_processor->IsRunning())
+ if (!m_processor->CECInitialised())
device->MarkAsActiveSource();
else if (device->HasValidPhysicalAddress())
return device->ActivateSource();
bool CCECClient::SetConfiguration(const libcec_configuration &configuration)
{
- bool bIsRunning(m_processor && m_processor->IsRunning());
+ bool bIsRunning(m_processor && m_processor->CECInitialised());
CCECBusDevice *primary = bIsRunning ? GetPrimaryDevice() : NULL;
uint16_t iPA = primary ? primary->GetCurrentPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS;
if (primary && !primary->GetCurrentOSDName().Equals(strDeviceName))
{
primary->SetOSDName(strDeviceName);
- if (m_processor && m_processor->IsRunning())
+ if (m_processor && m_processor->CECInitialised())
primary->TransmitOSDName(CECDEVICE_TV);
}
}
{
CLockObject lock(m_mutex);
- bNeedReinit = m_processor && m_processor->IsRunning() &&
+ bNeedReinit = m_processor && m_processor->CECInitialised() &&
(m_configuration.deviceTypes != deviceTypes);
m_configuration.deviceTypes = deviceTypes;
}
// reactivate the previous active source
if (reactivateSource != CECDEVICE_UNKNOWN &&
- m_processor->IsRunning() &&
+ m_processor->CECInitialised() &&
IsInitialised())
{
CCECBusDevice *device = m_processor->GetDevice(reactivateSource);
}
}
- // mark as initialised
- SetCECInitialised(true);
-
return true;
}
m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened");
+ // mark as initialised
+ SetCECInitialised(true);
+
return bReturn;
}
bool CCECProcessor::RegisterClient(CCECClient *client)
{
- if (!client || !IsRunning())
+ if (!client || !CECInitialised())
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register a new CEC client: CEC processor is not initialised");
return false;
+ }
// unregister the client first if it's already been marked as registered
if (client->IsRegistered())
m_client = newClient;
// register the new client
- if (m_cec->IsRunning())
+ if (m_cec->CECInitialised())
m_cec->RegisterClient(newClient);
return newClient;
CLockObject lock(m_mutex);
/* set the ackmask to 0 before closing the connection */
- if (IsRunning() && m_port->IsOpen() && m_port->GetErrorNumber() == 0)
+ if (IsOpen() && m_port->GetErrorNumber() == 0)
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - closing the connection", __FUNCTION__);
SetAckMask(0);
bool CUSBCECAdapterCommunication::WriteToDevice(CCECAdapterMessage *message)
{
CLockObject adapterLock(m_mutex);
- if (!m_port->IsOpen())
+ if (!IsOpen())
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "error writing command '%s' to serial port '%s': the connection is closed", CCECAdapterMessage::ToString(message->Message()), m_port->GetName().c_str());
message->state = ADAPTER_MESSAGE_STATE_ERROR;
/* read from the serial port */
{
CLockObject lock(m_mutex);
- if (!m_port || !m_port->IsOpen())
+ if (!IsOpen())
return false;
iBytesRead = m_port->Read(buff, sizeof(uint8_t) * iSize, iTimeout);
CCECAdapterMessage *CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode, CCECAdapterMessage ¶ms, bool bIsRetry /* = false */)
{
- if (!m_port || !m_port->IsOpen() ||
- !m_adapterMessageQueue)
+ if (!m_port->IsOpen() || !m_adapterMessageQueue)
return NULL;
/* create the adapter message for this command */
if (m_iAckMask == iMask)
return true;
- if (m_port && m_port->IsOpen() && m_commands->SetAckMask(iMask))
+ if (IsOpen() && m_commands->SetAckMask(iMask))
{
m_iAckMask = iMask;
return true;
}
+ LIB_CEC->AddLog(CEC_LOG_ERROR, "couldn't change the ackmask: the connection is closed");
return false;
}
bool CUSBCECAdapterCommunication::PingAdapter(void)
{
- return m_port->IsOpen() ? m_commands->PingAdapter() : false;
+ return IsOpen() ? m_commands->PingAdapter() : false;
}
uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void)
{
- return m_commands->GetFirmwareVersion();
+ return IsOpen() ? m_commands->GetFirmwareVersion() : CEC_FW_VERSION_UNKNOWN;
}
uint32_t CUSBCECAdapterCommunication::GetFirmwareBuildDate(void)
{
- return m_commands->RequestBuildDate();
+ return IsOpen() ? m_commands->RequestBuildDate() : 0;
}
bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void)
bool CUSBCECAdapterCommunication::PersistConfiguration(const libcec_configuration &configuration)
{
- return m_port->IsOpen() ? m_commands->PersistConfiguration(configuration) : false;
+ return IsOpen() ? m_commands->PersistConfiguration(configuration) : false;
}
bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration &configuration)
{
- return m_port->IsOpen() ? m_commands->GetConfiguration(configuration) : false;
+ return IsOpen() ? m_commands->GetConfiguration(configuration) : false;
}
CStdString CUSBCECAdapterCommunication::GetPortName(void)
bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled)
{
- return m_port->IsOpen() ? m_commands->SetControlledMode(controlled) : false;
+ return IsOpen() ? m_commands->SetControlledMode(controlled) : false;
}
void *CAdapterPingThread::Process(void)
bool CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
{
- if (m_processor->IsRunning() && command.parameters.size > 0)
+ if (m_processor->CECInitialised() && command.parameters.size > 0)
{
CCECClient *client = m_processor->GetClient(command.destination);
bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
return true;
bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
{
- if (m_processor->IsRunning())
+ if (m_processor->CECInitialised())
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator);
m_processor->GetDevice(command.initiator)->SetPowerStatus(CEC_POWER_STATUS_ON);
bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
{
- if (m_processor->IsRunning() && command.parameters.size >= 2)
+ if (m_processor->CECInitialised() && command.parameters.size >= 2)
{
uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
{
- if (m_processor->IsRunning() &&
+ if (m_processor->CECInitialised() &&
m_processor->IsHandledByLibCEC(command.destination) &&
command.parameters.size > 0)
{
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
}
bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command)
{
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
{
bool bReturn(false);
- if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination) && command.initiator == CECDEVICE_TV)
+ if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination) && command.initiator == CECDEVICE_TV)
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetCurrentPowerStatus() != CEC_POWER_STATUS_ON)
bool CSLCommandHandler::HandleRequestActiveSource(const cec_command &command)
{
- if (m_processor->IsRunning())
+ if (m_processor->CECInitialised())
{
if (ActiveSourceSent())
LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source, ignored", (uint8_t) command.initiator);