blob: fa27086b0586a791f0545a92e66ff342a060f73c [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -05003#include <sdbusplus/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05004#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -05005#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Saqib Khan7254f0e2017-04-10 21:45:37 -05006#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
Saqib Khan942df8a2017-06-01 14:09:27 -05007#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
Michael Tritz1793b642017-06-28 18:35:58 -05008#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -05009#include "xyz/openbmc_project/Object/Delete/server.hpp"
Saqib Khanc350c612017-08-13 13:36:44 -050010#include "org/openbmc/Associations/server.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050011
12namespace openpower
13{
14namespace software
15{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050016namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017{
18
Gunnar Mills3edb84b2017-08-18 15:13:15 -050019using AssociationList =
20 std::vector<std::tuple<std::string, std::string, std::string>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050021using ActivationInherit = sdbusplus::server::object::object<
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050022 sdbusplus::xyz::openbmc_project::Object::server::Delete,
Saqib Khan7254f0e2017-04-10 21:45:37 -050023 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050024 sdbusplus::xyz::openbmc_project::Software::server::Activation,
25 sdbusplus::org::openbmc::server::Associations>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050026using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050028using RedundancyPriorityInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050030using ActivationProgressInherit = sdbusplus::server::object::object<
31 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050032
Michael Tritz9d25b602017-06-14 14:41:43 -050033namespace sdbusRule = sdbusplus::bus::match::rules;
34
Saqib Khan81bac882017-06-08 12:17:01 -050035class ItemUpdater;
36class Activation;
37class RedundancyPriority;
38
Saqib Khan942df8a2017-06-01 14:09:27 -050039/** @class RedundancyPriority
40 * @brief OpenBMC RedundancyPriority implementation
41 * @details A concrete implementation for
42 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
43 */
44class RedundancyPriority : public RedundancyPriorityInherit
45{
46 public:
47 /** @brief Constructs RedundancyPriority.
48 *
49 * @param[in] bus - The Dbus bus object
50 * @param[in] path - The Dbus object path
Saqib Khan81bac882017-06-08 12:17:01 -050051 * @param[in] parent - Parent object.
52 * @param[in] value - The redundancyPriority value
Saqib Khan942df8a2017-06-01 14:09:27 -050053 */
54 RedundancyPriority(sdbusplus::bus::bus& bus,
Saqib Khan81bac882017-06-08 12:17:01 -050055 const std::string& path,
56 Activation& parent,
57 uint8_t value) :
Saqib Khan942df8a2017-06-01 14:09:27 -050058 RedundancyPriorityInherit(bus,
Saqib Khan81bac882017-06-08 12:17:01 -050059 path.c_str(), true),
Adriana Kobylaka8eda562017-07-17 15:24:29 -050060 parent(parent),
61 bus(bus),
62 path(path)
Saqib Khan942df8a2017-06-01 14:09:27 -050063 {
64 // Set Property
Saqib Khan81bac882017-06-08 12:17:01 -050065 priority(value);
Adriana Kobylaka8eda562017-07-17 15:24:29 -050066 std::vector<std::string> interfaces({interface});
67 bus.emit_interfaces_added(path.c_str(), interfaces);
68 }
69
70 ~RedundancyPriority()
71 {
72 std::vector<std::string> interfaces({interface});
73 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan942df8a2017-06-01 14:09:27 -050074 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050075
76 /** @brief Overloaded Priority property set function
77 *
78 * @param[in] value - uint8_t
79 *
80 * @return Success or exception thrown
81 */
82 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050083
84 /** @brief Priority property get function
85 *
86 * @returns uint8_t - The Priority value
87 */
88 using RedundancyPriorityInherit::priority;
89
90 /** @brief Parent Object. */
91 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -050092
93 private:
94 // TODO Remove once openbmc/openbmc#1975 is resolved
95 static constexpr auto interface =
96 "xyz.openbmc_project.Software.RedundancyPriority";
97 sdbusplus::bus::bus& bus;
98 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -050099};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500100
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500101/** @class ActivationBlocksTransition
102 * @brief OpenBMC ActivationBlocksTransition implementation.
103 * @details A concrete implementation for
104 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
105 */
106class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
107{
108 public:
109 /** @brief Constructs ActivationBlocksTransition.
110 *
111 * @param[in] bus - The Dbus bus object
112 * @param[in] path - The Dbus object path
113 */
114 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
115 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500116 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
117 bus(bus),
118 path(path)
119 {
120 std::vector<std::string> interfaces({interface});
121 bus.emit_interfaces_added(path.c_str(), interfaces);
122 }
123
124 ~ActivationBlocksTransition()
125 {
126 std::vector<std::string> interfaces({interface});
127 bus.emit_interfaces_removed(path.c_str(), interfaces);
128 }
129
130 private:
131 // TODO Remove once openbmc/openbmc#1975 is resolved
132 static constexpr auto interface =
133 "xyz.openbmc_project.Software.ActivationBlocksTransition";
134 sdbusplus::bus::bus& bus;
135 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500136};
137
Michael Tritz1793b642017-06-28 18:35:58 -0500138class ActivationProgress : public ActivationProgressInherit
139{
140 public:
141 /** @brief Constructs ActivationProgress.
142 *
143 * @param[in] bus - The Dbus bus object
144 * @param[in] path - The Dbus object path
145 */
146 ActivationProgress(sdbusplus::bus::bus& bus,
147 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500148 ActivationProgressInherit(bus, path.c_str(), true),
149 bus(bus),
150 path(path)
Michael Tritz1793b642017-06-28 18:35:58 -0500151 {
152 progress(0);
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500153 std::vector<std::string> interfaces({interface});
154 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz1793b642017-06-28 18:35:58 -0500155 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500156
157 ~ActivationProgress()
158 {
159 std::vector<std::string> interfaces({interface});
160 bus.emit_interfaces_removed(path.c_str(), interfaces);
161 }
162
163 private:
164 // TODO Remove once openbmc/openbmc#1975 is resolved
165 static constexpr auto interface =
166 "xyz.openbmc_project.Software.ActivationProgress";
167 sdbusplus::bus::bus& bus;
168 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500169};
170
Adriana Kobylak2d8fa222017-03-15 12:34:32 -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 Khan81bac882017-06-08 12:17:01 -0500183 * @param[in] parent - Parent object.
Saqib Khan7254f0e2017-04-10 21:45:37 -0500184 * @param[in] versionId - The software version id
185 * @param[in] extVersion - The extended version
Saqib Khana8ade7e2017-04-12 10:27:56 -0500186 * @param[in] activationStatus - The status of Activation
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500187 * @param[in] assocs - Association objects
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500188 */
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500189 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan81bac882017-06-08 12:17:01 -0500190 ItemUpdater& parent,
Saqib Khan7254f0e2017-04-10 21:45:37 -0500191 std::string& versionId,
Saqib Khana8ade7e2017-04-12 10:27:56 -0500192 std::string& extVersion,
193 sdbusplus::xyz::openbmc_project::Software::
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500194 server::Activation::Activations activationStatus,
195 AssociationList& assocs) :
Saqib Khan7254f0e2017-04-10 21:45:37 -0500196 ActivationInherit(bus, path.c_str(), true),
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500197 bus(bus),
198 path(path),
Saqib Khan81bac882017-06-08 12:17:01 -0500199 parent(parent),
Michael Tritz9d25b602017-06-14 14:41:43 -0500200 versionId(versionId),
201 systemdSignals(
202 bus,
203 sdbusRule::type::signal() +
204 sdbusRule::member("JobRemoved") +
205 sdbusRule::path("/org/freedesktop/systemd1") +
206 sdbusRule::interface(
207 "org.freedesktop.systemd1.Manager"),
208 std::bind(std::mem_fn(&Activation::unitStateChange),
209 this, std::placeholders::_1))
Saqib Khan7254f0e2017-04-10 21:45:37 -0500210 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500211 // Enable systemd signals
212 subscribeToSystemdSignals();
Saqib Khan7254f0e2017-04-10 21:45:37 -0500213 // Set Properties.
214 extendedVersion(extVersion);
Saqib Khana8ade7e2017-04-12 10:27:56 -0500215 activation(activationStatus);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500216 associations(assocs);
217
Saqib Khan7254f0e2017-04-10 21:45:37 -0500218 // Emit deferred signal.
219 emit_object_added();
220 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500221
Saqib Khan2cbfa032017-08-17 14:52:37 -0500222 /** @brief Activation property get function
223 *
224 * @returns One of Activation::Activations
225 */
226 using ActivationInherit::activation;
227
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500228 /** @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;
235
236 /** @brief Overloaded requestedActivation property setter function
237 *
238 * @param[in] value - One of Activation::RequestedActivations
239 *
240 * @return Success or exception thrown
241 */
242 RequestedActivations requestedActivation(RequestedActivations value)
243 override;
244
Michael Tritz9d25b602017-06-14 14:41:43 -0500245 /** @brief Check if systemd state change is relevant to this object
246 *
247 * Instance specific interface to handle the detected systemd state
248 * change
249 *
250 * @param[in] msg - Data associated with subscribed signal
251 *
252 */
253 void unitStateChange(sdbusplus::message::message& msg);
254
255 /**
256 * @brief subscribe to the systemd signals
257 *
258 * This object needs to capture when it's systemd targets complete
259 * so it can keep it's state updated
260 *
261 **/
262 void subscribeToSystemdSignals();
263
Michael Tritz1cb127f2017-07-26 15:40:38 -0500264 /**
265 * @brief unsubscribe from the systemd signals
266 *
267 * Once the activation process has completed successfully, we can
268 * safely unsubscribe from systemd signals.
269 *
270 **/
271 void unsubscribeFromSystemdSignals();
272
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500273 /** @brief Persistent sdbusplus DBus bus connection */
274 sdbusplus::bus::bus& bus;
275
276 /** @brief Persistent DBus object path */
277 std::string path;
278
Saqib Khan81bac882017-06-08 12:17:01 -0500279 /** @brief Parent Object. */
280 ItemUpdater& parent;
281
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500282 /** @brief Version id */
283 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500284
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500285 /** @brief Persistent ActivationBlocksTransition dbus object */
286 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500287
Michael Tritz1793b642017-06-28 18:35:58 -0500288 /** @brief Persistent ActivationProgress dbus object */
289 std::unique_ptr<ActivationProgress> activationProgress;
290
Saqib Khan942df8a2017-06-01 14:09:27 -0500291 /** @brief Persistent RedundancyPriority dbus object */
292 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500293
294 /** @brief Used to subscribe to dbus systemd signals **/
295 sdbusplus::bus::match_t systemdSignals;
296
297 /** @brief Tracks whether the squashfs image has been loaded as part of
298 * the activation process. **/
299 bool squashfsLoaded = false;
300
301 /** @brief Tracks whether the read-write volumes have been created as
302 * part of the activation process. **/
303 bool rwVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500304
305 /** @brief activation status property get function
306 *
307 * @returns Activations - The activation value
308 */
309 using ActivationInherit::activation;
310
311 /** @brief Deletes the d-bus object.
312 *
313 *
314 * */
315 void delete_() override;
316
Michael Tritz1cb127f2017-07-26 15:40:38 -0500317 private:
318 /** @brief Member function for clarity & brevity at activation start */
319 void startActivation();
320
321 /** @brief Member function for clarity & brevity at activation end */
322 void finishActivation();
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500323};
324
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500325} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500326} // namespace software
327} // namespace openpower