Merge branch 'master' into release
[deb_libcec.git] / src / lib / AdapterCommunication.h
index 29b716a078553fbb63cefa6cce57e7f67fd09d17..ef5e0aa7c2934c55649dcef5915b65130da3a52f 100644 (file)
 #include <cectypes.h>
 #include "platform/threads.h"
 #include "util/buffer.h"
+#include "util/StdString.h"
 #include <string>
 #include <boost/enable_shared_from_this.hpp>
 #include <boost/shared_ptr.hpp>
 
 namespace CEC
 {
+  typedef enum cec_adapter_message_state
+  {
+    ADAPTER_MESSAGE_STATE_UNKNOWN = 0,
+    ADAPTER_MESSAGE_STATE_WAITING,
+    ADAPTER_MESSAGE_STATE_SENT,
+    ADAPTER_MESSAGE_STATE_RECEIVED,
+    ADAPTER_MESSAGE_STATE_ERROR
+  } cec_adapter_message_state;
+
+
   class CCECAdapterMessage : public boost::enable_shared_from_this<CCECAdapterMessage>
   {
   public:
-    CCECAdapterMessage(void) {}
+    CCECAdapterMessage(void) { clear(); }
     CCECAdapterMessage(const cec_command &command);
     CCECAdapterMessage &operator =(const CCECAdapterMessage &msg);
+    CStdString ToString(void) const;
+    CStdString MessageCodeAsString(void) const;
 
     bool                    empty(void) const             { return packet.empty(); }
     uint8_t                 operator[](uint8_t pos) const { return packet[pos]; }
     uint8_t                 at(uint8_t pos) const         { return packet[pos]; }
     uint8_t                 size(void) const              { return packet.size; }
-    void                    clear(void)                   { packet.clear(); }
+    void                    clear(void)                   { state = ADAPTER_MESSAGE_STATE_UNKNOWN; transmit_timeout = 0; packet.clear(); }
     void                    shift(uint8_t iShiftBy)       { packet.shift(iShiftBy); }
     void                    push_back(uint8_t add)        { packet.push_back(add); }
     cec_adapter_messagecode message(void) const           { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.at(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK))  : MSGCODE_NOTHING; }
@@ -59,9 +72,14 @@ namespace CEC
     bool                    ack(void) const               { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_ACK) != 0 : false; }
     cec_logical_address     initiator(void) const         { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) >> 4)  : CECDEVICE_UNKNOWN; };
     cec_logical_address     destination(void) const       { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) & 0xF) : CECDEVICE_UNKNOWN; };
+    bool                    is_error(void) const;
     void                    push_escaped(int16_t byte);
 
-    cec_datapacket packet;
+    cec_datapacket            packet;
+    cec_adapter_message_state state;
+    int32_t                   transmit_timeout;
+    CMutex                    mutex;
+    CCondition                condition;
   };
   typedef boost::shared_ptr<CCECAdapterMessage> CCECAdapterMessagePtr;
 
@@ -85,7 +103,6 @@ namespace CEC
     void *Process(void);
 
     bool StartBootloader(void);
-    bool SetAckMask(uint16_t iMask);
 
   private:
     void WriteNextCommand(void);
@@ -98,5 +115,6 @@ namespace CEC
     CecBuffer<CCECAdapterMessagePtr> m_outBuffer;
     CMutex                           m_mutex;
     CCondition                       m_rcvCondition;
+    CCondition                       m_startCondition;
   };
 };