presence: Add JSON config class

Add a JSON config class that will be used to parse a given JSON config
file and generate the fan presence policies from that config.

Tested:
    N/A

Change-Id: Iac1703ea8d9e1e1d0d40e15a58145181d4f1a0f9
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/Makefile.am b/presence/Makefile.am
index 28412ee..6145699 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -11,7 +11,8 @@
 	gpio.cpp \
 	psensor.cpp \
 	tach.cpp \
-	tach_detect.cpp
+	tach_detect.cpp \
+	json_config.cpp
 
 phosphor_fan_presence_tach_LDADD = \
 	$(SDBUSPLUS_LIBS) \
diff --git a/presence/json_config.cpp b/presence/json_config.cpp
new file mode 100644
index 0000000..5bb7c3c
--- /dev/null
+++ b/presence/json_config.cpp
@@ -0,0 +1,41 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <string>
+
+#include "json_config.hpp"
+
+namespace phosphor
+{
+namespace fan
+{
+namespace presence
+{
+
+policies JsonConfig::_policies;
+
+JsonConfig::JsonConfig(const std::string& jsonFile)
+{
+
+}
+
+const policies& JsonConfig::get()
+{
+    return _policies;
+}
+
+} // namespace presence
+} // namespace fan
+} // namespace phosphor
diff --git a/presence/json_config.hpp b/presence/json_config.hpp
new file mode 100644
index 0000000..dcb1aa3
--- /dev/null
+++ b/presence/json_config.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "config.h"
+#include "rpolicy.hpp"
+
+namespace phosphor
+{
+namespace fan
+{
+namespace presence
+{
+
+using policies = std::vector<std::unique_ptr<RedundancyPolicy>>;
+
+class JsonConfig
+{
+    public:
+
+        JsonConfig() = delete;
+        JsonConfig(const JsonConfig&) = delete;
+        JsonConfig(JsonConfig&&) = delete;
+        JsonConfig& operator=(const JsonConfig&) = delete;
+        JsonConfig& operator=(JsonConfig&&) = delete;
+        ~JsonConfig() = default;
+
+        /**
+         * Constructor
+         * Parses and populates the fan presence policies from a json file
+         *
+         * @param[in] jsonFile - json configuration file
+         */
+        explicit JsonConfig(const std::string& jsonFile);
+
+        /**
+         * @brief Get the json config based fan presence policies
+         *
+         * @return - The fan presence policies
+         */
+        static const policies& get();
+
+    private:
+
+        /* Fan presence policies */
+        static policies _policies;
+};
+
+} // namespace presence
+} // namespace fan
+} // namespace phosphor
diff --git a/presence/tach_detect.cpp b/presence/tach_detect.cpp
index 9b23571..c0bee2b 100644
--- a/presence/tach_detect.cpp
+++ b/presence/tach_detect.cpp
@@ -13,7 +13,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "config.h"
+#ifdef PRESENCE_JSON_FILE
+#include "json_config.hpp"
+#else
 #include "generated.hpp"
+#endif
 #include "sdbusplus.hpp"
 #include <sdeventplus/event.hpp>
 
@@ -25,10 +30,19 @@
     util::SDBusPlus::getBus().attach_event(
             event.get(), SD_EVENT_PRIORITY_NORMAL);
 
+#ifdef PRESENCE_JSON_FILE
+    // Use json file for presence config
+    presence::JsonConfig config(PRESENCE_JSON_FILE);
+    for (auto& p: presence::JsonConfig::get())
+    {
+        p->monitor();
+    }
+#else
     for (auto& p: presence::ConfigPolicy::get())
     {
         p->monitor();
     }
+#endif
 
     return event.loop();
 }