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