blob: 515409eb508bc7f6147761b5363c58880450a01c [file] [log] [blame]
Andrew Geissler36529022016-11-29 15:23:54 -06001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/State/Host/server.hpp"
5
6namespace phosphor
7{
8namespace state
9{
10namespace manager
11{
12
13/** @class Host
14 * @brief OpenBMC host state management implementation.
15 * @details A concrete implementation for xyz.openbmc_project.State.Host
16 * DBus API.
17 */
18class Host : public sdbusplus::server::object::object<
19 sdbusplus::xyz::openbmc_project::State::server::Host>
20{
21 public:
22 /** @brief Constructs Host State Manager
23 *
Andrew Geissleref3c1842016-12-01 12:33:09 -060024 * @note This constructor passes 'true' to the base class in order to
25 * defer dbus object registration until we can run
26 * determineInitialState() and set our properties
27 *
Andrew Geissler36529022016-11-29 15:23:54 -060028 * @param[in] bus - The Dbus bus object
29 * @param[in] busName - The Dbus name to own
30 * @param[in] objPath - The Dbus object path
31 */
32 Host(sdbusplus::bus::bus& bus,
33 const char* busName,
34 const char* objPath) :
35 sdbusplus::server::object::object<
36 sdbusplus::xyz::openbmc_project::State::server::Host>(
Andrew Geissleref3c1842016-12-01 12:33:09 -060037 bus, objPath, true),
Andrew Geissleref621162016-12-08 12:56:21 -060038 bus(bus),
39 stateSignal(bus,
40 "type='signal',member='GotoSystemState'",
41 handleSysStateChange,
42 this)
Andrew Geissleref3c1842016-12-01 12:33:09 -060043 {
44 // Will throw exception on fail
45 determineInitialState();
46
47 // We deferred this until we could get our property correct
48 this->emit_object_added();
49 }
50
51 /**
52 * @brief Determine initial host state and set internally
53 *
54 * @return Will throw exceptions on failure
55 **/
56 void determineInitialState();
57
58 /** @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 Geissler0cd2eaf2016-12-07 10:50:13 -060065 /** @brief Execute the transition request
66 *
67 * This function assumes the state has been validated and the host
68 * is in an appropriate state for the transition to be started.
69 *
70 * @param[in] tranReq - Transition requested
71 */
72 void executeTransition(Transition tranReq);
73
Andrew Geissleref621162016-12-08 12:56:21 -060074 /** @brief Callback function on system state changes
75 *
76 * Check if the state is relevant to the Host and if so, update
77 * corresponding host object's state
78 *
79 * @param[in] msg - Data associated with subscribed signal
80 * @param[in] userData - Pointer to this object instance
81 * @param[in] retError - Return error data
82 *
83 */
84 static int handleSysStateChange(sd_bus_message* msg,
85 void* userData,
86 sd_bus_error* retError);
87
Andrew Geissleref3c1842016-12-01 12:33:09 -060088 /** @brief Persistent sdbusplus DBus bus connection. */
89 sdbusplus::bus::bus& bus;
Andrew Geissleref621162016-12-08 12:56:21 -060090
91 /** @brief Used to subscribe to dbus system state changes */
92 sdbusplus::server::match::match stateSignal;
Andrew Geissler36529022016-11-29 15:23:54 -060093};
94
95} // namespace manager
96} // namespace state
97} // namespace phosphor