blob: b2b9aec8bb91b82a4b7a0c2ee2cf16ca132fa1af [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"
Gunnar Millsec1b41c2017-05-02 12:20:36 -05009
10namespace phosphor
11{
12namespace software
13{
14namespace updater
15{
16
Gunnar Millsb60add12017-08-24 16:41:42 -050017using AssociationList =
18 std::vector<std::tuple<std::string, std::string, std::string>>;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050019using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050020 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Michael Tritz4254bec2017-10-03 17:18:22 -050021 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050022using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050024using RedundancyPriorityInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050026using ActivationProgressInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050028
Michael Tritzbed88af2017-07-19 16:00:06 -050029namespace sdbusRule = sdbusplus::bus::match::rules;
30
Saqib Khan4c1aec02017-07-06 11:46:13 -050031class ItemUpdater;
32class Activation;
33class RedundancyPriority;
34
35/** @class RedundancyPriority
36 * @brief OpenBMC RedundancyPriority implementation
37 * @details A concrete implementation for
38 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
39 */
40class RedundancyPriority : public RedundancyPriorityInherit
41{
42 public:
43 /** @brief Constructs RedundancyPriority.
44 *
45 * @param[in] bus - The Dbus bus object
46 * @param[in] path - The Dbus object path
47 * @param[in] parent - Parent object.
48 * @param[in] value - The redundancyPriority value
Adriana Kobylakb77551c2017-10-27 12:46:23 -050049 * @param[in] freePriority - Call freePriorioty, default to true
Saqib Khan4c1aec02017-07-06 11:46:13 -050050 */
51 RedundancyPriority(sdbusplus::bus::bus& bus,
52 const std::string& path,
53 Activation& parent,
Adriana Kobylakb77551c2017-10-27 12:46:23 -050054 uint8_t value,
55 bool freePriority=true) :
Saqib Khan4c1aec02017-07-06 11:46:13 -050056 RedundancyPriorityInherit(bus,
57 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050058 parent(parent),
59 bus(bus),
60 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050061 {
62 // Set Property
Adriana Kobylakb77551c2017-10-27 12:46:23 -050063 if (freePriority)
64 {
65 priority(value);
66 }
67 else
68 {
69 sdbusPriority(value);
70 }
71
Saqib Khan140fcb12017-08-07 09:06:57 -050072 std::vector<std::string> interfaces({interface});
73 bus.emit_interfaces_added(path.c_str(), interfaces);
74 }
75
76 ~RedundancyPriority()
77 {
78 std::vector<std::string> interfaces({interface});
79 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050080 }
81
Adriana Kobylakb77551c2017-10-27 12:46:23 -050082 /** @brief Overriden Priority property set function, calls freePriority
83 * to bump the duplicated priority values.
Saqib Khan4c1aec02017-07-06 11:46:13 -050084 *
85 * @param[in] value - uint8_t
86 *
87 * @return Success or exception thrown
88 */
89 uint8_t priority(uint8_t value) override;
90
Adriana Kobylakb77551c2017-10-27 12:46:23 -050091 /** @brief Non-Overriden Priority property set function
92 *
93 * @param[in] value - uint8_t
94 *
95 * @return Success or exception thrown
96 */
97 uint8_t sdbusPriority(uint8_t value);
98
Saqib Khan4c1aec02017-07-06 11:46:13 -050099 /** @brief Priority property get function
100 *
101 * @returns uint8_t - The Priority value
102 */
103 using RedundancyPriorityInherit::priority;
104
105 /** @brief Parent Object. */
106 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -0500107
108 private:
109 // TODO Remove once openbmc/openbmc#1975 is resolved
110 static constexpr auto interface =
111 "xyz.openbmc_project.Software.RedundancyPriority";
112 sdbusplus::bus::bus& bus;
113 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500114};
Saqib Khanb0774702017-05-23 16:02:41 -0500115
116/** @class ActivationBlocksTransition
117 * @brief OpenBMC ActivationBlocksTransition implementation.
118 * @details A concrete implementation for
119 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
120 */
121class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
122{
123 public:
124 /** @brief Constructs ActivationBlocksTransition.
125 *
126 * @param[in] bus - The Dbus bus object
127 * @param[in] path - The Dbus object path
128 */
129 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
130 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500131 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
132 bus(bus),
133 path(path)
134 {
135 std::vector<std::string> interfaces({interface});
136 bus.emit_interfaces_added(path.c_str(), interfaces);
Saqib Khanf37cefc2017-09-12 08:44:41 -0500137 enableRebootGuard();
Saqib Khan140fcb12017-08-07 09:06:57 -0500138 }
139
140 ~ActivationBlocksTransition()
141 {
142 std::vector<std::string> interfaces({interface});
143 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khanf37cefc2017-09-12 08:44:41 -0500144 disableRebootGuard();
Saqib Khan140fcb12017-08-07 09:06:57 -0500145 }
146
147 private:
148 // TODO Remove once openbmc/openbmc#1975 is resolved
149 static constexpr auto interface =
150 "xyz.openbmc_project.Software.ActivationBlocksTransition";
151 sdbusplus::bus::bus& bus;
152 std::string path;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500153
154 /** @brief Enables a Guard that blocks any BMC reboot commands */
155 void enableRebootGuard();
156
157 /** @brief Disables any guard that was blocking the BMC reboot */
158 void disableRebootGuard();
Saqib Khanb0774702017-05-23 16:02:41 -0500159};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500160
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500161class ActivationProgress : public ActivationProgressInherit
162{
163 public:
164 /** @brief Constructs ActivationProgress.
165 *
166 * @param[in] bus - The Dbus bus object
167 * @param[in] path - The Dbus object path
168 */
169 ActivationProgress(sdbusplus::bus::bus& bus,
170 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500171 ActivationProgressInherit(bus, path.c_str(), true),
172 bus(bus),
173 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500174 {
175 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500176 std::vector<std::string> interfaces({interface});
177 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500178 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500179
180 ~ActivationProgress()
181 {
182 std::vector<std::string> interfaces({interface});
183 bus.emit_interfaces_removed(path.c_str(), interfaces);
184 }
185
186 private:
187 // TODO Remove once openbmc/openbmc#1975 is resolved
188 static constexpr auto interface =
189 "xyz.openbmc_project.Software.ActivationProgress";
190 sdbusplus::bus::bus& bus;
191 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500192};
193
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500194/** @class Activation
195 * @brief OpenBMC activation software management implementation.
196 * @details A concrete implementation for
197 * xyz.openbmc_project.Software.Activation DBus API.
198 */
199class Activation : public ActivationInherit
200{
201 public:
202 /** @brief Constructs Activation Software Manager
203 *
204 * @param[in] bus - The Dbus bus object
205 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500206 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500207 * @param[in] versionId - The software version id
208 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500209 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500210 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500211 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500212 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500213 std::string& versionId,
214 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500215 server::Activation::Activations activationStatus,
216 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500217 ActivationInherit(bus, path.c_str(), true),
218 bus(bus),
219 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500220 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500221 versionId(versionId),
222 systemdSignals(
223 bus,
224 sdbusRule::type::signal() +
225 sdbusRule::member("JobRemoved") +
226 sdbusRule::path("/org/freedesktop/systemd1") +
227 sdbusRule::interface(
228 "org.freedesktop.systemd1.Manager"),
229 std::bind(std::mem_fn(&Activation::unitStateChange),
230 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500231 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500232 // Enable systemd signals
233 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500234 // Set Properties.
235 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500236 associations(assocs);
237
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500238 // Emit deferred signal.
239 emit_object_added();
240 }
241
Saqib Khanb0774702017-05-23 16:02:41 -0500242 /** @brief Overloaded Activation property setter function
243 *
244 * @param[in] value - One of Activation::Activations
245 *
246 * @return Success or exception thrown
247 */
248 Activations activation(Activations value) override;
249
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500250 /** @brief Activation */
251 using ActivationInherit::activation;
252
Saqib Khanb0774702017-05-23 16:02:41 -0500253 /** @brief Overloaded requestedActivation property setter function
254 *
255 * @param[in] value - One of Activation::RequestedActivations
256 *
257 * @return Success or exception thrown
258 */
259 RequestedActivations requestedActivation(RequestedActivations value)
260 override;
261
Michael Tritzbed88af2017-07-19 16:00:06 -0500262 /** @brief Check if systemd state change is relevant to this object
263 *
264 * Instance specific interface to handle the detected systemd state
265 * change
266 *
267 * @param[in] msg - Data associated with subscribed signal
268 *
269 */
270 void unitStateChange(sdbusplus::message::message& msg);
271
272 /**
273 * @brief subscribe to the systemd signals
274 *
275 * This object needs to capture when it's systemd targets complete
276 * so it can keep it's state updated
277 *
278 */
279 void subscribeToSystemdSignals();
280
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500281 /**
282 * @brief unsubscribe from the systemd signals
283 *
284 * systemd signals are only of interest during the activation process.
285 * Once complete, we want to unsubscribe to avoid unnecessary calls of
286 * unitStateChange().
287 *
288 */
289 void unsubscribeFromSystemdSignals();
290
Saqib Khanee13e832017-10-23 12:53:11 -0500291 /**
292 * @brief Deletes the version from Image Manager and the
293 * untar image from image upload dir.
294 */
295 void deleteImageManagerObject();
296
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500297 /** @brief Persistent sdbusplus DBus bus connection */
298 sdbusplus::bus::bus& bus;
299
300 /** @brief Persistent DBus object path */
301 std::string path;
302
Saqib Khan4c1aec02017-07-06 11:46:13 -0500303 /** @brief Parent Object. */
304 ItemUpdater& parent;
305
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500306 /** @brief Version id */
307 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500308
309 /** @brief Persistent ActivationBlocksTransition dbus object */
310 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500311
312 /** @brief Persistent RedundancyPriority dbus object */
313 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500314
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500315 /** @brief Persistent ActivationProgress dbus object */
316 std::unique_ptr<ActivationProgress> activationProgress;
317
Michael Tritzbed88af2017-07-19 16:00:06 -0500318 /** @brief Used to subscribe to dbus systemd signals **/
319 sdbusplus::bus::match_t systemdSignals;
320
321 /** @brief Tracks whether the read-write volume has been created as
322 * part of the activation process. **/
323 bool rwVolumeCreated = false;
324
325 /** @brief Tracks whether the read-only volume has been created as
326 * part of the activation process. **/
327 bool roVolumeCreated = false;
Adriana Kobylak4c3edc92018-01-24 14:50:15 -0600328
329 /** @brief Tracks if the service that updates the U-Boot environment
330 * variables has completed. **/
331 bool ubootEnvVarsUpdated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500332};
333
334} // namespace updater
335} // namespace software
336} // namespace phosphor