1 #pragma once 2 3 #include <functional> 4 #include <sdbusplus/bus.hpp> 5 #include "xyz/openbmc_project/State/BMC/server.hpp" 6 7 namespace phosphor 8 { 9 namespace state 10 { 11 namespace manager 12 { 13 14 using BMCInherit = sdbusplus::server::object::object< 15 sdbusplus::xyz::openbmc_project::State::server::BMC>; 16 namespace sdbusRule = sdbusplus::bus::match::rules; 17 18 /** @class BMC 19 * @brief OpenBMC BMC state management implementation. 20 * @details A concrete implementation for xyz.openbmc_project.State.BMC 21 * DBus API. 22 */ 23 class BMC : public BMCInherit 24 { 25 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 }; 46 47 /** @brief Set value of BMCTransition **/ 48 Transition requestedBMCTransition(Transition value) override; 49 50 /** @brief Set value of CurrentBMCState **/ 51 BMCState currentBMCState(BMCState value) override; 52 53 /** @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 63 private: 64 /** 65 * @brief discover the state of the bmc 66 **/ 67 void discoverInitialState(); 68 69 /** 70 * @brief subscribe to the systemd signals 71 **/ 72 void subscribeToSystemdSignals(); 73 74 /** @brief Execute the transition request 75 * 76 * @param[in] tranReq - Transition requested 77 */ 78 void executeTransition(Transition tranReq); 79 80 /** @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); 89 90 /** @brief Persistent sdbusplus DBus bus connection. **/ 91 sdbusplus::bus::bus& bus; 92 93 /** @brief Used to subscribe to dbus system state changes **/ 94 std::unique_ptr<sdbusplus::bus::match_t> stateSignal; 95 }; 96 97 } // namespace manager 98 } // namespace state 99 } // namespace phosphor 100