From: Lars Op den Kamp Date: Mon, 14 May 2012 11:53:15 +0000 (+0200) Subject: cec: check if the processor thread is marked as initialised, not if the thread is... X-Git-Tag: upstream/2.2.0~1^2~28^2~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0b8c7eab61e750b7dd6370e7d75e2c6a0cf0da12;p=deb_libcec.git cec: check if the processor thread is marked as initialised, not if the thread is running. check if the thread is running too, not just if the port is open in CUSBCECAdapterCommunication --- diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index 6df9dba..4ac7243 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -148,7 +148,7 @@ bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_ } // 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 @@ -196,7 +196,7 @@ void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration) { // 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 @@ -234,7 +234,7 @@ bool CCECClient::SetPhysicalAddress(const uint16_t iPhysicalAddress) } // persist the new configuration - if (m_processor->IsRunning()) + if (m_processor->CECInitialised()) m_processor->PersistConfiguration(m_configuration); // set the physical address for each device @@ -467,7 +467,7 @@ bool CCECClient::SendSetActiveSource(const cec_device_type type /* = CEC_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(); @@ -747,7 +747,7 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration) 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; @@ -1044,7 +1044,7 @@ void CCECClient::SetOSDName(const CStdString &strDeviceName) 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); } } @@ -1109,7 +1109,7 @@ bool CCECClient::SetDeviceTypes(const cec_device_type_list &deviceTypes) { CLockObject lock(m_mutex); - bNeedReinit = m_processor && m_processor->IsRunning() && + bNeedReinit = m_processor && m_processor->CECInitialised() && (m_configuration.deviceTypes != deviceTypes); m_configuration.deviceTypes = deviceTypes; } @@ -1157,7 +1157,7 @@ bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress) // reactivate the previous active source if (reactivateSource != CECDEVICE_UNKNOWN && - m_processor->IsRunning() && + m_processor->CECInitialised() && IsInitialised()) { CCECBusDevice *device = m_processor->GetDevice(reactivateSource); diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7c2e08a..e90d5cb 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -86,9 +86,6 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = CEC_SERIA } } - // mark as initialised - SetCECInitialised(true); - return true; } @@ -156,6 +153,9 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened"); + // mark as initialised + SetCECInitialised(true); + return bReturn; } @@ -615,8 +615,11 @@ CCECTuner *CCECProcessor::GetTuner(cec_logical_address address) const 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()) diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 5f22f9a..9eaf9ce 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -915,7 +915,7 @@ CCECClient *CLibCEC::RegisterClient(libcec_configuration &configuration) m_client = newClient; // register the new client - if (m_cec->IsRunning()) + if (m_cec->CECInitialised()) m_cec->RegisterClient(newClient); return newClient; diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 3e3ba08..a68cfd3 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -169,7 +169,7 @@ void CUSBCECAdapterCommunication::Close(void) 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); @@ -314,7 +314,7 @@ bool CUSBCECAdapterCommunication::SetLineTimeout(uint8_t iTimeout) 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; @@ -345,7 +345,7 @@ bool CUSBCECAdapterCommunication::ReadFromDevice(uint32_t iTimeout, size_t iSize /* 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); @@ -371,8 +371,7 @@ bool CUSBCECAdapterCommunication::ReadFromDevice(uint32_t iTimeout, size_t iSize 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 */ @@ -488,12 +487,13 @@ bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask) 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; } @@ -504,17 +504,17 @@ uint16_t CUSBCECAdapterCommunication::GetAckMask(void) 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) @@ -525,12 +525,12 @@ 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) @@ -540,7 +540,7 @@ 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) diff --git a/src/lib/implementations/ANCommandHandler.cpp b/src/lib/implementations/ANCommandHandler.cpp index ed4218e..7c2d059 100644 --- a/src/lib/implementations/ANCommandHandler.cpp +++ b/src/lib/implementations/ANCommandHandler.cpp @@ -50,7 +50,7 @@ CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice) : 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); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index f35dd32..2902ac1 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -245,7 +245,7 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) 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; @@ -267,7 +267,7 @@ bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) 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) @@ -279,7 +279,7 @@ bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) 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) @@ -291,7 +291,7 @@ bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) 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)) @@ -303,7 +303,7 @@ bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) 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) @@ -315,7 +315,7 @@ bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) 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) @@ -327,7 +327,7 @@ bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) 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) @@ -339,7 +339,7 @@ bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) 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) @@ -351,7 +351,7 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) 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) @@ -363,7 +363,7 @@ bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) 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) @@ -381,7 +381,7 @@ bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) 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) @@ -450,7 +450,7 @@ bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) 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); @@ -533,7 +533,7 @@ bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) 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); @@ -548,7 +548,7 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) 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) @@ -620,7 +620,7 @@ bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { - if (m_processor->IsRunning() && + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination) && command.parameters.size > 0) { @@ -684,7 +684,7 @@ void CCECCommandHandler::UnhandledCommand(const cec_command &command) { 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); } diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index e1632ee..f39aef8 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -245,7 +245,7 @@ void CSLCommandHandler::TransmitVendorCommandSetDeviceMode(const cec_logical_add 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)) @@ -275,7 +275,7 @@ bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command) 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) @@ -317,7 +317,7 @@ bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) 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);