blob: 41310d632808998196cd4146f780c487d4f8e288 [file] [log] [blame]
Andrew Geissler36529022016-11-29 15:23:54 -06001#pragma once
2
Michael Tritz206a8332017-02-06 16:01:23 -06003#include <string>
Patrick Williamsd22706f2017-05-04 05:42:49 -05004#include <functional>
Andrew Geissler36529022016-11-29 15:23:54 -06005#include <sdbusplus/bus.hpp>
Dhruvaraj Subhashchandran2710e732017-06-19 06:43:22 -05006#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 Geissler36529022016-11-29 15:23:54 -06009#include "xyz/openbmc_project/State/Host/server.hpp"
Deepak Kodihalli3dd08a52017-07-25 07:34:44 -050010#include "settings.hpp"
Dhruvaraj Subhashchandran2710e732017-06-19 06:43:22 -050011#include "config.h"
Andrew Geissler36529022016-11-29 15:23:54 -060012
13namespace phosphor
14{
15namespace state
16{
17namespace manager
18{
19
Patrick Williamsd22706f2017-05-04 05:42:49 -050020using HostInherit = sdbusplus::server::object::object<
Dhruvaraj Subhashchandran2710e732017-06-19 06:43:22 -050021 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 Williamsd22706f2017-05-04 05:42:49 -050026namespace sdbusRule = sdbusplus::bus::match::rules;
27
Andrew Geissler36529022016-11-29 15:23:54 -060028/** @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 Williamsd22706f2017-05-04 05:42:49 -050033class Host : public HostInherit
Andrew Geissler36529022016-11-29 15:23:54 -060034{
35 public:
36 /** @brief Constructs Host State Manager
37 *
Andrew Geissleref3c1842016-12-01 12:33:09 -060038 * @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 Geissler36529022016-11-29 15:23:54 -060042 * @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 Williamsd22706f2017-05-04 05:42:49 -050047 const char* busName,
48 const char* objPath) :
49 HostInherit(bus, objPath, true),
Andrew Geissleref621162016-12-08 12:56:21 -060050 bus(bus),
Patrick Williamsd22706f2017-05-04 05:42:49 -050051 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 Kodihalli3dd08a52017-07-25 07:34:44 -050059 this, std::placeholders::_1)),
60 settings(bus)
Andrew Geissleref3c1842016-12-01 12:33:09 -060061 {
Andrew Geissler4da7e002017-01-24 15:21:40 -060062 // Enable systemd signals
63 subscribeToSystemdSignals();
64
Andrew Geissleref3c1842016-12-01 12:33:09 -060065 // Will throw exception on fail
66 determineInitialState();
67
Dhruvaraj Subhashchandran2710e732017-06-19 06:43:22 -050068 attemptsLeft(BOOT_COUNT_MAX_ALLOWED);
69
Andrew Geissleref3c1842016-12-01 12:33:09 -060070 // We deferred this until we could get our property correct
71 this->emit_object_added();
72 }
73
Andrew Geissleref3c1842016-12-01 12:33:09 -060074 /** @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 Geissler36529022016-11-29 15:23:54 -060079
80 private:
Andrew Geissler4da7e002017-01-24 15:21:40 -060081 /**
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 Geissler0cd2eaf2016-12-07 10:50:13 -060097 /** @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 Tritz206a8332017-02-06 16:01:23 -0600106 /**
Josh D. King929ef702017-03-02 10:58:11 -0600107 * @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 Tritz206a8332017-02-06 16:01:23 -0600119 * @brief Determine if auto reboot flag is set
120 *
121 * @return boolean corresponding to current auto_reboot setting
122 **/
123 bool isAutoReboot();
124
Andrew Geissler4da7e002017-01-24 15:21:40 -0600125 /** @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 Geissler4da7e002017-01-24 15:21:40 -0600131 *
132 */
Patrick Williamsd22706f2017-05-04 05:42:49 -0500133 void sysStateChange(sdbusplus::message::message& msg);
Andrew Geissler4da7e002017-01-24 15:21:40 -0600134
Dhruvaraj Subhashchandran3f475242017-07-12 00:44:27 -0500135 /** @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 Geissleref3c1842016-12-01 12:33:09 -0600141 /** @brief Persistent sdbusplus DBus bus connection. */
142 sdbusplus::bus::bus& bus;
Andrew Geissleref621162016-12-08 12:56:21 -0600143
Andrew Geissler4da7e002017-01-24 15:21:40 -0600144 /** @brief Used to subscribe to dbus systemd signals **/
Patrick Williamsd22706f2017-05-04 05:42:49 -0500145 sdbusplus::bus::match_t systemdSignals;
Deepak Kodihalli3dd08a52017-07-25 07:34:44 -0500146
147 // Settings objects of interest
148 settings::Objects settings;
Andrew Geissler36529022016-11-29 15:23:54 -0600149};
150
151} // namespace manager
152} // namespace state
153} // namespace phosphor