Persist zone object properties option

Add functions to set and get persisted properties on a zone by the
interface and property name. When a property exists, it is persisted
each time it is updated.

Tested:
    Current property is added and persisted.
    When Current property not added, it is not persisted.

Change-Id: I2540c3673affcda871c9342cad44e85a4510d756
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/zone.cpp b/control/zone.cpp
index 6efbe73..fddca53 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -638,6 +638,25 @@
     return empty;
 }
 
+auto Zone::getPersisted(const std::string& intf,
+                        const std::string& prop)
+{
+    auto persisted = false;
+
+    auto it = _persisted.find(intf);
+    if (it != _persisted.end())
+    {
+        return std::any_of(it->second.begin(),
+                           it->second.end(),
+                           [&prop](auto& p)
+                           {
+                               return prop == p;
+                           });
+    }
+
+    return persisted;
+}
+
 std::string Zone::current(std::string value)
 {
     auto current = ThermalObject::current();
@@ -656,7 +675,10 @@
     if (value != current && isSupported)
     {
         current = ThermalObject::current(value);
-        saveCurrentMode();
+        if (getPersisted("xyz.openbmc_project.Control.ThermalMode", "Current"))
+        {
+            saveCurrentMode();
+        }
         // Trigger event(s) for current mode property change
         auto eData = _objects[_path]
                              ["xyz.openbmc_project.Control.ThermalMode"]
diff --git a/control/zone.hpp b/control/zone.hpp
index 2633902..6da3091 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -470,6 +470,29 @@
                                        int32_t depth);
 
         /**
+         * @brief Set a property to be persisted
+         *
+         * @param[in] intf - Interface containing property
+         * @param[in] prop - Property to be persisted
+         */
+        inline void setPersisted(const std::string& intf,
+                                 const std::string& prop)
+        {
+            _persisted[intf].emplace_back(prop);
+        }
+
+        /**
+         * @brief Get persisted property
+         *
+         * @param[in] intf - Interface containing property
+         * @param[in] prop - Property persisted
+         *
+         * @return - True if property is to be persisted, false otherwise
+         */
+        auto getPersisted(const std::string& intf,
+                          const std::string& prop);
+
+        /**
          * @brief Get a property value from the zone object or the bus when
          * the property requested is not on the zone object
          *
@@ -653,6 +676,11 @@
                                    EventData*>>> _objects;
 
         /**
+         * @brief Map of interfaces to persisted properties
+         */
+        std::map<std::string, std::vector<std::string>> _persisted;
+
+        /**
          * @brief Map of active fan control allowed by groups
          */
         std::map<const Group, bool> _active;