blob: c2d78f104926d917e3d11c730f5a297373c34e75 [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>
Matthew Barth250d0a92020-02-28 13:04:24 -06005#include <sdbusplus/bus/match.hpp>
Matthew Barth29e9e382020-01-23 13:40:49 -06006#include <sdbusplus/server/object.hpp>
Matthew Barthf2bcf1f2020-01-29 14:42:47 -06007#include <sdeventplus/event.hpp>
Matthew Barth7cbc5532020-01-29 15:13:13 -06008#include <sdeventplus/source/signal.hpp>
Matthew Barthf2bcf1f2020-01-29 14:42:47 -06009#include <sdeventplus/utility/timer.hpp>
Matthew Barth29e9e382020-01-23 13:40:49 -060010
Matthew Barthbbc7c582020-02-03 15:55:15 -060011#include <algorithm>
12
Matthew Barth29e9e382020-01-23 13:40:49 -060013namespace phosphor::power::regulators
14{
15
16constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
17constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
Matthew Barth23a5e592020-01-30 13:11:08 -060018constexpr auto sysDbusObj = "/xyz/openbmc_project/inventory";
19constexpr auto sysDbusPath = "/xyz/openbmc_project/inventory/system";
20constexpr auto sysDbusIntf = "xyz.openbmc_project.Inventory.Item.System";
21constexpr auto sysDbusProp = "Identifier";
Matthew Barth29e9e382020-01-23 13:40:49 -060022
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060023using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
24
Matthew Barth29e9e382020-01-23 13:40:49 -060025using ManagerObject = sdbusplus::server::object::object<
26 phosphor::power::regulators::interface::ManagerInterface>;
27
28class Manager : public ManagerObject
29{
30 public:
31 Manager() = delete;
32 Manager(const Manager&) = delete;
33 Manager(Manager&&) = delete;
34 Manager& operator=(const Manager&) = delete;
35 Manager& operator=(Manager&&) = delete;
36 ~Manager() = default;
37
38 /**
39 * Constructor
40 * Creates a manager over the regulators.
41 *
42 * @param[in] bus - the dbus bus
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060043 * @param[in] event - the sdevent event
Matthew Barth29e9e382020-01-23 13:40:49 -060044 */
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060045 Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
Matthew Barth29e9e382020-01-23 13:40:49 -060046
47 /**
48 * @brief Overridden manager object's configure method
49 */
50 void configure() override;
51
52 /**
53 * @brief Overridden manager object's monitor method
54 *
55 * @param[in] enable - Enable or disable regulator monitoring
56 */
57 void monitor(bool enable) override;
58
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060059 /**
60 * @brief Timer expired callback function
61 */
62 void timerExpired();
63
Matthew Barth7cbc5532020-01-29 15:13:13 -060064 /**
65 * @brief Callback function to handle receiving a HUP signal
66 * to reload the configuration data.
67 *
68 * @param[in] sigSrc - sd_event_source signal wrapper
69 * @param[in] sigInfo - signal info on signal fd
70 */
71 void sighupHandler(sdeventplus::source::Signal& sigSrc,
72 const struct signalfd_siginfo* sigInfo);
73
Matthew Barth250d0a92020-02-28 13:04:24 -060074 /**
75 * @brief Callback function to handle interfacesAdded dbus signals
76 *
77 * @param[in] msg - Expanded sdbusplus message data
78 */
79 void signalHandler(sdbusplus::message::message& msg);
80
Matthew Barth29e9e382020-01-23 13:40:49 -060081 private:
82 /**
83 * The dbus bus
84 */
85 sdbusplus::bus::bus& bus;
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060086
87 /**
88 * Event to loop on
89 */
90 sdeventplus::Event eventLoop;
91
92 /**
93 * List of event timers
94 */
95 std::vector<Timer> timers;
Matthew Barthbbc7c582020-02-03 15:55:15 -060096
97 /**
Matthew Barth250d0a92020-02-28 13:04:24 -060098 * List of dbus signal matches
99 */
100 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> signals;
101
102 /**
Matthew Barthbbc7c582020-02-03 15:55:15 -0600103 * JSON configuration data filename
104 */
105 std::string fileName;
106
107 /**
108 * @brief Set the JSON configuration data filename
109 *
110 * @param[in] fName = filename without `.json` extension
111 */
112 inline void setFileName(const std::string& fName)
113 {
114 fileName = fName;
115 if (!fileName.empty())
116 {
117 // Replace all spaces with underscores
118 std::replace(fileName.begin(), fileName.end(), ' ', '_');
119 fileName.append(".json");
120 }
121 };
122
123 /**
124 * @brief Get the JSON configuration data filename from dbus
125 *
126 * @return - JSON configuration data filename
127 */
128 const std::string getFileNameDbus();
Matthew Barth29e9e382020-01-23 13:40:49 -0600129};
130
131} // namespace phosphor::power::regulators