blob: 82049314557a35fee2f6a290a4bb1e3acb4314b9 [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"
Deepak Kodihalli3dd08a52017-07-25 07:34:44 -05007#include "settings.hpp"
Andrew Geissler36529022016-11-29 15:23:54 -06008
9namespace phosphor
10{
11namespace state
12{
13namespace manager
14{
15
Patrick Williamsd22706f2017-05-04 05:42:49 -050016using HostInherit = sdbusplus::server::object::object<
17 sdbusplus::xyz::openbmc_project::State::server::Host>;
18namespace sdbusRule = sdbusplus::bus::match::rules;
19
Andrew Geissler36529022016-11-29 15:23:54 -060020/** @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 Williamsd22706f2017-05-04 05:42:49 -050025class Host : public HostInherit
Andrew Geissler36529022016-11-29 15:23:54 -060026{
27 public:
28 /** @brief Constructs Host State Manager
29 *
Andrew Geissleref3c1842016-12-01 12:33:09 -060030 * @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 Geissler36529022016-11-29 15:23:54 -060034 * @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 Williamsd22706f2017-05-04 05:42:49 -050039 const char* busName,
40 const char* objPath) :
41 HostInherit(bus, objPath, true),
Andrew Geissleref621162016-12-08 12:56:21 -060042 bus(bus),
Patrick Williamsd22706f2017-05-04 05:42:49 -050043 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 Kodihalli3dd08a52017-07-25 07:34:44 -050051 this, std::placeholders::_1)),
52 settings(bus)
Andrew Geissleref3c1842016-12-01 12:33:09 -060053 {
Andrew Geissler4da7e002017-01-24 15:21:40 -060054 // Enable systemd signals
55 subscribeToSystemdSignals();
56
Andrew Geissleref3c1842016-12-01 12:33:09 -060057 // 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 Geissleref3c1842016-12-01 12:33:09 -060064 /** @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 Geissler36529022016-11-29 15:23:54 -060069
70 private:
Andrew Geissler4da7e002017-01-24 15:21:40 -060071 /**
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 Geissler0cd2eaf2016-12-07 10:50:13 -060087 /** @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 Tritz206a8332017-02-06 16:01:23 -060096 /**
Josh D. King929ef702017-03-02 10:58:11 -060097 * @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 Khand5ac6352017-04-04 09:53:59 -0500109 * @brief Set the HOST BOOTCOUNT Sensor value
110 *
111 * @param[in] bootCount - new BOOTCOUNT value
112 */
113 void setHostbootCount(int bootCount);
114
115 /**
Michael Tritz206a8332017-02-06 16:01:23 -0600116 * @brief Determine if auto reboot flag is set
117 *
118 * @return boolean corresponding to current auto_reboot setting
119 **/
120 bool isAutoReboot();
121
Andrew Geissler4da7e002017-01-24 15:21:40 -0600122 /** @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 Geissler4da7e002017-01-24 15:21:40 -0600128 *
129 */
Patrick Williamsd22706f2017-05-04 05:42:49 -0500130 void sysStateChange(sdbusplus::message::message& msg);
Andrew Geissler4da7e002017-01-24 15:21:40 -0600131
Dhruvaraj Subhashchandran3f475242017-07-12 00:44:27 -0500132 /** @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 Geissleref3c1842016-12-01 12:33:09 -0600138 /** @brief Persistent sdbusplus DBus bus connection. */
139 sdbusplus::bus::bus& bus;
Andrew Geissleref621162016-12-08 12:56:21 -0600140
Andrew Geissler4da7e002017-01-24 15:21:40 -0600141 /** @brief Used to subscribe to dbus systemd signals **/
Patrick Williamsd22706f2017-05-04 05:42:49 -0500142 sdbusplus::bus::match_t systemdSignals;
Deepak Kodihalli3dd08a52017-07-25 07:34:44 -0500143
144 // Settings objects of interest
145 settings::Objects settings;
Andrew Geissler36529022016-11-29 15:23:54 -0600146};
147
148} // namespace manager
149} // namespace state
150} // namespace phosphor