presence: Sensor generation framework

Add the framework necessary to construct the presence sensor specific to
the type of method needed for that type of sensor. This uses the method
type to index into a map of types-to-functions where the function will
return the pointer associated to the entry based on the method type.

Tested:
    Supported method types produce no error
    Unsupported method types throw exception

Change-Id: I7e583df5747561d14e124cb0762c1be0dcb8c187
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/json_config.hpp b/presence/json_config.hpp
index 2e7ad72..c41b8d5 100644
--- a/presence/json_config.hpp
+++ b/presence/json_config.hpp
@@ -8,6 +8,7 @@
 #include "config.h"
 #include "rpolicy.hpp"
 #include "fan.hpp"
+#include "psensor.hpp"
 
 namespace phosphor
 {
@@ -18,6 +19,9 @@
 
 using json = nlohmann::json;
 using policies = std::vector<std::unique_ptr<RedundancyPolicy>>;
+// Presence method handler function
+using methodHandler = std::function<
+    std::unique_ptr<PresenceSensor>(size_t, const json&)>;
 
 class JsonConfig
 {
@@ -53,6 +57,12 @@
         /* List of Fan objects to have presence policies */
         std::vector<Fan> _fans;
 
+        /* Presence methods mapping to their associated handler function */
+        static const std::map<std::string, methodHandler> _methods;
+
+        /* List of fan presence sensors */
+        std::vector<std::unique_ptr<PresenceSensor>> _sensors;
+
         /**
          * @brief Process the json config to extract the defined fan presence
          * policies.
@@ -62,6 +72,35 @@
         void process(const json& jsonConf);
 };
 
+/**
+ * Methods of fan presence detection function declarations
+ */
+namespace method
+{
+    /**
+     * @brief Fan presence detection method by tach feedback
+     *
+     * @param[in] fanIndex - fan object index to add tach method
+     * @param[in] method - json properties for a tach method
+     *
+     * @return - A presence sensor to detect fan presence by tach feedback
+     */
+    std::unique_ptr<PresenceSensor> getTach(size_t fanIndex,
+                                            const json& method);
+
+    /**
+     * @brief Fan presence detection method by gpio
+     *
+     * @param[in] fanIndex - fan object index to add gpio method
+     * @param[in] method - json properties for a gpio method
+     *
+     * @return - A presence sensor to detect fan presence by gpio
+     */
+    std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex,
+                                            const json& method);
+
+} // namespace method
+
 } // namespace presence
 } // namespace fan
 } // namespace phosphor