blob: 878822b7ab6453dd11c44481443583f1aeb0fb83 [file] [log] [blame]
Andrew Geissler32016d12017-06-20 15:46:52 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/bus/match.hpp>
5#include "occ_status.hpp"
6#include "config.h"
7
8namespace open_power
9{
10namespace occ
11{
12namespace powercap
13{
14
15namespace 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
25class PowerCap
26{
27public:
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
52private:
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
63 /** @brief Reference to sdbus **/
64 sdbusplus::bus::bus& bus;
65
66 /* @brief OCC Status object */
67 Status &occStatus;
68
69 /** @brief Used to subscribe to dbus pcap propety changes **/
70 sdbusplus::bus::match_t pcapMatch;
71
72 };
73
74} // namespace open_power
75
76} // namespace occ
77
78}// namespace powercap