monitor: Support for running with power off

Put in the remaining changes necessary so that fan monitor doesn't need
to be killed when power turns off.

This includes things like:
* Support for starting before the Present property is on D-Bus.
* Support for starting before the config file name is available.
* Stopping any running timers when power is turned off.
* Checking the power off rules when power turns on.

Most, but not all, of the changes are common between the JSON and YAML
modes, but this only truly supported when compiled for JSON.

This also removes the init vs monitor modes of operation, if compiled
for JSON.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic2c6848f24511c9dc763227e05bbebb4c8c80cd1
diff --git a/monitor/system.cpp b/monitor/system.cpp
index 4c30f9f..44da0ba 100644
--- a/monitor/system.cpp
+++ b/monitor/system.cpp
@@ -48,11 +48,18 @@
         bus, std::bind(std::mem_fn(&System::powerStateChanged), this,
                        std::placeholders::_1))),
     _thermalAlert(bus, THERMAL_ALERT_OBJPATH)
-{
+{}
 
+void System::start(
+#ifdef MONITOR_USE_JSON
+    const std::string& confFile
+#endif
+)
+{
+    _started = true;
     json jsonObj = json::object();
 #ifdef MONITOR_USE_JSON
-    jsonObj = getJsonObj(bus);
+    jsonObj = fan::JsonConfig::load(confFile);
 #endif
     // Retrieve and set trust groups within the trust manager
     setTrustMgr(getTrustGroups(jsonObj));
@@ -61,20 +68,10 @@
     setFaultConfig(jsonObj);
     log<level::INFO>("Configuration loaded");
 
-    // Since this doesn't run at standby yet, powerStateChanged
-    // will never be called so for now treat start up as the
-    // pgood.  When this does run at standby, the 'atPgood'
-    // rules won't need to be checked here.
     if (_powerState->isPowerOn())
     {
         std::for_each(_powerOffRules.begin(), _powerOffRules.end(),
                       [this](auto& rule) {
-                          rule->check(PowerRuleState::atPgood, _fanHealth);
-                      });
-        // Runtime rules still need to be checked since fans may already
-        // be missing that could trigger a runtime rule.
-        std::for_each(_powerOffRules.begin(), _powerOffRules.end(),
-                      [this](auto& rule) {
                           rule->check(PowerRuleState::runtime, _fanHealth);
                       });
     }
@@ -202,8 +199,18 @@
 
 void System::powerStateChanged(bool powerStateOn)
 {
+    std::for_each(_fans.begin(), _fans.end(), [powerStateOn](auto& fan) {
+        fan->powerStateChanged(powerStateOn);
+    });
+
     if (powerStateOn)
     {
+        if (!_started)
+        {
+            log<level::ERR>("No conf file found at power on");
+            throw std::runtime_error("No conf file fount at power on");
+        }
+
         std::for_each(_powerOffRules.begin(), _powerOffRules.end(),
                       [this](auto& rule) {
                           rule->check(PowerRuleState::atPgood, _fanHealth);