cec: abi fixes (binary compat with v1.2)
[deb_libcec.git] / src / lib / adapter / USBCECAdapterMessageQueue.h
index 5163090b6e33676aa231c8222ba5e0f7fd747569..44c930be3cd7efcc84001506ac8c9943655222dd 100644 (file)
  */
 
 #include "USBCECAdapterMessage.h"
+#include "../platform/threads/threads.h"
+#include <map>
 
 namespace CEC
 {
   class CUSBCECAdapterCommunication;
+  class CCECAdapterMessageQueue;
 
   class CCECAdapterMessageQueueEntry
   {
   public:
-    CCECAdapterMessageQueueEntry(CCECAdapterMessage *message);
+    CCECAdapterMessageQueueEntry(CCECAdapterMessageQueue *queue, CCECAdapterMessage *message);
     virtual ~CCECAdapterMessageQueueEntry(void);
 
     /*!
@@ -84,28 +87,33 @@ namespace CEC
      */
     const char *ToString(void) const;
 
-  private:
     /*!
      * @brief Called when a 'command accepted' message was received.
      * @param message The message that was received.
-     * @return True when the waiting thread need to be signaled, false otherwise.
+     * @return True when the message was handled, false otherwise.
      */
     bool MessageReceivedCommandAccepted(const CCECAdapterMessage &message);
 
     /*!
      * @brief Called when a 'transmit succeeded' message was received.
      * @param message The message that was received.
-     * @return True when the waiting thread need to be signaled, false otherwise.
+     * @return True when the message was handled, false otherwise.
      */
     bool MessageReceivedTransmitSucceeded(const CCECAdapterMessage &message);
 
     /*!
      * @brief Called when a message that's not a 'command accepted' or 'transmit succeeded' message was received.
      * @param message The message that was received.
-     * @return True when the waiting thread need to be signaled, false otherwise.
+     * @return True when the message was handled, false otherwise.
      */
     bool MessageReceivedResponse(const CCECAdapterMessage &message);
 
+    /*!
+     * @brief Signals the waiting thread.
+     */
+    void Signal(void);
+
+    CCECAdapterMessageQueue *  m_queue;
     CCECAdapterMessage *       m_message;      /**< the message that was sent */
     uint8_t                    m_iPacketsLeft; /**< the amount of acks that we're waiting on */
     bool                       m_bSucceeded;   /**< true when the command received a response, false otherwise */
@@ -114,9 +122,10 @@ namespace CEC
     PLATFORM::CMutex           m_mutex;        /**< mutex for changes to this class */
   };
 
-  class CCECAdapterMessageQueue
+  class CCECAdapterMessageQueue : public PLATFORM::CThread
   {
     friend class CUSBCECAdapterCommunication;
+    friend class CCECAdapterMessageQueueEntry;
 
   public:
     /*!
@@ -124,9 +133,14 @@ namespace CEC
      * @param com The communication handler callback to use.
      * @param iQueueSize The outgoing message queue size.
      */
-    CCECAdapterMessageQueue(CUSBCECAdapterCommunication *com, size_t iQueueSize = 64) :
+    CCECAdapterMessageQueue(CUSBCECAdapterCommunication *com) :
+      PLATFORM::CThread(),
       m_com(com),
-      m_messages(iQueueSize) {}
+      m_iNextMessage(0)
+    {
+      m_currentCECFrame.Clear();
+    }
+
     virtual ~CCECAdapterMessageQueue(void);
 
     /*!
@@ -154,15 +168,14 @@ namespace CEC
      */
     bool Write(CCECAdapterMessage *msg);
 
-  private:
-    /*!
-     * @return The next message in the queue, or NULL if there is none.
-     */
-    CCECAdapterMessageQueueEntry *GetNextQueuedEntry(void);
+    virtual void *Process(void);
 
+  private:
     CUSBCECAdapterCommunication *                          m_com;                    /**< the communication handler */
     PLATFORM::CMutex                                       m_mutex;                  /**< mutex for changes to this class */
-    PLATFORM::SyncedBuffer<CCECAdapterMessageQueueEntry *> m_messages;               /**< the outgoing message queue */
+    std::map<uint64_t, CCECAdapterMessageQueueEntry *>     m_messages;               /**< the outgoing message queue */
+    PLATFORM::SyncedBuffer<CCECAdapterMessageQueueEntry *> m_writeQueue;             /**< the queue for messages that are to be written */
+    uint64_t                                               m_iNextMessage;           /**< the index of the next message */
     CCECAdapterMessage                                     m_incomingAdapterMessage; /**< the current incoming message that's being assembled */
     cec_command                                            m_currentCECFrame;        /**< the current incoming CEC command that's being assembled */
   };