blob: b46105b37c365dea8a0ab7304e062aa17981c31f [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 YU12c9f4c2019-09-11 15:08:15 +0800131 versionId(versionId), bus(bus), path(path),
132 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 YU12c9f4c2019-09-11 15:08:15 +0800174 /** @brief Version id */
175 std::string versionId;
176
177 private:
178 /** @brief Check if systemd state change is relevant to this object
179 *
180 * Instance specific interface to handle the detected systemd state
181 * change
182 *
183 * @param[in] msg - Data associated with subscribed signal
184 *
185 */
186 void unitStateChange(sdbusplus::message::message& msg);
187
Lei YUd0bbfa92019-09-11 16:10:54 +0800188 /**
189 * @brief Delete the version from Image Manager and the
190 * untar image from image upload dir.
191 */
192 void deleteImageManagerObject();
193
Lei YUff83c2a2019-09-12 13:55:18 +0800194 /** @brief Invoke the update service for the PSU
195 *
196 * @param[in] psuInventoryPath - The PSU inventory to be updated.
197 *
198 * @return true if the update starts, and false if it fails.
199 */
200 bool doUpdate(const std::string& psuInventoryPath);
201
202 /** @brief Do PSU update one-by-one
203 *
204 * @return true if the update starts, and false if it fails.
205 */
206 bool doUpdate();
207
208 /** @brief Handle an update done event */
209 void onUpdateDone();
210
211 /** @brief Handle an update failure event */
212 void onUpdateFailed();
213
Lei YU12c9f4c2019-09-11 15:08:15 +0800214 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800215 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800216
217 /** @brief Finish PSU update */
218 void finishActivation();
219
Lei YU9edb7332019-09-19 14:46:19 +0800220 /** @brief Check if the PSU is comaptible with this software*/
221 bool isCompatible(const std::string& psuInventoryPath);
222
Lei YU01539e72019-07-31 10:57:38 +0800223 /** @brief Persistent sdbusplus DBus bus connection */
224 sdbusplus::bus::bus& bus;
225
226 /** @brief Persistent DBus object path */
227 std::string path;
228
Lei YU12c9f4c2019-09-11 15:08:15 +0800229 /** @brief Used to subscribe to dbus systemd signals */
230 sdbusplus::bus::match_t systemdSignals;
231
Lei YUff83c2a2019-09-12 13:55:18 +0800232 /** @brief The queue of psu objects to be updated */
233 std::queue<std::string> psuQueue;
234
235 /** @brief The progress step for each PSU update is done */
236 uint32_t progressStep;
237
Lei YU12c9f4c2019-09-11 15:08:15 +0800238 /** @brief The PSU update systemd unit */
239 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800240
Lei YU7f2a2152019-09-16 16:50:18 +0800241 /** @brief The PSU Inventory path of the current updating PSU */
242 std::string currentUpdatingPsu;
243
Lei YU81c67722019-09-11 16:47:29 +0800244 /** @brief Persistent ActivationBlocksTransition dbus object */
245 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800246
247 /** @brief Persistent ActivationProgress dbus object */
248 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800249
250 /** @brief The AssociationInterface pointer */
251 AssociationInterface* associationInterface;
Lei YU9edb7332019-09-19 14:46:19 +0800252
253 /** @brief The PSU manufacturer of the software */
254 std::string manufacturer;
255
256 /** @brief The PSU model of the software */
257 std::string model;
Lei YU01539e72019-07-31 10:57:38 +0800258};
259
260} // namespace updater
261} // namespace software
262} // namespace phosphor