Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 5 | #include "types.hpp" |
| 6 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 7 | #include <queue> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 8 | #include <sdbusplus/server.hpp> |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> |
| 14 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 15 | class TestActivation; |
| 16 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace software |
| 20 | { |
| 21 | namespace updater |
| 22 | { |
| 23 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 24 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 25 | |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 26 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 27 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 28 | ActivationBlocksTransition>; |
| 29 | |
| 30 | /** @class ActivationBlocksTransition |
| 31 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 32 | * @details A concrete implementation for |
| 33 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 34 | */ |
| 35 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 36 | { |
| 37 | public: |
| 38 | /** @brief Constructs ActivationBlocksTransition. |
| 39 | * |
| 40 | * @param[in] bus - The Dbus bus object |
| 41 | * @param[in] path - The Dbus object path |
| 42 | */ |
| 43 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 44 | const std::string& path) : |
| 45 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 46 | bus(bus), path(path) |
| 47 | { |
| 48 | std::vector<std::string> interfaces({interface}); |
| 49 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 50 | } |
| 51 | |
| 52 | ~ActivationBlocksTransition() |
| 53 | { |
| 54 | std::vector<std::string> interfaces({interface}); |
| 55 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 60 | static constexpr auto interface = |
| 61 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 62 | sdbusplus::bus::bus& bus; |
| 63 | std::string path; |
| 64 | }; |
| 65 | |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 66 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 67 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
| 68 | |
| 69 | class ActivationProgress : public ActivationProgressInherit |
| 70 | { |
| 71 | public: |
| 72 | /** @brief Constructs ActivationProgress. |
| 73 | * |
| 74 | * @param[in] bus - The Dbus bus object |
| 75 | * @param[in] path - The Dbus object path |
| 76 | */ |
| 77 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 78 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 79 | { |
| 80 | progress(0); |
| 81 | std::vector<std::string> interfaces({interface}); |
| 82 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 83 | } |
| 84 | |
| 85 | ~ActivationProgress() |
| 86 | { |
| 87 | std::vector<std::string> interfaces({interface}); |
| 88 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 89 | } |
| 90 | |
| 91 | private: |
| 92 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 93 | static constexpr auto interface = |
| 94 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 95 | sdbusplus::bus::bus& bus; |
| 96 | std::string path; |
| 97 | }; |
| 98 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 99 | using ActivationInherit = sdbusplus::server::object::object< |
| 100 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 101 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
| 102 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 103 | |
| 104 | /** @class Activation |
| 105 | * @brief OpenBMC activation software management implementation. |
| 106 | * @details A concrete implementation for |
| 107 | * xyz.openbmc_project.Software.Activation DBus API. |
| 108 | */ |
| 109 | class Activation : public ActivationInherit |
| 110 | { |
| 111 | public: |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 112 | friend class ::TestActivation; |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 113 | using Status = Activations; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 114 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 115 | /** @brief Constructs Activation Software Manager |
| 116 | * |
| 117 | * @param[in] bus - The Dbus bus object |
| 118 | * @param[in] path - The Dbus object path |
| 119 | * @param[in] versionId - The software version id |
| 120 | * @param[in] extVersion - The extended version |
| 121 | * @param[in] activationStatus - The status of Activation |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 122 | * @param[in] assocs - Association objects |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 123 | */ |
| 124 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 125 | const std::string& versionId, const std::string& extVersion, |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 126 | Status activationStatus, const AssociationList& assocs) : |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 127 | ActivationInherit(bus, path.c_str(), true), |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 128 | versionId(versionId), bus(bus), path(path), |
| 129 | systemdSignals( |
| 130 | bus, |
| 131 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 132 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 133 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 134 | std::bind(&Activation::unitStateChange, this, |
| 135 | std::placeholders::_1)) |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 136 | { |
| 137 | // Set Properties. |
| 138 | extendedVersion(extVersion); |
| 139 | activation(activationStatus); |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 140 | associations(assocs); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 141 | |
| 142 | // Emit deferred signal. |
| 143 | emit_object_added(); |
| 144 | } |
| 145 | |
| 146 | /** @brief Overloaded Activation property setter function |
| 147 | * |
| 148 | * @param[in] value - One of Activation::Activations |
| 149 | * |
| 150 | * @return Success or exception thrown |
| 151 | */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 152 | Status activation(Status value) override; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 153 | |
| 154 | /** @brief Activation */ |
| 155 | using ActivationInherit::activation; |
| 156 | |
| 157 | /** @brief Overloaded requestedActivation property setter function |
| 158 | * |
| 159 | * @param[in] value - One of Activation::RequestedActivations |
| 160 | * |
| 161 | * @return Success or exception thrown |
| 162 | */ |
| 163 | RequestedActivations |
| 164 | requestedActivation(RequestedActivations value) override; |
| 165 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 166 | /** @brief Version id */ |
| 167 | std::string versionId; |
| 168 | |
| 169 | private: |
| 170 | /** @brief Check if systemd state change is relevant to this object |
| 171 | * |
| 172 | * Instance specific interface to handle the detected systemd state |
| 173 | * change |
| 174 | * |
| 175 | * @param[in] msg - Data associated with subscribed signal |
| 176 | * |
| 177 | */ |
| 178 | void unitStateChange(sdbusplus::message::message& msg); |
| 179 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 180 | /** |
| 181 | * @brief Delete the version from Image Manager and the |
| 182 | * untar image from image upload dir. |
| 183 | */ |
| 184 | void deleteImageManagerObject(); |
| 185 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 186 | /** @brief Invoke the update service for the PSU |
| 187 | * |
| 188 | * @param[in] psuInventoryPath - The PSU inventory to be updated. |
| 189 | * |
| 190 | * @return true if the update starts, and false if it fails. |
| 191 | */ |
| 192 | bool doUpdate(const std::string& psuInventoryPath); |
| 193 | |
| 194 | /** @brief Do PSU update one-by-one |
| 195 | * |
| 196 | * @return true if the update starts, and false if it fails. |
| 197 | */ |
| 198 | bool doUpdate(); |
| 199 | |
| 200 | /** @brief Handle an update done event */ |
| 201 | void onUpdateDone(); |
| 202 | |
| 203 | /** @brief Handle an update failure event */ |
| 204 | void onUpdateFailed(); |
| 205 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 206 | /** @brief Start PSU update */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 207 | Status startActivation(); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 208 | |
| 209 | /** @brief Finish PSU update */ |
| 210 | void finishActivation(); |
| 211 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 212 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 213 | sdbusplus::bus::bus& bus; |
| 214 | |
| 215 | /** @brief Persistent DBus object path */ |
| 216 | std::string path; |
| 217 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 218 | /** @brief Used to subscribe to dbus systemd signals */ |
| 219 | sdbusplus::bus::match_t systemdSignals; |
| 220 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame^] | 221 | /** @brief The queue of psu objects to be updated */ |
| 222 | std::queue<std::string> psuQueue; |
| 223 | |
| 224 | /** @brief The progress step for each PSU update is done */ |
| 225 | uint32_t progressStep; |
| 226 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 227 | /** @brief The PSU update systemd unit */ |
| 228 | std::string psuUpdateUnit; |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 229 | |
| 230 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 231 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 232 | |
| 233 | /** @brief Persistent ActivationProgress dbus object */ |
| 234 | std::unique_ptr<ActivationProgress> activationProgress; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | } // namespace updater |
| 238 | } // namespace software |
| 239 | } // namespace phosphor |