control: JSON parsing compile framework

Add the enabling framework of use of JSON config files for fan control.

Tested:
    Compile passes when `--enable-json` configure flag given
    Compile passes without enabling JSON
    No functional change when not using JSON

Change-Id: Ic70bfc63ad74cb79559ed839784cd214df403cb2
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/Makefile.am b/control/Makefile.am
index 8812b58..3ce3617 100644
--- a/control/Makefile.am
+++ b/control/Makefile.am
@@ -15,9 +15,6 @@
 	triggers.cpp \
 	zone.cpp
 
-nodist_phosphor_fan_control_SOURCES = \
-	fan_zone_defs.cpp
-
 phosphor_fan_control_LDADD = \
 	-lstdc++fs \
 	$(SDBUSPLUS_LIBS) \
@@ -33,7 +30,13 @@
 	${PHOSPHOR_DBUS_INTERFACES_CFLAGS} \
 	-flto
 
+if WANT_JSON
+phosphor_fan_control_SOURCES += json_parser.cpp
+else
 BUILT_SOURCES = fan_zone_defs.cpp
+nodist_phosphor_fan_control_SOURCES = \
+	fan_zone_defs.cpp
 
 fan_zone_defs.cpp: ${srcdir}/gen-fan-zone-defs.py
 	$(AM_V_GEN)$(GEN_FAN_ZONE_DEFS) > ${builddir}/$@
+endif
diff --git a/control/json_parser.cpp b/control/json_parser.cpp
new file mode 100644
index 0000000..2f5ddae
--- /dev/null
+++ b/control/json_parser.cpp
@@ -0,0 +1,19 @@
+/**
+ * Copyright © 2020 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 "json_parser.hpp"
+
+namespace phosphor::fan::control
+{} // namespace phosphor::fan::control
diff --git a/control/json_parser.hpp b/control/json_parser.hpp
new file mode 100644
index 0000000..eea2564
--- /dev/null
+++ b/control/json_parser.hpp
@@ -0,0 +1,19 @@
+/**
+ * Copyright © 2020 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.
+ */
+#pragma once
+
+namespace phosphor::fan::control
+{} // namespace phosphor::fan::control
diff --git a/control/manager.cpp b/control/manager.cpp
index 543d42f..d202fea 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -90,6 +90,7 @@
     // actual system configuration.
 
     // Find the 1 ZoneGroup that meets all of its conditions
+#ifndef CONTROL_USE_JSON
     for (auto& group : _zoneLayouts)
     {
         auto& conditions = std::get<conditionListPos>(group);
@@ -114,6 +115,7 @@
             break;
         }
     }
+#endif
 
     if (mode == Mode::control)
     {
@@ -127,13 +129,13 @@
     {
         z.second->setFullSpeed();
     }
-
+#ifndef CONTROL_USE_JSON
     auto delay = _powerOnDelay;
     while (delay > 0)
     {
         delay = sleep(delay);
     }
-
+#endif
     util::SDBusPlus::callMethod(_bus, SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
                                 SYSTEMD_INTERFACE, "StartUnit",
                                 FAN_CONTROL_READY_TARGET, "replace");
diff --git a/control/manager.hpp b/control/manager.hpp
index 34ae0b9..a2e44f5 100644
--- a/control/manager.hpp
+++ b/control/manager.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "config.h"
+
 #include "types.hpp"
 #include "zone.hpp"
 
@@ -65,7 +67,7 @@
      * The fan zones in the system
      */
     ZoneMap _zones;
-
+#ifndef CONTROL_USE_JSON
     /**
      * The fan zone layout for the system.
      * This is generated data.
@@ -78,6 +80,7 @@
      * to give them a chance to get there.
      */
     static const unsigned int _powerOnDelay;
+#endif
 };
 
 } // namespace control