blob: c55c82251131a4d422488b37a8652c8445470b4a [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
Matt Spinlere6710b72018-07-12 16:05:55 -050053 /** @brief Returns the last time the BMC was rebooted
54 *
55 * @details Uses uptime information to determine when
56 * the BMC was last rebooted.
57 *
58 * @return uint64_t - Epoch time, in milliseconds, of the
59 * last reboot.
60 */
61 uint64_t lastRebootTime() const override;
62
Andrew Geissler58a18012018-01-19 19:36:05 -080063 private:
64 /**
65 * @brief discover the state of the bmc
66 **/
67 void discoverInitialState();
Josh D. Kingd3e58472017-02-02 11:09:11 -060068
Andrew Geissler58a18012018-01-19 19:36:05 -080069 /**
70 * @brief subscribe to the systemd signals
71 **/
72 void subscribeToSystemdSignals();
Josh D. King6db38222016-12-19 14:52:40 -060073
Andrew Geissler58a18012018-01-19 19:36:05 -080074 /** @brief Execute the transition request
75 *
76 * @param[in] tranReq - Transition requested
77 */
78 void executeTransition(Transition tranReq);
Josh D. King5162a7b2016-12-19 16:15:00 -060079
Andrew Geissler58a18012018-01-19 19:36:05 -080080 /** @brief Callback function on bmc state change
81 *
82 * Check if the state is relevant to the BMC and if so, update
83 * corresponding BMC object's state
84 *
85 * @param[in] msg - Data associated with subscribed signal
86 *
87 */
88 int bmcStateChange(sdbusplus::message::message& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060089
Andrew Geissler58a18012018-01-19 19:36:05 -080090 /** @brief Persistent sdbusplus DBus bus connection. **/
91 sdbusplus::bus::bus& bus;
Josh D. King6db38222016-12-19 14:52:40 -060092
Andrew Geissler58a18012018-01-19 19:36:05 -080093 /** @brief Used to subscribe to dbus system state changes **/
94 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060095};
96
97} // namespace manager
98} // namespace state
99} // namespace phosphor