blob: 6253c3870b4b044adeb3d6e504171d544d28f364 [file] [log] [blame]
Andrew Geisslerfe270d32021-01-27 14:06:46 -06001#pragma once
2
3#include "config.h"
4
5#include "settings.hpp"
6#include "xyz/openbmc_project/State/Host/server.hpp"
7
8#include <sdbusplus/bus.hpp>
9
10namespace phosphor
11{
12namespace state
13{
14namespace manager
15{
16
Patrick Williamsf053e6f2022-07-22 19:26:54 -050017using HypervisorInherit = sdbusplus::server::object_t<
Andrew Geisslerfe270d32021-01-27 14:06:46 -060018 sdbusplus::xyz::openbmc_project::State::server::Host>;
19
20namespace server = sdbusplus::xyz::openbmc_project::State::server;
Andrew Geisslerc74716e2021-02-09 15:11:10 -060021namespace sdbusRule = sdbusplus::bus::match::rules;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060022
23/** @class Host
24 * @brief OpenBMC host state management implementation.
25 * @details A concrete implementation for xyz.openbmc_project.State.Host
26 * DBus API.
27 */
28class Hypervisor : public HypervisorInherit
29{
30 public:
31 Hypervisor() = delete;
32 Hypervisor(const Hypervisor&) = delete;
33 Hypervisor& operator=(const Hypervisor&) = delete;
34 Hypervisor(Hypervisor&&) = delete;
35 Hypervisor& operator=(Hypervisor&&) = delete;
36 virtual ~Hypervisor() = default;
37
38 /** @brief Constructs Hypervisor State Manager
39 *
40 * @param[in] bus - The Dbus bus object
41 * @param[in] objPath - The Dbus object path
42 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050043 Hypervisor(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Williams76070742022-04-05 15:20:12 -050044 HypervisorInherit(bus, objPath,
45 HypervisorInherit::action::emit_object_added),
46 bus(bus),
Patrick Williams9e5cd382023-05-10 07:50:38 -050047 bootProgressChangeSignal(bus,
48 sdbusRule::propertiesChanged(
49 "/xyz/openbmc_project/state/host0",
50 "xyz.openbmc_project.State.Boot.Progress"),
51 [this](sdbusplus::message_t& m) {
52 bootProgressChangeEvent(m);
53 })
Andrew Geisslerfe270d32021-01-27 14:06:46 -060054 {}
55
56 /** @brief Set value of HostTransition */
57 server::Host::Transition
58 requestedHostTransition(server::Host::Transition value) override;
59
60 /** @brief Set value of CurrentHostState */
61 server::Host::HostState
62 currentHostState(server::Host::HostState value) override;
63
Andrew Geisslerc74716e2021-02-09 15:11:10 -060064 /** @brief Return value of CurrentHostState */
65 server::Host::HostState currentHostState();
66
67 /** @brief Check if BootProgress change affects hypervisor state
68 *
69 * @param[in] bootProgress - BootProgress value to check
70 *
71 */
72 void updateCurrentHostState(std::string& bootProgress);
73
Andrew Geisslerfe270d32021-01-27 14:06:46 -060074 private:
Andrew Geisslerc74716e2021-02-09 15:11:10 -060075 /** @brief Process BootProgress property changes
76 *
77 * Instance specific interface to monitor for changes to the BootProgress
78 * property which may impact Hypervisor state.
79 *
80 * @param[in] msg - Data associated with subscribed signal
81 *
82 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050083 void bootProgressChangeEvent(sdbusplus::message_t& msg);
Andrew Geisslerc74716e2021-02-09 15:11:10 -060084
Andrew Geisslerfe270d32021-01-27 14:06:46 -060085 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050086 sdbusplus::bus_t& bus;
Andrew Geisslerc74716e2021-02-09 15:11:10 -060087
88 /** @brief Watch BootProgress changes to know hypervisor state **/
89 sdbusplus::bus::match_t bootProgressChangeSignal;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060090};
91
92} // namespace manager
93} // namespace state
94} // namespace phosphor