blob: eb0cef82a1cb38fdcf0ec68629ff398c55fdc851 [file] [log] [blame]
Matthew Barth29e9e382020-01-23 13:40:49 -06001#pragma once
2
3#include <interfaces/manager_interface.hpp>
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
Matthew Barthf2bcf1f2020-01-29 14:42:47 -06006#include <sdeventplus/event.hpp>
Matthew Barth7cbc5532020-01-29 15:13:13 -06007#include <sdeventplus/source/signal.hpp>
Matthew Barthf2bcf1f2020-01-29 14:42:47 -06008#include <sdeventplus/utility/timer.hpp>
Matthew Barth29e9e382020-01-23 13:40:49 -06009
Matthew Barthbbc7c582020-02-03 15:55:15 -060010#include <algorithm>
11
Matthew Barth29e9e382020-01-23 13:40:49 -060012namespace phosphor::power::regulators
13{
14
15constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
16constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
Matthew Barth23a5e592020-01-30 13:11:08 -060017constexpr auto sysDbusObj = "/xyz/openbmc_project/inventory";
18constexpr auto sysDbusPath = "/xyz/openbmc_project/inventory/system";
19constexpr auto sysDbusIntf = "xyz.openbmc_project.Inventory.Item.System";
20constexpr auto sysDbusProp = "Identifier";
Matthew Barth29e9e382020-01-23 13:40:49 -060021
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060022using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
23
Matthew Barth29e9e382020-01-23 13:40:49 -060024using ManagerObject = sdbusplus::server::object::object<
25 phosphor::power::regulators::interface::ManagerInterface>;
26
27class Manager : public ManagerObject
28{
29 public:
30 Manager() = delete;
31 Manager(const Manager&) = delete;
32 Manager(Manager&&) = delete;
33 Manager& operator=(const Manager&) = delete;
34 Manager& operator=(Manager&&) = delete;
35 ~Manager() = default;
36
37 /**
38 * Constructor
39 * Creates a manager over the regulators.
40 *
41 * @param[in] bus - the dbus bus
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060042 * @param[in] event - the sdevent event
Matthew Barth29e9e382020-01-23 13:40:49 -060043 */
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060044 Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
Matthew Barth29e9e382020-01-23 13:40:49 -060045
46 /**
47 * @brief Overridden manager object's configure method
48 */
49 void configure() override;
50
51 /**
52 * @brief Overridden manager object's monitor method
53 *
54 * @param[in] enable - Enable or disable regulator monitoring
55 */
56 void monitor(bool enable) override;
57
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060058 /**
59 * @brief Timer expired callback function
60 */
61 void timerExpired();
62
Matthew Barth7cbc5532020-01-29 15:13:13 -060063 /**
64 * @brief Callback function to handle receiving a HUP signal
65 * to reload the configuration data.
66 *
67 * @param[in] sigSrc - sd_event_source signal wrapper
68 * @param[in] sigInfo - signal info on signal fd
69 */
70 void sighupHandler(sdeventplus::source::Signal& sigSrc,
71 const struct signalfd_siginfo* sigInfo);
72
Matthew Barth29e9e382020-01-23 13:40:49 -060073 private:
74 /**
75 * The dbus bus
76 */
77 sdbusplus::bus::bus& bus;
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060078
79 /**
80 * Event to loop on
81 */
82 sdeventplus::Event eventLoop;
83
84 /**
85 * List of event timers
86 */
87 std::vector<Timer> timers;
Matthew Barthbbc7c582020-02-03 15:55:15 -060088
89 /**
90 * JSON configuration data filename
91 */
92 std::string fileName;
93
94 /**
95 * @brief Set the JSON configuration data filename
96 *
97 * @param[in] fName = filename without `.json` extension
98 */
99 inline void setFileName(const std::string& fName)
100 {
101 fileName = fName;
102 if (!fileName.empty())
103 {
104 // Replace all spaces with underscores
105 std::replace(fileName.begin(), fileName.end(), ' ', '_');
106 fileName.append(".json");
107 }
108 };
109
110 /**
111 * @brief Get the JSON configuration data filename from dbus
112 *
113 * @return - JSON configuration data filename
114 */
115 const std::string getFileNameDbus();
Matthew Barth29e9e382020-01-23 13:40:49 -0600116};
117
118} // namespace phosphor::power::regulators