Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 3 | #include "xyz/openbmc_project/State/BMC/server.hpp" |
| 4 | |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | |
| 7 | #include <functional> |
| 8 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace state |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 16 | using BMCInherit = sdbusplus::server::object::object< |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 17 | sdbusplus::xyz::openbmc_project::State::server::BMC>; |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 18 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 19 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 20 | /** @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 Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 25 | class BMC : public BMCInherit |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 26 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 27 | 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. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 48 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 49 | /** @brief Set value of BMCTransition **/ |
| 50 | Transition requestedBMCTransition(Transition value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 51 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 52 | /** @brief Set value of CurrentBMCState **/ |
| 53 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 54 | |
Matt Spinler | e6710b7 | 2018-07-12 16:05:55 -0500 | [diff] [blame] | 55 | /** @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 Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 65 | private: |
| 66 | /** |
| 67 | * @brief discover the state of the bmc |
| 68 | **/ |
| 69 | void discoverInitialState(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 70 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 71 | /** |
| 72 | * @brief subscribe to the systemd signals |
| 73 | **/ |
| 74 | void subscribeToSystemdSignals(); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 75 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 76 | /** @brief Execute the transition request |
| 77 | * |
| 78 | * @param[in] tranReq - Transition requested |
| 79 | */ |
| 80 | void executeTransition(Transition tranReq); |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 81 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 82 | /** @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. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 91 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 92 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
| 93 | sdbusplus::bus::bus& bus; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 94 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 95 | /** @brief Used to subscribe to dbus system state changes **/ |
| 96 | std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace manager |
| 100 | } // namespace state |
| 101 | } // namespace phosphor |