1 #pragma once 2 3 #include <sdbusplus/bus.hpp> 4 #include "xyz/openbmc_project/State/BMC/server.hpp" 5 6 namespace phosphor 7 { 8 namespace state 9 { 10 namespace manager 11 { 12 13 /** @class BMC 14 * @brief OpenBMC BMC state management implementation. 15 * @details A concrete implementation for xyz.openbmc_project.State.BMC 16 * DBus API. 17 */ 18 class BMC : public sdbusplus::server::object::object< 19 sdbusplus::xyz::openbmc_project::State::server::BMC> 20 { 21 public: 22 /** @brief Constructs BMC State Manager 23 * 24 * @param[in] bus - The Dbus bus object 25 * @param[in] busName - The Dbus name to own 26 * @param[in] objPath - The Dbus object path 27 */ 28 BMC(sdbusplus::bus::bus& bus, 29 const char* objPath) : 30 sdbusplus::server::object::object< 31 sdbusplus::xyz::openbmc_project::State::server::BMC>( 32 bus, objPath), 33 bus(bus), 34 stateSignal( 35 std::make_unique< 36 decltype(stateSignal)::element_type>( 37 bus, 38 "type='signal'," 39 "member='JobRemoved'," 40 "path='/org/freedesktop/systemd1'," 41 "interface='org.freedesktop.systemd1.Manager'", 42 bmcStateChangeSignal, 43 this)) 44 { 45 subscribeToSystemdSignals(); 46 }; 47 48 /** @brief Set value of BMCTransition **/ 49 Transition requestedBMCTransition(Transition value) override; 50 51 /** @brief Set value of CurrentBMCState **/ 52 BMCState currentBMCState(BMCState value) override; 53 54 private: 55 /** 56 * @brief subscribe to the systemd signals 57 **/ 58 void subscribeToSystemdSignals(); 59 60 /** @brief Execute the transition request 61 * 62 * @param[in] tranReq - Transition requested 63 */ 64 void executeTransition(Transition tranReq); 65 66 /** @brief Callback used to direct you into the class 67 * 68 * @param[in] msg - Data associated with subscribed signal 69 * @param[in] userData - Pointer to this object instance 70 * @param[out] retError - return error data if any 71 * 72 */ 73 static int bmcStateChangeSignal(sd_bus_message* msg, 74 void* userData, 75 sd_bus_error* retError); 76 77 /** @brief Callback function on bmc state change 78 * 79 * Check if the state is relevant to the BMC and if so, update 80 * corresponding BMC object's state 81 * 82 * @param[in] msg - Data associated with subscribed signal 83 * @param[out] retError - return error data if any 84 * 85 */ 86 int bmcStateChange(sd_bus_message* msg, 87 sd_bus_error* retError); 88 89 /** @brief Persistent sdbusplus DBus bus connection. **/ 90 sdbusplus::bus::bus& bus; 91 92 /** @brief Used to subscribe to dbus system state changes **/ 93 std::unique_ptr<sdbusplus::server::match::match> stateSignal; 94 }; 95 96 } // namespace manager 97 } // namespace state 98 } // namespace phosphor 99