Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 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>( |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame^] | 32 | bus, objPath, true), |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 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)) |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 44 | { |
| 45 | subscribeToSystemdSignals(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame^] | 46 | discoverInitialState(); |
| 47 | this->emit_object_added(); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /** @brief Set value of BMCTransition **/ |
| 51 | Transition requestedBMCTransition(Transition value) override; |
| 52 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 53 | /** @brief Set value of CurrentBMCState **/ |
| 54 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | /** |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame^] | 58 | * @brief discover the state of the bmc |
| 59 | **/ |
| 60 | void discoverInitialState(); |
| 61 | |
| 62 | /** |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 63 | * @brief subscribe to the systemd signals |
| 64 | **/ |
| 65 | void subscribeToSystemdSignals(); |
| 66 | |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 67 | /** @brief Execute the transition request |
| 68 | * |
| 69 | * @param[in] tranReq - Transition requested |
| 70 | */ |
| 71 | void executeTransition(Transition tranReq); |
| 72 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 73 | /** @brief Callback used to direct you into the class |
| 74 | * |
| 75 | * @param[in] msg - Data associated with subscribed signal |
| 76 | * @param[in] userData - Pointer to this object instance |
| 77 | * @param[out] retError - return error data if any |
| 78 | * |
| 79 | */ |
| 80 | static int bmcStateChangeSignal(sd_bus_message* msg, |
| 81 | void* userData, |
| 82 | sd_bus_error* retError); |
| 83 | |
| 84 | /** @brief Callback function on bmc state change |
| 85 | * |
| 86 | * Check if the state is relevant to the BMC and if so, update |
| 87 | * corresponding BMC object's state |
| 88 | * |
| 89 | * @param[in] msg - Data associated with subscribed signal |
| 90 | * @param[out] retError - return error data if any |
| 91 | * |
| 92 | */ |
| 93 | int bmcStateChange(sd_bus_message* msg, |
| 94 | sd_bus_error* retError); |
| 95 | |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 96 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
| 97 | sdbusplus::bus::bus& bus; |
| 98 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 99 | /** @brief Used to subscribe to dbus system state changes **/ |
| 100 | std::unique_ptr<sdbusplus::server::match::match> stateSignal; |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // namespace manager |
| 104 | } // namespace state |
| 105 | } // namespace phosphor |