Save properties to persistent storage when host is on

1. When host is on, set properties as requested properties instead
of notify listeners;
2. When host becomes off, and requested properties are not empty, notify
the listners and reset the requested properties.

Add unit tests.

Change-Id: I9359c801c698df0c6e5eab43e12427bb5a6da611
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/manager.hpp b/manager.hpp
index ef3315f..7edb30f 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -24,6 +24,7 @@
 {
     public:
         friend class TestManager;
+
         explicit Manager(sdbusplus::bus::bus& bus);
         Manager(const Manager&) = delete;
         Manager& operator=(const Manager&) = delete;
@@ -51,12 +52,21 @@
         /** @brief The value to indicate if host is on */
         bool hostOn = false;
 
+        /** @brief The requested time mode when host is on*/
+        std::string requestedMode;
+
+        /** @brief The requested time owner when host is on*/
+        std::string requestedOwner;
+
         /** @brief The current time mode */
         Mode timeMode;
 
         /** @brief The current time owner */
         Owner timeOwner;
 
+        /** @brief Restore saved settings */
+        void restoreSettings();
+
         /** @brief Check if host is on and update hostOn variable */
         void checkHostOn();
 
@@ -94,6 +104,28 @@
          */
         void onPgoodChanged(bool pgood);
 
+        /** @brief Set the property as requested time mode/owner
+         *
+         * @param[in] key - The property name
+         * @param[in] value - The property value
+         */
+        void setPropertyAsRequested(const std::string& key,
+                                    const std::string& value);
+
+        /** @brief Set the current mode to user requested one
+         *  if conditions allow it
+         *
+         * @param[in] mode - The string of time mode
+         */
+        void setRequestedMode(const std::string& mode);
+
+        /** @brief Set the current owner to user requested one
+         *  if conditions allow it
+         *
+         * @param[in] owner - The string of time owner
+         */
+        void setRequestedOwner(const std::string& owner);
+
         /** @brief The static function called on settings property changed
          *
          * @param[in] msg - Data associated with subscribed signal
@@ -138,6 +170,12 @@
          */
         static Owner convertToOwner(const std::string& owner);
 
+        /** @brief The string of time mode property */
+        static constexpr auto PROPERTY_TIME_MODE = "time_mode";
+
+        /** @brief The string of time owner property */
+        static constexpr auto PROPERTY_TIME_OWNER = "time_owner";
+
         using Updater = std::function<void(const std::string&)>;
 
         /** @brief Map the property string to functions that shall
@@ -145,10 +183,10 @@
          */
         const std::map<std::string, Updater> propertyUpdaters =
         {
-            {"time_mode", std::bind(&Manager::setCurrentTimeMode,
-                                    this, std::placeholders::_1)},
-            {"time_owner", std::bind(&Manager::setCurrentTimeOwner,
-                                     this, std::placeholders::_1)}
+            {PROPERTY_TIME_MODE, std::bind(&Manager::setCurrentTimeMode,
+                                           this, std::placeholders::_1)},
+            {PROPERTY_TIME_OWNER, std::bind(&Manager::setCurrentTimeOwner,
+                                            this, std::placeholders::_1)}
         };
 
         /** @brief The properties that manager shall notify the
@@ -158,6 +196,12 @@
 
         /** @brief The map that maps the string to Owners */
         static const std::map<std::string, Owner> ownerMap;
+
+        /** @brief The file name of saved time mode */
+        static constexpr auto modeFile = "/var/lib/obmc/saved_time_mode";
+
+        /** @brief The file name of saved time owner */
+        static constexpr auto ownerFile = "/var/lib/obmc/saved_time_owner";
 };
 
 }