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> |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 4 | #include <functional> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include "xyz/openbmc_project/State/Host/server.hpp" |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 7 | #include "settings.hpp" |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace state |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 16 | using HostInherit = sdbusplus::server::object::object< |
| 17 | sdbusplus::xyz::openbmc_project::State::server::Host>; |
| 18 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 19 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 20 | /** @class Host |
| 21 | * @brief OpenBMC host state management implementation. |
| 22 | * @details A concrete implementation for xyz.openbmc_project.State.Host |
| 23 | * DBus API. |
| 24 | */ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 25 | class Host : public HostInherit |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 26 | { |
| 27 | public: |
| 28 | /** @brief Constructs Host State Manager |
| 29 | * |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 30 | * @note This constructor passes 'true' to the base class in order to |
| 31 | * defer dbus object registration until we can run |
| 32 | * determineInitialState() and set our properties |
| 33 | * |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 34 | * @param[in] bus - The Dbus bus object |
| 35 | * @param[in] busName - The Dbus name to own |
| 36 | * @param[in] objPath - The Dbus object path |
| 37 | */ |
| 38 | Host(sdbusplus::bus::bus& bus, |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 39 | const char* busName, |
| 40 | const char* objPath) : |
| 41 | HostInherit(bus, objPath, true), |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 42 | bus(bus), |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 43 | systemdSignals( |
| 44 | bus, |
| 45 | sdbusRule::type::signal() + |
| 46 | sdbusRule::member("JobRemoved") + |
| 47 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 48 | sdbusRule::interface( |
| 49 | "org.freedesktop.systemd1.Manager"), |
| 50 | std::bind(std::mem_fn(&Host::sysStateChange), |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 51 | this, std::placeholders::_1)), |
| 52 | settings(bus) |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 53 | { |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 54 | // Enable systemd signals |
| 55 | subscribeToSystemdSignals(); |
| 56 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 57 | // Will throw exception on fail |
| 58 | determineInitialState(); |
| 59 | |
| 60 | // We deferred this until we could get our property correct |
| 61 | this->emit_object_added(); |
| 62 | } |
| 63 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 64 | /** @brief Set value of HostTransition */ |
| 65 | Transition requestedHostTransition(Transition value) override; |
| 66 | |
| 67 | /** @brief Set value of CurrentHostState */ |
| 68 | HostState currentHostState(HostState value) override; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 69 | |
| 70 | private: |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 71 | /** |
| 72 | * @brief subscribe to the systemd signals |
| 73 | * |
| 74 | * This object needs to capture when it's systemd targets complete |
| 75 | * so it can keep it's state updated |
| 76 | * |
| 77 | **/ |
| 78 | void subscribeToSystemdSignals(); |
| 79 | |
| 80 | /** |
| 81 | * @brief Determine initial host state and set internally |
| 82 | * |
| 83 | * @return Will throw exceptions on failure |
| 84 | **/ |
| 85 | void determineInitialState(); |
| 86 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 87 | /** @brief Execute the transition request |
| 88 | * |
| 89 | * This function assumes the state has been validated and the host |
| 90 | * is in an appropriate state for the transition to be started. |
| 91 | * |
| 92 | * @param[in] tranReq - Transition requested |
| 93 | */ |
| 94 | void executeTransition(Transition tranReq); |
| 95 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 96 | /** |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 97 | * @brief Determine if target is active |
| 98 | * |
| 99 | * This function determines if the target is active and |
| 100 | * helps prevent misleading log recorded states. |
| 101 | * |
| 102 | * @param[in] target - Target string to check on |
| 103 | * |
| 104 | * @return boolean corresponding to state active |
| 105 | **/ |
| 106 | bool stateActive(const std::string& target); |
| 107 | |
| 108 | /** |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 109 | * @brief Set the HOST BOOTCOUNT Sensor value |
| 110 | * |
| 111 | * @param[in] bootCount - new BOOTCOUNT value |
| 112 | */ |
| 113 | void setHostbootCount(int bootCount); |
| 114 | |
| 115 | /** |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 116 | * @brief Determine if auto reboot flag is set |
| 117 | * |
| 118 | * @return boolean corresponding to current auto_reboot setting |
| 119 | **/ |
| 120 | bool isAutoReboot(); |
| 121 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 122 | /** @brief Check if systemd state change is relevant to this object |
| 123 | * |
| 124 | * Instance specific interface to handle the detected systemd state |
| 125 | * change |
| 126 | * |
| 127 | * @param[in] msg - Data associated with subscribed signal |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 128 | * |
| 129 | */ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 130 | void sysStateChange(sdbusplus::message::message& msg); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 131 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 132 | /** @brief Determine whether restoring of host requested state is enabled |
| 133 | * |
| 134 | * @return boolean corresponding to restore setting |
| 135 | */ |
| 136 | bool getStateRestoreSetting() const; |
| 137 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 138 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 139 | sdbusplus::bus::bus& bus; |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 140 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 141 | /** @brief Used to subscribe to dbus systemd signals **/ |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 142 | sdbusplus::bus::match_t systemdSignals; |
Deepak Kodihalli | 3dd08a5 | 2017-07-25 07:34:44 -0500 | [diff] [blame] | 143 | |
| 144 | // Settings objects of interest |
| 145 | settings::Objects settings; |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace manager |
| 149 | } // namespace state |
| 150 | } // namespace phosphor |