blob: 0c6d5a1661a268205d6903e17a9a30e56720d9cf [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
Josh D. King697474c2017-03-02 11:15:55 -060083 /**
84 * @brief Determine if target is active
85 *
86 * This function determines if the target is active and
87 * helps prevent misleading log recorded states.
88 *
89 * @param[in] target - Target string to check on
90 *
91 * @return boolean corresponding to state active
92 **/
93 bool stateActive(const std::string& target);
94
Andrew Geissler0029a5d2017-01-24 14:48:35 -060095 /** @brief Callback function on systemd state changes
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060096 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -060097 * Will just do a call into the appropriate object for processing
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060098 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -060099 * @param[in] msg - Data associated with subscribed signal
100 * @param[in] userData - Pointer to this object instance
101 * @param[out] retError - Not used but required with signal API
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600102 *
103 */
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600104 static int sysStateChangeSignal(sd_bus_message* msg,
105 void* userData,
106 sd_bus_error* retError);
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600107
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600108 /** @brief Check if systemd state change is relevant to this object
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600109 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600110 * Instance specific interface to handle the detected systemd state
111 * change
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600112 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600113 * @param[in] msg - Data associated with subscribed signal
114 * @param[out] retError - Not used but required with signal API
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600115 *
116 */
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600117 int sysStateChange(sd_bus_message* msg,
118 sd_bus_error* retError);
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600119
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600120 /** @brief Persistent sdbusplus DBus connection. */
121 sdbusplus::bus::bus& bus;
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600122
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600123 /** @brief Used to subscribe to dbus systemd signals **/
124 sdbusplus::server::match::match systemdSignals;
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600125};
126
127} // namespace manager
128} // namespace state
129} // namespace phosphor