Implement PSU Event

Expose PSU Event AC Lost, Fan Fault, Failure, Predictive D-Bus interface.
Read alarm and max_alarm, min_alarm, crit_alarm, lcrit_alarm and
assert or deassert the related properties on PSU Event.

Tested By:
After run /usr/sbin/psusensor below D-Bus interface are exposed
/xyz/openbmc_project/State/Decorator/PSU1_OperationalStatus
/xyz/openbmc_project/State/Decorator/PSU2_OperationalStatus
After plugging out AC cable from PSU1, the functional property in
PSU1_OperationalStatus changes to "false" from "true".
After plugging in AC cable again, the property changes back to "true".

Change-Id: Ic21513471c4632835c39148ea313808fdcc816fa
Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
diff --git a/include/PSUEvent.hpp b/include/PSUEvent.hpp
new file mode 100644
index 0000000..f7834e2
--- /dev/null
+++ b/include/PSUEvent.hpp
@@ -0,0 +1,70 @@
+/*
+// Copyright (c) 2019 Intel 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
+
+#include <sdbusplus/asio/object_server.hpp>
+
+class PSUSubEvent
+{
+  public:
+    PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
+                const std::string& path, boost::asio::io_service& io,
+                const std::string& eventName,
+                std::shared_ptr<std::set<std::string>> asserts,
+                std::shared_ptr<std::set<std::string>> combineEvent,
+                std::shared_ptr<bool> state);
+    ~PSUSubEvent();
+
+    std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
+    std::shared_ptr<std::set<std::string>> asserts;
+    std::shared_ptr<std::set<std::string>> combineEvent;
+    std::shared_ptr<bool> assertState;
+
+  private:
+    int value = 0;
+    int errCount;
+    std::string path;
+    std::string eventName;
+    boost::asio::deadline_timer waitTimer;
+    boost::asio::streambuf readBuf;
+    void setupRead(void);
+    void handleResponse(const boost::system::error_code& err);
+    void updateValue(const int& newValue);
+    boost::asio::posix::stream_descriptor inputDev;
+    static constexpr unsigned int eventPollMs = 1000;
+    static constexpr size_t warnAfterErrorCount = 10;
+};
+
+class PSUCombineEvent
+{
+  public:
+    PSUCombineEvent(
+        sdbusplus::asio::object_server& objectSever,
+        boost::asio::io_service& io, const std::string& psuName,
+        boost::container::flat_map<std::string, std::vector<std::string>>&
+            eventPathList,
+        const std::string& combineEventName);
+    ~PSUCombineEvent();
+
+    sdbusplus::asio::object_server& objServer;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
+    boost::container::flat_map<std::string,
+                               std::vector<std::unique_ptr<PSUSubEvent>>>
+        events;
+    std::vector<std::shared_ptr<std::set<std::string>>> asserts;
+    std::vector<std::shared_ptr<bool>> states;
+};