blob: a6e11116f2d0c46fa2c3b134e8af17de2db7d336 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
Saqib Khanb0774702017-05-23 16:02:41 -05003#include <sdbusplus/server.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05004#include <xyz/openbmc_project/Software/Activation/server.hpp>
Saqib Khanb0774702017-05-23 16:02:41 -05005#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Saqib Khan4c1aec02017-07-06 11:46:13 -05006#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
Michael Tritz0edd4ad2017-07-26 14:27:42 -05007#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
Gunnar Millsf5eaf392017-08-22 16:36:55 -05008#include "org/openbmc/Associations/server.hpp"
Eddie James9440f492017-08-30 11:34:16 -05009#include "xyz/openbmc_project/Object/Delete/server.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -050010
11namespace phosphor
12{
13namespace software
14{
15namespace updater
16{
17
Gunnar Millsb60add12017-08-24 16:41:42 -050018using AssociationList =
19 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050020using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050021 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Michael Tritz4254bec2017-10-03 17:18:22 -050022 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050023using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
24 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050025using RedundancyPriorityInherit = sdbusplus::server::object::object<
26 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050027using ActivationProgressInherit = sdbusplus::server::object::object<
28 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Michael Tritz4254bec2017-10-03 17:18:22 -050029using DeleteInherit = sdbusplus::server::object::object<
30 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050031
Michael Tritzbed88af2017-07-19 16:00:06 -050032namespace sdbusRule = sdbusplus::bus::match::rules;
33
Saqib Khan4c1aec02017-07-06 11:46:13 -050034class ItemUpdater;
35class Activation;
36class RedundancyPriority;
37
38/** @class RedundancyPriority
39 * @brief OpenBMC RedundancyPriority implementation
40 * @details A concrete implementation for
41 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
42 */
43class RedundancyPriority : public RedundancyPriorityInherit
44{
45 public:
46 /** @brief Constructs RedundancyPriority.
47 *
48 * @param[in] bus - The Dbus bus object
49 * @param[in] path - The Dbus object path
50 * @param[in] parent - Parent object.
51 * @param[in] value - The redundancyPriority value
Adriana Kobylakb77551c2017-10-27 12:46:23 -050052 * @param[in] freePriority - Call freePriorioty, default to true
Saqib Khan4c1aec02017-07-06 11:46:13 -050053 */
54 RedundancyPriority(sdbusplus::bus::bus& bus,
55 const std::string& path,
56 Activation& parent,
Adriana Kobylakb77551c2017-10-27 12:46:23 -050057 uint8_t value,
58 bool freePriority=true) :
Saqib Khan4c1aec02017-07-06 11:46:13 -050059 RedundancyPriorityInherit(bus,
60 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050061 parent(parent),
62 bus(bus),
63 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050064 {
65 // Set Property
Adriana Kobylakb77551c2017-10-27 12:46:23 -050066 if (freePriority)
67 {
68 priority(value);
69 }
70 else
71 {
72 sdbusPriority(value);
73 }
74
Saqib Khan140fcb12017-08-07 09:06:57 -050075 std::vector<std::string> interfaces({interface});
76 bus.emit_interfaces_added(path.c_str(), interfaces);
77 }
78
79 ~RedundancyPriority()
80 {
81 std::vector<std::string> interfaces({interface});
82 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050083 }
84
Adriana Kobylakb77551c2017-10-27 12:46:23 -050085 /** @brief Overriden Priority property set function, calls freePriority
86 * to bump the duplicated priority values.
Saqib Khan4c1aec02017-07-06 11:46:13 -050087 *
88 * @param[in] value - uint8_t
89 *
90 * @return Success or exception thrown
91 */
92 uint8_t priority(uint8_t value) override;
93
Adriana Kobylakb77551c2017-10-27 12:46:23 -050094 /** @brief Non-Overriden Priority property set function
95 *
96 * @param[in] value - uint8_t
97 *
98 * @return Success or exception thrown
99 */
100 uint8_t sdbusPriority(uint8_t value);
101
Saqib Khan4c1aec02017-07-06 11:46:13 -0500102 /** @brief Priority property get function
103 *
104 * @returns uint8_t - The Priority value
105 */
106 using RedundancyPriorityInherit::priority;
107
108 /** @brief Parent Object. */
109 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -0500110
111 private:
112 // TODO Remove once openbmc/openbmc#1975 is resolved
113 static constexpr auto interface =
114 "xyz.openbmc_project.Software.RedundancyPriority";
115 sdbusplus::bus::bus& bus;
116 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500117};
Saqib Khanb0774702017-05-23 16:02:41 -0500118
119/** @class ActivationBlocksTransition
120 * @brief OpenBMC ActivationBlocksTransition implementation.
121 * @details A concrete implementation for
122 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
123 */
124class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
125{
126 public:
127 /** @brief Constructs ActivationBlocksTransition.
128 *
129 * @param[in] bus - The Dbus bus object
130 * @param[in] path - The Dbus object path
131 */
132 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
133 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500134 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
135 bus(bus),
136 path(path)
137 {
138 std::vector<std::string> interfaces({interface});
139 bus.emit_interfaces_added(path.c_str(), interfaces);
140 }
141
142 ~ActivationBlocksTransition()
143 {
144 std::vector<std::string> interfaces({interface});
145 bus.emit_interfaces_removed(path.c_str(), interfaces);
146 }
147
148 private:
149 // TODO Remove once openbmc/openbmc#1975 is resolved
150 static constexpr auto interface =
151 "xyz.openbmc_project.Software.ActivationBlocksTransition";
152 sdbusplus::bus::bus& bus;
153 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500154};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500155
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500156class ActivationProgress : public ActivationProgressInherit
157{
158 public:
159 /** @brief Constructs ActivationProgress.
160 *
161 * @param[in] bus - The Dbus bus object
162 * @param[in] path - The Dbus object path
163 */
164 ActivationProgress(sdbusplus::bus::bus& bus,
165 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500166 ActivationProgressInherit(bus, path.c_str(), true),
167 bus(bus),
168 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500169 {
170 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500171 std::vector<std::string> interfaces({interface});
172 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500173 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500174
175 ~ActivationProgress()
176 {
177 std::vector<std::string> interfaces({interface});
178 bus.emit_interfaces_removed(path.c_str(), interfaces);
179 }
180
181 private:
182 // TODO Remove once openbmc/openbmc#1975 is resolved
183 static constexpr auto interface =
184 "xyz.openbmc_project.Software.ActivationProgress";
185 sdbusplus::bus::bus& bus;
186 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500187};
188
Michael Tritz4254bec2017-10-03 17:18:22 -0500189/** @class ActivationDelete
190 * @brief OpenBMC Delete implementation.
191 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
192 * DBus API.
193 */
194class Delete : public DeleteInherit
195{
196 public:
197 /** @brief Constructs Delete.
198 *
199 * @param[in] bus - The Dbus bus object
200 * @param[in] path - The Dbus object path
201 * @param[in] parent - Parent object.
202 */
203 // Delete(sdbusplus::bus::bus& bus, const std::string& path) :
204 Delete(sdbusplus::bus::bus& bus,
205 const std::string& path,
206 Activation& parent) :
207 DeleteInherit(bus, path.c_str(), true),
208 parent(parent),
209 bus(bus),
210 path(path)
211 {
212 std::vector<std::string> interfaces({interface});
213 bus.emit_interfaces_added(path.c_str(), interfaces);
214 }
215
216 ~Delete()
217 {
218 std::vector<std::string> interfaces({interface});
219 bus.emit_interfaces_removed(path.c_str(), interfaces);
220 }
221
222 /**
223 * @brief delete the d-bus object.
224 */
225 void delete_() override;
226
227 /** @brief Parent Object. */
228 Activation& parent;
229
230 private:
231 // TODO Remove once openbmc/openbmc#1975 is resolved
232 static constexpr auto interface =
233 "xyz.openbmc_project.Object.Delete";
234 sdbusplus::bus::bus& bus;
235 std::string path;
236};
237
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500238/** @class Activation
239 * @brief OpenBMC activation software management implementation.
240 * @details A concrete implementation for
241 * xyz.openbmc_project.Software.Activation DBus API.
242 */
243class Activation : public ActivationInherit
244{
245 public:
246 /** @brief Constructs Activation Software Manager
247 *
248 * @param[in] bus - The Dbus bus object
249 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500250 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500251 * @param[in] versionId - The software version id
252 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500253 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500254 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500255 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500256 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500257 std::string& versionId,
258 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500259 server::Activation::Activations activationStatus,
260 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500261 ActivationInherit(bus, path.c_str(), true),
262 bus(bus),
263 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500264 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500265 versionId(versionId),
266 systemdSignals(
267 bus,
268 sdbusRule::type::signal() +
269 sdbusRule::member("JobRemoved") +
270 sdbusRule::path("/org/freedesktop/systemd1") +
271 sdbusRule::interface(
272 "org.freedesktop.systemd1.Manager"),
273 std::bind(std::mem_fn(&Activation::unitStateChange),
274 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500275 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500276 // Enable systemd signals
277 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500278 // Set Properties.
279 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500280 associations(assocs);
281
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500282 // Emit deferred signal.
283 emit_object_added();
284 }
285
Saqib Khanb0774702017-05-23 16:02:41 -0500286 /** @brief Overloaded Activation property setter function
287 *
288 * @param[in] value - One of Activation::Activations
289 *
290 * @return Success or exception thrown
291 */
292 Activations activation(Activations value) override;
293
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500294 /** @brief Activation */
295 using ActivationInherit::activation;
296
Saqib Khanb0774702017-05-23 16:02:41 -0500297 /** @brief Overloaded requestedActivation property setter function
298 *
299 * @param[in] value - One of Activation::RequestedActivations
300 *
301 * @return Success or exception thrown
302 */
303 RequestedActivations requestedActivation(RequestedActivations value)
304 override;
305
Michael Tritzbed88af2017-07-19 16:00:06 -0500306 /** @brief Check if systemd state change is relevant to this object
307 *
308 * Instance specific interface to handle the detected systemd state
309 * change
310 *
311 * @param[in] msg - Data associated with subscribed signal
312 *
313 */
314 void unitStateChange(sdbusplus::message::message& msg);
315
316 /**
317 * @brief subscribe to the systemd signals
318 *
319 * This object needs to capture when it's systemd targets complete
320 * so it can keep it's state updated
321 *
322 */
323 void subscribeToSystemdSignals();
324
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500325 /**
326 * @brief unsubscribe from the systemd signals
327 *
328 * systemd signals are only of interest during the activation process.
329 * Once complete, we want to unsubscribe to avoid unnecessary calls of
330 * unitStateChange().
331 *
332 */
333 void unsubscribeFromSystemdSignals();
334
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500335 /** @brief Persistent sdbusplus DBus bus connection */
336 sdbusplus::bus::bus& bus;
337
338 /** @brief Persistent DBus object path */
339 std::string path;
340
Saqib Khan4c1aec02017-07-06 11:46:13 -0500341 /** @brief Parent Object. */
342 ItemUpdater& parent;
343
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500344 /** @brief Version id */
345 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500346
347 /** @brief Persistent ActivationBlocksTransition dbus object */
348 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500349
350 /** @brief Persistent RedundancyPriority dbus object */
351 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500352
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500353 /** @brief Persistent ActivationProgress dbus object */
354 std::unique_ptr<ActivationProgress> activationProgress;
355
Michael Tritz4254bec2017-10-03 17:18:22 -0500356 /** @brief Persistent Delete dbus object */
357 std::unique_ptr<Delete> deleteObject;
358
Michael Tritzbed88af2017-07-19 16:00:06 -0500359 /** @brief Used to subscribe to dbus systemd signals **/
360 sdbusplus::bus::match_t systemdSignals;
361
362 /** @brief Tracks whether the read-write volume has been created as
363 * part of the activation process. **/
364 bool rwVolumeCreated = false;
365
366 /** @brief Tracks whether the read-only volume has been created as
367 * part of the activation process. **/
368 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500369};
370
371} // namespace updater
372} // namespace software
373} // namespace phosphor