Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "fw-update/update_manager.hpp" |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
| 7 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
| 8 | #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | namespace pldm |
| 13 | { |
| 14 | |
| 15 | namespace fw_update |
| 16 | { |
| 17 | |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 18 | using ActivationIntf = sdbusplus::server::object_t< |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::Software::server::Activation>; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 20 | using ActivationProgressIntf = sdbusplus::server::object_t< |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 22 | using DeleteIntf = sdbusplus::server::object_t< |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 23 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
| 24 | |
| 25 | /** @class ActivationProgress |
| 26 | * |
| 27 | * Concrete implementation of xyz.openbmc_project.Software.ActivationProgress |
| 28 | * D-Bus interface |
| 29 | */ |
| 30 | class ActivationProgress : public ActivationProgressIntf |
| 31 | { |
| 32 | public: |
| 33 | /** @brief Constructor |
| 34 | * |
| 35 | * @param[in] bus - Bus to attach to |
| 36 | * @param[in] objPath - D-Bus object path |
| 37 | */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 38 | ActivationProgress(sdbusplus::bus_t& bus, const std::string& objPath) : |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 39 | ActivationProgressIntf(bus, objPath.c_str(), |
| 40 | action::emit_interface_added) |
| 41 | { |
| 42 | progress(0); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | /** @class Delete |
| 47 | * |
| 48 | * Concrete implementation of xyz.openbmc_project.Object.Delete D-Bus interface |
| 49 | */ |
| 50 | class Delete : public DeleteIntf |
| 51 | { |
| 52 | public: |
| 53 | /** @brief Constructor |
| 54 | * |
| 55 | * @param[in] bus - Bus to attach to |
| 56 | * @param[in] objPath - D-Bus object path |
| 57 | * @param[in] updateManager - Reference to FW update manager |
| 58 | */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 59 | Delete(sdbusplus::bus_t& bus, const std::string& objPath, |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 60 | UpdateManager* updateManager) : |
| 61 | DeleteIntf(bus, objPath.c_str(), action::emit_interface_added), |
| 62 | updateManager(updateManager) |
| 63 | {} |
| 64 | |
| 65 | /** @brief Delete the Activation D-Bus object for the FW update package */ |
| 66 | void delete_() override |
| 67 | { |
| 68 | updateManager->clearActivationInfo(); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | UpdateManager* updateManager; |
| 73 | }; |
| 74 | |
| 75 | /** @class Activation |
| 76 | * |
| 77 | * Concrete implementation of xyz.openbmc_project.Object.Activation D-Bus |
| 78 | * interface |
| 79 | */ |
| 80 | class Activation : public ActivationIntf |
| 81 | { |
| 82 | public: |
| 83 | /** @brief Constructor |
| 84 | * |
| 85 | * @param[in] bus - Bus to attach to |
| 86 | * @param[in] objPath - D-Bus object path |
| 87 | * @param[in] updateManager - Reference to FW update manager |
| 88 | */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 89 | Activation(sdbusplus::bus_t& bus, std::string objPath, |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 90 | Activations activationStatus, UpdateManager* updateManager) : |
Patrick Williams | 357b72d | 2022-04-13 09:01:35 -0500 | [diff] [blame] | 91 | ActivationIntf(bus, objPath.c_str(), |
| 92 | ActivationIntf::action::defer_emit), |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 93 | bus(bus), objPath(objPath), updateManager(updateManager) |
| 94 | { |
| 95 | activation(activationStatus); |
| 96 | deleteImpl = std::make_unique<Delete>(bus, objPath, updateManager); |
| 97 | emit_object_added(); |
| 98 | } |
| 99 | |
| 100 | using sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 101 | activation; |
| 102 | using sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 103 | requestedActivation; |
| 104 | |
| 105 | /** @brief Overriding Activation property setter function |
| 106 | */ |
| 107 | Activations activation(Activations value) override |
| 108 | { |
| 109 | if (value == Activations::Activating) |
| 110 | { |
| 111 | deleteImpl.reset(); |
| 112 | updateManager->activatePackage(); |
| 113 | } |
| 114 | else if (value == Activations::Active || value == Activations::Failed) |
| 115 | { |
| 116 | if (!deleteImpl) |
| 117 | { |
| 118 | deleteImpl = |
| 119 | std::make_unique<Delete>(bus, objPath, updateManager); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return ActivationIntf::activation(value); |
| 124 | } |
| 125 | |
| 126 | /** @brief Overriding RequestedActivations property setter function |
| 127 | */ |
| 128 | RequestedActivations |
| 129 | requestedActivation(RequestedActivations value) override |
| 130 | { |
| 131 | if ((value == RequestedActivations::Active) && |
| 132 | (requestedActivation() != RequestedActivations::Active)) |
| 133 | { |
| 134 | if ((ActivationIntf::activation() == Activations::Ready)) |
| 135 | { |
| 136 | activation(Activations::Activating); |
| 137 | } |
| 138 | } |
| 139 | return ActivationIntf::requestedActivation(value); |
| 140 | } |
| 141 | |
| 142 | private: |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame^] | 143 | sdbusplus::bus_t& bus; |
Tom Joseph | 4d8d577 | 2021-08-17 07:35:05 -0700 | [diff] [blame] | 144 | const std::string objPath; |
| 145 | UpdateManager* updateManager; |
| 146 | std::unique_ptr<Delete> deleteImpl; |
| 147 | }; |
| 148 | |
| 149 | } // namespace fw_update |
| 150 | |
| 151 | } // namespace pldm |