psu: Introduce the PowerSupply class
The Power Supply Manager (PSUManager) class will need a list of power
supplies to work with. Create these via the PowerSupply class.
Update Power Supply Manager to call the initialization function, and
update the power state.
Update clearFaults() to go through the list of power supplies and call
their individual clearFaults() functions.
Update the power supply manager analyze() function to go through the
list of power supplies and call their analyze() function.
Update the power supply manager updateInventory() function to call the
updateInventory() function in each power supply in the list.
Update the meson.build file to include the header files in the parent
directory, and link with the library containing the utility functions
the binary will need to use.
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I743180d47f1b25d34c7e7001b64a6197905b86ff
diff --git a/phosphor-power-supply/main.cpp b/phosphor-power-supply/main.cpp
index d19a254..2622c6a 100644
--- a/phosphor-power-supply/main.cpp
+++ b/phosphor-power-supply/main.cpp
@@ -22,39 +22,55 @@
#include <filesystem>
+using namespace phosphor::power::manager;
+
int main(int argc, char* argv[])
{
- using namespace phosphor::logging;
-
- CLI::App app{"OpenBMC Power Supply Unit Monitor"};
-
- std::string configfile;
- app.add_option("-c,--config", configfile, "JSON configuration file path")
- ->check(CLI::ExistingFile);
-
- // Read the arguments.
- CLI11_PARSE(app, argc, argv);
- if (configfile.empty())
+ try
{
- configfile = "/etc/phosphor-psu-monitor/psu_config.json";
- }
+ using namespace phosphor::logging;
- if (!std::filesystem::exists(configfile))
+ CLI::App app{"OpenBMC Power Supply Unit Monitor"};
+
+ std::string configfile;
+ app.add_option("-c,--config", configfile,
+ "JSON configuration file path");
+
+ // Read the arguments.
+ CLI11_PARSE(app, argc, argv);
+ if (configfile.empty())
+ {
+ configfile = "/etc/phosphor-psu-monitor/psu_config.json";
+ }
+
+ if (!std::filesystem::exists(configfile))
+ {
+ log<level::ERR>("Configuration file does not exist",
+ entry("FILENAME=%s", configfile.c_str()));
+ return -1;
+ }
+
+ auto bus = sdbusplus::bus::new_default();
+ auto event = sdeventplus::Event::get_default();
+
+ // Attach the event object to the bus object so we can
+ // handle both sd_events (for the timers) and dbus signals.
+ bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+
+ // TODO: Should get polling interval from JSON file.
+ auto pollInterval = std::chrono::milliseconds(1000);
+ PSUManager manager(bus, event, pollInterval);
+
+ return manager.run();
+ }
+ catch (const std::exception& e)
{
- log<level::ERR>("Configuration file does not exist",
- entry("FILENAME=%s", configfile.c_str()));
- return -1;
+ log<level::ERR>(e.what());
+ return -2;
}
-
- auto bus = sdbusplus::bus::new_default();
- auto event = sdeventplus::Event::get_default();
-
- // Attach the event object to the bus object so we can
- // handle both sd_events (for the timers) and dbus signals.
- bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
-
- // TODO: Should get polling interval from JSON file.
- auto pollInterval = std::chrono::milliseconds(1000);
-
- return phosphor::power::manager::PSUManager(bus, event, pollInterval).run();
+ catch (...)
+ {
+ log<level::ERR>("Caught unexpected exception type");
+ return -3;
+ }
}