blob: e9158a39ff6fd8a11fd019ecf47d524022b1d12b [file] [log] [blame]
Andrew Geissler36529022016-11-29 15:23:54 -06001#pragma once
2
Michael Tritz206a8332017-02-06 16:01:23 -06003#include <string>
Andrew Geissler36529022016-11-29 15:23:54 -06004#include <sdbusplus/bus.hpp>
5#include "xyz/openbmc_project/State/Host/server.hpp"
6
7namespace phosphor
8{
9namespace state
10{
11namespace manager
12{
13
14/** @class Host
15 * @brief OpenBMC host state management implementation.
16 * @details A concrete implementation for xyz.openbmc_project.State.Host
17 * DBus API.
18 */
19class Host : public sdbusplus::server::object::object<
20 sdbusplus::xyz::openbmc_project::State::server::Host>
21{
22 public:
23 /** @brief Constructs Host State Manager
24 *
Andrew Geissleref3c1842016-12-01 12:33:09 -060025 * @note This constructor passes 'true' to the base class in order to
26 * defer dbus object registration until we can run
27 * determineInitialState() and set our properties
28 *
Andrew Geissler36529022016-11-29 15:23:54 -060029 * @param[in] bus - The Dbus bus object
30 * @param[in] busName - The Dbus name to own
31 * @param[in] objPath - The Dbus object path
32 */
33 Host(sdbusplus::bus::bus& bus,
34 const char* busName,
35 const char* objPath) :
36 sdbusplus::server::object::object<
37 sdbusplus::xyz::openbmc_project::State::server::Host>(
Andrew Geissleref3c1842016-12-01 12:33:09 -060038 bus, objPath, true),
Andrew Geissleref621162016-12-08 12:56:21 -060039 bus(bus),
Andrew Geissler4da7e002017-01-24 15:21:40 -060040 systemdSignals(bus,
41 "type='signal',"
42 "member='JobRemoved',"
43 "path='/org/freedesktop/systemd1',"
44 "interface='org.freedesktop.systemd1.Manager'",
45 sysStateChangeSignal,
46 this)
Andrew Geissleref3c1842016-12-01 12:33:09 -060047 {
Andrew Geissler4da7e002017-01-24 15:21:40 -060048 // Enable systemd signals
49 subscribeToSystemdSignals();
50
Andrew Geissleref3c1842016-12-01 12:33:09 -060051 // Will throw exception on fail
52 determineInitialState();
53
54 // We deferred this until we could get our property correct
55 this->emit_object_added();
56 }
57
Andrew Geissleref3c1842016-12-01 12:33:09 -060058 /** @brief Set value of HostTransition */
59 Transition requestedHostTransition(Transition value) override;
60
61 /** @brief Set value of CurrentHostState */
62 HostState currentHostState(HostState value) override;
Andrew Geissler36529022016-11-29 15:23:54 -060063
64 private:
Andrew Geissler4da7e002017-01-24 15:21:40 -060065 /**
66 * @brief subscribe to the systemd signals
67 *
68 * This object needs to capture when it's systemd targets complete
69 * so it can keep it's state updated
70 *
71 **/
72 void subscribeToSystemdSignals();
73
74 /**
75 * @brief Determine initial host state and set internally
76 *
77 * @return Will throw exceptions on failure
78 **/
79 void determineInitialState();
80
Andrew Geissler0cd2eaf2016-12-07 10:50:13 -060081 /** @brief Execute the transition request
82 *
83 * This function assumes the state has been validated and the host
84 * is in an appropriate state for the transition to be started.
85 *
86 * @param[in] tranReq - Transition requested
87 */
88 void executeTransition(Transition tranReq);
89
Michael Tritz206a8332017-02-06 16:01:23 -060090 /**
Josh D. King929ef702017-03-02 10:58:11 -060091 * @brief Determine if target is active
92 *
93 * This function determines if the target is active and
94 * helps prevent misleading log recorded states.
95 *
96 * @param[in] target - Target string to check on
97 *
98 * @return boolean corresponding to state active
99 **/
100 bool stateActive(const std::string& target);
101
102 /**
Saqib Khand5ac6352017-04-04 09:53:59 -0500103 * @brief Set the HOST BOOTCOUNT Sensor value
104 *
105 * @param[in] bootCount - new BOOTCOUNT value
106 */
107 void setHostbootCount(int bootCount);
108
109 /**
Michael Tritz206a8332017-02-06 16:01:23 -0600110 * @brief Determine if auto reboot flag is set
111 *
112 * @return boolean corresponding to current auto_reboot setting
113 **/
114 bool isAutoReboot();
115
Andrew Geissler4da7e002017-01-24 15:21:40 -0600116 /** @brief Callback function on systemd state changes
Andrew Geissleref621162016-12-08 12:56:21 -0600117 *
Andrew Geissler4da7e002017-01-24 15:21:40 -0600118 * Will just do a call into the appropriate object for processing
Andrew Geissleref621162016-12-08 12:56:21 -0600119 *
Andrew Geissler4da7e002017-01-24 15:21:40 -0600120 * @param[in] msg - Data associated with subscribed signal
121 * @param[in] userData - Pointer to this object instance
122 * @param[out] retError - Not used but required with signal API
Andrew Geissleref621162016-12-08 12:56:21 -0600123 *
124 */
Andrew Geissler4da7e002017-01-24 15:21:40 -0600125 static int sysStateChangeSignal(sd_bus_message* msg,
Andrew Geissleref621162016-12-08 12:56:21 -0600126 void* userData,
127 sd_bus_error* retError);
128
Andrew Geissler4da7e002017-01-24 15:21:40 -0600129 /** @brief Check if systemd state change is relevant to this object
130 *
131 * Instance specific interface to handle the detected systemd state
132 * change
133 *
134 * @param[in] msg - Data associated with subscribed signal
135 * @param[out] retError - Not used but required with signal API
136 *
137 */
138 int sysStateChange(sd_bus_message* msg,
139 sd_bus_error* retError);
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 **/
145 sdbusplus::server::match::match systemdSignals;
Andrew Geissler36529022016-11-29 15:23:54 -0600146};
147
148} // namespace manager
149} // namespace state
150} // namespace phosphor