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