control: remove NaN from D-Bus properties

When sensors are offline, its possible for some driver parameters to
appear as NaN. These values are prevented from being stored in fan
control and are removed if they are detected in the cache.

Signed-off-by: Mike Capps <mikepcapps@gmail.com>
Change-Id: I22aa0c551faffdfc83eb1992b1242ac477d08180
diff --git a/control/json/manager.hpp b/control/json/manager.hpp
index 23dda2b..a11bc5e 100644
--- a/control/json/manager.hpp
+++ b/control/json/manager.hpp
@@ -114,6 +114,20 @@
                               std::unique_ptr<sdbusplus::bus::match_t>>;
 
 /**
+ * Package of data from a D-Bus call to get managed objects
+ * Tuple constructed of:
+ *     std::map<Path,            // D-Bus Path
+ *       std::map<Intf,          // D-Bus Interface
+ *         std::map<Property,    // D-Bus Property
+ *         std::variant>>>       // Variant value of that property
+ */
+using Path_v = sdbusplus::message::object_path;
+using Intf_v = std::string;
+using Prop_v = std::string;
+using ManagedObjects =
+    std::map<Path_v, std::map<Intf_v, std::map<Prop_v, PropertyVariantType>>>;
+
+/**
  * @class Manager - Represents the fan control manager's configuration
  *
  * A fan control manager configuration is optional, therefore the "manager.json"
@@ -339,10 +353,7 @@
      * @param[in] value - Dbus object's property value
      */
     void setProperty(const std::string& path, const std::string& intf,
-                     const std::string& prop, PropertyVariantType value)
-    {
-        _objects[path][intf][prop] = std::move(value);
-    }
+                     const std::string& prop, PropertyVariantType value);
 
     /**
      * @brief Remove an object's interface
@@ -488,6 +499,26 @@
     static const std::string dumpFile;
 
   private:
+    /**
+     * @brief Helper to detect when a property's double contains a NaN
+     * (not-a-number) value.
+     *
+     * @param[in] value - The property to test
+     */
+    static bool PropertyContainsNan(const PropertyVariantType& value)
+    {
+        return (std::holds_alternative<double>(value) &&
+                std::isnan(std::get<double>(value)));
+    }
+
+    /**
+     * @brief Insert managed objects into cache, but filter out properties
+     * containing unwanted NaN (not-a-number) values.
+     *
+     * @param[in] ref - The map of ManagedObjects to insert into cache
+     */
+    void insertFilteredObjects(ManagedObjects& ref);
+
     /* The sdbusplus bus object to use */
     sdbusplus::bus::bus& _bus;