+void CCECProcessor::ResetMembers(void)
+{
+ // close the connection
+ if (m_communication)
+ {
+ delete m_communication;
+ m_communication = NULL;
+ }
+
+ // reset the other members to the initial state
+ m_bMonitor = false;
+ m_iPreviousAckMask = 0;
+ 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");
+
+ 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();
+ }
+
+ return false;
+}
+
+void CCECProcessor::ReplaceHandlers(void)
+{
+ if (!CECInitialised())
+ return;
+
+ // check each device
+ for (CECDEVICEMAP::iterator it = m_busDevices->Begin(); it != m_busDevices->End(); it++)
+ it->second->ReplaceHandler(true);
+}
+
+bool CCECProcessor::OnCommandReceived(const cec_command &command)
+{
+ return m_inBuffer.Push(command);
+}
+
+void *CCECProcessor::Process(void)
+{
+ m_libcec->AddLog(CEC_LOG_DEBUG, "processor thread started");