blob: cf53795be59916190742136629cd4cec234088a1 [file] [log] [blame]
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06001#pragma once
2
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06003#include "xyz/openbmc_project/State/BMC/server.hpp"
4
Andrew Geisslere426b582020-05-28 12:40:55 -05005#include <sdbusplus/bus.hpp>
6
7#include <functional>
8
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06009namespace phosphor
10{
11namespace state
12{
13namespace manager
14{
15
Patrick Williamsd32f8182017-05-05 15:55:24 -050016using BMCInherit = sdbusplus::server::object::object<
Andrew Geissler58a18012018-01-19 19:36:05 -080017 sdbusplus::xyz::openbmc_project::State::server::BMC>;
Patrick Williamsd32f8182017-05-05 15:55:24 -050018namespace sdbusRule = sdbusplus::bus::match::rules;
19
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060020/** @class BMC
21 * @brief OpenBMC BMC state management implementation.
22 * @details A concrete implementation for xyz.openbmc_project.State.BMC
23 * DBus API.
24 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050025class BMC : public BMCInherit
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060026{
Andrew Geissler58a18012018-01-19 19:36:05 -080027 public:
28 /** @brief Constructs BMC State Manager
29 *
30 * @param[in] bus - The Dbus bus object
31 * @param[in] busName - The Dbus name to own
32 * @param[in] objPath - The Dbus object path
33 */
34 BMC(sdbusplus::bus::bus& bus, const char* objPath) :
35 BMCInherit(bus, objPath, true), bus(bus),
36 stateSignal(std::make_unique<decltype(stateSignal)::element_type>(
37 bus,
38 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
39 sdbusRule::path("/org/freedesktop/systemd1") +
40 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
41 std::bind(std::mem_fn(&BMC::bmcStateChange), this,
42 std::placeholders::_1)))
43 {
44 subscribeToSystemdSignals();
45 discoverInitialState();
46 this->emit_object_added();
47 };
Josh D. King6db38222016-12-19 14:52:40 -060048
Andrew Geissler58a18012018-01-19 19:36:05 -080049 /** @brief Set value of BMCTransition **/
50 Transition requestedBMCTransition(Transition value) override;
Josh D. King6db38222016-12-19 14:52:40 -060051
Andrew Geissler58a18012018-01-19 19:36:05 -080052 /** @brief Set value of CurrentBMCState **/
53 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060054
Matt Spinlere6710b72018-07-12 16:05:55 -050055 /** @brief Returns the last time the BMC was rebooted
56 *
57 * @details Uses uptime information to determine when
58 * the BMC was last rebooted.
59 *
60 * @return uint64_t - Epoch time, in milliseconds, of the
61 * last reboot.
62 */
63 uint64_t lastRebootTime() const override;
64
Andrew Geissler58a18012018-01-19 19:36:05 -080065 private:
66 /**
67 * @brief discover the state of the bmc
68 **/
69 void discoverInitialState();
Josh D. Kingd3e58472017-02-02 11:09:11 -060070
Andrew Geissler58a18012018-01-19 19:36:05 -080071 /**
72 * @brief subscribe to the systemd signals
73 **/
74 void subscribeToSystemdSignals();
Josh D. King6db38222016-12-19 14:52:40 -060075
Andrew Geissler58a18012018-01-19 19:36:05 -080076 /** @brief Execute the transition request
77 *
78 * @param[in] tranReq - Transition requested
79 */
80 void executeTransition(Transition tranReq);
Josh D. King5162a7b2016-12-19 16:15:00 -060081
Andrew Geissler58a18012018-01-19 19:36:05 -080082 /** @brief Callback function on bmc state change
83 *
84 * Check if the state is relevant to the BMC and if so, update
85 * corresponding BMC object's state
86 *
87 * @param[in] msg - Data associated with subscribed signal
88 *
89 */
90 int bmcStateChange(sdbusplus::message::message& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060091
Andrew Geissler58a18012018-01-19 19:36:05 -080092 /** @brief Persistent sdbusplus DBus bus connection. **/
93 sdbusplus::bus::bus& bus;
Josh D. King6db38222016-12-19 14:52:40 -060094
Andrew Geissler58a18012018-01-19 19:36:05 -080095 /** @brief Used to subscribe to dbus system state changes **/
96 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060097};
98
99} // namespace manager
100} // namespace state
101} // namespace phosphor