transition dbus-configuration to run-time check

This now checks dbus if there is no json file configuration found.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ic8f5b0531b7131a3d333c2127043b7054924c156
diff --git a/main.cpp b/main.cpp
index 73e43c8..712d2cf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -18,6 +18,7 @@
 
 #include "build/buildjson.hpp"
 #include "conf.hpp"
+#include "dbus/dbusconfiguration.hpp"
 #include "interfaces.hpp"
 #include "pid/builder.hpp"
 #include "pid/buildjson.hpp"
@@ -36,6 +37,7 @@
 #include <sdbusplus/bus.hpp>
 
 #include <chrono>
+#include <filesystem>
 #include <iostream>
 #include <list>
 #include <map>
@@ -45,10 +47,6 @@
 #include <utility>
 #include <vector>
 
-#if CONFIGURE_DBUS
-#include "dbus/dbusconfiguration.hpp"
-#endif
-
 namespace pid_control
 {
 
@@ -86,34 +84,36 @@
 
     timers.clear();
 
-#if CONFIGURE_DBUS
-
-    static boost::asio::steady_timer reloadTimer(io);
-    if (!dbus_configuration::init(modeControlBus, reloadTimer))
-    {
-        return; // configuration not ready
-    }
-
-#else
     const std::string& path =
         (configPath.length() > 0) ? configPath : jsonConfigurationPath;
 
-    /*
-     * When building the sensors, if any of the dbus passive ones aren't on the
-     * bus, it'll fail immediately.
-     */
-    try
+    if (std::filesystem::exists(path))
     {
-        auto jsonData = parseValidateJson(path);
-        sensorConfig = buildSensorsFromJson(jsonData);
-        std::tie(zoneConfig, zoneDetailsConfig) = buildPIDsFromJson(jsonData);
+        /*
+         * When building the sensors, if any of the dbus passive ones aren't on
+         * the bus, it'll fail immediately.
+         */
+        try
+        {
+            auto jsonData = parseValidateJson(path);
+            sensorConfig = buildSensorsFromJson(jsonData);
+            std::tie(zoneConfig, zoneDetailsConfig) =
+                buildPIDsFromJson(jsonData);
+        }
+        catch (const std::exception& e)
+        {
+            std::cerr << "Failed during building: " << e.what() << "\n";
+            exit(EXIT_FAILURE); /* fatal error. */
+        }
     }
-    catch (const std::exception& e)
+    else
     {
-        std::cerr << "Failed during building: " << e.what() << "\n";
-        exit(EXIT_FAILURE); /* fatal error. */
+        static boost::asio::steady_timer reloadTimer(io);
+        if (!dbus_configuration::init(modeControlBus, reloadTimer))
+        {
+            return; // configuration not ready
+        }
     }
-#endif
 
     mgmr = buildSensors(sensorConfig, passiveBus, hostBus);
     zones = buildZones(zoneConfig, zoneDetailsConfig, mgmr, modeControlBus);