blob: d0fdaba8cc0f1fc69d171f6bec3fbb7e6513e8a2 [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"
7
Lei YUff83c2a2019-09-12 13:55:18 +08008#include <queue>
Lei YU01539e72019-07-31 10:57:38 +08009#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080010#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080011#include <xyz/openbmc_project/Software/Activation/server.hpp>
Lei YU81c67722019-09-11 16:47:29 +080012#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90c8a8b2019-09-11 17:20:03 +080013#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080014#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
15
Lei YUff83c2a2019-09-12 13:55:18 +080016class TestActivation;
17
Lei YU01539e72019-07-31 10:57:38 +080018namespace phosphor
19{
20namespace software
21{
22namespace updater
23{
24
Lei YU12c9f4c2019-09-11 15:08:15 +080025namespace sdbusRule = sdbusplus::bus::match::rules;
26
Lei YU81c67722019-09-11 16:47:29 +080027using 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 */
36class 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 YU90c8a8b2019-09-11 17:20:03 +080067using ActivationProgressInherit = sdbusplus::server::object::object<
68 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
69
70class 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 YU01539e72019-07-31 10:57:38 +0800100using ActivationInherit = sdbusplus::server::object::object<
101 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +0800102 sdbusplus::xyz::openbmc_project::Software::server::Activation,
103 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +0800104
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 */
110class Activation : public ActivationInherit
111{
112 public:
Lei YUff83c2a2019-09-12 13:55:18 +0800113 friend class ::TestActivation;
Lei YU12c9f4c2019-09-11 15:08:15 +0800114 using Status = Activations;
Lei YUff83c2a2019-09-12 13:55:18 +0800115
Lei YU01539e72019-07-31 10:57:38 +0800116 /** @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 YU91029442019-08-01 15:57:31 +0800123 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +0800124 */
125 Activation(sdbusplus::bus::bus& bus, const std::string& path,
126 const std::string& versionId, const std::string& extVersion,
Lei YU7f2a2152019-09-16 16:50:18 +0800127 Status activationStatus, const AssociationList& assocs,
128 AssociationInterface* associationInterface) :
Lei YU01539e72019-07-31 10:57:38 +0800129 ActivationInherit(bus, path.c_str(), true),
Lei YU12c9f4c2019-09-11 15:08:15 +0800130 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 YU7f2a2152019-09-16 16:50:18 +0800137 std::placeholders::_1)),
138 associationInterface(associationInterface)
Lei YU01539e72019-07-31 10:57:38 +0800139 {
140 // Set Properties.
141 extendedVersion(extVersion);
142 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800143 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +0800144
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 YUff83c2a2019-09-12 13:55:18 +0800155 Status activation(Status value) override;
Lei YU01539e72019-07-31 10:57:38 +0800156
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 YU12c9f4c2019-09-11 15:08:15 +0800169 /** @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 YUd0bbfa92019-09-11 16:10:54 +0800183 /**
184 * @brief Delete the version from Image Manager and the
185 * untar image from image upload dir.
186 */
187 void deleteImageManagerObject();
188
Lei YUff83c2a2019-09-12 13:55:18 +0800189 /** @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 YU12c9f4c2019-09-11 15:08:15 +0800209 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800210 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800211
212 /** @brief Finish PSU update */
213 void finishActivation();
214
Lei YU01539e72019-07-31 10:57:38 +0800215 /** @brief Persistent sdbusplus DBus bus connection */
216 sdbusplus::bus::bus& bus;
217
218 /** @brief Persistent DBus object path */
219 std::string path;
220
Lei YU12c9f4c2019-09-11 15:08:15 +0800221 /** @brief Used to subscribe to dbus systemd signals */
222 sdbusplus::bus::match_t systemdSignals;
223
Lei YUff83c2a2019-09-12 13:55:18 +0800224 /** @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 YU12c9f4c2019-09-11 15:08:15 +0800230 /** @brief The PSU update systemd unit */
231 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800232
Lei YU7f2a2152019-09-16 16:50:18 +0800233 /** @brief The PSU Inventory path of the current updating PSU */
234 std::string currentUpdatingPsu;
235
Lei YU81c67722019-09-11 16:47:29 +0800236 /** @brief Persistent ActivationBlocksTransition dbus object */
237 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800238
239 /** @brief Persistent ActivationProgress dbus object */
240 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800241
242 /** @brief The AssociationInterface pointer */
243 AssociationInterface* associationInterface;
Lei YU01539e72019-07-31 10:57:38 +0800244};
245
246} // namespace updater
247} // namespace software
248} // namespace phosphor