blob: a3f2a62c7fae6aa8c2dc7e36b459cfb5840610cb [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,
Eddie James9440f492017-08-30 11:34:16 -050022 sdbusplus::org::openbmc::server::Associations,
23 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanb0774702017-05-23 16:02:41 -050024using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050026using RedundancyPriorityInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050028using ActivationProgressInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050030
Michael Tritzbed88af2017-07-19 16:00:06 -050031namespace sdbusRule = sdbusplus::bus::match::rules;
32
Saqib Khan4c1aec02017-07-06 11:46:13 -050033class ItemUpdater;
34class Activation;
35class RedundancyPriority;
36
37/** @class RedundancyPriority
38 * @brief OpenBMC RedundancyPriority implementation
39 * @details A concrete implementation for
40 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
41 */
42class RedundancyPriority : public RedundancyPriorityInherit
43{
44 public:
45 /** @brief Constructs RedundancyPriority.
46 *
47 * @param[in] bus - The Dbus bus object
48 * @param[in] path - The Dbus object path
49 * @param[in] parent - Parent object.
50 * @param[in] value - The redundancyPriority value
51 */
52 RedundancyPriority(sdbusplus::bus::bus& bus,
53 const std::string& path,
54 Activation& parent,
55 uint8_t value) :
56 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
63 priority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050064 std::vector<std::string> interfaces({interface});
65 bus.emit_interfaces_added(path.c_str(), interfaces);
66 }
67
68 ~RedundancyPriority()
69 {
70 std::vector<std::string> interfaces({interface});
71 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050072 }
73
74 /** @brief Overloaded Priority property set function
75 *
76 * @param[in] value - uint8_t
77 *
78 * @return Success or exception thrown
79 */
80 uint8_t priority(uint8_t value) override;
81
82 /** @brief Priority property get function
83 *
84 * @returns uint8_t - The Priority value
85 */
86 using RedundancyPriorityInherit::priority;
87
88 /** @brief Parent Object. */
89 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -050090
91 private:
92 // TODO Remove once openbmc/openbmc#1975 is resolved
93 static constexpr auto interface =
94 "xyz.openbmc_project.Software.RedundancyPriority";
95 sdbusplus::bus::bus& bus;
96 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -050097};
Saqib Khanb0774702017-05-23 16:02:41 -050098
99/** @class ActivationBlocksTransition
100 * @brief OpenBMC ActivationBlocksTransition implementation.
101 * @details A concrete implementation for
102 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
103 */
104class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
105{
106 public:
107 /** @brief Constructs ActivationBlocksTransition.
108 *
109 * @param[in] bus - The Dbus bus object
110 * @param[in] path - The Dbus object path
111 */
112 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
113 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500114 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
115 bus(bus),
116 path(path)
117 {
118 std::vector<std::string> interfaces({interface});
119 bus.emit_interfaces_added(path.c_str(), interfaces);
120 }
121
122 ~ActivationBlocksTransition()
123 {
124 std::vector<std::string> interfaces({interface});
125 bus.emit_interfaces_removed(path.c_str(), interfaces);
126 }
127
128 private:
129 // TODO Remove once openbmc/openbmc#1975 is resolved
130 static constexpr auto interface =
131 "xyz.openbmc_project.Software.ActivationBlocksTransition";
132 sdbusplus::bus::bus& bus;
133 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500134};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500135
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500136class ActivationProgress : public ActivationProgressInherit
137{
138 public:
139 /** @brief Constructs ActivationProgress.
140 *
141 * @param[in] bus - The Dbus bus object
142 * @param[in] path - The Dbus object path
143 */
144 ActivationProgress(sdbusplus::bus::bus& bus,
145 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500146 ActivationProgressInherit(bus, path.c_str(), true),
147 bus(bus),
148 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500149 {
150 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500151 std::vector<std::string> interfaces({interface});
152 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500153 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500154
155 ~ActivationProgress()
156 {
157 std::vector<std::string> interfaces({interface});
158 bus.emit_interfaces_removed(path.c_str(), interfaces);
159 }
160
161 private:
162 // TODO Remove once openbmc/openbmc#1975 is resolved
163 static constexpr auto interface =
164 "xyz.openbmc_project.Software.ActivationProgress";
165 sdbusplus::bus::bus& bus;
166 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500167};
168
Gunnar Millsded875d2017-08-28 16:44:52 -0500169// TODO: openbmc/openbmc#2086 - Add removeActiveAssociation() after
170// Delete() is implemented
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500171/** @class Activation
172 * @brief OpenBMC activation software management implementation.
173 * @details A concrete implementation for
174 * xyz.openbmc_project.Software.Activation DBus API.
175 */
176class Activation : public ActivationInherit
177{
178 public:
179 /** @brief Constructs Activation Software Manager
180 *
181 * @param[in] bus - The Dbus bus object
182 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500183 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500184 * @param[in] versionId - The software version id
185 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500186 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500187 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500188 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500189 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500190 std::string& versionId,
191 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500192 server::Activation::Activations activationStatus,
193 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500194 ActivationInherit(bus, path.c_str(), true),
195 bus(bus),
196 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500197 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500198 versionId(versionId),
199 systemdSignals(
200 bus,
201 sdbusRule::type::signal() +
202 sdbusRule::member("JobRemoved") +
203 sdbusRule::path("/org/freedesktop/systemd1") +
204 sdbusRule::interface(
205 "org.freedesktop.systemd1.Manager"),
206 std::bind(std::mem_fn(&Activation::unitStateChange),
207 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500208 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500209 // Enable systemd signals
210 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500211 // Set Properties.
212 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500213 associations(assocs);
214
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500215 // Emit deferred signal.
216 emit_object_added();
217 }
218
Saqib Khanb0774702017-05-23 16:02:41 -0500219 /** @brief Overloaded Activation property setter function
220 *
221 * @param[in] value - One of Activation::Activations
222 *
223 * @return Success or exception thrown
224 */
225 Activations activation(Activations value) override;
226
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500227 /** @brief Activation */
228 using ActivationInherit::activation;
229
Saqib Khanb0774702017-05-23 16:02:41 -0500230 /** @brief Overloaded requestedActivation property setter function
231 *
232 * @param[in] value - One of Activation::RequestedActivations
233 *
234 * @return Success or exception thrown
235 */
236 RequestedActivations requestedActivation(RequestedActivations value)
237 override;
238
Michael Tritzbed88af2017-07-19 16:00:06 -0500239 /** @brief Check if systemd state change is relevant to this object
240 *
241 * Instance specific interface to handle the detected systemd state
242 * change
243 *
244 * @param[in] msg - Data associated with subscribed signal
245 *
246 */
247 void unitStateChange(sdbusplus::message::message& msg);
248
249 /**
250 * @brief subscribe to the systemd signals
251 *
252 * This object needs to capture when it's systemd targets complete
253 * so it can keep it's state updated
254 *
255 */
256 void subscribeToSystemdSignals();
257
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500258 /**
259 * @brief unsubscribe from the systemd signals
260 *
261 * systemd signals are only of interest during the activation process.
262 * Once complete, we want to unsubscribe to avoid unnecessary calls of
263 * unitStateChange().
264 *
265 */
266 void unsubscribeFromSystemdSignals();
267
Eddie James9440f492017-08-30 11:34:16 -0500268 /**
Saqib Khanb9da6632017-09-13 09:48:37 -0500269 * @brief Updates the uboot variables to point to versionId, so that
270 * the systems boots from this version on the next boot.
271 */
272 void updateUbootEnvVars();
273
274 /**
Eddie James9440f492017-08-30 11:34:16 -0500275 * @brief delete the d-bus object.
276 */
277 void delete_() override;
278
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500279 /** @brief Persistent sdbusplus DBus bus connection */
280 sdbusplus::bus::bus& bus;
281
282 /** @brief Persistent DBus object path */
283 std::string path;
284
Saqib Khan4c1aec02017-07-06 11:46:13 -0500285 /** @brief Parent Object. */
286 ItemUpdater& parent;
287
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500288 /** @brief Version id */
289 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500290
291 /** @brief Persistent ActivationBlocksTransition dbus object */
292 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500293
294 /** @brief Persistent RedundancyPriority dbus object */
295 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500296
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500297 /** @brief Persistent ActivationProgress dbus object */
298 std::unique_ptr<ActivationProgress> activationProgress;
299
Michael Tritzbed88af2017-07-19 16:00:06 -0500300 /** @brief Used to subscribe to dbus systemd signals **/
301 sdbusplus::bus::match_t systemdSignals;
302
303 /** @brief Tracks whether the read-write volume has been created as
304 * part of the activation process. **/
305 bool rwVolumeCreated = false;
306
307 /** @brief Tracks whether the read-only volume has been created as
308 * part of the activation process. **/
309 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500310};
311
312} // namespace updater
313} // namespace software
314} // namespace phosphor