added protection against standby without a notification from XBMC and clock changes...
[deb_libcec.git] / src / lib / CECProcessor.h
index 48154fe9842de770fe692dbe73789bf313e7f970..44f1fc170bf1d22d674e7d057c44fa4024b5afb6 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.
@@ -32,7 +32,6 @@
  */
 
 #include <string>
-#include "../../include/cectypes.h"
 
 #include "platform/threads/threads.h"
 #include "platform/util/buffer.h"
@@ -52,6 +51,19 @@ namespace CEC
   class CCECTuner;
   class CCECTV;
   class CCECClient;
+  class CCECProcessor;
+  class CCECStandbyProtection;
+
+  class CCECAllocateLogicalAddress : public PLATFORM::CThread
+  {
+  public:
+    CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client);
+    void* Process(void);
+
+  private:
+    CCECProcessor* m_processor;
+    CCECClient*    m_client;
+  };
 
   class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback
   {
@@ -64,14 +76,16 @@ namespace CEC
       void Close(void);
 
       bool RegisterClient(CCECClient *client);
-      void UnregisterClient(CCECClient *client);
+      bool UnregisterClient(CCECClient *client);
       void UnregisterClients(void);
+      uint16_t GetPhysicalAddressFromEeprom(void);
       CCECClient *GetPrimaryClient(void);
       CCECClient *GetClient(const cec_logical_address address);
 
       bool                  OnCommandReceived(const cec_command &command);
+      void                  HandleLogicalAddressLost(cec_logical_address oldAddress);
+      void                  HandlePhysicalAddressChanged(uint16_t iNewAddress);
 
-      bool                  IsMonitoring(void) const { return m_bMonitor; }
       CCECBusDevice *       GetDevice(cec_logical_address address) const;
       CCECAudioSystem *     GetAudioSystem(void) const;
       CCECPlaybackDevice *  GetPlaybackDevice(cec_logical_address address) const;
@@ -80,9 +94,9 @@ namespace CEC
       CCECTV *              GetTV(void) const;
 
       CCECBusDevice *       GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true);
-      CCECBusDevice *       GetPrimaryDevice(void) const;
-      cec_logical_address   GetLogicalAddress(void) const;
-      cec_logical_addresses GetLogicalAddresses(void) const;
+      CCECBusDevice *       GetPrimaryDevice(void);
+      cec_logical_address   GetLogicalAddress(void);
+      cec_logical_addresses GetLogicalAddresses(void);
       bool                  IsPresentDevice(cec_logical_address address);
       bool                  IsPresentDeviceType(cec_device_type type);
       uint16_t              GetDetectedPhysicalAddress(void) const;
@@ -90,7 +104,6 @@ namespace CEC
       cec_logical_address   GetActiveSource(bool bRequestActiveSource = true);
       bool                  IsActiveSource(cec_logical_address iAddress);
       bool                  CECInitialised(void);
-      bool                  SetStreamPath(uint16_t iPhysicalAddress);
 
       bool                  StandbyDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices);
       bool                  StandbyDevice(const cec_logical_address initiator, cec_logical_address address);
@@ -98,18 +111,20 @@ namespace CEC
       bool                  PowerOnDevice(const cec_logical_address initiator, cec_logical_address address);
 
       bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
-      bool SetActiveSource(uint16_t iStreamPath);
-      bool SwitchMonitoring(bool bEnable);
+      bool ActivateSource(uint16_t iStreamPath);
+      void SetActiveSource(bool bSetTo, bool bClientUnregistered);
       bool PollDevice(cec_logical_address iAddress);
       void SetStandardLineTimeout(uint8_t iTimeout);
+      uint8_t GetStandardLineTimeout(void);
       void SetRetryLineTimeout(uint8_t iTimeout);
+      uint8_t GetRetryLineTimeout(void);
       bool CanPersistConfiguration(void);
-      bool PersistConfiguration(libcec_configuration *configuration);
+      bool PersistConfiguration(const libcec_configuration &configuration);
       void RescanActiveDevices(void);
 
       bool SetLineTimeout(uint8_t iTimeout);
 
-      bool Transmit(const cec_command &data);
+      bool Transmit(const cec_command &data, bool bIsReply);
       void TransmitAbort(cec_logical_address source, cec_logical_address destination, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
 
       bool StartBootloader(const char *strPort = NULL);
@@ -126,29 +141,54 @@ namespace CEC
 
       bool IsHandledByLibCEC(const cec_logical_address address) const;
 
-      bool TryLogicalAddress(cec_logical_address address);
-  private:
+      bool TryLogicalAddress(cec_logical_address address, cec_version libCECSpecVersion = CEC_VERSION_1_4);
+
+      bool IsRunningLatestFirmware(void);
+      void SwitchMonitoring(bool bSwitchTo);
+
+      bool AllocateLogicalAddresses(CCECClient* client);
+
+      uint16_t GetAdapterVendorId(void) const;
+      uint16_t GetAdapterProductId(void) const;
+    private:
       bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true);
       void SetCECInitialised(bool bSetTo = true);
 
       void ReplaceHandlers(void);
       bool PhysicalAddressInUse(uint16_t iPhysicalAddress);
-      bool SetAckMask(uint16_t iMask);
+
+      bool ClearLogicalAddresses(void);
+      bool SetLogicalAddresses(const cec_logical_addresses &addresses);
 
       void LogOutput(const cec_command &data);
-      void ParseCommand(const cec_command &command);
+      void ProcessCommand(const cec_command &command);
+
+      void ResetMembers(void);
 
       bool                                        m_bInitialised;
       PLATFORM::CMutex                            m_mutex;
       IAdapterCommunication *                     m_communication;
       CLibCEC*                                    m_libcec;
-      bool                                        m_bMonitor;
-      uint16_t                                    m_iPreviousAckMask;
       uint8_t                                     m_iStandardLineTimeout;
       uint8_t                                     m_iRetryLineTimeout;
       uint64_t                                    m_iLastTransmission;
       CCECInputBuffer                             m_inBuffer;
       CCECDeviceMap *                             m_busDevices;
       std::map<cec_logical_address, CCECClient *> m_clients;
+      bool                                        m_bMonitor;
+      CCECAllocateLogicalAddress*                 m_addrAllocator;
+      bool                                        m_bStallCommunication;
+      CCECStandbyProtection*                      m_connCheck;
+  };
+
+  class CCECStandbyProtection : public PLATFORM::CThread
+  {
+  public:
+    CCECStandbyProtection(CCECProcessor* processor);
+    virtual ~CCECStandbyProtection(void);
+    void* Process(void);
+
+  private:
+    CCECProcessor* m_processor;
   };
 };