1 #pragma once 2 3 #include <interfaces/manager_interface.hpp> 4 #include <sdbusplus/bus.hpp> 5 #include <sdbusplus/bus/match.hpp> 6 #include <sdbusplus/server/object.hpp> 7 #include <sdeventplus/event.hpp> 8 #include <sdeventplus/source/signal.hpp> 9 #include <sdeventplus/utility/timer.hpp> 10 11 #include <algorithm> 12 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"; 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"; 22 23 using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; 24 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 43 * @param[in] event - the sdevent event 44 */ 45 Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); 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 59 /** 60 * @brief Timer expired callback function 61 */ 62 void timerExpired(); 63 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 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 81 private: 82 /** 83 * The dbus bus 84 */ 85 sdbusplus::bus::bus& bus; 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; 96 97 /** 98 * List of dbus signal matches 99 */ 100 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> signals; 101 102 /** 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(); 129 }; 130 131 } // namespace phosphor::power::regulators 132