blob: 7ad03c94a63d46a89c7e0b6b8a7e1c676a60c74b [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
Lei YU7f2a2152019-09-16 16:50:18 +08005#include "association_interface.hpp"
Lei YU91029442019-08-01 15:57:31 +08006#include "types.hpp"
Lei YU9edb7332019-09-19 14:46:19 +08007#include "version.hpp"
Lei YU91029442019-08-01 15:57:31 +08008
Lei YUff83c2a2019-09-12 13:55:18 +08009#include <queue>
Lei YU01539e72019-07-31 10:57:38 +080010#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080012#include <xyz/openbmc_project/Software/Activation/server.hpp>
Lei YU81c67722019-09-11 16:47:29 +080013#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90c8a8b2019-09-11 17:20:03 +080014#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080015#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
16
Lei YUff83c2a2019-09-12 13:55:18 +080017class TestActivation;
18
Lei YU01539e72019-07-31 10:57:38 +080019namespace phosphor
20{
21namespace software
22{
23namespace updater
24{
25
Lei YU12c9f4c2019-09-11 15:08:15 +080026namespace sdbusRule = sdbusplus::bus::match::rules;
27
Lei YU81c67722019-09-11 16:47:29 +080028using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::
30 ActivationBlocksTransition>;
31
32/** @class ActivationBlocksTransition
33 * @brief OpenBMC ActivationBlocksTransition implementation.
34 * @details A concrete implementation for
35 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
36 */
37class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
38{
39 public:
40 /** @brief Constructs ActivationBlocksTransition.
41 *
42 * @param[in] bus - The Dbus bus object
43 * @param[in] path - The Dbus object path
44 */
45 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
46 const std::string& path) :
47 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
48 bus(bus), path(path)
49 {
50 std::vector<std::string> interfaces({interface});
51 bus.emit_interfaces_added(path.c_str(), interfaces);
52 }
53
54 ~ActivationBlocksTransition()
55 {
56 std::vector<std::string> interfaces({interface});
57 bus.emit_interfaces_removed(path.c_str(), interfaces);
58 }
59
60 private:
61 // TODO Remove once openbmc/openbmc#1975 is resolved
62 static constexpr auto interface =
63 "xyz.openbmc_project.Software.ActivationBlocksTransition";
64 sdbusplus::bus::bus& bus;
65 std::string path;
66};
67
Lei YU90c8a8b2019-09-11 17:20:03 +080068using ActivationProgressInherit = sdbusplus::server::object::object<
69 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
70
71class ActivationProgress : public ActivationProgressInherit
72{
73 public:
74 /** @brief Constructs ActivationProgress.
75 *
76 * @param[in] bus - The Dbus bus object
77 * @param[in] path - The Dbus object path
78 */
79 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
80 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
81 {
82 progress(0);
83 std::vector<std::string> interfaces({interface});
84 bus.emit_interfaces_added(path.c_str(), interfaces);
85 }
86
87 ~ActivationProgress()
88 {
89 std::vector<std::string> interfaces({interface});
90 bus.emit_interfaces_removed(path.c_str(), interfaces);
91 }
92
93 private:
94 // TODO Remove once openbmc/openbmc#1975 is resolved
95 static constexpr auto interface =
96 "xyz.openbmc_project.Software.ActivationProgress";
97 sdbusplus::bus::bus& bus;
98 std::string path;
99};
100
Lei YU01539e72019-07-31 10:57:38 +0800101using ActivationInherit = sdbusplus::server::object::object<
102 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +0800103 sdbusplus::xyz::openbmc_project::Software::server::Activation,
104 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +0800105
106/** @class Activation
107 * @brief OpenBMC activation software management implementation.
108 * @details A concrete implementation for
109 * xyz.openbmc_project.Software.Activation DBus API.
110 */
111class Activation : public ActivationInherit
112{
113 public:
Lei YUff83c2a2019-09-12 13:55:18 +0800114 friend class ::TestActivation;
Lei YU12c9f4c2019-09-11 15:08:15 +0800115 using Status = Activations;
Lei YUff83c2a2019-09-12 13:55:18 +0800116
Lei YU01539e72019-07-31 10:57:38 +0800117 /** @brief Constructs Activation Software Manager
118 *
119 * @param[in] bus - The Dbus bus object
120 * @param[in] path - The Dbus object path
121 * @param[in] versionId - The software version id
122 * @param[in] extVersion - The extended version
123 * @param[in] activationStatus - The status of Activation
Lei YU91029442019-08-01 15:57:31 +0800124 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +0800125 */
126 Activation(sdbusplus::bus::bus& bus, const std::string& path,
127 const std::string& versionId, const std::string& extVersion,
Lei YU7f2a2152019-09-16 16:50:18 +0800128 Status activationStatus, const AssociationList& assocs,
129 AssociationInterface* associationInterface) :
Lei YU01539e72019-07-31 10:57:38 +0800130 ActivationInherit(bus, path.c_str(), true),
Lei YUa5c47bb2019-09-29 11:28:53 +0800131 bus(bus), path(path), versionId(versionId),
Lei YU12c9f4c2019-09-11 15:08:15 +0800132 systemdSignals(
133 bus,
134 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
135 sdbusRule::path("/org/freedesktop/systemd1") +
136 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
137 std::bind(&Activation::unitStateChange, this,
Lei YU7f2a2152019-09-16 16:50:18 +0800138 std::placeholders::_1)),
139 associationInterface(associationInterface)
Lei YU01539e72019-07-31 10:57:38 +0800140 {
141 // Set Properties.
142 extendedVersion(extVersion);
143 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800144 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +0800145
Lei YU9edb7332019-09-19 14:46:19 +0800146 auto info = Version::getExtVersionInfo(extVersion);
147 manufacturer = info["manufacturer"];
148 model = info["model"];
149
Lei YU01539e72019-07-31 10:57:38 +0800150 // Emit deferred signal.
151 emit_object_added();
152 }
153
154 /** @brief Overloaded Activation property setter function
155 *
156 * @param[in] value - One of Activation::Activations
157 *
158 * @return Success or exception thrown
159 */
Lei YUff83c2a2019-09-12 13:55:18 +0800160 Status activation(Status value) override;
Lei YU01539e72019-07-31 10:57:38 +0800161
162 /** @brief Activation */
163 using ActivationInherit::activation;
164
165 /** @brief Overloaded requestedActivation property setter function
166 *
167 * @param[in] value - One of Activation::RequestedActivations
168 *
169 * @return Success or exception thrown
170 */
171 RequestedActivations
172 requestedActivation(RequestedActivations value) override;
173
Lei YUa5c47bb2019-09-29 11:28:53 +0800174 /** @brief Get the version ID */
175 const std::string& getVersionId() const
176 {
177 return versionId;
178 }
Lei YU12c9f4c2019-09-11 15:08:15 +0800179
180 private:
181 /** @brief Check if systemd state change is relevant to this object
182 *
183 * Instance specific interface to handle the detected systemd state
184 * change
185 *
186 * @param[in] msg - Data associated with subscribed signal
187 *
188 */
189 void unitStateChange(sdbusplus::message::message& msg);
190
Lei YUd0bbfa92019-09-11 16:10:54 +0800191 /**
192 * @brief Delete the version from Image Manager and the
193 * untar image from image upload dir.
194 */
195 void deleteImageManagerObject();
196
Lei YUff83c2a2019-09-12 13:55:18 +0800197 /** @brief Invoke the update service for the PSU
198 *
199 * @param[in] psuInventoryPath - The PSU inventory to be updated.
200 *
201 * @return true if the update starts, and false if it fails.
202 */
203 bool doUpdate(const std::string& psuInventoryPath);
204
205 /** @brief Do PSU update one-by-one
206 *
207 * @return true if the update starts, and false if it fails.
208 */
209 bool doUpdate();
210
211 /** @brief Handle an update done event */
212 void onUpdateDone();
213
214 /** @brief Handle an update failure event */
215 void onUpdateFailed();
216
Lei YU12c9f4c2019-09-11 15:08:15 +0800217 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800218 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800219
220 /** @brief Finish PSU update */
221 void finishActivation();
222
Lei YU9edb7332019-09-19 14:46:19 +0800223 /** @brief Check if the PSU is comaptible with this software*/
224 bool isCompatible(const std::string& psuInventoryPath);
225
Lei YU01539e72019-07-31 10:57:38 +0800226 /** @brief Persistent sdbusplus DBus bus connection */
227 sdbusplus::bus::bus& bus;
228
229 /** @brief Persistent DBus object path */
230 std::string path;
231
Lei YUa5c47bb2019-09-29 11:28:53 +0800232 /** @brief Version id */
233 std::string versionId;
234
Lei YU12c9f4c2019-09-11 15:08:15 +0800235 /** @brief Used to subscribe to dbus systemd signals */
236 sdbusplus::bus::match_t systemdSignals;
237
Lei YUff83c2a2019-09-12 13:55:18 +0800238 /** @brief The queue of psu objects to be updated */
239 std::queue<std::string> psuQueue;
240
241 /** @brief The progress step for each PSU update is done */
242 uint32_t progressStep;
243
Lei YU12c9f4c2019-09-11 15:08:15 +0800244 /** @brief The PSU update systemd unit */
245 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800246
Lei YU7f2a2152019-09-16 16:50:18 +0800247 /** @brief The PSU Inventory path of the current updating PSU */
248 std::string currentUpdatingPsu;
249
Lei YU81c67722019-09-11 16:47:29 +0800250 /** @brief Persistent ActivationBlocksTransition dbus object */
251 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800252
253 /** @brief Persistent ActivationProgress dbus object */
254 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800255
256 /** @brief The AssociationInterface pointer */
257 AssociationInterface* associationInterface;
Lei YU9edb7332019-09-19 14:46:19 +0800258
259 /** @brief The PSU manufacturer of the software */
260 std::string manufacturer;
261
262 /** @brief The PSU model of the software */
263 std::string model;
Lei YU01539e72019-07-31 10:57:38 +0800264};
265
266} // namespace updater
267} // namespace software
268} // namespace phosphor