blob: 54f0afd95112484ac5d9adb50dac3a1b3db23cbf [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<
Andrew Geissler58a18012018-01-19 19:36:05 -080015 sdbusplus::xyz::openbmc_project::State::server::Chassis>;
Patrick Williams8f8ba392017-05-05 15:47:39 -050016namespace 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{
Andrew Geissler58a18012018-01-19 19:36:05 -080025 public:
26 /** @brief Constructs Chassis State Manager
27 *
28 * @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 *
32 * @param[in] bus - The Dbus bus object
33 * @param[in] instance - The instance of this object
34 * @param[in] objPath - The Dbus object path
35 */
36 Chassis(sdbusplus::bus::bus& bus, const char* busName,
37 const char* objPath) :
38 ChassisInherit(bus, objPath, true),
39 bus(bus),
40 systemdSignals(
41 bus,
42 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
43 sdbusRule::path("/org/freedesktop/systemd1") +
44 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
45 std::bind(std::mem_fn(&Chassis::sysStateChange), this,
46 std::placeholders::_1))
47 {
48 subscribeToSystemdSignals();
Andrew Geissler0029a5d2017-01-24 14:48:35 -060049
Andrew Geissler58a18012018-01-19 19:36:05 -080050 determineInitialState();
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060051
Andrew Geissler58a18012018-01-19 19:36:05 -080052 // We deferred this until we could get our property correct
53 this->emit_object_added();
54 }
Andrew Geisslerdff50ed2016-12-13 20:39:04 -060055
Andrew Geissler58a18012018-01-19 19:36:05 -080056 /** @brief Set value of RequestedPowerTransition */
57 Transition requestedPowerTransition(Transition value) override;
Andrew Geisslera90a31a2016-12-13 16:16:28 -060058
Andrew Geissler58a18012018-01-19 19:36:05 -080059 /** @brief Set value of CurrentPowerState */
60 PowerState currentPowerState(PowerState value) override;
Andrew Geisslera90a31a2016-12-13 16:16:28 -060061
Andrew Geissler58a18012018-01-19 19:36:05 -080062 private:
63 /** @brief Determine initial chassis state and set internally */
64 void determineInitialState();
Andrew Geissler0029a5d2017-01-24 14:48:35 -060065
Andrew Geissler58a18012018-01-19 19:36:05 -080066 /**
67 * @brief subscribe to the systemd signals
68 *
69 * This object needs to capture when it's systemd targets complete
70 * so it can keep it's state updated
71 *
72 **/
73 void subscribeToSystemdSignals();
Andrew Geissler0029a5d2017-01-24 14:48:35 -060074
Andrew Geissler58a18012018-01-19 19:36:05 -080075 /** @brief Execute the transition request
76 *
77 * This function calls the appropriate systemd target for the input
78 * transition.
79 *
80 * @param[in] tranReq - Transition requested
81 */
82 void executeTransition(Transition tranReq);
Andrew Geisslerce80f242017-01-24 13:25:33 -060083
Andrew Geissler58a18012018-01-19 19:36:05 -080084 /**
85 * @brief Determine if target is active
86 *
87 * This function determines if the target is active and
88 * helps prevent misleading log recorded states.
89 *
90 * @param[in] target - Target string to check on
91 *
92 * @return boolean corresponding to state active
93 **/
94 bool stateActive(const std::string& target);
Josh D. King697474c2017-03-02 11:15:55 -060095
Andrew Geissler58a18012018-01-19 19:36:05 -080096 /** @brief Check if systemd state change is relevant to this object
97 *
98 * Instance specific interface to handle the detected systemd state
99 * change
100 *
101 * @param[in] msg - Data associated with subscribed signal
102 *
103 */
104 int sysStateChange(sdbusplus::message::message& msg);
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600105
Andrew Geissler58a18012018-01-19 19:36:05 -0800106 /** @brief Persistent sdbusplus DBus connection. */
107 sdbusplus::bus::bus& bus;
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -0600108
Andrew Geissler58a18012018-01-19 19:36:05 -0800109 /** @brief Used to subscribe to dbus systemd signals **/
110 sdbusplus::bus::match_t systemdSignals;
Andrew Geisslera90a31a2016-12-13 16:16:28 -0600111};
112
113} // namespace manager
114} // namespace state
115} // namespace phosphor