blob: 9c1fde9c1c6301615ca8480e457212e97414d575 [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);
137 }
138
139 ~ActivationBlocksTransition()
140 {
141 std::vector<std::string> interfaces({interface});
142 bus.emit_interfaces_removed(path.c_str(), interfaces);
143 }
144
145 private:
146 // TODO Remove once openbmc/openbmc#1975 is resolved
147 static constexpr auto interface =
148 "xyz.openbmc_project.Software.ActivationBlocksTransition";
149 sdbusplus::bus::bus& bus;
150 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500151};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500152
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500153class ActivationProgress : public ActivationProgressInherit
154{
155 public:
156 /** @brief Constructs ActivationProgress.
157 *
158 * @param[in] bus - The Dbus bus object
159 * @param[in] path - The Dbus object path
160 */
161 ActivationProgress(sdbusplus::bus::bus& bus,
162 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500163 ActivationProgressInherit(bus, path.c_str(), true),
164 bus(bus),
165 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500166 {
167 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500168 std::vector<std::string> interfaces({interface});
169 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500170 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500171
172 ~ActivationProgress()
173 {
174 std::vector<std::string> interfaces({interface});
175 bus.emit_interfaces_removed(path.c_str(), interfaces);
176 }
177
178 private:
179 // TODO Remove once openbmc/openbmc#1975 is resolved
180 static constexpr auto interface =
181 "xyz.openbmc_project.Software.ActivationProgress";
182 sdbusplus::bus::bus& bus;
183 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500184};
185
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500186/** @class Activation
187 * @brief OpenBMC activation software management implementation.
188 * @details A concrete implementation for
189 * xyz.openbmc_project.Software.Activation DBus API.
190 */
191class Activation : public ActivationInherit
192{
193 public:
194 /** @brief Constructs Activation Software Manager
195 *
196 * @param[in] bus - The Dbus bus object
197 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500198 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500199 * @param[in] versionId - The software version id
200 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500201 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500202 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500203 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500204 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500205 std::string& versionId,
206 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500207 server::Activation::Activations activationStatus,
208 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500209 ActivationInherit(bus, path.c_str(), true),
210 bus(bus),
211 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500212 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500213 versionId(versionId),
214 systemdSignals(
215 bus,
216 sdbusRule::type::signal() +
217 sdbusRule::member("JobRemoved") +
218 sdbusRule::path("/org/freedesktop/systemd1") +
219 sdbusRule::interface(
220 "org.freedesktop.systemd1.Manager"),
221 std::bind(std::mem_fn(&Activation::unitStateChange),
222 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500223 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500224 // Enable systemd signals
225 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500226 // Set Properties.
227 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500228 associations(assocs);
229
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500230 // Emit deferred signal.
231 emit_object_added();
232 }
233
Saqib Khanb0774702017-05-23 16:02:41 -0500234 /** @brief Overloaded Activation property setter function
235 *
236 * @param[in] value - One of Activation::Activations
237 *
238 * @return Success or exception thrown
239 */
240 Activations activation(Activations value) override;
241
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500242 /** @brief Activation */
243 using ActivationInherit::activation;
244
Saqib Khanb0774702017-05-23 16:02:41 -0500245 /** @brief Overloaded requestedActivation property setter function
246 *
247 * @param[in] value - One of Activation::RequestedActivations
248 *
249 * @return Success or exception thrown
250 */
251 RequestedActivations requestedActivation(RequestedActivations value)
252 override;
253
Michael Tritzbed88af2017-07-19 16:00:06 -0500254 /** @brief Check if systemd state change is relevant to this object
255 *
256 * Instance specific interface to handle the detected systemd state
257 * change
258 *
259 * @param[in] msg - Data associated with subscribed signal
260 *
261 */
262 void unitStateChange(sdbusplus::message::message& msg);
263
264 /**
265 * @brief subscribe to the systemd signals
266 *
267 * This object needs to capture when it's systemd targets complete
268 * so it can keep it's state updated
269 *
270 */
271 void subscribeToSystemdSignals();
272
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500273 /**
274 * @brief unsubscribe from the systemd signals
275 *
276 * systemd signals are only of interest during the activation process.
277 * Once complete, we want to unsubscribe to avoid unnecessary calls of
278 * unitStateChange().
279 *
280 */
281 void unsubscribeFromSystemdSignals();
282
Saqib Khanee13e832017-10-23 12:53:11 -0500283 /**
284 * @brief Deletes the version from Image Manager and the
285 * untar image from image upload dir.
286 */
287 void deleteImageManagerObject();
288
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500289 /** @brief Persistent sdbusplus DBus bus connection */
290 sdbusplus::bus::bus& bus;
291
292 /** @brief Persistent DBus object path */
293 std::string path;
294
Saqib Khan4c1aec02017-07-06 11:46:13 -0500295 /** @brief Parent Object. */
296 ItemUpdater& parent;
297
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500298 /** @brief Version id */
299 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500300
301 /** @brief Persistent ActivationBlocksTransition dbus object */
302 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500303
304 /** @brief Persistent RedundancyPriority dbus object */
305 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500306
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500307 /** @brief Persistent ActivationProgress dbus object */
308 std::unique_ptr<ActivationProgress> activationProgress;
309
Michael Tritzbed88af2017-07-19 16:00:06 -0500310 /** @brief Used to subscribe to dbus systemd signals **/
311 sdbusplus::bus::match_t systemdSignals;
312
313 /** @brief Tracks whether the read-write volume has been created as
314 * part of the activation process. **/
315 bool rwVolumeCreated = false;
316
317 /** @brief Tracks whether the read-only volume has been created as
318 * part of the activation process. **/
319 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500320};
321
322} // namespace updater
323} // namespace software
324} // namespace phosphor