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> |
| 5 | #include <sdbusplus/server/object.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 6 | #include <sdeventplus/event.hpp> |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 7 | #include <sdeventplus/source/signal.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 8 | #include <sdeventplus/utility/timer.hpp> |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 9 | |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 10 | #include <algorithm> |
| 11 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 12 | namespace phosphor::power::regulators |
| 13 | { |
| 14 | |
| 15 | constexpr auto busName = "xyz.openbmc_project.Power.Regulators"; |
| 16 | constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager"; |
Matthew Barth | 23a5e59 | 2020-01-30 13:11:08 -0600 | [diff] [blame] | 17 | constexpr auto sysDbusObj = "/xyz/openbmc_project/inventory"; |
| 18 | constexpr auto sysDbusPath = "/xyz/openbmc_project/inventory/system"; |
| 19 | constexpr auto sysDbusIntf = "xyz.openbmc_project.Inventory.Item.System"; |
| 20 | constexpr auto sysDbusProp = "Identifier"; |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 21 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 22 | using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; |
| 23 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 24 | using ManagerObject = sdbusplus::server::object::object< |
| 25 | phosphor::power::regulators::interface::ManagerInterface>; |
| 26 | |
| 27 | class 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 Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 42 | * @param[in] event - the sdevent event |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 43 | */ |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 44 | Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 45 | |
| 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 Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 58 | /** |
| 59 | * @brief Timer expired callback function |
| 60 | */ |
| 61 | void timerExpired(); |
| 62 | |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 63 | /** |
| 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 Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 73 | private: |
| 74 | /** |
| 75 | * The dbus bus |
| 76 | */ |
| 77 | sdbusplus::bus::bus& bus; |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 78 | |
| 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 Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 88 | |
| 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 Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace phosphor::power::regulators |