psu-ng: Implement the PowerSystemInputs interface

Implement the PowerSystemInputs interface which contains the status of
the power inputs to the chassis. The psu monitor app will use the status
property to communicate if a brownout condition exists.
Implement this interface under a /chassis0 path to specify it applies to
the current chassis. This can later be enhanced to support a
multi-chassis configuration.

Tested: The status property exists and it's set to default value Good:
root@p10bmc:~# busctl get-property xyz.openbmc_project.Power.PSUMonitor\
    /xyz/openbmc_project/power/power_supplies/chassis0/psus\
    xyz.openbmc_project.State.Decorator.PowerSystemInputs Status
s "xyz.openbmc_project.State.Decorator.PowerSystemInputs.Status.Good"

Change-Id: I7cf4d13e632841e0b19b52af0d9eac886eb161ce
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/phosphor-power-supply/meson.build b/phosphor-power-supply/meson.build
index f806861..bb90aea 100644
--- a/phosphor-power-supply/meson.build
+++ b/phosphor-power-supply/meson.build
@@ -13,6 +13,7 @@
         sdeventplus,
         fmt,
         libgpiodcxx,
+        phosphor_dbus_interfaces,
     ],
     include_directories: '..',
     install: true,
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index 3ad94cc..e6a3225 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -12,6 +12,11 @@
 
 namespace phosphor::power::manager
 {
+constexpr auto managerBusName = "xyz.openbmc_project.Power.PSUMonitor";
+constexpr auto objectManagerObjPath =
+    "/xyz/openbmc_project/power/power_supplies";
+constexpr auto powerSystemsInputsObjPath =
+    "/xyz/openbmc_project/power/power_supplies/chassis0/psus";
 
 constexpr auto IBMCFFPSInterface =
     "xyz.openbmc_project.Configuration.IBMCFFPSConnector";
@@ -24,7 +29,8 @@
     "xyz.openbmc_project.Configuration.SupportedConfiguration";
 
 PSUManager::PSUManager(sdbusplus::bus::bus& bus, const sdeventplus::Event& e) :
-    bus(bus)
+    bus(bus), powerSystemInputs(bus, powerSystemsInputsObjPath),
+    objectManager(bus, objectManagerObjPath)
 {
     // Subscribe to InterfacesAdded before doing a property read, otherwise
     // the interface could be created after the read attempt but before the
@@ -39,6 +45,10 @@
     getPSUConfiguration();
     getSystemProperties();
 
+    // Request the bus name before the analyze() function, which is the one that
+    // determines the brownout condition and sets the status d-bus property.
+    bus.request_name(managerBusName);
+
     using namespace sdeventplus;
     auto interval = std::chrono::milliseconds(1000);
     timer = std::make_unique<utility::Timer<ClockId::Monotonic>>(
diff --git a/phosphor-power-supply/psu_manager.hpp b/phosphor-power-supply/psu_manager.hpp
index 2754eab..d291324 100644
--- a/phosphor-power-supply/psu_manager.hpp
+++ b/phosphor-power-supply/psu_manager.hpp
@@ -6,8 +6,11 @@
 
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus/match.hpp>
+#include <sdbusplus/server/manager.hpp>
+#include <sdbusplus/server/object.hpp>
 #include <sdeventplus/event.hpp>
 #include <sdeventplus/utility/timer.hpp>
+#include <xyz/openbmc_project/State/Decorator/PowerSystemInputs/server.hpp>
 
 struct sys_properties
 {
@@ -22,11 +25,28 @@
 namespace phosphor::power::manager
 {
 
+using PowerSystemInputsInterface = sdbusplus::xyz::openbmc_project::State::
+    Decorator::server::PowerSystemInputs;
+using PowerSystemInputsObject =
+    sdbusplus::server::object_t<PowerSystemInputsInterface>;
+
 // Validation timeout. Allow 10s to detect if new EM interfaces show up in D-Bus
 // before performing the validation.
 constexpr auto validationTimeout = std::chrono::seconds(10);
 
 /**
+ * @class PowerSystemInputs
+ * @brief A concrete implementation for the PowerSystemInputs interface.
+ */
+class PowerSystemInputs : public PowerSystemInputsObject
+{
+  public:
+    PowerSystemInputs(sdbusplus::bus::bus& bus, const std::string& path) :
+        PowerSystemInputsObject(bus, path.c_str())
+    {}
+};
+
+/**
  * @class PSUManager
  *
  * This class will create an object used to manage and monitor a list of power
@@ -319,6 +339,16 @@
      * @brief The libgpiod object for setting the power supply config
      */
     std::unique_ptr<GPIOInterfaceBase> powerConfigGPIO = nullptr;
+
+    /**
+     * @brief PowerSystemInputs object
+     */
+    PowerSystemInputs powerSystemInputs;
+
+    /**
+     * @brief Implement the org.freedesktop.DBus.ObjectManager interface
+     */
+    sdbusplus::server::manager_t objectManager;
 };
 
 } // namespace phosphor::power::manager