blob: 46787465c072e0ffb51fb9eeb92b48aee0a3ee51 [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 /**
91 * @brief Determine if auto reboot flag is set
92 *
93 * @return boolean corresponding to current auto_reboot setting
94 **/
95 bool isAutoReboot();
96
Andrew Geissler4da7e002017-01-24 15:21:40 -060097 /** @brief Callback function on systemd state changes
Andrew Geissleref621162016-12-08 12:56:21 -060098 *
Andrew Geissler4da7e002017-01-24 15:21:40 -060099 * Will just do a call into the appropriate object for processing
Andrew Geissleref621162016-12-08 12:56:21 -0600100 *
Andrew Geissler4da7e002017-01-24 15:21:40 -0600101 * @param[in] msg - Data associated with subscribed signal
102 * @param[in] userData - Pointer to this object instance
103 * @param[out] retError - Not used but required with signal API
Andrew Geissleref621162016-12-08 12:56:21 -0600104 *
105 */
Andrew Geissler4da7e002017-01-24 15:21:40 -0600106 static int sysStateChangeSignal(sd_bus_message* msg,
Andrew Geissleref621162016-12-08 12:56:21 -0600107 void* userData,
108 sd_bus_error* retError);
109
Andrew Geissler4da7e002017-01-24 15:21:40 -0600110 /** @brief Check if systemd state change is relevant to this object
111 *
112 * Instance specific interface to handle the detected systemd state
113 * change
114 *
115 * @param[in] msg - Data associated with subscribed signal
116 * @param[out] retError - Not used but required with signal API
117 *
118 */
119 int sysStateChange(sd_bus_message* msg,
120 sd_bus_error* retError);
121
Andrew Geissleref3c1842016-12-01 12:33:09 -0600122 /** @brief Persistent sdbusplus DBus bus connection. */
123 sdbusplus::bus::bus& bus;
Andrew Geissleref621162016-12-08 12:56:21 -0600124
Andrew Geissler4da7e002017-01-24 15:21:40 -0600125 /** @brief Used to subscribe to dbus systemd signals **/
126 sdbusplus::server::match::match systemdSignals;
Andrew Geissler36529022016-11-29 15:23:54 -0600127};
128
129} // namespace manager
130} // namespace state
131} // namespace phosphor