Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include "xyz/openbmc_project/State/Host/server.hpp" |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace state |
| 9 | { |
| 10 | namespace manager |
| 11 | { |
| 12 | |
| 13 | /** @class Host |
| 14 | * @brief OpenBMC host state management implementation. |
| 15 | * @details A concrete implementation for xyz.openbmc_project.State.Host |
| 16 | * DBus API. |
| 17 | */ |
| 18 | class Host : public sdbusplus::server::object::object< |
| 19 | sdbusplus::xyz::openbmc_project::State::server::Host> |
| 20 | { |
| 21 | public: |
| 22 | /** @brief Constructs Host State Manager |
| 23 | * |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 24 | * @note This constructor passes 'true' to the base class in order to |
| 25 | * defer dbus object registration until we can run |
| 26 | * determineInitialState() and set our properties |
| 27 | * |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 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 | Host(sdbusplus::bus::bus& bus, |
| 33 | const char* busName, |
| 34 | const char* objPath) : |
| 35 | sdbusplus::server::object::object< |
| 36 | sdbusplus::xyz::openbmc_project::State::server::Host>( |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 37 | bus, objPath, true), |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 38 | bus(bus), |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 39 | systemdSignals(bus, |
| 40 | "type='signal'," |
| 41 | "member='JobRemoved'," |
| 42 | "path='/org/freedesktop/systemd1'," |
| 43 | "interface='org.freedesktop.systemd1.Manager'", |
| 44 | sysStateChangeSignal, |
| 45 | this) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 46 | { |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 47 | // Enable systemd signals |
| 48 | subscribeToSystemdSignals(); |
| 49 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 50 | // Will throw exception on fail |
| 51 | determineInitialState(); |
| 52 | |
| 53 | // We deferred this until we could get our property correct |
| 54 | this->emit_object_added(); |
| 55 | } |
| 56 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 57 | /** @brief Set value of HostTransition */ |
| 58 | Transition requestedHostTransition(Transition value) override; |
| 59 | |
| 60 | /** @brief Set value of CurrentHostState */ |
| 61 | HostState currentHostState(HostState value) override; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 62 | |
| 63 | private: |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 64 | /** |
| 65 | * @brief subscribe to the systemd signals |
| 66 | * |
| 67 | * This object needs to capture when it's systemd targets complete |
| 68 | * so it can keep it's state updated |
| 69 | * |
| 70 | **/ |
| 71 | void subscribeToSystemdSignals(); |
| 72 | |
| 73 | /** |
| 74 | * @brief Determine initial host state and set internally |
| 75 | * |
| 76 | * @return Will throw exceptions on failure |
| 77 | **/ |
| 78 | void determineInitialState(); |
| 79 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 80 | /** @brief Execute the transition request |
| 81 | * |
| 82 | * This function assumes the state has been validated and the host |
| 83 | * is in an appropriate state for the transition to be started. |
| 84 | * |
| 85 | * @param[in] tranReq - Transition requested |
| 86 | */ |
| 87 | void executeTransition(Transition tranReq); |
| 88 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 89 | /** @brief Callback function on systemd state changes |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 90 | * |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 91 | * Will just do a call into the appropriate object for processing |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 92 | * |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 93 | * @param[in] msg - Data associated with subscribed signal |
| 94 | * @param[in] userData - Pointer to this object instance |
| 95 | * @param[out] retError - Not used but required with signal API |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 96 | * |
| 97 | */ |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 98 | static int sysStateChangeSignal(sd_bus_message* msg, |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 99 | void* userData, |
| 100 | sd_bus_error* retError); |
| 101 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 102 | /** @brief Check if systemd state change is relevant to this object |
| 103 | * |
| 104 | * Instance specific interface to handle the detected systemd state |
| 105 | * change |
| 106 | * |
| 107 | * @param[in] msg - Data associated with subscribed signal |
| 108 | * @param[out] retError - Not used but required with signal API |
| 109 | * |
| 110 | */ |
| 111 | int sysStateChange(sd_bus_message* msg, |
| 112 | sd_bus_error* retError); |
| 113 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 114 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 115 | sdbusplus::bus::bus& bus; |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 116 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 117 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 118 | sdbusplus::server::match::match systemdSignals; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace manager |
| 122 | } // namespace state |
| 123 | } // namespace phosphor |