1 #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 
10 namespace phosphor
11 {
12 namespace state
13 {
14 namespace manager
15 {
16 
17 using HypervisorInherit = sdbusplus::server::object_t<
18     sdbusplus::xyz::openbmc_project::State::server::Host>;
19 
20 namespace server = sdbusplus::xyz::openbmc_project::State::server;
21 namespace sdbusRule = sdbusplus::bus::match::rules;
22 
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  */
28 class 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      */
43     Hypervisor(sdbusplus::bus_t& bus, const char* objPath) :
44         HypervisorInherit(bus, objPath,
45                           HypervisorInherit::action::emit_object_added),
46         bus(bus),
47         bootProgressChangeSignal(
48             bus,
49             sdbusRule::propertiesChanged(
50                 "/xyz/openbmc_project/state/host0",
51                 "xyz.openbmc_project.State.Boot.Progress"),
52             [this](sdbusplus::message_t& m) { bootProgressChangeEvent(m); })
53     {}
54 
55     /** @brief Set value of HostTransition */
56     server::Host::Transition
57         requestedHostTransition(server::Host::Transition value) override;
58 
59     /** @brief Set value of CurrentHostState */
60     server::Host::HostState
61         currentHostState(server::Host::HostState value) override;
62 
63     /** @brief Return value of CurrentHostState */
64     server::Host::HostState currentHostState();
65 
66     /** @brief Check if BootProgress change affects hypervisor state
67      *
68      * @param[in]  bootProgress     - BootProgress value to check
69      *
70      */
71     void updateCurrentHostState(std::string& bootProgress);
72 
73   private:
74     /** @brief Process BootProgress property changes
75      *
76      * Instance specific interface to monitor for changes to the BootProgress
77      * property which may impact Hypervisor state.
78      *
79      * @param[in]  msg              - Data associated with subscribed signal
80      *
81      */
82     void bootProgressChangeEvent(sdbusplus::message_t& msg);
83 
84     /** @brief Persistent sdbusplus DBus bus connection. */
85     sdbusplus::bus_t& bus;
86 
87     /** @brief Watch BootProgress changes to know hypervisor state **/
88     sdbusplus::bus::match_t bootProgressChangeSignal;
89 };
90 
91 } // namespace manager
92 } // namespace state
93 } // namespace phosphor
94