blob: 16456bf38449e05d48d5e53a44e07a67034f8619 [file] [log] [blame]
Andrew Geisslera90a31a2016-12-13 16:16:28 -06001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/State/Chassis/server.hpp"
5
6namespace phosphor
7{
8namespace state
9{
10namespace manager
11{
12
13/** @class Chassis
14 * @brief OpenBMC chassis state management implementation.
15 * @details A concrete implementation for xyz.openbmc_project.State.Chassis
16 * DBus API.
17 */
18class Chassis : public sdbusplus::server::object::object<
19 sdbusplus::xyz::openbmc_project::State::server::Chassis>
20{
21 public:
22 /** @brief Constructs Chassis State Manager
23 *
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060024 * @note This constructor passes 'true' to the base class in order to
25 * defer dbus object registration until we can run
26 * determineInitialState() and set our properties
27 *
Andrew Geisslera90a31a2016-12-13 16:16:28 -060028 * @param[in] bus - The Dbus bus object
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060029 * @param[in] instance - The instance of this object
Andrew Geisslera90a31a2016-12-13 16:16:28 -060030 * @param[in] objPath - The Dbus object path
31 */
32 Chassis(sdbusplus::bus::bus& bus,
33 const char* busName,
34 const char* objPath) :
35 sdbusplus::server::object::object<
36 sdbusplus::xyz::openbmc_project::State::server::Chassis>(
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060037 bus, objPath, true),
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060038 bus(bus),
39 pgoodOn(bus,
40 "type='signal',member='PowerGood'",
41 Chassis::handlePgoodOn,
42 this),
43 pgoodOff(bus,
44 "type='signal',member='PowerLost'",
45 Chassis::handlePgoodOff,
46 this)
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060047 {
48 determineInitialState();
49
50 // We deferred this until we could get our property correct
51 this->emit_object_added();
52 }
53
54 /** @brief Determine initial chassis state and set internally */
55 void determineInitialState();
Andrew Geisslera90a31a2016-12-13 16:16:28 -060056
57 /** @brief Set value of RequestedPowerTransition */
58 Transition requestedPowerTransition(Transition value) override;
59
60 /** @brief Set value of CurrentPowerState */
61 PowerState currentPowerState(PowerState value) override;
62
63 private:
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060064 /** @brief Callback function for pgood going to on state
65 *
66 * Update chassis object state to reflect pgood going to on state
67 *
68 * @param[in] msg - Data associated with subscribed signal
69 * @param[in] userData - Pointer to this object instance
70 * @param[in] retError - Return error data
71 *
72 */
73 static int handlePgoodOn(sd_bus_message* msg,
74 void* userData,
75 sd_bus_error* retError);
76
77 /** @brief Callback function for pgood going to off state
78 *
79 * Update chassis object state to reflect pgood going to off state
80 *
81 * @param[in] msg - Data associated with subscribed signal
82 * @param[in] userData - Pointer to this object instance
83 * @param[in] retError - Return error data
84 *
85 */
86 static int handlePgoodOff(sd_bus_message* msg,
87 void* userData,
88 sd_bus_error* retError);
89
Andrew Geisslera90a31a2016-12-13 16:16:28 -060090 /** @brief Persistent sdbusplus DBus connection. */
91 sdbusplus::bus::bus& bus;
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060092
93 /** @brief Used to subscribe to dbus pgood on state changes */
94 sdbusplus::server::match::match pgoodOn;
95
96 /** @brief Used to subscribe to dbus pgood off state changes */
97 sdbusplus::server::match::match pgoodOff;
Andrew Geisslera90a31a2016-12-13 16:16:28 -060098};
99
100} // namespace manager
101} // namespace state
102} // namespace phosphor