cec: moved SetLineTimeout() to CAdapterCommunication
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 4 Dec 2011 00:19:10 +0000 (01:19 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 4 Dec 2011 02:28:25 +0000 (03:28 +0100)
src/lib/AdapterCommunication.cpp
src/lib/AdapterCommunication.h
src/lib/CECProcessor.cpp

index fc650f0651f82a986dd2cfe7df730d47dfa4b033..3a1cfeb735b022749de36aa61cb18f4622d62d02 100644 (file)
@@ -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();
index 461ed586f887e427615feb5a2ccb30f95ab9cc93..1e2e1c0a587e578a46f9df8e832cf52a7d5500f6 100644 (file)
@@ -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;
   };
 };
index f8ea3bc871f9eee71c4e2fe33fd7ff753708ca52..d1d7c6d472c6d56d1fa626c17ddfbc1439f145a8 100644 (file)
@@ -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;
 }