using namespace PLATFORM;
CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) :
+ m_bConnectionOpened(false),
m_bInitialised(false),
m_communication(NULL),
m_controller(controller),
}
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),
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;
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())
{
/* 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 */
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);
return false;
}
- cec_adapter_message_state retVal(ADAPTER_MESSAGE_STATE_UNKNOWN);
+ uint8_t iMaxTries(0);
{
CLockObject lock(m_mutex);
LogOutput(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 */)