From: Lars Op den Kamp Date: Sun, 4 Dec 2011 00:19:10 +0000 (+0100) Subject: cec: moved SetLineTimeout() to CAdapterCommunication X-Git-Tag: upstream/2.2.0~1^2~44^2~56 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a171d2fdf17b447edd79134c5a092abe4658c919;p=deb_libcec.git cec: moved SetLineTimeout() to CAdapterCommunication --- diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index fc650f0..3a1cfeb 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -246,7 +246,8 @@ void CCECAdapterMessage::push_escaped(uint8_t byte) CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) : m_port(NULL), - m_processor(processor) + m_processor(processor), + m_iLineTimeout(0) { m_port = new CSerialPort; } @@ -495,6 +496,27 @@ bool CAdapterCommunication::PingAdapter(void) return bReturn; } +bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout) +{ + bool bReturn(m_iLineTimeout != iTimeout); + + if (!bReturn) + { + CCECAdapterMessage *output = new CCECAdapterMessage; + + output->push_back(MSGSTART); + output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); + output->push_escaped(iTimeout); + output->push_back(MSGEND); + + if ((bReturn = Write(output)) == false) + m_processor->AddLog(CEC_LOG_ERROR, "could not set the idletime"); + delete output; + } + + return bReturn; +} + bool CAdapterCommunication::IsOpen(void) const { return !IsStopped() && m_port->IsOpen() && IsRunning(); diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 461ed58..1e2e1c0 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -110,6 +110,7 @@ namespace CEC void *Process(void); + bool SetLineTimeout(uint8_t iTimeout); bool StartBootloader(void); private: @@ -125,5 +126,6 @@ namespace CEC CMutex m_mutex; CCondition m_rcvCondition; CCondition m_startCondition; + uint8_t m_iLineTimeout; }; }; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index f8ea3bc..d1d7c6d 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -55,8 +55,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec m_strDeviceName(strDeviceName), m_controller(controller), m_bMonitor(false), - m_busScan(NULL), - m_iLineTimeout(0) + m_busScan(NULL) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -73,8 +72,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con m_strDeviceName(strDeviceName), m_types(types), m_controller(controller), - m_bMonitor(false), - m_iLineTimeout(0) + m_bMonitor(false) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -242,27 +240,6 @@ bool CCECProcessor::FindLogicalAddresses(void) return bReturn; } -bool CCECProcessor::SetLineTimeout(uint8_t iTimeout) -{ - bool bReturn(m_iLineTimeout != iTimeout); - - if (!bReturn) - { - CCECAdapterMessage *output = new CCECAdapterMessage; - - output->push_back(MSGSTART); - output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); - output->push_escaped(iTimeout); - output->push_back(MSGEND); - - if ((bReturn = Transmit(output)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime"); - delete output; - } - - return bReturn; -} - void *CCECProcessor::Process(void) { bool bParseFrame(false); @@ -681,12 +658,12 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) bool bReturn(false); CLockObject lock(&m_mutex); { - SetLineTimeout(3); + m_communication->SetLineTimeout(3); do { if (output->tries > 0) - SetLineTimeout(5); + m_communication->SetLineTimeout(5); CLockObject msgLock(&output->mutex); if (!m_communication || !m_communication->Write(output)) @@ -711,7 +688,7 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries <= output->maxTries); } - SetLineTimeout(3); + m_communication->SetLineTimeout(3); return bReturn; }