separate mutex for CUSBCECAdapterCommunication::MarkAsWaiting()
[deb_libcec.git] / src / lib / adapter / Pulse-Eight / USBCECAdapterCommunication.h
index a14b3a5d85b7f463b1459ae85a09a1b8a64985c6..bac9437917cd4d06d3437aac331cf7568a426991 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * This file is part of the libCEC(R) library.
  *
- * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited.  All rights reserved.
  * libCEC(R) is an original work, containing original code.
  *
  * libCEC(R) is a trademark of Pulse-Eight Limited.
@@ -33,6 +33,7 @@
 
 #include "lib/platform/threads/threads.h"
 #include "lib/adapter/AdapterCommunication.h"
+#include "USBCECAdapterMessage.h"
 
 namespace PLATFORM
 {
@@ -43,6 +44,7 @@ namespace CEC
 {
   class CCECProcessor;
   class CAdapterPingThread;
+  class CAdapterEepromWriteThread;
   class CUSBCECAdapterCommands;
   class CCECAdapterMessageQueue;
   class CCECAdapterMessage;
@@ -51,6 +53,7 @@ namespace CEC
   {
     friend class CUSBCECAdapterCommands;
     friend class CCECAdapterMessageQueue;
+    friend class CAdapterEepromWriteThread;
 
   public:
     /*!
@@ -84,8 +87,14 @@ namespace CEC
     bool SetControlledMode(bool controlled);
     cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }
     bool SupportsSourceLogicalAddress(const cec_logical_address UNUSED(address)) { return true; }
+    cec_adapter_type GetAdapterType(void);
+    uint16_t GetAdapterVendorId(void) const;
+    uint16_t GetAdapterProductId(void) const;
+    void SetActiveSource(bool bSetTo, bool bClientUnregistered);
     ///}
 
+    bool ProvidesExtendedResponse(void);
+
     void *Process(void);
 
   private:
@@ -169,11 +178,33 @@ namespace CEC
     bool                                         m_bInitialised;         /**< true when the connection is initialised, false otherwise */
     bool                                         m_bWaitingForAck[15];   /**< array in which we store from which devices we're expecting acks */
     CAdapterPingThread *                         m_pingThread;           /**< ping thread, that pings the adapter every 15 seconds */
+    CAdapterEepromWriteThread *                  m_eepromWriteThread;    /**< eeprom writes are done async */
     CUSBCECAdapterCommands *                     m_commands;             /**< commands that can be sent to the adapter */
     CCECAdapterMessageQueue *                    m_adapterMessageQueue;  /**< the incoming and outgoing message queue */
     cec_logical_addresses                        m_logicalAddresses;     /**< the logical address list that this instance is using */
-    uint64_t                                     m_iLastEepromWrite;     /**< last time that this instance did an eeprom write */
-    bool                                         m_iScheduleEepromWrite; /**< in case there were more than 2 changes within 30 seconds, do another write at this time */
+    PLATFORM::CMutex                             m_waitingMutex;
+  };
+
+  class CAdapterEepromWriteThread : public PLATFORM::CThread
+  {
+  public:
+    CAdapterEepromWriteThread(CUSBCECAdapterCommunication *com) :
+        m_com(com),
+        m_bWrite(false),
+        m_iLastEepromWrite(0),
+        m_iScheduleEepromWrite(0) {}
+    virtual ~CAdapterEepromWriteThread(void) {}
+
+    bool Write(void);
+    void* Process(void);
+    void Stop(void);
+  private:
+    CUSBCECAdapterCommunication *m_com;
+    bool                         m_bWrite;
+    PLATFORM::CCondition<bool>   m_condition;
+    PLATFORM::CMutex             m_mutex;
+    int64_t                      m_iLastEepromWrite;     /**< last time that this instance did an eeprom write */
+    int64_t                      m_iScheduleEepromWrite; /**< in case there were more than 2 changes within 30 seconds, do another write at this time */
   };
 
   class CAdapterPingThread : public PLATFORM::CThread
@@ -184,7 +215,7 @@ namespace CEC
         m_timeout(iTimeout){}
     virtual ~CAdapterPingThread(void) {}
 
-    virtual void* Process(void);
+    void* Process(void);
   private:
     CUSBCECAdapterCommunication *m_com;
     PLATFORM::CTimeout           m_timeout;