blob: 0e52a25ebeae3a2c76d9f7942e3791e30e3b2449 [file] [log] [blame]
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/State/BMC/server.hpp"
5
6namespace phosphor
7{
8namespace state
9{
10namespace manager
11{
12
13/** @class BMC
14 * @brief OpenBMC BMC state management implementation.
15 * @details A concrete implementation for xyz.openbmc_project.State.BMC
16 * DBus API.
17 */
18class BMC : public sdbusplus::server::object::object<
19 sdbusplus::xyz::openbmc_project::State::server::BMC>
20{
21 public:
22 /** @brief Constructs BMC State Manager
23 *
24 * @param[in] bus - The Dbus bus object
25 * @param[in] busName - The Dbus name to own
26 * @param[in] objPath - The Dbus object path
27 */
28 BMC(sdbusplus::bus::bus& bus,
29 const char* objPath) :
30 sdbusplus::server::object::object<
31 sdbusplus::xyz::openbmc_project::State::server::BMC>(
Josh D. Kingd3e58472017-02-02 11:09:11 -060032 bus, objPath, true),
Josh D. Kingd613b812016-12-19 16:47:45 -060033 bus(bus),
34 stateSignal(
35 std::make_unique<
36 decltype(stateSignal)::element_type>(
37 bus,
38 "type='signal',"
39 "member='JobRemoved',"
40 "path='/org/freedesktop/systemd1',"
41 "interface='org.freedesktop.systemd1.Manager'",
42 bmcStateChangeSignal,
43 this))
Josh D. King6db38222016-12-19 14:52:40 -060044 {
45 subscribeToSystemdSignals();
Josh D. Kingd3e58472017-02-02 11:09:11 -060046 discoverInitialState();
47 this->emit_object_added();
Josh D. King6db38222016-12-19 14:52:40 -060048 };
49
50 /** @brief Set value of BMCTransition **/
51 Transition requestedBMCTransition(Transition value) override;
52
Josh D. Kingd613b812016-12-19 16:47:45 -060053 /** @brief Set value of CurrentBMCState **/
54 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060055
56 private:
57 /**
Josh D. Kingd3e58472017-02-02 11:09:11 -060058 * @brief discover the state of the bmc
59 **/
60 void discoverInitialState();
61
62 /**
Josh D. King6db38222016-12-19 14:52:40 -060063 * @brief subscribe to the systemd signals
64 **/
65 void subscribeToSystemdSignals();
66
Josh D. King5162a7b2016-12-19 16:15:00 -060067 /** @brief Execute the transition request
68 *
69 * @param[in] tranReq - Transition requested
70 */
71 void executeTransition(Transition tranReq);
72
Josh D. Kingd613b812016-12-19 16:47:45 -060073 /** @brief Callback used to direct you into the class
74 *
75 * @param[in] msg - Data associated with subscribed signal
76 * @param[in] userData - Pointer to this object instance
77 * @param[out] retError - return error data if any
78 *
79 */
80 static int bmcStateChangeSignal(sd_bus_message* msg,
81 void* userData,
82 sd_bus_error* retError);
83
84 /** @brief Callback function on bmc state change
85 *
86 * Check if the state is relevant to the BMC and if so, update
87 * corresponding BMC object's state
88 *
89 * @param[in] msg - Data associated with subscribed signal
90 * @param[out] retError - return error data if any
91 *
92 */
93 int bmcStateChange(sd_bus_message* msg,
94 sd_bus_error* retError);
95
Josh D. King6db38222016-12-19 14:52:40 -060096 /** @brief Persistent sdbusplus DBus bus connection. **/
97 sdbusplus::bus::bus& bus;
98
Josh D. Kingd613b812016-12-19 16:47:45 -060099 /** @brief Used to subscribe to dbus system state changes **/
100 std::unique_ptr<sdbusplus::server::match::match> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -0600101};
102
103} // namespace manager
104} // namespace state
105} // namespace phosphor