Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/bus/match.hpp> |
| 5 | #include "occ_status.hpp" |
| 6 | #include "config.h" |
| 7 | |
| 8 | namespace open_power |
| 9 | { |
| 10 | namespace occ |
| 11 | { |
| 12 | namespace powercap |
| 13 | { |
| 14 | |
| 15 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 16 | |
| 17 | /** @class PowerCap |
| 18 | * @brief Monitors for changes to the power cap and notifies occ |
| 19 | * |
| 20 | * The customer power cap is provided to the OCC by host TMGT when the occ |
| 21 | * first goes active or is reset. This code is responsible for sending |
| 22 | * the power cap to the OCC if the cap is changed while the occ is active. |
| 23 | */ |
| 24 | |
| 25 | class PowerCap |
| 26 | { |
| 27 | public: |
| 28 | /** @brief PowerCap object to inform occ of changes to cap |
| 29 | * |
| 30 | * This object will monitor for changes to the power cap setting and |
| 31 | * power cap enable properties. If a change is detected, and the occ |
| 32 | * is active, then this object will notify the OCC of the change. |
| 33 | * |
| 34 | * @param[in] bus - The Dbus bus object |
| 35 | * @param[in] occStatus - The occ status object |
| 36 | */ |
| 37 | PowerCap(sdbusplus::bus::bus &bus, |
| 38 | Status &occStatus) : |
| 39 | bus(bus), |
| 40 | occStatus(occStatus), |
| 41 | pcapMatch( |
| 42 | bus, |
| 43 | sdbusRule::member("PropertiesChanged") + |
| 44 | sdbusRule::path( |
| 45 | "/xyz/openbmc_project/control/host0/power_cap") + |
| 46 | sdbusRule::argN(0, "xyz.openbmc_project.Control.Power.Cap") + |
| 47 | sdbusRule::interface("org.freedesktop.DBus.Properties"), |
| 48 | std::bind(std::mem_fn(&PowerCap::pcapChanged), |
| 49 | this, std::placeholders::_1)) |
| 50 | {}; |
| 51 | |
| 52 | private: |
| 53 | |
| 54 | /** @brief Callback for pcap setting changes |
| 55 | * |
| 56 | * Process change and inform OCC |
| 57 | * |
| 58 | * @param[in] msg - Data associated with pcap change signal |
| 59 | * |
| 60 | */ |
| 61 | void pcapChanged(sdbusplus::message::message& msg); |
| 62 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame^] | 63 | /** @brief Look up DBUS service for input path/interface |
| 64 | * |
| 65 | * @param[in] path - DBUS path |
| 66 | * @param[in] path - DBUS interface |
| 67 | * |
| 68 | * @return Distinct service name for input path/interface |
| 69 | */ |
| 70 | std::string getService(std::string path, |
| 71 | std::string interface); |
| 72 | |
| 73 | /** @brief Get the power cap property |
| 74 | * |
| 75 | * @return Power cap, 0 on failure to indicate no pcap |
| 76 | */ |
| 77 | uint32_t getPcap(); |
| 78 | |
| 79 | /** @brief Get the power cap enable property |
| 80 | * |
| 81 | * @return Whether power cap enabled, will return false on error |
| 82 | */ |
| 83 | bool getPcapEnabled(); |
| 84 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 85 | /** @brief Reference to sdbus **/ |
| 86 | sdbusplus::bus::bus& bus; |
| 87 | |
| 88 | /* @brief OCC Status object */ |
| 89 | Status &occStatus; |
| 90 | |
| 91 | /** @brief Used to subscribe to dbus pcap propety changes **/ |
| 92 | sdbusplus::bus::match_t pcapMatch; |
| 93 | |
| 94 | }; |
| 95 | |
| 96 | } // namespace open_power |
| 97 | |
| 98 | } // namespace occ |
| 99 | |
| 100 | }// namespace powercap |