blob: f6f7540d898d65f020a4d7b5598287c540bd44f2 [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<
15 sdbusplus::xyz::openbmc_project::State::server::BMC>;
16namespace sdbusRule = sdbusplus::bus::match::rules;
17
18
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060019/** @class BMC
20 * @brief OpenBMC BMC state management implementation.
21 * @details A concrete implementation for xyz.openbmc_project.State.BMC
22 * DBus API.
23 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050024class BMC : public BMCInherit
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060025{
26 public:
27 /** @brief Constructs BMC State Manager
28 *
29 * @param[in] bus - The Dbus bus object
30 * @param[in] busName - The Dbus name to own
31 * @param[in] objPath - The Dbus object path
32 */
33 BMC(sdbusplus::bus::bus& bus,
34 const char* objPath) :
Patrick Williamsd32f8182017-05-05 15:55:24 -050035 BMCInherit(bus, objPath, true),
36 bus(bus),
37 stateSignal(
38 std::make_unique<decltype(stateSignal)::element_type>(
Josh D. Kingd613b812016-12-19 16:47:45 -060039 bus,
Patrick Williamsd32f8182017-05-05 15:55:24 -050040 sdbusRule::type::signal() +
41 sdbusRule::member("JobRemoved") +
42 sdbusRule::path("/org/freedesktop/systemd1") +
43 sdbusRule::interface(
44 "org.freedesktop.systemd1.Manager"),
45 std::bind(std::mem_fn(&BMC::bmcStateChange),
46 this, std::placeholders::_1)))
Josh D. King6db38222016-12-19 14:52:40 -060047 {
48 subscribeToSystemdSignals();
Josh D. Kingd3e58472017-02-02 11:09:11 -060049 discoverInitialState();
50 this->emit_object_added();
Josh D. King6db38222016-12-19 14:52:40 -060051 };
52
53 /** @brief Set value of BMCTransition **/
54 Transition requestedBMCTransition(Transition value) override;
55
Josh D. Kingd613b812016-12-19 16:47:45 -060056 /** @brief Set value of CurrentBMCState **/
57 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060058
59 private:
60 /**
Josh D. Kingd3e58472017-02-02 11:09:11 -060061 * @brief discover the state of the bmc
62 **/
63 void discoverInitialState();
64
65 /**
Josh D. King6db38222016-12-19 14:52:40 -060066 * @brief subscribe to the systemd signals
67 **/
68 void subscribeToSystemdSignals();
69
Josh D. King5162a7b2016-12-19 16:15:00 -060070 /** @brief Execute the transition request
71 *
72 * @param[in] tranReq - Transition requested
73 */
74 void executeTransition(Transition tranReq);
75
Josh D. Kingd613b812016-12-19 16:47:45 -060076 /** @brief Callback function on bmc state change
77 *
78 * Check if the state is relevant to the BMC and if so, update
79 * corresponding BMC object's state
80 *
81 * @param[in] msg - Data associated with subscribed signal
Josh D. Kingd613b812016-12-19 16:47:45 -060082 *
83 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050084 int bmcStateChange(sdbusplus::message::message& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060085
Josh D. King6db38222016-12-19 14:52:40 -060086 /** @brief Persistent sdbusplus DBus bus connection. **/
87 sdbusplus::bus::bus& bus;
88
Josh D. Kingd613b812016-12-19 16:47:45 -060089 /** @brief Used to subscribe to dbus system state changes **/
Patrick Williamsd32f8182017-05-05 15:55:24 -050090 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060091};
92
93} // namespace manager
94} // namespace state
95} // namespace phosphor