Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #include <iostream> |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 2 | #include <map> |
| 3 | #include <string> |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 4 | #include <systemd/sd-bus.h> |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 5 | #include <sdbusplus/server.hpp> |
Saqib Khan | a8006a2 | 2017-02-14 11:37:08 -0600 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 7 | #include "host_state_manager.hpp" |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace state |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Andrew Geissler | 3e3b84b | 2016-12-02 15:46:17 -0600 | [diff] [blame] | 16 | // When you see server:: you know we're referencing our base class |
| 17 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
| 18 | |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 19 | using namespace phosphor::logging; |
| 20 | |
Josh D. King | ca35792 | 2017-04-11 13:44:09 -0500 | [diff] [blame] | 21 | constexpr auto HOST_STATE_POWEROFF_TGT = "obmc-host-stop@0.target"; |
| 22 | constexpr auto HOST_STATE_POWERON_TGT = "obmc-host-start@0.target"; |
Josh D. King | cc3fb5d | 2017-04-19 15:45:10 -0500 | [diff] [blame] | 23 | constexpr auto HOST_STATE_QUIESCE_TGT = "obmc-host-quiesce@0.target"; |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 24 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 25 | constexpr auto ACTIVE_STATE = "active"; |
| 26 | constexpr auto ACTIVATING_STATE = "activating"; |
| 27 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 28 | /* Map a transition to it's systemd target */ |
| 29 | const std::map<server::Host::Transition,std::string> SYSTEMD_TARGET_TABLE = |
| 30 | { |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 31 | {server::Host::Transition::Off, HOST_STATE_POWEROFF_TGT}, |
| 32 | {server::Host::Transition::On, HOST_STATE_POWERON_TGT} |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 36 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 37 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 38 | |
| 39 | constexpr auto SYSTEM_SERVICE = "org.openbmc.managers.System"; |
| 40 | constexpr auto SYSTEM_OBJ_PATH = "/org/openbmc/managers/System"; |
| 41 | constexpr auto SYSTEM_INTERFACE = SYSTEM_SERVICE; |
| 42 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 43 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
Leonel Gonzalez | f318d87 | 2017-03-16 13:47:49 -0500 | [diff] [blame] | 44 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 45 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 46 | |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 47 | constexpr auto REBOOTCOUNTER_SERVICE("org.openbmc.Sensors"); |
| 48 | constexpr auto REBOOTCOUNTER_PATH("/org/openbmc/sensors/host/BootCount"); |
| 49 | constexpr auto REBOOTCOUNTER_INTERFACE("org.openbmc.SensorValue"); |
| 50 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 51 | constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 52 | constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit"; |
| 53 | |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 54 | constexpr auto DEFAULT_BOOTCOUNT = 2; |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 55 | |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 56 | /* Map a system state to the HostState */ |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 57 | const std::map<std::string, server::Host::HostState> SYS_HOST_STATE_TABLE = { |
| 58 | {"HOST_BOOTING", server::Host::HostState::Running}, |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 59 | {"HOST_POWERED_OFF", server::Host::HostState::Off}, |
| 60 | {"HOST_QUIESCED", server::Host::HostState::Quiesced} |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 61 | }; |
| 62 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 63 | void Host::subscribeToSystemdSignals() |
| 64 | { |
| 65 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 66 | SYSTEMD_OBJ_PATH, |
| 67 | SYSTEMD_INTERFACE, |
| 68 | "Subscribe"); |
| 69 | this->bus.call_noreply(method); |
| 70 | |
| 71 | return; |
| 72 | } |
| 73 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 74 | // TODO - Will be rewritten once sdbusplus client bindings are in place |
| 75 | // and persistent storage design is in place |
| 76 | void Host::determineInitialState() |
| 77 | { |
| 78 | std::string sysState; |
| 79 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 80 | auto method = this->bus.new_method_call(SYSTEM_SERVICE, |
| 81 | SYSTEM_OBJ_PATH, |
| 82 | SYSTEM_INTERFACE, |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 83 | "getSystemState"); |
| 84 | |
| 85 | auto reply = this->bus.call(method); |
| 86 | |
| 87 | reply.read(sysState); |
| 88 | |
| 89 | if(sysState == "HOST_BOOTED") |
| 90 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 91 | log<level::INFO>("Initial Host State will be Running", |
| 92 | entry("CURRENT_HOST_STATE=%s", |
| 93 | convertForMessage(HostState::Running).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 94 | server::Host::currentHostState(HostState::Running); |
| 95 | server::Host::requestedHostTransition(Transition::On); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 96 | } |
| 97 | else |
| 98 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 99 | log<level::INFO>("Initial Host State will be Off", |
| 100 | entry("CURRENT_HOST_STATE=%s", |
| 101 | convertForMessage(HostState::Off).c_str())); |
Andrew Geissler | 9792414 | 2017-01-24 16:10:18 -0600 | [diff] [blame] | 102 | server::Host::currentHostState(HostState::Off); |
| 103 | server::Host::requestedHostTransition(Transition::Off); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // Set transition initially to Off |
| 107 | // TODO - Eventually need to restore this from persistent storage |
Andrew Geissler | 3e3b84b | 2016-12-02 15:46:17 -0600 | [diff] [blame] | 108 | server::Host::requestedHostTransition(Transition::Off); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 109 | |
| 110 | return; |
| 111 | } |
| 112 | |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 113 | void Host::executeTransition(Transition tranReq) |
| 114 | { |
| 115 | auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second; |
| 116 | |
| 117 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 118 | SYSTEMD_OBJ_PATH, |
| 119 | SYSTEMD_INTERFACE, |
| 120 | "StartUnit"); |
| 121 | |
| 122 | method.append(sysdUnit); |
| 123 | method.append("replace"); |
| 124 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 125 | this->bus.call_noreply(method); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 126 | |
| 127 | return; |
| 128 | } |
| 129 | |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 130 | bool Host::stateActive(const std::string& target) |
| 131 | { |
| 132 | sdbusplus::message::variant<std::string> currentState; |
| 133 | sdbusplus::message::object_path unitTargetPath; |
| 134 | |
| 135 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 136 | SYSTEMD_OBJ_PATH, |
| 137 | SYSTEMD_INTERFACE, |
| 138 | "GetUnit"); |
| 139 | |
| 140 | method.append(target); |
| 141 | auto result = this->bus.call(method); |
| 142 | |
| 143 | //Check that the bus call didn't result in an error |
| 144 | if(result.is_method_error()) |
| 145 | { |
| 146 | log<level::ERR>("Error in bus call - could not resolve GetUnit for:", |
| 147 | entry(" %s", SYSTEMD_INTERFACE)); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | result.read(unitTargetPath); |
| 152 | |
| 153 | method = this->bus.new_method_call(SYSTEMD_SERVICE, |
| 154 | static_cast<const std::string&> |
| 155 | (unitTargetPath).c_str(), |
| 156 | SYSTEMD_PROPERTY_IFACE, |
| 157 | "Get"); |
| 158 | |
| 159 | method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState"); |
| 160 | result = this->bus.call(method); |
| 161 | |
| 162 | //Check that the bus call didn't result in an error |
| 163 | if(result.is_method_error()) |
| 164 | { |
| 165 | log<level::ERR>("Error in bus call - could not resolve Get for:", |
| 166 | entry(" %s", SYSTEMD_PROPERTY_IFACE)); |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | result.read(currentState); |
| 171 | |
| 172 | if(currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE) |
| 173 | { |
| 174 | //False - not active |
| 175 | return false; |
| 176 | } |
| 177 | //True - active |
| 178 | return true; |
| 179 | } |
| 180 | |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 181 | void Host::setHostbootCount(int bootCount) |
| 182 | { |
| 183 | auto method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE, |
| 184 | REBOOTCOUNTER_PATH, |
| 185 | REBOOTCOUNTER_INTERFACE, |
| 186 | "setValue"); |
| 187 | sdbusplus::message::variant<int> newParam = bootCount; |
| 188 | method.append(newParam); |
| 189 | this->bus.call_noreply(method); |
| 190 | } |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 191 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 192 | bool Host::isAutoReboot() |
| 193 | { |
| 194 | sdbusplus::message::variant<std::string> autoRebootParam; |
| 195 | std::string strParam; |
| 196 | |
| 197 | std::string HOST_PATH("/org/openbmc/settings/host0"); |
| 198 | std::string HOST_INTERFACE("org.openbmc.settings.Host"); |
| 199 | |
| 200 | auto mapper = this->bus.new_method_call(MAPPER_BUSNAME, |
| 201 | MAPPER_PATH, |
| 202 | MAPPER_INTERFACE, |
| 203 | "GetObject"); |
| 204 | |
| 205 | mapper.append(HOST_PATH, std::vector<std::string>({HOST_INTERFACE})); |
| 206 | auto mapperResponseMsg = this->bus.call(mapper); |
| 207 | |
| 208 | if (mapperResponseMsg.is_method_error()) |
| 209 | { |
| 210 | log<level::ERR>("Error in mapper call"); |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 215 | mapperResponseMsg.read(mapperResponse); |
| 216 | if (mapperResponse.empty()) |
| 217 | { |
| 218 | log<level::ERR>("Error reading mapper response"); |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | const auto& host = mapperResponse.begin()->first; |
| 223 | |
| 224 | auto method = this->bus.new_method_call(host.c_str(), |
| 225 | HOST_PATH.c_str(), |
| 226 | "org.freedesktop.DBus.Properties", |
| 227 | "Get"); |
| 228 | |
| 229 | method.append(HOST_INTERFACE.c_str(), "auto_reboot"); |
| 230 | auto reply = this->bus.call(method); |
| 231 | |
| 232 | if (reply.is_method_error()) |
| 233 | { |
| 234 | log<level::ERR>("Error in auto_reboot Get"); |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | reply.read(autoRebootParam); |
| 239 | strParam = |
| 240 | sdbusplus::message::variant_ns::get<std::string>(autoRebootParam); |
| 241 | |
| 242 | if (strParam.empty()) |
| 243 | { |
| 244 | log<level::ERR>("Error reading auto_reboot response"); |
| 245 | return false; |
| 246 | } |
| 247 | |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 248 | sdbusplus::message::variant<int> rebootCounterParam = 0; |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 249 | method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE, |
| 250 | REBOOTCOUNTER_PATH, |
| 251 | REBOOTCOUNTER_INTERFACE, |
| 252 | "getValue"); |
| 253 | reply = this->bus.call(method); |
| 254 | if (reply.is_method_error()) |
| 255 | { |
| 256 | log<level::ERR>("Error in BOOTCOUNT getValue"); |
| 257 | return false; |
| 258 | } |
| 259 | reply.read(rebootCounterParam); |
| 260 | |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 261 | if (strParam == "yes") |
| 262 | { |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 263 | if( rebootCounterParam > 0) |
| 264 | { |
| 265 | // Reduce BOOTCOUNT by 1 |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 266 | log<level::INFO>("Auto reboot enabled. " |
| 267 | "Reducing HOST BOOTCOUNT by 1."); |
| 268 | Host::setHostbootCount((sdbusplus::message::variant_ns:: |
| 269 | get<int>(rebootCounterParam)) - 1); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 270 | return true; |
| 271 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 272 | else if(rebootCounterParam == 0) |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 273 | { |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 274 | // Reset reboot counter and go to quiesce state |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 275 | log<level::INFO>("Auto reboot enabled. " |
| 276 | "HOST BOOTCOUNT already set to 0."); |
| 277 | Host::setHostbootCount(DEFAULT_BOOTCOUNT); |
| 278 | return false; |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | log<level::INFO>("Auto reboot enabled. " |
| 283 | "HOST BOOTCOUNT has an invalid value."); |
Saqib Khan | cbe08d1 | 2017-03-10 01:29:20 -0600 | [diff] [blame] | 284 | return false; |
| 285 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 286 | } |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 287 | else |
| 288 | { |
| 289 | log<level::INFO>("Auto reboot disabled."); |
| 290 | return false; |
| 291 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 292 | } |
| 293 | |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 294 | void Host::sysStateChange(sdbusplus::message::message& msg) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 295 | { |
| 296 | uint32_t newStateID {}; |
| 297 | sdbusplus::message::object_path newStateObjPath; |
| 298 | std::string newStateUnit{}; |
| 299 | std::string newStateResult{}; |
| 300 | |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 301 | //Read the msg and populate each variable |
Patrick Williams | d22706f | 2017-05-04 05:42:49 -0500 | [diff] [blame] | 302 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 303 | |
| 304 | if((newStateUnit == HOST_STATE_POWEROFF_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 305 | (newStateResult == "done") && |
| 306 | (!stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 307 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 308 | log<level::INFO>("Received signal that host is off"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 309 | this->currentHostState(server::Host::HostState::Off); |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 310 | |
| 311 | // Check if we need to start a new transition (i.e. a Reboot) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 312 | if(this->server::Host::requestedHostTransition() == |
| 313 | Transition::Reboot) |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 314 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 315 | log<level::DEBUG>("Reached intermediate state, going to next"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 316 | this->executeTransition(server::Host::Transition::On); |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 317 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 318 | } |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 319 | else if((newStateUnit == HOST_STATE_POWERON_TGT) && |
Josh D. King | 929ef70 | 2017-03-02 10:58:11 -0600 | [diff] [blame] | 320 | (newStateResult == "done") && |
| 321 | (stateActive(HOST_STATE_POWERON_TGT))) |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 322 | { |
Andrew Jeffery | 55b983e | 2017-04-19 11:11:26 +0930 | [diff] [blame] | 323 | log<level::INFO>("Received signal that host is running"); |
Andrew Geissler | 4da7e00 | 2017-01-24 15:21:40 -0600 | [diff] [blame] | 324 | this->currentHostState(server::Host::HostState::Running); |
| 325 | } |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 326 | else if((newStateUnit == HOST_STATE_QUIESCE_TGT) && |
Josh D. King | 29d025d | 2017-04-27 12:40:22 -0500 | [diff] [blame^] | 327 | (newStateResult == "done") && |
| 328 | (stateActive(HOST_STATE_QUIESCE_TGT))) |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 329 | { |
| 330 | if (Host::isAutoReboot()) |
| 331 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 332 | log<level::INFO>("Beginning reboot..."); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 333 | Host::requestedHostTransition(server::Host::Transition::Reboot); |
| 334 | } |
| 335 | else |
| 336 | { |
Saqib Khan | d5ac635 | 2017-04-04 09:53:59 -0500 | [diff] [blame] | 337 | log<level::INFO>("Maintaining quiesce"); |
Saqib Khan | adaa721 | 2017-02-23 13:19:28 -0600 | [diff] [blame] | 338 | this->currentHostState(server::Host::HostState::Quiesced); |
Michael Tritz | 206a833 | 2017-02-06 16:01:23 -0600 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | } |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 342 | } |
| 343 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 344 | Host::Transition Host::requestedHostTransition(Transition value) |
| 345 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 346 | log<level::INFO>( |
| 347 | "Host State transaction request", |
| 348 | entry("REQUESTED_HOST_TRANSITION=%s", |
| 349 | convertForMessage(value).c_str())); |
Andrew Geissler | 0cd2eaf | 2016-12-07 10:50:13 -0600 | [diff] [blame] | 350 | |
Andrew Geissler | 06dbc5b | 2016-12-13 11:46:16 -0600 | [diff] [blame] | 351 | Transition tranReq = value; |
| 352 | if(value == server::Host::Transition::Reboot) |
| 353 | { |
| 354 | // On reboot requests we just need to do a off if we're on and |
| 355 | // vice versa. The handleSysStateChange() code above handles the |
| 356 | // second part of the reboot |
| 357 | if(this->server::Host::currentHostState() == |
| 358 | server::Host::HostState::Off) |
| 359 | { |
| 360 | tranReq = server::Host::Transition::On; |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | tranReq = server::Host::Transition::Off; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | executeTransition(tranReq); |
Andrew Geissler | 3e3b84b | 2016-12-02 15:46:17 -0600 | [diff] [blame] | 369 | return server::Host::requestedHostTransition(value); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 370 | } |
| 371 | |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 372 | Host::HostState Host::currentHostState(HostState value) |
| 373 | { |
Andrew Geissler | 1e3bf94 | 2016-12-13 15:32:22 -0600 | [diff] [blame] | 374 | log<level::INFO>("Change to Host State", |
| 375 | entry("CURRENT_HOST_STATE=%s", |
| 376 | convertForMessage(value).c_str())); |
Andrew Geissler | ef62116 | 2016-12-08 12:56:21 -0600 | [diff] [blame] | 377 | return server::Host::currentHostState(value); |
Andrew Geissler | ef3c184 | 2016-12-01 12:33:09 -0600 | [diff] [blame] | 378 | } |
| 379 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 380 | } // namespace manager |
| 381 | } // namespace state |
| 382 | } // namepsace phosphor |