Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
| 5 | #include "settings.hpp" |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 6 | |
| 7 | #include <sdbusplus/bus.hpp> |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 8 | #include <xyz/openbmc_project/State/Boot/Progress/client.hpp> |
| 9 | #include <xyz/openbmc_project/State/Host/server.hpp> |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace state |
| 14 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 18 | using HypervisorInherit = sdbusplus::server::object_t< |
Patrick Williams | 7e969cb | 2023-08-23 16:24:23 -0500 | [diff] [blame] | 19 | sdbusplus::server::xyz::openbmc_project::state::Host>; |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 20 | using BootProgress = |
| 21 | sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 22 | |
Patrick Williams | 7e969cb | 2023-08-23 16:24:23 -0500 | [diff] [blame] | 23 | namespace server = sdbusplus::server::xyz::openbmc_project::state; |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 24 | namespace sdbusRule = sdbusplus::bus::match::rules; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 25 | |
| 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 | */ |
| 31 | class 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 Barithaya | 44acab7 | 2024-06-21 08:11:13 -0500 | [diff] [blame] | 39 | ~Hypervisor() override = default; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 40 | |
| 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 Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 46 | Hypervisor(sdbusplus::bus_t& bus, const char* objPath) : |
Patrick Williams | 7607074 | 2022-04-05 15:20:12 -0500 | [diff] [blame] | 47 | HypervisorInherit(bus, objPath, |
| 48 | HypervisorInherit::action::emit_object_added), |
| 49 | bus(bus), |
Patrick Williams | 30538e8 | 2023-10-20 11:18:54 -0500 | [diff] [blame] | 50 | bootProgressChangeSignal( |
| 51 | bus, |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 52 | sdbusRule::propertiesChanged("/xyz/openbmc_project/state/host0", |
| 53 | BootProgress::interface), |
Patrick Williams | 30538e8 | 2023-10-20 11:18:54 -0500 | [diff] [blame] | 54 | [this](sdbusplus::message_t& m) { bootProgressChangeEvent(m); }) |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 55 | {} |
| 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 Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 65 | /** @brief Return value of CurrentHostState */ |
Andrew Geissler | e4a39de | 2023-08-22 15:11:09 -0400 | [diff] [blame] | 66 | server::Host::HostState currentHostState() const override; |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 67 | |
| 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 Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 75 | private: |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 76 | /** @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 Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 84 | void bootProgressChangeEvent(sdbusplus::message_t& msg); |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 85 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 86 | /** @brief Persistent sdbusplus DBus bus connection. */ |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 87 | sdbusplus::bus_t& bus; |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 88 | |
| 89 | /** @brief Watch BootProgress changes to know hypervisor state **/ |
| 90 | sdbusplus::bus::match_t bootProgressChangeSignal; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace manager |
| 94 | } // namespace state |
| 95 | } // namespace phosphor |