cec: show the build date for firmwares that have this command
[deb_libcec.git] / src / lib / adapter / AdapterCommunication.h
index 98f55e61588911ad5c70c1f3da2b6cb1d188db27..db0fbe6cc4e72f1cc3c4a915ddd3a37e111ee50e 100644 (file)
  */
 
 #include "../platform/util/StdString.h"
+#include "USBCECAdapterMessage.h"
 
 namespace CEC
 {
-  typedef enum cec_adapter_message_state
-  {
-    ADAPTER_MESSAGE_STATE_UNKNOWN = 0,          /**< the initial state */
-    ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT,   /**< waiting in the send queue of the adapter, or timed out */
-    ADAPTER_MESSAGE_STATE_SENT,                 /**< sent and waiting on an ACK */
-    ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED,       /**< sent, but failed to ACK */
-    ADAPTER_MESSAGE_STATE_SENT_ACKED,           /**< sent, and ACK received */
-    ADAPTER_MESSAGE_STATE_INCOMING,             /**< received from another device */
-    ADAPTER_MESSAGE_STATE_ERROR                 /**< an error occured */
-  } cec_adapter_message_state;
-
   class IAdapterCommunicationCallback
   {
   public:
@@ -58,23 +48,40 @@ namespace CEC
      * @return True when it was handled by this listener, false otherwise.
      */
     virtual bool OnCommandReceived(const cec_command &command) = 0;
+
+    /*!
+     * @brief Callback method for IAdapterCommunication, called when a poll was received.
+     * @param initiator The initiator that sent the poll.
+     * @param destination The destination of the poll message.
+     */
+    virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination) = 0;
+
+    /*!
+     * @brief Callback method for IAdapterCommunication, called when a receive failed message was received.
+     * @param initiator The initiator that sent the receive failed message.
+     * @return True when this is an error, false otherwise.
+     */
+    virtual bool HandleReceiveFailed(cec_logical_address initiator) = 0;
   };
 
   class IAdapterCommunication
   {
   public:
-    IAdapterCommunication(void) {}
+    /*!
+     * @param callback The callback struct. if set to NULL, the Read() method has to be used to read commands. if set, OnCommandReceived() will be called for each command that was received
+     */
+    IAdapterCommunication(IAdapterCommunicationCallback *callback) :
+      m_callback(callback) {}
     virtual ~IAdapterCommunication(void) {}
 
     /*!
      * @brief Open a connection to the CEC adapter
-     * @param cb The callback struct. if set to NULL, the Read() method has to be used to read commands. if set, OnCommandReceived() will be called for each command that was received
      * @param iTimeoutMs Connection timeout in ms
      * @param bSkipChecks Skips all initial checks of the adapter, and starts the reader/writer threads directly after connecting.
      * @param bStartListening Start a listener thread when true. False to just open a connection, read the device info, and close the connection.
      * @return True when connected, false otherwise
      */
-    virtual bool Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true) = 0;
+    virtual bool Open(uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true) = 0;
 
     /*!
      * @brief Close an open connection
@@ -91,23 +98,14 @@ namespace CEC
      */
     virtual CStdString GetError(void) const = 0;
 
-    /*!
-     * @brief Reads one cec_command from the adapter
-     * @param command The command that will be read (output)
-     * @param iTimeout The read timeout
-     * @return True when a command has been read, false otherwise.
-     */
-    virtual bool Read(cec_command &command, uint32_t iTimeout) = 0;
-
     /*!
      * @brief Write a cec_command to the adapter
      * @param data The command to write
-     * @param iMaxTries The maximum number of tries
-     * @param iLineTimeout The line timeout for the first try
-     * @param iRetryLineTimeout The line timeout for each next try
+     * @param bRetry The command can be retried
+     * @param iLineTimeout The line timeout to be used
      * @return The last state of the transmitted command
      */
-    virtual cec_adapter_message_state Write(const cec_command &data, uint8_t iMaxTries, uint8_t iLineTimeout = 3, uint8_t iRetryLineTimeout = 3) = 0;
+    virtual cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout = 3) = 0;
 
     /*!
      * @brief Change the current line timeout on the CEC bus
@@ -140,6 +138,11 @@ namespace CEC
      */
     virtual uint16_t GetFirmwareVersion(void) = 0;
 
+    /*!
+     * @return The build date in seconds since epoch, or 0 when no (valid) reply was received.
+     */
+    virtual uint32_t GetFirmwareBuildDate(void) = 0;
+
     /*!
      * @return True when the control mode has been set, false otherwise.
      */
@@ -168,5 +171,8 @@ namespace CEC
      * @return The physical address, if the adapter supports this. 0 otherwise.
      */
     virtual uint16_t GetPhysicalAddress(void) = 0;
+
+  protected:
+    IAdapterCommunicationCallback *m_callback;
   };
 };