blob: bbace381ea0fe4b23f16f0eb25c8f3704655ff7d [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. King6db38222016-12-19 14:52:40 -060032 bus, objPath),
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();
46 };
47
48 /** @brief Set value of BMCTransition **/
49 Transition requestedBMCTransition(Transition value) override;
50
Josh D. Kingd613b812016-12-19 16:47:45 -060051 /** @brief Set value of CurrentBMCState **/
52 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060053
54 private:
55 /**
56 * @brief subscribe to the systemd signals
57 **/
58 void subscribeToSystemdSignals();
59
Josh D. King5162a7b2016-12-19 16:15:00 -060060 /** @brief Execute the transition request
61 *
62 * @param[in] tranReq - Transition requested
63 */
64 void executeTransition(Transition tranReq);
65
Josh D. Kingd613b812016-12-19 16:47:45 -060066 /** @brief Callback used to direct you into the class
67 *
68 * @param[in] msg - Data associated with subscribed signal
69 * @param[in] userData - Pointer to this object instance
70 * @param[out] retError - return error data if any
71 *
72 */
73 static int bmcStateChangeSignal(sd_bus_message* msg,
74 void* userData,
75 sd_bus_error* retError);
76
77 /** @brief Callback function on bmc state change
78 *
79 * Check if the state is relevant to the BMC and if so, update
80 * corresponding BMC object's state
81 *
82 * @param[in] msg - Data associated with subscribed signal
83 * @param[out] retError - return error data if any
84 *
85 */
86 int bmcStateChange(sd_bus_message* msg,
87 sd_bus_error* retError);
88
Josh D. King6db38222016-12-19 14:52:40 -060089 /** @brief Persistent sdbusplus DBus bus connection. **/
90 sdbusplus::bus::bus& bus;
91
Josh D. Kingd613b812016-12-19 16:47:45 -060092 /** @brief Used to subscribe to dbus system state changes **/
93 std::unique_ptr<sdbusplus::server::match::match> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060094};
95
96} // namespace manager
97} // namespace state
98} // namespace phosphor