blob: ae43a3f62ac5b4f0ba74f1fc91ffc01a71996f79 [file] [log] [blame]
Andrew Geisslerfe270d32021-01-27 14:06:46 -06001#pragma once
2
3#include "config.h"
4
5#include "settings.hpp"
Andrew Geisslerfe270d32021-01-27 14:06:46 -06006
7#include <sdbusplus/bus.hpp>
Patrick Williams9a286db2024-01-17 06:29:47 -06008#include <xyz/openbmc_project/State/Boot/Progress/client.hpp>
9#include <xyz/openbmc_project/State/Host/server.hpp>
Andrew Geisslerfe270d32021-01-27 14:06:46 -060010
11namespace phosphor
12{
13namespace state
14{
15namespace manager
16{
17
Patrick Williamsf053e6f2022-07-22 19:26:54 -050018using HypervisorInherit = sdbusplus::server::object_t<
Patrick Williams7e969cb2023-08-23 16:24:23 -050019 sdbusplus::server::xyz::openbmc_project::state::Host>;
Patrick Williams9a286db2024-01-17 06:29:47 -060020using BootProgress =
21 sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060022
Patrick Williams7e969cb2023-08-23 16:24:23 -050023namespace server = sdbusplus::server::xyz::openbmc_project::state;
Andrew Geisslerc74716e2021-02-09 15:11:10 -060024namespace sdbusRule = sdbusplus::bus::match::rules;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060025
26/** @class Host
27 * @brief OpenBMC host state management implementation.
28 * @details A concrete implementation for xyz.openbmc_project.State.Host
29 * DBus API.
30 */
31class Hypervisor : public HypervisorInherit
32{
33 public:
34 Hypervisor() = delete;
35 Hypervisor(const Hypervisor&) = delete;
36 Hypervisor& operator=(const Hypervisor&) = delete;
37 Hypervisor(Hypervisor&&) = delete;
38 Hypervisor& operator=(Hypervisor&&) = delete;
Pavithra Barithaya44acab72024-06-21 08:11:13 -050039 ~Hypervisor() override = default;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060040
41 /** @brief Constructs Hypervisor State Manager
42 *
43 * @param[in] bus - The Dbus bus object
44 * @param[in] objPath - The Dbus object path
45 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050046 Hypervisor(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Williams76070742022-04-05 15:20:12 -050047 HypervisorInherit(bus, objPath,
48 HypervisorInherit::action::emit_object_added),
49 bus(bus),
Patrick Williams30538e82023-10-20 11:18:54 -050050 bootProgressChangeSignal(
51 bus,
Patrick Williams9a286db2024-01-17 06:29:47 -060052 sdbusRule::propertiesChanged("/xyz/openbmc_project/state/host0",
53 BootProgress::interface),
Patrick Williams30538e82023-10-20 11:18:54 -050054 [this](sdbusplus::message_t& m) { bootProgressChangeEvent(m); })
Andrew Geisslerfe270d32021-01-27 14:06:46 -060055 {}
56
57 /** @brief Set value of HostTransition */
58 server::Host::Transition
59 requestedHostTransition(server::Host::Transition value) override;
60
61 /** @brief Set value of CurrentHostState */
62 server::Host::HostState
63 currentHostState(server::Host::HostState value) override;
64
Andrew Geisslerc74716e2021-02-09 15:11:10 -060065 /** @brief Return value of CurrentHostState */
Andrew Geisslere4a39de2023-08-22 15:11:09 -040066 server::Host::HostState currentHostState() const override;
Andrew Geisslerc74716e2021-02-09 15:11:10 -060067
68 /** @brief Check if BootProgress change affects hypervisor state
69 *
70 * @param[in] bootProgress - BootProgress value to check
71 *
72 */
73 void updateCurrentHostState(std::string& bootProgress);
74
Andrew Geisslerfe270d32021-01-27 14:06:46 -060075 private:
Andrew Geisslerc74716e2021-02-09 15:11:10 -060076 /** @brief Process BootProgress property changes
77 *
78 * Instance specific interface to monitor for changes to the BootProgress
79 * property which may impact Hypervisor state.
80 *
81 * @param[in] msg - Data associated with subscribed signal
82 *
83 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050084 void bootProgressChangeEvent(sdbusplus::message_t& msg);
Andrew Geisslerc74716e2021-02-09 15:11:10 -060085
Andrew Geisslerfe270d32021-01-27 14:06:46 -060086 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050087 sdbusplus::bus_t& bus;
Andrew Geisslerc74716e2021-02-09 15:11:10 -060088
89 /** @brief Watch BootProgress changes to know hypervisor state **/
90 sdbusplus::bus::match_t bootProgressChangeSignal;
Andrew Geisslerfe270d32021-01-27 14:06:46 -060091};
92
93} // namespace manager
94} // namespace state
95} // namespace phosphor