cec: persist settings directly when they're changed, only persist settings that actua...
[deb_libcec.git] / src / lib / adapter / USBCECAdapterCommands.h
index b5f12fb7a1f3ccf92da6a04c76434ffe81c05b9d..b88651e11619dfe5456074d43010f04853ceaf19 100644 (file)
@@ -38,9 +38,7 @@ namespace CEC
   class CUSBCECAdapterCommands
   {
   public:
-    CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) :
-      m_comm(comm),
-      m_iFirmwareVersion(CEC_FW_VERSION_UNKNOWN) {}
+    CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm);
 
     /*!
      * @brief Request the firmware version from the adapter.
@@ -48,6 +46,67 @@ namespace CEC
      */
     uint16_t RequestFirmwareVersion(void);
 
+    /*!
+     * @return The firmware version of the adapter, retrieved when the connection is opened.
+     */
+    uint16_t GetFirmwareVersion(void) const { return m_persistedConfiguration.iFirmwareVersion; };
+
+    /*!
+     * @brief Persist the current configuration in the EEPROM.
+     * @attention Not all settings are persisted at this time.
+     * @param configuration The configuration to persist.
+     * @return True when persisted, false otherwise.
+     */
+    bool PersistConfiguration(libcec_configuration *configuration);
+
+    /*!
+     * @brief Get the persisted configuration from the EEPROM.
+     * @param configuration The persisted configuration.
+     * @return True when retrieved, false otherwise.
+     */
+    bool GetConfiguration(libcec_configuration *configuration);
+
+    /*!
+     * @brief Send a ping command to the adapter.
+     * @return True when acked by the adapter, false otherwise.
+     */
+    bool PingAdapter(void);
+
+    /*!
+     * @brief Change the ackmask of the adapter.
+     * @param iMask The new mask.
+     * @return True when the change was acked by the adapter, false otherwise.
+     */
+    bool SetAckMask(uint16_t iMask);
+
+    /*!
+     * @brief Put the adapter in bootloader mode.
+     * @attention The connection needs to be closed after this call, since the adapter will no longer be available.
+     * @return True when the command was sent, false otherwise.
+     */
+    bool StartBootloader(void);
+
+    /*!
+     * @brief Change the current CEC line timeout.
+     * @param iTimeout The new timeout.
+     * @return True when the change was acked by the adapter, false otherwise.
+     */
+    bool SetLineTimeout(uint8_t iTimeout);
+
+    /*!
+     * @brief Put the adapter in controlled or autonomous mode.
+     * @param controlled True to switch to controlled mode, false to switch to auto mode.
+     * @return True when acked by the controller, false otherwise.
+     */
+    bool SetControlledMode(bool controlled);
+
+  private:
+    /*!
+     * @brief Reads all settings from the eeprom.
+     * @return True when read, false otherwise.
+     */
+    bool RequestSettings(void);
+
     /*!
      * @brief Request a setting value from the adapter.
      * @param msgCode The setting to retrieve.
@@ -64,10 +123,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "auto enabled" setting from the adapter.
-     * @param enabled The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingAutoEnabled(bool &enabled);
+    bool RequestSettingAutoEnabled(void);
 
     /*!
      * @brief Change the value of the "device type" setting, used when the device is in autonomous mode.
@@ -78,10 +136,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "device type" setting from the adapter.
-     * @param type The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingDeviceType(cec_device_type &type);
+    bool RequestSettingDeviceType(void);
 
     /*!
      * @brief Change the value of the "default logical address" setting, used when the device is in autonomous mode.
@@ -92,10 +149,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "default logical address" setting from the adapter.
-     * @param address The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingDefaultLogicalAddress(cec_logical_address &address);
+    bool RequestSettingDefaultLogicalAddress(void);
 
     /*!
      * @brief Change the value of the "logical address mask" setting, used when the device is in autonomous mode.
@@ -106,10 +162,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "logical address mask" setting from the adapter.
-     * @param iMask The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingLogicalAddressMask(uint16_t &iMask);
+    bool RequestSettingLogicalAddressMask(void);
 
     /*!
      * @brief Change the value of the "physical address" setting, used when the device is in autonomous mode.
@@ -120,10 +175,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "physical address" setting from the adapter.
-     * @param iPhysicalAddress The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingPhysicalAddress(uint16_t &iPhysicalAddress);
+    bool RequestSettingPhysicalAddress(void);
 
     /*!
      * @brief Change the value of the "CEC version" setting, used when the device is in autonomous mode.
@@ -134,10 +188,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "CEC version" setting from the adapter.
-     * @param version The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingCECVersion(cec_version &version);
+    bool RequestSettingCECVersion(void);
 
     /*!
      * @brief Change the value of the "OSD name" setting, used when the device is in autonomous mode.
@@ -148,10 +201,9 @@ namespace CEC
 
     /*!
      * @brief Request the value of the "OSD name" setting from the adapter.
-     * @param strOSDName The current value.
      * @return True when retrieved, false otherwise.
      */
