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< |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 15 | sdbusplus::xyz::openbmc_project::State::server::BMC>; |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 16 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 17 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 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 | */ |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 23 | class BMC : public BMCInherit |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 24 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 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 | }; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 46 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 47 | /** @brief Set value of BMCTransition **/ |
| 48 | Transition requestedBMCTransition(Transition value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 49 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 50 | /** @brief Set value of CurrentBMCState **/ |
| 51 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 52 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 53 | private: |
| 54 | /** |
| 55 | * @brief discover the state of the bmc |
| 56 | **/ |
| 57 | void discoverInitialState(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 58 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 59 | /** |
| 60 | * @brief subscribe to the systemd signals |
| 61 | **/ |
| 62 | void subscribeToSystemdSignals(); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 63 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 64 | /** @brief Execute the transition request |
| 65 | * |
| 66 | * @param[in] tranReq - Transition requested |
| 67 | */ |
| 68 | void executeTransition(Transition tranReq); |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 69 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 70 | /** @brief Callback function on bmc state change |
| 71 | * |
| 72 | * Check if the state is relevant to the BMC and if so, update |
| 73 | * corresponding BMC object's state |
| 74 | * |
| 75 | * @param[in] msg - Data associated with subscribed signal |
| 76 | * |
| 77 | */ |
| 78 | int bmcStateChange(sdbusplus::message::message& msg); |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 79 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 80 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
| 81 | sdbusplus::bus::bus& bus; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 82 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame^] | 83 | /** @brief Used to subscribe to dbus system state changes **/ |
| 84 | std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace manager |
| 88 | } // namespace state |
| 89 | } // namespace phosphor |