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