cec: wait for messages to be transmitted before continueing in CCECProcessor::Transmit()
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 09:29:19 +0000 (10:29 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 09:29:19 +0000 (10:29 +0100)
src/lib/AdapterCommunication.cpp
src/lib/AdapterCommunication.h
src/lib/CECProcessor.cpp

index c05abdf8421f3d14d2a7d9a3d4cd3def70d66543..4845f57b97eed9e62edf52e3e07859cb866982cb 100644 (file)
@@ -215,6 +215,7 @@ void CAdapterCommunication::WriteNextCommand(void)
   CCECAdapterMessagePtr msg;
   if (m_outBuffer.Pop(msg))
   {
+    CLockObject lock(&msg->mutex);
     if (m_port->Write(msg) != (int32_t) msg.get()->size())
     {
       CStdString strError;
@@ -226,6 +227,7 @@ void CAdapterCommunication::WriteNextCommand(void)
       m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
       CCondition::Sleep((uint32_t) msg.get()->size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/);
     }
+    msg->condition.Signal();
   }
 }
 
index 5e099d8d69d41b1ef8f115dcc14294b494d8f505..a82f32c673b42d5775b678bed909d3fbba432c38 100644 (file)
@@ -61,6 +61,8 @@ namespace CEC
     void                    push_escaped(int16_t byte);
 
     cec_datapacket packet;
+    CMutex         mutex;
+    CCondition     condition;
 
   private:
     CCECAdapterMessage &operator =(const CCECAdapterMessage &msg);
index 54794c343853a2727d27cd50a56098d439e2bb7f..350958f41d1b1f9342d53731d6c1062d0bb1c934 100644 (file)
@@ -195,8 +195,13 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true
   CCECAdapterMessagePtr output(new CCECAdapterMessage(data));
 
   CLockObject lock(&m_mutex);
-  if (!m_communication || !m_communication->Write(output))
-    return bReturn;
+  {
+    CLockObject msgLock(&output->mutex);
+    if (!m_communication || !m_communication->Write(output))
+      return bReturn;
+    else
+      output->condition.Wait(&output->mutex);
+  }
 
   if (bWaitForAck)
   {