blob: a56924e14bf9a360ea497e94d4f819ad9aa6e054 [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),
Andrew Geissler0029a5d2017-01-24 14:48:35 -060039 systemdSignals(bus,
40 "type='signal',"
41 "member='JobRemoved',"
42 "path='/org/freedesktop/systemd1',"
43 "interface='org.freedesktop.systemd1.Manager'",
44 sysStateChangeSignal,
45 this)
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060046 {
Andrew Geissler0029a5d2017-01-24 14:48:35 -060047 subscribeToSystemdSignals();
48
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060049 determineInitialState();
50
51 // We deferred this until we could get our property correct
52 this->emit_object_added();
53 }
54
Andrew Geisslera90a31a2016-12-13 16:16:28 -060055 /** @brief Set value of RequestedPowerTransition */
56 Transition requestedPowerTransition(Transition value) override;
57
58 /** @brief Set value of CurrentPowerState */
59 PowerState currentPowerState(PowerState value) override;
60
61 private:
Andrew Geissler0029a5d2017-01-24 14:48:35 -060062 /** @brief Determine initial chassis state and set internally */
63 void determineInitialState();
64
65 /**
66 * @brief subscribe to the systemd signals
67 *
68 * This object needs to capture when it's systemd targets complete
69 * so it can keep it's state updated
70 *
71 **/
72 void subscribeToSystemdSignals();
73
Andrew Geisslerce80f242017-01-24 13:25:33 -060074 /** @brief Execute the transition request
75 *
76 * This function calls the appropriate systemd target for the input
77 * transition.
78 *
79 * @param[in] tranReq - Transition requested
80 */
81 void executeTransition(Transition tranReq);
82
Andrew Geissler0029a5d2017-01-24 14:48:35 -060083 /** @brief Callback function on systemd state changes
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060084 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -060085 * Will just do a call into the appropriate object for processing
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060086 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -060087 * @param[in] msg - Data associated with subscribed signal
88 * @param[in] userData - Pointer to this object instance
89 * @param[out] retError - Not used but required with signal API
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060090 *
91 */
Andrew Geissler0029a5d2017-01-24 14:48:35 -060092 static int sysStateChangeSignal(sd_bus_message* msg,
93 void* userData,
94 sd_bus_error* retError);
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060095
Andrew Geissler0029a5d2017-01-24 14:48:35 -060096 /** @brief Check if systemd state change is relevant to this object
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060097 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -060098 * Instance specific interface to handle the detected systemd state
99 * change
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600100 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600101 * @param[in] msg - Data associated with subscribed signal
102 * @param[out] retError - Not used but required with signal API
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600103 *
104 */
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600105 int sysStateChange(sd_bus_message* msg,
106 sd_bus_error* retError);
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600107
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600108 /** @brief Persistent sdbusplus DBus connection. */
109 sdbusplus::bus::bus& bus;
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600110
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600111 /** @brief Used to subscribe to dbus systemd signals **/
112 sdbusplus::server::match::match systemdSignals;
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600113};
114
115} // namespace manager
116} // namespace state
117} // namespace phosphor