-    bool RequestSettingOSDName(CStdString &strOSDName);
+    bool RequestSettingOSDName(void);
 
     /*!
      * @brief Persist the current settings in the EEPROM
@@ -159,62 +211,12 @@ namespace CEC
      */
     bool WriteEEPROM(void);
 
-    /*!
-     * @return The firmware version of the adapter, retrieved when the connection is opened.
-     */
-    uint16_t GetFirmwareVersion(void) const { return m_iFirmwareVersion; };
-
-    /*!
-     * @brief Persist the current configuration in the EEPROM.
-     * @attention Not all settings are persisted at this time.
-     * @param configuration The configuration to persist.
-     * @return True when persisted, false otherwise.
-     */
-    bool PersistConfiguration(libcec_configuration *configuration);
-
-    /*!
-     * @brief Get the persisted configuration from the EEPROM.
-     * @param configuration The persisted configuration.
-     * @return True when retrieved, false otherwise.
-     */
-    bool GetConfiguration(libcec_configuration *configuration);
-
-    /*!
-     * @brief Send a ping command to the adapter.
-     * @return True when acked by the adapter, false otherwise.
-     */
-    bool PingAdapter(void);
-
-    /*!
-     * @brief Change the ackmask of the adapter.
-     * @param iMask The new mask.
-     * @return True when the change was acked by the adapter, false otherwise.
-     */
-    bool SetAckMask(uint16_t iMask);
-
-    /*!
-     * @brief Put the adapter in bootloader mode.
-     * @attention The connection needs to be closed after this call, since the adapter will no longer be available.
-     * @return True when the command was sent, false otherwise.
-     */
-    bool StartBootloader(void);
-
-    /*!
-     * @brief Change the current CEC line timeout.
-     * @param iTimeout The new timeout.
-     * @return True when the change was acked by the adapter, false otherwise.
-     */
-    bool SetLineTimeout(uint8_t iTimeout);
-
-    /*!
-     * @brief Put the adapter in controlled or autonomous mode.
-     * @param controlled True to switch to controlled mode, false to switch to auto mode.
-     * @return True when acked by the controller, false otherwise.
-     */
-    bool SetControlledMode(bool controlled);
-
-  private:
-    CUSBCECAdapterCommunication *m_comm;             /**< the communication handler */
-    uint16_t                     m_iFirmwareVersion; /**< the firwmare version that was retrieved while opening the connection */
+    CUSBCECAdapterCommunication *m_comm;                   /**< the communication handler */
+    bool                         m_bSettingsRetrieved;     /**< true when the settings were read from the eeprom, false otherwise */
+    bool                         m_bSettingAutoEnabled;    /**< the value of the auto-enabled setting */
+    cec_version                  m_settingCecVersion;      /**< the value of the cec version setting */
+    uint16_t                     m_iSettingLAMask;         /**< the value of the LA mask setting */
+    bool                         m_bNeedsWrite;            /**< true when we sent changed settings to the adapter that have not been persisted */
+    libcec_configuration         m_persistedConfiguration; /**< the configuration that is persisted in the eeprom */
   };
 }