cec: moved WaitForTransmitSucceeded() to CAdapterCommunication
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 24 Jan 2012 10:40:42 +0000 (11:40 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 24 Jan 2012 10:40:42 +0000 (11:40 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/adapter/AdapterCommunication.cpp
src/lib/adapter/AdapterCommunication.h

index dd47c0d09077d0ca44cf2171ddcb8bcccf715148..3a5742bd8c8c789fd56b2f6e42a1aeae351ee056 100644 (file)
@@ -885,7 +885,7 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output)
 
       if (output->transmit_timeout > 0)
       {
-        if ((bReturn = WaitForTransmitSucceeded(output)) == false)
+        if ((bReturn = m_communication->WaitForTransmitSucceeded(output)) == false)
           m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
       }
       else
@@ -911,74 +911,6 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode
   Transmit(command);
 }
 
-bool CCECProcessor::WaitForTransmitSucceeded(CCECAdapterMessage *message)
-{
-  bool bError(false);
-  bool bTransmitSucceeded(false);
-  uint8_t iPacketsLeft(message->Size() / 4);
-
-  int64_t iNow = GetTimeMs();
-  int64_t iTargetTime = iNow + message->transmit_timeout;
-
-  while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
-  {
-    CCECAdapterMessage msg;
-
-    if (!m_communication->Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
-    {
-      iNow = GetTimeMs();
-      continue;
-    }
-
-    if (msg.Message() == MSGCODE_FRAME_START && msg.IsACK())
-    {
-      m_busDevices[msg.Initiator()]->GetHandler()->HandlePoll(msg.Initiator(), msg.Destination());
-      m_lastInitiator = msg.Initiator();
-      iNow = GetTimeMs();
-      continue;
-    }
-
-    bError = msg.IsError();
-    if (msg.Message() == MSGCODE_RECEIVE_FAILED &&
-        m_lastInitiator != CECDEVICE_UNKNOWN &&
-        !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed())
-    {
-      iNow = GetTimeMs();
-      continue;
-    }
-
-    if (bError)
-    {
-      message->reply = msg.Message();
-      m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
-    }
-    else
-    {
-      switch(msg.Message())
-      {
-      case MSGCODE_COMMAND_ACCEPTED:
-        m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
-        if (iPacketsLeft > 0)
-          iPacketsLeft--;
-        break;
-      case MSGCODE_TRANSMIT_SUCCEEDED:
-        m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
-        bTransmitSucceeded = (iPacketsLeft == 0);
-        bError = !bTransmitSucceeded;
-        message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
-        break;
-      default:
-        // ignore other data while waiting
-        break;
-      }
-
-      iNow = GetTimeMs();
-    }
-  }
-
-  return bTransmitSucceeded && !bError;
-}
-
 bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
 {
   bool bEom(false);
@@ -1533,3 +1465,15 @@ bool CCECProcessor::PingAdapter(void)
 {
   return m_communication->PingAdapter();
 }
+
+void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
+{
+  m_busDevices[initiator]->GetHandler()->HandlePoll(initiator, destination);
+  m_lastInitiator = initiator;
+}
+
+bool CCECProcessor::HandleReceiveFailed(void)
+{
+  return m_lastInitiator != CECDEVICE_UNKNOWN &&
+      !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
+}
index 55286f8065a239d233047cf311adbe45bf50cf66..82ea16f0fb441141d32089c04b9be169c4b7bb3d 100644 (file)
@@ -129,6 +129,8 @@ namespace CEC
 
       virtual bool StartBootloader(void);
       virtual bool PingAdapter(void);
+      virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
+      virtual bool HandleReceiveFailed(void);
 
       CCECBusDevice *  m_busDevices[16];
       PLATFORM::CMutex m_transmitMutex;
@@ -148,7 +150,6 @@ namespace CEC
       bool FindLogicalAddressAudioSystem(void);
 
       void LogOutput(const cec_command &data);
-      bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
       bool ParseMessage(const CCECAdapterMessage &msg);
       void ParseCommand(cec_command &command);
 
index 4a136ab113f4bef0a8e1fcdd83b19506d49f7eb1..a792a1d77071de9c9cb80cd3b395a429a69a605e 100644 (file)
@@ -275,6 +275,72 @@ bool CAdapterCommunication::IsOpen(void)
   return !IsStopped() && m_port->IsOpen() && IsRunning();
 }
 
+bool CAdapterCommunication::WaitForTransmitSucceeded(CCECAdapterMessage *message)
+{
+  bool bError(false);
+  bool bTransmitSucceeded(false);
+  uint8_t iPacketsLeft(message->Size() / 4);
+
+  int64_t iNow = GetTimeMs();
+  int64_t iTargetTime = iNow + message->transmit_timeout;
+
+  while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
+  {
+    CCECAdapterMessage msg;
+
+    if (!Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
+    {
+      iNow = GetTimeMs();
+      continue;
+    }
+
+    if (msg.Message() == MSGCODE_FRAME_START && msg.IsACK())
+    {
+      m_processor->HandlePoll(msg.Initiator(), msg.Destination());
+      iNow = GetTimeMs();
+      continue;
+    }
+
+    if (msg.Message() == MSGCODE_RECEIVE_FAILED &&
+        m_processor->HandleReceiveFailed())
+    {
+      iNow = GetTimeMs();
+      continue;
+    }
+
+    bError = msg.IsError();
+    if (bError)
+    {
+      message->reply = msg.Message();
+      m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString());
+    }
+    else
+    {
+      switch(msg.Message())
+      {
+      case MSGCODE_COMMAND_ACCEPTED:
+        m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString());
+        if (iPacketsLeft > 0)
+          iPacketsLeft--;
+        break;
+      case MSGCODE_TRANSMIT_SUCCEEDED:
+        m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString());
+        bTransmitSucceeded = (iPacketsLeft == 0);
+        bError = !bTransmitSucceeded;
+        message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
+        break;
+      default:
+        // ignore other data while waiting
+        break;
+      }
+
+      iNow = GetTimeMs();
+    }
+  }
+
+  return bTransmitSucceeded && !bError;
+}
+
 void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
 {
   CLockObject lock(m_mutex);
index 4367e4025e9f79a3ae87768d6e2c0df156fbc582..51734e16e523e9ef2dee562ed4b88f132284cc58 100644 (file)
@@ -63,6 +63,8 @@ namespace CEC
     bool SetLineTimeout(uint8_t iTimeout);
     bool StartBootloader(void);
 
+    bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
+
   private:
     void SendMessageToAdapter(CCECAdapterMessage *msg);
     void WriteNextCommand(void);