blob: b060ccd66f376a05dcb2bbe51e246d947447272e [file] [log] [blame]
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06001#pragma once
2
Patrick Williamsd32f8182017-05-05 15:55:24 -05003#include <functional>
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06004#include <sdbusplus/bus.hpp>
5#include "xyz/openbmc_project/State/BMC/server.hpp"
6
7namespace phosphor
8{
9namespace state
10{
11namespace manager
12{
13
Patrick Williamsd32f8182017-05-05 15:55:24 -050014using BMCInherit = sdbusplus::server::object::object<
Andrew Geissler58a18012018-01-19 19:36:05 -080015 sdbusplus::xyz::openbmc_project::State::server::BMC>;
Patrick Williamsd32f8182017-05-05 15:55:24 -050016namespace sdbusRule = sdbusplus::bus::match::rules;
17
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060018/** @class BMC
19 * @brief OpenBMC BMC state management implementation.
20 * @details A concrete implementation for xyz.openbmc_project.State.BMC
21 * DBus API.
22 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050023class BMC : public BMCInherit
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060024{
Andrew Geissler58a18012018-01-19 19:36:05 -080025 public:
26 /** @brief Constructs BMC State Manager
27 *
28 * @param[in] bus - The Dbus bus object
29 * @param[in] busName - The Dbus name to own
30 * @param[in] objPath - The Dbus object path
31 */
32 BMC(sdbusplus::bus::bus& bus, const char* objPath) :
33 BMCInherit(bus, objPath, true), bus(bus),
34 stateSignal(std::make_unique<decltype(stateSignal)::element_type>(
35 bus,
36 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
37 sdbusRule::path("/org/freedesktop/systemd1") +
38 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
39 std::bind(std::mem_fn(&BMC::bmcStateChange), this,
40 std::placeholders::_1)))
41 {
42 subscribeToSystemdSignals();
43 discoverInitialState();
44 this->emit_object_added();
45 };
Josh D. King6db38222016-12-19 14:52:40 -060046
Andrew Geissler58a18012018-01-19 19:36:05 -080047 /** @brief Set value of BMCTransition **/
48 Transition requestedBMCTransition(Transition value) override;
Josh D. King6db38222016-12-19 14:52:40 -060049
Andrew Geissler58a18012018-01-19 19:36:05 -080050 /** @brief Set value of CurrentBMCState **/
51 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060052
Andrew Geissler58a18012018-01-19 19:36:05 -080053 private:
54 /**
55 * @brief discover the state of the bmc
56 **/
57 void discoverInitialState();
Josh D. Kingd3e58472017-02-02 11:09:11 -060058
Andrew Geissler58a18012018-01-19 19:36:05 -080059 /**
60 * @brief subscribe to the systemd signals
61 **/
62 void subscribeToSystemdSignals();
Josh D. King6db38222016-12-19 14:52:40 -060063
Andrew Geissler58a18012018-01-19 19:36:05 -080064 /** @brief Execute the transition request
65 *
66 * @param[in] tranReq - Transition requested
67 */
68 void executeTransition(Transition tranReq);
Josh D. King5162a7b2016-12-19 16:15:00 -060069
Andrew Geissler58a18012018-01-19 19:36:05 -080070 /** @brief Callback function on bmc state change
71 *
72 * Check if the state is relevant to the BMC and if so, update
73 * corresponding BMC object's state
74 *
75 * @param[in] msg - Data associated with subscribed signal
76 *
77 */
78 int bmcStateChange(sdbusplus::message::message& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060079
Andrew Geissler58a18012018-01-19 19:36:05 -080080 /** @brief Persistent sdbusplus DBus bus connection. **/
81 sdbusplus::bus::bus& bus;
Josh D. King6db38222016-12-19 14:52:40 -060082
Andrew Geissler58a18012018-01-19 19:36:05 -080083 /** @brief Used to subscribe to dbus system state changes **/
84 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060085};
86
87} // namespace manager
88} // namespace state
89} // namespace phosphor