+ return true;
+}
+
+void CCECProcessor::Close(void)
+{
+ // mark as uninitialised
+ SetCECInitialised(false);
+
+ // stop the processor
+ StopThread();
+
+ // close the connection
+ DELETE_AND_NULL(m_communication);
+}
+
+void CCECProcessor::ResetMembers(void)
+{
+ // close the connection
+ DELETE_AND_NULL(m_communication);
+
+ // reset the other members to the initial state
+ m_iStandardLineTimeout = 3;
+ m_iRetryLineTimeout = 3;
+ m_iLastTransmission = 0;
+ m_busDevices->ResetDeviceStatus();
+}
+
+bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
+{
+ bool bReturn(false);
+ CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
+
+ // ensure that a previous connection is closed
+ Close();
+
+ // reset all member to the initial state
+ ResetMembers();
+
+ // check whether the Close() method deleted any previous connection
+ if (m_communication)
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "previous connection could not be closed");
+ return bReturn;
+ }
+
+ // create a new connection
+ m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate);
+
+ // open a new connection
+ unsigned iConnectTry(0);
+ while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open((timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false)
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
+ m_communication->Close();
+ CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT);
+ }
+
+ m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened");
+
+ // mark as initialised
+ SetCECInitialised(true);
+
+ return bReturn;
+}
+
+bool CCECProcessor::CECInitialised(void)
+{
+ CLockObject lock(m_threadMutex);
+ return m_bInitialised;
+}
+
+void CCECProcessor::SetCECInitialised(bool bSetTo /* = true */)
+{
+ {
+ CLockObject lock(m_mutex);
+ m_bInitialised = bSetTo;
+ }
+ if (!bSetTo)
+ UnregisterClients();
+}
+
+bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
+{
+ // find the device
+ CCECBusDevice *device = m_busDevices->At(address);
+ if (device)
+ {
+ // check if it's already marked as present or used
+ if (device->IsPresent() || device->IsHandledByLibCEC())
+ return false;
+
+ // poll the LA if not
+ SetAckMask(0);
+ return device->TryLogicalAddress();
+ }