| #pragma once |
| |
| #include <functional> |
| #include <sdbusplus/bus.hpp> |
| #include "xyz/openbmc_project/State/BMC/server.hpp" |
| |
| namespace phosphor |
| { |
| namespace state |
| { |
| namespace manager |
| { |
| |
| using BMCInherit = sdbusplus::server::object::object< |
| sdbusplus::xyz::openbmc_project::State::server::BMC>; |
| namespace sdbusRule = sdbusplus::bus::match::rules; |
| |
| |
| /** @class BMC |
| * @brief OpenBMC BMC state management implementation. |
| * @details A concrete implementation for xyz.openbmc_project.State.BMC |
| * DBus API. |
| */ |
| class BMC : public BMCInherit |
| { |
| public: |
| /** @brief Constructs BMC State Manager |
| * |
| * @param[in] bus - The Dbus bus object |
| * @param[in] busName - The Dbus name to own |
| * @param[in] objPath - The Dbus object path |
| */ |
| BMC(sdbusplus::bus::bus& bus, |
| const char* objPath) : |
| BMCInherit(bus, objPath, true), |
| bus(bus), |
| stateSignal( |
| std::make_unique<decltype(stateSignal)::element_type>( |
| bus, |
| sdbusRule::type::signal() + |
| sdbusRule::member("JobRemoved") + |
| sdbusRule::path("/org/freedesktop/systemd1") + |
| sdbusRule::interface( |
| "org.freedesktop.systemd1.Manager"), |
| std::bind(std::mem_fn(&BMC::bmcStateChange), |
| this, std::placeholders::_1))) |
| { |
| subscribeToSystemdSignals(); |
| discoverInitialState(); |
| this->emit_object_added(); |
| }; |
| |
| /** @brief Set value of BMCTransition **/ |
| Transition requestedBMCTransition(Transition value) override; |
| |
| /** @brief Set value of CurrentBMCState **/ |
| BMCState currentBMCState(BMCState value) override; |
| |
| private: |
| /** |
| * @brief discover the state of the bmc |
| **/ |
| void discoverInitialState(); |
| |
| /** |
| * @brief subscribe to the systemd signals |
| **/ |
| void subscribeToSystemdSignals(); |
| |
| /** @brief Execute the transition request |
| * |
| * @param[in] tranReq - Transition requested |
| */ |
| void executeTransition(Transition tranReq); |
| |
| /** @brief Callback function on bmc state change |
| * |
| * Check if the state is relevant to the BMC and if so, update |
| * corresponding BMC object's state |
| * |
| * @param[in] msg - Data associated with subscribed signal |
| * |
| */ |
| int bmcStateChange(sdbusplus::message::message& msg); |
| |
| /** @brief Persistent sdbusplus DBus bus connection. **/ |
| sdbusplus::bus::bus& bus; |
| |
| /** @brief Used to subscribe to dbus system state changes **/ |
| std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
| }; |
| |
| } // namespace manager |
| } // namespace state |
| } // namespace phosphor |