Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 3 | #include <functional> |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 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 | |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 14 | using BMCInherit = sdbusplus::server::object::object< |
| 15 | sdbusplus::xyz::openbmc_project::State::server::BMC>; |
| 16 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 17 | |
| 18 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 19 | /** @class BMC |
| 20 | * @brief OpenBMC BMC state management implementation. |
| 21 | * @details A concrete implementation for xyz.openbmc_project.State.BMC |
| 22 | * DBus API. |
| 23 | */ |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 24 | class BMC : public BMCInherit |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 25 | { |
| 26 | public: |
| 27 | /** @brief Constructs BMC State Manager |
| 28 | * |
| 29 | * @param[in] bus - The Dbus bus object |
| 30 | * @param[in] busName - The Dbus name to own |
| 31 | * @param[in] objPath - The Dbus object path |
| 32 | */ |
| 33 | BMC(sdbusplus::bus::bus& bus, |
| 34 | const char* objPath) : |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 35 | BMCInherit(bus, objPath, true), |
| 36 | bus(bus), |
| 37 | stateSignal( |
| 38 | std::make_unique<decltype(stateSignal)::element_type>( |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 39 | bus, |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 40 | sdbusRule::type::signal() + |
| 41 | sdbusRule::member("JobRemoved") + |
| 42 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 43 | sdbusRule::interface( |
| 44 | "org.freedesktop.systemd1.Manager"), |
| 45 | std::bind(std::mem_fn(&BMC::bmcStateChange), |
| 46 | this, std::placeholders::_1))) |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 47 | { |
| 48 | subscribeToSystemdSignals(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 49 | discoverInitialState(); |
| 50 | this->emit_object_added(); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** @brief Set value of BMCTransition **/ |
| 54 | Transition requestedBMCTransition(Transition value) override; |
| 55 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 56 | /** @brief Set value of CurrentBMCState **/ |
| 57 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | /** |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 61 | * @brief discover the state of the bmc |
| 62 | **/ |
| 63 | void discoverInitialState(); |
| 64 | |
| 65 | /** |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 66 | * @brief subscribe to the systemd signals |
| 67 | **/ |
| 68 | void subscribeToSystemdSignals(); |
| 69 | |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 70 | /** @brief Execute the transition request |
| 71 | * |
| 72 | * @param[in] tranReq - Transition requested |
| 73 | */ |
| 74 | void executeTransition(Transition tranReq); |
| 75 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 76 | /** @brief Callback function on bmc state change |
| 77 | * |
| 78 | * Check if the state is relevant to the BMC and if so, update |
| 79 | * corresponding BMC object's state |
| 80 | * |
| 81 | * @param[in] msg - Data associated with subscribed signal |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 82 | * |
| 83 | */ |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 84 | int bmcStateChange(sdbusplus::message::message& msg); |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 85 | |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 86 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
| 87 | sdbusplus::bus::bus& bus; |
| 88 | |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 89 | /** @brief Used to subscribe to dbus system state changes **/ |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 90 | std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace manager |
| 94 | } // namespace state |
| 95 | } // namespace phosphor |