X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=63009a87202617066ab8ef96227a83381d6790b2;hb=d05a1e9c14b9b3c7cf9ec975956eb23bb44bbc8f;hp=afe87a979f48cdfb944291575a969f9d5009fcd7;hpb=f6b94ad2fcaf7b7e09734b32c885d507cc30e45d;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index afe87a9..63009a8 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -48,6 +48,7 @@ using namespace std; using namespace PLATFORM; CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) : + m_bConnectionOpened(false), m_bInitialised(false), m_communication(NULL), m_controller(controller), @@ -69,6 +70,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configur } CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress) : + m_bConnectionOpened(false), m_bInitialised(false), m_communication(NULL), m_controller(controller), @@ -143,8 +145,14 @@ void CCECProcessor::Close(void) SetInitialised(false); StopThread(); - CLockObject lock(m_mutex); - if (m_communication) + bool bClose(false); + { + CLockObject lock(m_mutex); + bClose = m_bConnectionOpened; + m_bConnectionOpened = false; + } + + if (bClose && m_communication) { m_communication->Close(); delete m_communication; @@ -155,16 +163,19 @@ void CCECProcessor::Close(void) bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs) { bool bReturn(false); - CLockObject lock(m_mutex); - if (m_communication) + Close(); + { - CLibCEC::AddLog(CEC_LOG_WARNING, "existing connection handler found, deleting it"); - m_communication->Close(); - delete m_communication; + CLockObject lock(m_mutex); + if (m_bConnectionOpened) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened"); + return false; + } + m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); + m_bConnectionOpened = (m_communication != NULL); } - m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); - /* check for an already opened connection */ if (m_communication->IsOpen()) { @@ -218,6 +229,10 @@ bool CCECProcessor::Initialise(void) /* only set our OSD name for the primary device */ m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName; + + /* make the primary device the active source if the option is set */ + if (m_configuration.bActivateSource == 1) + m_busDevices[m_logicalAddresses.primary]->m_bActiveSource = true; } /* get the vendor id from the TV, so we are using the correct handler */ @@ -233,8 +248,12 @@ bool CCECProcessor::Initialise(void) else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false) CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice); + if (m_configuration.bActivateSource == 1) + m_busDevices[m_logicalAddresses.primary]->ActivateSource(); + SetInitialised(bReturn); - CLibCEC::ConfigurationChanged(m_configuration); + if (bReturn) + CLibCEC::ConfigurationChanged(m_configuration); return bReturn; } @@ -864,7 +883,7 @@ bool CCECProcessor::Transmit(const cec_command &data) return false; } - cec_adapter_message_state retVal(ADAPTER_MESSAGE_STATE_UNKNOWN); + uint8_t iMaxTries(0); { CLockObject lock(m_mutex); LogOutput(data); @@ -874,16 +893,11 @@ bool CCECProcessor::Transmit(const cec_command &data) CLibCEC::AddLog(CEC_LOG_ERROR, "cannot transmit command: connection closed"); return false; } - uint8_t iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1; - retVal = m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout); + iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1; } - /* set to "not present" on failed ack */ - if (retVal == ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED && - data.destination != CECDEVICE_BROADCAST) - m_busDevices[data.destination]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT); - - return retVal == ADAPTER_MESSAGE_STATE_SENT_ACKED; + return m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout) + == ADAPTER_MESSAGE_STATE_SENT_ACKED; } void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) @@ -1303,6 +1317,8 @@ const char *CCECProcessor::ToString(const cec_opcode opcode) return "system audio mode status"; case CEC_OPCODE_SET_AUDIO_RATE: return "set audio rate"; + case CEC_OPCODE_NONE: + return "poll"; default: return "UNKNOWN"; }