Monitor UCD90160 for faults at runtime

Add the RuntimeMonitor class that will monitor the
UCD90160 faults in 2 ways:

1) Watch for the PowerLost signal, meaning system
   PGOOD was lost.  When it occurs, analyze the
   chip for errors and then issue a proper shutdown
   so a faulted device doesn't keep getting power.

2) Poll on an interval for nonfatal errors that need
   to be logged but don't cause a PGOOD loss.

The main executable can now launch either the PGOODMonitor
or the RuntimeMonitor based on commandline arguments.

Change-Id: If2856f173d5d6288d8333538334b4b4cb4a60097
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-sequencer/runtime_monitor.cpp b/power-sequencer/runtime_monitor.cpp
new file mode 100644
index 0000000..3873ac0
--- /dev/null
+++ b/power-sequencer/runtime_monitor.cpp
@@ -0,0 +1,58 @@
+/**
+ * Copyright © 2017 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 <phosphor-logging/log.hpp>
+#include "runtime_monitor.hpp"
+#include "utility.hpp"
+
+namespace witherspoon
+{
+namespace power
+{
+
+using namespace phosphor::logging;
+
+int RuntimeMonitor::run()
+{
+    device->clearFaults();
+
+    return DeviceMonitor::run();
+}
+
+void RuntimeMonitor::onPowerLost(sdbusplus::message::message& msg)
+{
+    log<level::INFO>("PGOOD failure detected.  Checking for faults.");
+
+    try
+    {
+        timer.stop();
+
+        device->onFailure();
+
+        //Note: This application only runs when the system has
+        //power, so it will be killed by systemd sometime shortly
+        //after this power off is issued.
+
+        util::powerOff(bus);
+    }
+    catch (std::exception& e)
+    {
+        //No need to crash
+        log<level::ERR>(e.what());
+    }
+}
+
+}
+}