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 | /** |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 91 | * @brief Determine if target is active |
| 92 | * |
| 93 | * This function determines if the target is active and |
| 94 | * helps prevent misleading log recorded states. |
| 95 | * |
| 96 | * @param[in] target - Target string to check on |
| 97 | * |
| 98 | * @return boolean corresponding to state active |
| 99 | **/ |
| 100 | bool stateActive(const std::string& target); |
| 101 | |
| 102 | /** |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 103 | * @brief Set the HOST BOOTCOUNT Sensor value |
| 104 | * |
| 105 | * @param[in] bootCount - new BOOTCOUNT value |
| 106 | */ |
| 107 | void setHostbootCount(int bootCount); |
| 108 | |
| 109 | /** |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 110 | * @brief Determine if auto reboot flag is set |
| 111 | * |
| 112 | * @return boolean corresponding to current auto_reboot setting |
| 113 | **/ |
| 114 | bool isAutoReboot(); |
| 115 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 116 | /** @brief Callback function on systemd state changes |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 117 | * |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 118 | * Will just do a call into the appropriate object for processing |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 119 | * |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 120 | * @param[in] msg - Data associated with subscribed signal |
| 121 | * @param[in] userData - Pointer to this object instance |
| 122 | * @param[out] retError - Not used but required with signal API |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 123 | * |
| 124 | */ |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 125 | static int sysStateChangeSignal(sd_bus_message* msg, |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 126 | void* userData, |
| 127 | sd_bus_error* retError); |
| 128 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 129 | /** @brief Check if systemd state change is relevant to this object |
| 130 | * |
| 131 | * Instance specific interface to handle the detected systemd state |
| 132 | * change |
| 133 | * |
| 134 | * @param[in] msg - Data associated with subscribed signal |
| 135 | * @param[out] retError - Not used but required with signal API |
| 136 | * |
| 137 | */ |
| 138 | int sysStateChange(sd_bus_message* msg, |
| 139 | sd_bus_error* retError); |
| 140 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 141 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 142 | sdbusplus::bus::bus& bus; |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 143 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 144 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 145 | sdbusplus::server::match::match systemdSignals; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace manager |
| 149 | } // namespace state |
| 150 | } // namespace phosphor |