Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <interfaces/manager_interface.hpp> |
| 4 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 5 | #include <sdbusplus/bus/match.hpp> |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 6 | #include <sdbusplus/server/object.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 7 | #include <sdeventplus/event.hpp> |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 8 | #include <sdeventplus/source/signal.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 9 | #include <sdeventplus/utility/timer.hpp> |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 10 | |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 11 | #include <algorithm> |
| 12 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 13 | namespace phosphor::power::regulators |
| 14 | { |
| 15 | |
| 16 | constexpr auto busName = "xyz.openbmc_project.Power.Regulators"; |
| 17 | constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager"; |
Matthew Barth | 23a5e59 | 2020-01-30 13:11:08 -0600 | [diff] [blame] | 18 | constexpr auto sysDbusObj = "/xyz/openbmc_project/inventory"; |
| 19 | constexpr auto sysDbusPath = "/xyz/openbmc_project/inventory/system"; |
| 20 | constexpr auto sysDbusIntf = "xyz.openbmc_project.Inventory.Item.System"; |
| 21 | constexpr auto sysDbusProp = "Identifier"; |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 22 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 23 | using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; |
| 24 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 25 | using ManagerObject = sdbusplus::server::object::object< |
| 26 | phosphor::power::regulators::interface::ManagerInterface>; |
| 27 | |
| 28 | class 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 Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 43 | * @param[in] event - the sdevent event |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 44 | */ |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 45 | Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 46 | |
| 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 Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 59 | /** |
| 60 | * @brief Timer expired callback function |
| 61 | */ |
| 62 | void timerExpired(); |
| 63 | |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 64 | /** |
| 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 Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 74 | /** |
| 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 Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 81 | private: |
| 82 | /** |
| 83 | * The dbus bus |
| 84 | */ |
| 85 | sdbusplus::bus::bus& bus; |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 86 | |
| 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 Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 96 | |
| 97 | /** |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 98 | * List of dbus signal matches |
| 99 | */ |
| 100 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> signals; |
| 101 | |
| 102 | /** |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 103 | * 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 Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace phosphor::power::regulators |