blob: 51756f2044a59955b8d50131c35abb33bda993ea [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 =
Adriana Kobylak2285fe02018-02-27 15:36:59 -060018 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<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060023 sdbusplus::xyz::openbmc_project::Software::server::
24 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>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050029
Michael Tritzbed88af2017-07-19 16:00:06 -050030namespace sdbusRule = sdbusplus::bus::match::rules;
31
Saqib Khan4c1aec02017-07-06 11:46:13 -050032class ItemUpdater;
33class Activation;
34class RedundancyPriority;
35
36/** @class RedundancyPriority
37 * @brief OpenBMC RedundancyPriority implementation
38 * @details A concrete implementation for
39 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
40 */
41class RedundancyPriority : public RedundancyPriorityInherit
42{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060043 public:
44 /** @brief Constructs RedundancyPriority.
45 *
46 * @param[in] bus - The Dbus bus object
47 * @param[in] path - The Dbus object path
48 * @param[in] parent - Parent object.
49 * @param[in] value - The redundancyPriority value
50 * @param[in] freePriority - Call freePriorioty, default to true
51 */
52 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
53 Activation& parent, uint8_t value,
54 bool freePriority = true) :
55 RedundancyPriorityInherit(bus, path.c_str(), true),
56 parent(parent), bus(bus), path(path)
57 {
58 // Set Property
59 if (freePriority)
Saqib Khan4c1aec02017-07-06 11:46:13 -050060 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060061 priority(value);
62 }
63 else
64 {
65 sdbusPriority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050066 }
67
Adriana Kobylak2285fe02018-02-27 15:36:59 -060068 std::vector<std::string> interfaces({interface});
69 bus.emit_interfaces_added(path.c_str(), interfaces);
70 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050071
Adriana Kobylak2285fe02018-02-27 15:36:59 -060072 ~RedundancyPriority()
73 {
74 std::vector<std::string> interfaces({interface});
75 bus.emit_interfaces_removed(path.c_str(), interfaces);
76 }
Saqib Khan4c1aec02017-07-06 11:46:13 -050077
Gunnar Millse11a2022018-03-23 12:04:48 -050078 /** @brief Overridden Priority property set function, calls freePriority
Adriana Kobylak2285fe02018-02-27 15:36:59 -060079 * to bump the duplicated priority values.
80 *
81 * @param[in] value - uint8_t
82 *
83 * @return Success or exception thrown
84 */
85 uint8_t priority(uint8_t value) override;
Adriana Kobylakb77551c2017-10-27 12:46:23 -050086
Adriana Kobylak2285fe02018-02-27 15:36:59 -060087 /** @brief Non-Overriden Priority property set function
88 *
89 * @param[in] value - uint8_t
90 *
91 * @return Success or exception thrown
92 */
93 uint8_t sdbusPriority(uint8_t value);
Saqib Khan4c1aec02017-07-06 11:46:13 -050094
Adriana Kobylak2285fe02018-02-27 15:36:59 -060095 /** @brief Priority property get function
96 *
97 * @returns uint8_t - The Priority value
98 */
99 using RedundancyPriorityInherit::priority;
Saqib Khan140fcb12017-08-07 09:06:57 -0500100
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600101 /** @brief Parent Object. */
102 Activation& parent;
103
104 private:
105 // TODO Remove once openbmc/openbmc#1975 is resolved
106 static constexpr auto interface =
107 "xyz.openbmc_project.Software.RedundancyPriority";
108 sdbusplus::bus::bus& bus;
109 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500110};
Saqib Khanb0774702017-05-23 16:02:41 -0500111
112/** @class ActivationBlocksTransition
113 * @brief OpenBMC ActivationBlocksTransition implementation.
114 * @details A concrete implementation for
115 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
116 */
117class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
118{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600119 public:
120 /** @brief Constructs ActivationBlocksTransition.
121 *
122 * @param[in] bus - The Dbus bus object
123 * @param[in] path - The Dbus object path
124 */
125 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
126 const std::string& path) :
127 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
128 bus(bus), path(path)
129 {
130 std::vector<std::string> interfaces({interface});
131 bus.emit_interfaces_added(path.c_str(), interfaces);
132 enableRebootGuard();
133 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500134
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600135 ~ActivationBlocksTransition()
136 {
137 std::vector<std::string> interfaces({interface});
138 bus.emit_interfaces_removed(path.c_str(), interfaces);
139 disableRebootGuard();
140 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500141
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600142 private:
143 // TODO Remove once openbmc/openbmc#1975 is resolved
144 static constexpr auto interface =
145 "xyz.openbmc_project.Software.ActivationBlocksTransition";
146 sdbusplus::bus::bus& bus;
147 std::string path;
Saqib Khanf37cefc2017-09-12 08:44:41 -0500148
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600149 /** @brief Enables a Guard that blocks any BMC reboot commands */
150 void enableRebootGuard();
Saqib Khanf37cefc2017-09-12 08:44:41 -0500151
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600152 /** @brief Disables any guard that was blocking the BMC reboot */
153 void disableRebootGuard();
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{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600158 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, const std::string& path) :
165 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
166 {
167 progress(0);
168 std::vector<std::string> interfaces({interface});
169 bus.emit_interfaces_added(path.c_str(), interfaces);
170 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500171
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600172 ~ActivationProgress()
173 {
174 std::vector<std::string> interfaces({interface});
175 bus.emit_interfaces_removed(path.c_str(), interfaces);
176 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500177
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600178 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{
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600193 public:
194 /** @brief Constructs Activation Software Manager
195 *
196 * @param[in] bus - The Dbus bus object
197 * @param[in] path - The Dbus object path
198 * @param[in] parent - Parent object.
199 * @param[in] versionId - The software version id
200 * @param[in] activationStatus - The status of Activation
201 * @param[in] assocs - Association objects
202 */
203 Activation(sdbusplus::bus::bus& bus, const std::string& path,
204 ItemUpdater& parent, std::string& versionId,
205 sdbusplus::xyz::openbmc_project::Software::server::Activation::
206 Activations activationStatus,
207 AssociationList& assocs) :
208 ActivationInherit(bus, path.c_str(), true),
209 bus(bus), path(path), parent(parent), versionId(versionId),
210 systemdSignals(
211 bus,
212 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
213 sdbusRule::path("/org/freedesktop/systemd1") +
214 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
215 std::bind(std::mem_fn(&Activation::unitStateChange), this,
216 std::placeholders::_1))
217 {
218 // Enable systemd signals
219 subscribeToSystemdSignals();
220 // Set Properties.
221 activation(activationStatus);
222 associations(assocs);
Gunnar Millsb60add12017-08-24 16:41:42 -0500223
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600224 // Emit deferred signal.
225 emit_object_added();
226 }
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500227
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600228 /** @brief Overloaded Activation property setter function
229 *
230 * @param[in] value - One of Activation::Activations
231 *
232 * @return Success or exception thrown
233 */
234 Activations activation(Activations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500235
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600236 /** @brief Activation */
237 using ActivationInherit::activation;
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500238
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600239 /** @brief Overloaded requestedActivation property setter function
240 *
241 * @param[in] value - One of Activation::RequestedActivations
242 *
243 * @return Success or exception thrown
244 */
245 RequestedActivations
246 requestedActivation(RequestedActivations value) override;
Saqib Khanb0774702017-05-23 16:02:41 -0500247
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600248 /** @brief Check if systemd state change is relevant to this object
249 *
250 * Instance specific interface to handle the detected systemd state
251 * change
252 *
253 * @param[in] msg - Data associated with subscribed signal
254 *
255 */
256 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritzbed88af2017-07-19 16:00:06 -0500257
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600258 /**
259 * @brief subscribe to the systemd signals
260 *
261 * This object needs to capture when it's systemd targets complete
262 * so it can keep it's state updated
263 *
264 */
265 void subscribeToSystemdSignals();
Michael Tritzbed88af2017-07-19 16:00:06 -0500266
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600267 /**
268 * @brief unsubscribe from the systemd signals
269 *
270 * systemd signals are only of interest during the activation process.
271 * Once complete, we want to unsubscribe to avoid unnecessary calls of
272 * unitStateChange().
273 *
274 */
275 void unsubscribeFromSystemdSignals();
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500276
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600277 /**
278 * @brief Deletes the version from Image Manager and the
279 * untar image from image upload dir.
280 */
281 void deleteImageManagerObject();
Saqib Khanee13e832017-10-23 12:53:11 -0500282
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600283 /** @brief Persistent sdbusplus DBus bus connection */
284 sdbusplus::bus::bus& bus;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500285
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600286 /** @brief Persistent DBus object path */
287 std::string path;
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500288
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600289 /** @brief Parent Object. */
290 ItemUpdater& parent;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500291
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600292 /** @brief Version id */
293 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500294
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600295 /** @brief Persistent ActivationBlocksTransition dbus object */
296 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500297
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600298 /** @brief Persistent RedundancyPriority dbus object */
299 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500300
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600301 /** @brief Persistent ActivationProgress dbus object */
302 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500303
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600304 /** @brief Used to subscribe to dbus systemd signals **/
305 sdbusplus::bus::match_t systemdSignals;
Michael Tritzbed88af2017-07-19 16:00:06 -0500306
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600307 /** @brief Tracks whether the read-write volume has been created as
308 * part of the activation process. **/
309 bool rwVolumeCreated = false;
Michael Tritzbed88af2017-07-19 16:00:06 -0500310
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600311 /** @brief Tracks whether the read-only volume has been created as
312 * part of the activation process. **/
313 bool roVolumeCreated = false;
Adriana Kobylak166bdf32018-04-09 14:24:06 -0500314
315 /** @brief Tracks if the service that updates the U-Boot environment
316 * variables has completed. **/
317 bool ubootEnvVarsUpdated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500318};
319
320} // namespace updater
321} // namespace software
322} // namespace phosphor