blob: af4fa15ab9a0e70242bd4d7e1cdfe12047cc8e4d [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>
6#include "xyz/openbmc_project/State/Host/server.hpp"
7
8namespace phosphor
9{
10namespace state
11{
12namespace manager
13{
14
Patrick Williamsd22706f2017-05-04 05:42:49 -050015using HostInherit = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::State::server::Host>;
17namespace sdbusRule = sdbusplus::bus::match::rules;
18
Andrew Geissler36529022016-11-29 15:23:54 -060019/** @class Host
20 * @brief OpenBMC host state management implementation.
21 * @details A concrete implementation for xyz.openbmc_project.State.Host
22 * DBus API.
23 */
Patrick Williamsd22706f2017-05-04 05:42:49 -050024class Host : public HostInherit
Andrew Geissler36529022016-11-29 15:23:54 -060025{
26 public:
27 /** @brief Constructs Host State Manager
28 *
Andrew Geissleref3c1842016-12-01 12:33:09 -060029 * @note This constructor passes 'true' to the base class in order to
30 * defer dbus object registration until we can run
31 * determineInitialState() and set our properties
32 *
Andrew Geissler36529022016-11-29 15:23:54 -060033 * @param[in] bus - The Dbus bus object
34 * @param[in] busName - The Dbus name to own
35 * @param[in] objPath - The Dbus object path
36 */
37 Host(sdbusplus::bus::bus& bus,
Patrick Williamsd22706f2017-05-04 05:42:49 -050038 const char* busName,
39 const char* objPath) :
40 HostInherit(bus, objPath, true),
Andrew Geissleref621162016-12-08 12:56:21 -060041 bus(bus),
Patrick Williamsd22706f2017-05-04 05:42:49 -050042 systemdSignals(
43 bus,
44 sdbusRule::type::signal() +
45 sdbusRule::member("JobRemoved") +
46 sdbusRule::path("/org/freedesktop/systemd1") +
47 sdbusRule::interface(
48 "org.freedesktop.systemd1.Manager"),
49 std::bind(std::mem_fn(&Host::sysStateChange),
50 this, std::placeholders::_1))
Andrew Geissleref3c1842016-12-01 12:33:09 -060051 {
Andrew Geissler4da7e002017-01-24 15:21:40 -060052 // Enable systemd signals
53 subscribeToSystemdSignals();
54
Andrew Geissleref3c1842016-12-01 12:33:09 -060055 // Will throw exception on fail
56 determineInitialState();
57
58 // We deferred this until we could get our property correct
59 this->emit_object_added();
60 }
61
Andrew Geissleref3c1842016-12-01 12:33:09 -060062 /** @brief Set value of HostTransition */
63 Transition requestedHostTransition(Transition value) override;
64
65 /** @brief Set value of CurrentHostState */
66 HostState currentHostState(HostState value) override;
Andrew Geissler36529022016-11-29 15:23:54 -060067
68 private:
Andrew Geissler4da7e002017-01-24 15:21:40 -060069 /**
70 * @brief subscribe to the systemd signals
71 *
72 * This object needs to capture when it's systemd targets complete
73 * so it can keep it's state updated
74 *
75 **/
76 void subscribeToSystemdSignals();
77
78 /**
79 * @brief Determine initial host state and set internally
80 *
81 * @return Will throw exceptions on failure
82 **/
83 void determineInitialState();
84
Andrew Geissler0cd2eaf2016-12-07 10:50:13 -060085 /** @brief Execute the transition request
86 *
87 * This function assumes the state has been validated and the host
88 * is in an appropriate state for the transition to be started.
89 *
90 * @param[in] tranReq - Transition requested
91 */
92 void executeTransition(Transition tranReq);
93
Michael Tritz206a8332017-02-06 16:01:23 -060094 /**
Josh D. King929ef702017-03-02 10:58:11 -060095 * @brief Determine if target is active
96 *
97 * This function determines if the target is active and
98 * helps prevent misleading log recorded states.
99 *
100 * @param[in] target - Target string to check on
101 *
102 * @return boolean corresponding to state active
103 **/
104 bool stateActive(const std::string& target);
105
106 /**
Saqib Khand5ac6352017-04-04 09:53:59 -0500107 * @brief Set the HOST BOOTCOUNT Sensor value
108 *
109 * @param[in] bootCount - new BOOTCOUNT value
110 */
111 void setHostbootCount(int bootCount);
112
113 /**
Michael Tritz206a8332017-02-06 16:01:23 -0600114 * @brief Determine if auto reboot flag is set
115 *
116 * @return boolean corresponding to current auto_reboot setting
117 **/
118 bool isAutoReboot();
119
Andrew Geissler4da7e002017-01-24 15:21:40 -0600120 /** @brief Check if systemd state change is relevant to this object
121 *
122 * Instance specific interface to handle the detected systemd state
123 * change
124 *
125 * @param[in] msg - Data associated with subscribed signal
Andrew Geissler4da7e002017-01-24 15:21:40 -0600126 *
127 */
Patrick Williamsd22706f2017-05-04 05:42:49 -0500128 void sysStateChange(sdbusplus::message::message& msg);
Andrew Geissler4da7e002017-01-24 15:21:40 -0600129
Dhruvaraj Subhashchandran3f475242017-07-12 00:44:27 -0500130 /** @brief Determine whether restoring of host requested state is enabled
131 *
132 * @return boolean corresponding to restore setting
133 */
134 bool getStateRestoreSetting() const;
135
Andrew Geissleref3c1842016-12-01 12:33:09 -0600136 /** @brief Persistent sdbusplus DBus bus connection. */
137 sdbusplus::bus::bus& bus;
Andrew Geissleref621162016-12-08 12:56:21 -0600138
Andrew Geissler4da7e002017-01-24 15:21:40 -0600139 /** @brief Used to subscribe to dbus systemd signals **/
Patrick Williamsd22706f2017-05-04 05:42:49 -0500140 sdbusplus::bus::match_t systemdSignals;
Andrew Geissler36529022016-11-29 15:23:54 -0600141};
142
143} // namespace manager
144} // namespace state
145} // namespace phosphor