blob: 132e30ef56414ca84174db3be7e8cb0e3d48778a [file] [log] [blame]
Andrew Geisslera90a31a2016-12-13 16:16:28 -06001#pragma once
2
Patrick Williams8f8ba392017-05-05 15:47:39 -05003#include <functional>
Andrew Geisslera90a31a2016-12-13 16:16:28 -06004#include <sdbusplus/bus.hpp>
5#include "xyz/openbmc_project/State/Chassis/server.hpp"
6
7namespace phosphor
8{
9namespace state
10{
11namespace manager
12{
13
Patrick Williams8f8ba392017-05-05 15:47:39 -050014using ChassisInherit = sdbusplus::server::object::object<
15 sdbusplus::xyz::openbmc_project::State::server::Chassis>;
16namespace sdbusRule = sdbusplus::bus::match::rules;
17
Andrew Geisslera90a31a2016-12-13 16:16:28 -060018/** @class Chassis
19 * @brief OpenBMC chassis state management implementation.
20 * @details A concrete implementation for xyz.openbmc_project.State.Chassis
21 * DBus API.
22 */
Patrick Williams8f8ba392017-05-05 15:47:39 -050023class Chassis : public ChassisInherit
Andrew Geisslera90a31a2016-12-13 16:16:28 -060024{
25 public:
26 /** @brief Constructs Chassis State Manager
27 *
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060028 * @note This constructor passes 'true' to the base class in order to
29 * defer dbus object registration until we can run
30 * determineInitialState() and set our properties
31 *
Andrew Geisslera90a31a2016-12-13 16:16:28 -060032 * @param[in] bus - The Dbus bus object
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060033 * @param[in] instance - The instance of this object
Andrew Geisslera90a31a2016-12-13 16:16:28 -060034 * @param[in] objPath - The Dbus object path
35 */
36 Chassis(sdbusplus::bus::bus& bus,
37 const char* busName,
38 const char* objPath) :
Patrick Williams8f8ba392017-05-05 15:47:39 -050039 ChassisInherit(bus, objPath, true),
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060040 bus(bus),
Andrew Geissler0029a5d2017-01-24 14:48:35 -060041 systemdSignals(bus,
Patrick Williams8f8ba392017-05-05 15:47:39 -050042 sdbusRule::type::signal() +
43 sdbusRule::member("JobRemoved") +
44 sdbusRule::path("/org/freedesktop/systemd1") +
45 sdbusRule::interface(
46 "org.freedesktop.systemd1.Manager"),
47 std::bind(std::mem_fn(&Chassis::sysStateChange),
48 this, std::placeholders::_1))
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060049 {
Andrew Geissler0029a5d2017-01-24 14:48:35 -060050 subscribeToSystemdSignals();
51
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060052 determineInitialState();
53
54 // We deferred this until we could get our property correct
55 this->emit_object_added();
56 }
57
Andrew Geisslera90a31a2016-12-13 16:16:28 -060058 /** @brief Set value of RequestedPowerTransition */
59 Transition requestedPowerTransition(Transition value) override;
60
61 /** @brief Set value of CurrentPowerState */
62 PowerState currentPowerState(PowerState value) override;
63
64 private:
Andrew Geissler0029a5d2017-01-24 14:48:35 -060065 /** @brief Determine initial chassis state and set internally */
66 void determineInitialState();
67
68 /**
69 * @brief subscribe to the systemd signals
70 *
71 * This object needs to capture when it's systemd targets complete
72 * so it can keep it's state updated
73 *
74 **/
75 void subscribeToSystemdSignals();
76
Andrew Geisslerce80f242017-01-24 13:25:33 -060077 /** @brief Execute the transition request
78 *
79 * This function calls the appropriate systemd target for the input
80 * transition.
81 *
82 * @param[in] tranReq - Transition requested
83 */
84 void executeTransition(Transition tranReq);
85
Josh D. King697474c2017-03-02 11:15:55 -060086 /**
87 * @brief Determine if target is active
88 *
89 * This function determines if the target is active and
90 * helps prevent misleading log recorded states.
91 *
92 * @param[in] target - Target string to check on
93 *
94 * @return boolean corresponding to state active
95 **/
96 bool stateActive(const std::string& target);
97
Andrew Geissler0029a5d2017-01-24 14:48:35 -060098 /** @brief Check if systemd state change is relevant to this object
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060099 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600100 * Instance specific interface to handle the detected systemd state
101 * change
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600102 *
Andrew Geissler0029a5d2017-01-24 14:48:35 -0600103 * @param[in] msg - Data associated with subscribed signal
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600104 *
105 */
Patrick Williams8f8ba392017-05-05 15:47:39 -0500106 int sysStateChange(sdbusplus::message::message& msg);
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 **/
Patrick Williams8f8ba392017-05-05 15:47:39 -0500112 sdbusplus::bus::match_t systemdSignals;
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600113};
114
115} // namespace manager
116} // namespace state
117} // namespace phosphor