blob: d1d050a9acd98bfefd282a1ff0b041154f6db85c [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
52 */
53 RedundancyPriority(sdbusplus::bus::bus& bus,
54 const std::string& path,
55 Activation& parent,
56 uint8_t value) :
57 RedundancyPriorityInherit(bus,
58 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050059 parent(parent),
60 bus(bus),
61 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050062 {
63 // Set Property
64 priority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050065 std::vector<std::string> interfaces({interface});
66 bus.emit_interfaces_added(path.c_str(), interfaces);
67 }
68
69 ~RedundancyPriority()
70 {
71 std::vector<std::string> interfaces({interface});
72 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050073 }
74
75 /** @brief Overloaded Priority property set function
76 *
77 * @param[in] value - uint8_t
78 *
79 * @return Success or exception thrown
80 */
81 uint8_t priority(uint8_t value) override;
82
83 /** @brief Priority property get function
84 *
85 * @returns uint8_t - The Priority value
86 */
87 using RedundancyPriorityInherit::priority;
88
89 /** @brief Parent Object. */
90 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -050091
92 private:
93 // TODO Remove once openbmc/openbmc#1975 is resolved
94 static constexpr auto interface =
95 "xyz.openbmc_project.Software.RedundancyPriority";
96 sdbusplus::bus::bus& bus;
97 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -050098};
Saqib Khanb0774702017-05-23 16:02:41 -050099
100/** @class ActivationBlocksTransition
101 * @brief OpenBMC ActivationBlocksTransition implementation.
102 * @details A concrete implementation for
103 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
104 */
105class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
106{
107 public:
108 /** @brief Constructs ActivationBlocksTransition.
109 *
110 * @param[in] bus - The Dbus bus object
111 * @param[in] path - The Dbus object path
112 */
113 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
114 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500115 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
116 bus(bus),
117 path(path)
118 {
119 std::vector<std::string> interfaces({interface});
120 bus.emit_interfaces_added(path.c_str(), interfaces);
121 }
122
123 ~ActivationBlocksTransition()
124 {
125 std::vector<std::string> interfaces({interface});
126 bus.emit_interfaces_removed(path.c_str(), interfaces);
127 }
128
129 private:
130 // TODO Remove once openbmc/openbmc#1975 is resolved
131 static constexpr auto interface =
132 "xyz.openbmc_project.Software.ActivationBlocksTransition";
133 sdbusplus::bus::bus& bus;
134 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500135};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500136
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500137class ActivationProgress : public ActivationProgressInherit
138{
139 public:
140 /** @brief Constructs ActivationProgress.
141 *
142 * @param[in] bus - The Dbus bus object
143 * @param[in] path - The Dbus object path
144 */
145 ActivationProgress(sdbusplus::bus::bus& bus,
146 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500147 ActivationProgressInherit(bus, path.c_str(), true),
148 bus(bus),
149 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500150 {
151 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500152 std::vector<std::string> interfaces({interface});
153 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500154 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500155
156 ~ActivationProgress()
157 {
158 std::vector<std::string> interfaces({interface});
159 bus.emit_interfaces_removed(path.c_str(), interfaces);
160 }
161
162 private:
163 // TODO Remove once openbmc/openbmc#1975 is resolved
164 static constexpr auto interface =
165 "xyz.openbmc_project.Software.ActivationProgress";
166 sdbusplus::bus::bus& bus;
167 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500168};
169
Michael Tritz4254bec2017-10-03 17:18:22 -0500170/** @class ActivationDelete
171 * @brief OpenBMC Delete implementation.
172 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
173 * DBus API.
174 */
175class Delete : public DeleteInherit
176{
177 public:
178 /** @brief Constructs Delete.
179 *
180 * @param[in] bus - The Dbus bus object
181 * @param[in] path - The Dbus object path
182 * @param[in] parent - Parent object.
183 */
184 // Delete(sdbusplus::bus::bus& bus, const std::string& path) :
185 Delete(sdbusplus::bus::bus& bus,
186 const std::string& path,
187 Activation& parent) :
188 DeleteInherit(bus, path.c_str(), true),
189 parent(parent),
190 bus(bus),
191 path(path)
192 {
193 std::vector<std::string> interfaces({interface});
194 bus.emit_interfaces_added(path.c_str(), interfaces);
195 }
196
197 ~Delete()
198 {
199 std::vector<std::string> interfaces({interface});
200 bus.emit_interfaces_removed(path.c_str(), interfaces);
201 }
202
203 /**
204 * @brief delete the d-bus object.
205 */
206 void delete_() override;
207
208 /** @brief Parent Object. */
209 Activation& parent;
210
211 private:
212 // TODO Remove once openbmc/openbmc#1975 is resolved
213 static constexpr auto interface =
214 "xyz.openbmc_project.Object.Delete";
215 sdbusplus::bus::bus& bus;
216 std::string path;
217};
218
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500219/** @class Activation
220 * @brief OpenBMC activation software management implementation.
221 * @details A concrete implementation for
222 * xyz.openbmc_project.Software.Activation DBus API.
223 */
224class Activation : public ActivationInherit
225{
226 public:
227 /** @brief Constructs Activation Software Manager
228 *
229 * @param[in] bus - The Dbus bus object
230 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500231 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500232 * @param[in] versionId - The software version id
233 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500234 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500235 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500236 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500237 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500238 std::string& versionId,
239 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500240 server::Activation::Activations activationStatus,
241 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500242 ActivationInherit(bus, path.c_str(), true),
243 bus(bus),
244 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500245 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500246 versionId(versionId),
247 systemdSignals(
248 bus,
249 sdbusRule::type::signal() +
250 sdbusRule::member("JobRemoved") +
251 sdbusRule::path("/org/freedesktop/systemd1") +
252 sdbusRule::interface(
253 "org.freedesktop.systemd1.Manager"),
254 std::bind(std::mem_fn(&Activation::unitStateChange),
255 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500256 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500257 // Enable systemd signals
258 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500259 // Set Properties.
260 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500261 associations(assocs);
262
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500263 // Emit deferred signal.
264 emit_object_added();
265 }
266
Saqib Khanb0774702017-05-23 16:02:41 -0500267 /** @brief Overloaded Activation property setter function
268 *
269 * @param[in] value - One of Activation::Activations
270 *
271 * @return Success or exception thrown
272 */
273 Activations activation(Activations value) override;
274
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500275 /** @brief Activation */
276 using ActivationInherit::activation;
277
Saqib Khanb0774702017-05-23 16:02:41 -0500278 /** @brief Overloaded requestedActivation property setter function
279 *
280 * @param[in] value - One of Activation::RequestedActivations
281 *
282 * @return Success or exception thrown
283 */
284 RequestedActivations requestedActivation(RequestedActivations value)
285 override;
286
Michael Tritzbed88af2017-07-19 16:00:06 -0500287 /** @brief Check if systemd state change is relevant to this object
288 *
289 * Instance specific interface to handle the detected systemd state
290 * change
291 *
292 * @param[in] msg - Data associated with subscribed signal
293 *
294 */
295 void unitStateChange(sdbusplus::message::message& msg);
296
297 /**
298 * @brief subscribe to the systemd signals
299 *
300 * This object needs to capture when it's systemd targets complete
301 * so it can keep it's state updated
302 *
303 */
304 void subscribeToSystemdSignals();
305
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500306 /**
307 * @brief unsubscribe from the systemd signals
308 *
309 * systemd signals are only of interest during the activation process.
310 * Once complete, we want to unsubscribe to avoid unnecessary calls of
311 * unitStateChange().
312 *
313 */
314 void unsubscribeFromSystemdSignals();
315
Eddie James9440f492017-08-30 11:34:16 -0500316 /**
Saqib Khanf0382c32017-10-24 13:36:22 -0500317 * @brief Updates the U-Boot variables to point to this activation's
318 * versionId, so that the systems boots from this version on
319 * the next reboot.
320 */
321 void updateUbootEnvVars();
322
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500323 /** @brief Persistent sdbusplus DBus bus connection */
324 sdbusplus::bus::bus& bus;
325
326 /** @brief Persistent DBus object path */
327 std::string path;
328
Saqib Khan4c1aec02017-07-06 11:46:13 -0500329 /** @brief Parent Object. */
330 ItemUpdater& parent;
331
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500332 /** @brief Version id */
333 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500334
335 /** @brief Persistent ActivationBlocksTransition dbus object */
336 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500337
338 /** @brief Persistent RedundancyPriority dbus object */
339 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500340
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500341 /** @brief Persistent ActivationProgress dbus object */
342 std::unique_ptr<ActivationProgress> activationProgress;
343
Michael Tritz4254bec2017-10-03 17:18:22 -0500344 /** @brief Persistent Delete dbus object */
345 std::unique_ptr<Delete> deleteObject;
346
Michael Tritzbed88af2017-07-19 16:00:06 -0500347 /** @brief Used to subscribe to dbus systemd signals **/
348 sdbusplus::bus::match_t systemdSignals;
349
350 /** @brief Tracks whether the read-write volume has been created as
351 * part of the activation process. **/
352 bool rwVolumeCreated = false;
353
354 /** @brief Tracks whether the read-only volume has been created as
355 * part of the activation process. **/
356 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500357};
358
359} // namespace updater
360} // namespace software
361} // namespace phosphor