blob: 7ab4e146eb10c6e90a9e8b9650eb6e94b204406c [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
19using ActivationInherit = sdbusplus::server::object::object<
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050020 sdbusplus::xyz::openbmc_project::Object::server::Delete,
Saqib Khan7254f0e2017-04-10 21:45:37 -050021 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050022 sdbusplus::xyz::openbmc_project::Software::server::Activation,
23 sdbusplus::org::openbmc::server::Associations>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050024using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050026using RedundancyPriorityInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050028using ActivationProgressInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050030
Michael Tritz9d25b602017-06-14 14:41:43 -050031namespace sdbusRule = sdbusplus::bus::match::rules;
32
Saqib Khan81bac882017-06-08 12:17:01 -050033class ItemUpdater;
34class Activation;
35class RedundancyPriority;
36
Saqib Khan942df8a2017-06-01 14:09:27 -050037/** @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
Saqib Khan81bac882017-06-08 12:17:01 -050049 * @param[in] parent - Parent object.
50 * @param[in] value - The redundancyPriority value
Saqib Khan942df8a2017-06-01 14:09:27 -050051 */
52 RedundancyPriority(sdbusplus::bus::bus& bus,
Saqib Khan81bac882017-06-08 12:17:01 -050053 const std::string& path,
54 Activation& parent,
55 uint8_t value) :
Saqib Khan942df8a2017-06-01 14:09:27 -050056 RedundancyPriorityInherit(bus,
Saqib Khan81bac882017-06-08 12:17:01 -050057 path.c_str(), true),
Adriana Kobylaka8eda562017-07-17 15:24:29 -050058 parent(parent),
59 bus(bus),
60 path(path)
Saqib Khan942df8a2017-06-01 14:09:27 -050061 {
62 // Set Property
Saqib Khan81bac882017-06-08 12:17:01 -050063 priority(value);
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Khan942df8a2017-06-01 14:09:27 -050072 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050073
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;
Saqib Khan81bac882017-06-08 12:17:01 -050081
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;
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Khan942df8a2017-06-01 14:09:27 -050097};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050098
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050099/** @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) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -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;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500134};
135
Michael Tritz1793b642017-06-28 18:35:58 -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) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500146 ActivationProgressInherit(bus, path.c_str(), true),
147 bus(bus),
148 path(path)
Michael Tritz1793b642017-06-28 18:35:58 -0500149 {
150 progress(0);
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500151 std::vector<std::string> interfaces({interface});
152 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz1793b642017-06-28 18:35:58 -0500153 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Tritz1793b642017-06-28 18:35:58 -0500167};
168
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500169/** @class Activation
170 * @brief OpenBMC activation software management implementation.
171 * @details A concrete implementation for
172 * xyz.openbmc_project.Software.Activation DBus API.
173 */
174class Activation : public ActivationInherit
175{
176 public:
177 /** @brief Constructs Activation Software Manager
178 *
179 * @param[in] bus - The Dbus bus object
180 * @param[in] path - The Dbus object path
Saqib Khan81bac882017-06-08 12:17:01 -0500181 * @param[in] parent - Parent object.
Saqib Khan7254f0e2017-04-10 21:45:37 -0500182 * @param[in] versionId - The software version id
183 * @param[in] extVersion - The extended version
Saqib Khana8ade7e2017-04-12 10:27:56 -0500184 * @param[in] activationStatus - The status of Activation
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500185 */
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500186 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan81bac882017-06-08 12:17:01 -0500187 ItemUpdater& parent,
Saqib Khan7254f0e2017-04-10 21:45:37 -0500188 std::string& versionId,
Saqib Khana8ade7e2017-04-12 10:27:56 -0500189 std::string& extVersion,
190 sdbusplus::xyz::openbmc_project::Software::
191 server::Activation::Activations activationStatus) :
Saqib Khan7254f0e2017-04-10 21:45:37 -0500192 ActivationInherit(bus, path.c_str(), true),
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500193 bus(bus),
194 path(path),
Saqib Khan81bac882017-06-08 12:17:01 -0500195 parent(parent),
Michael Tritz9d25b602017-06-14 14:41:43 -0500196 versionId(versionId),
197 systemdSignals(
198 bus,
199 sdbusRule::type::signal() +
200 sdbusRule::member("JobRemoved") +
201 sdbusRule::path("/org/freedesktop/systemd1") +
202 sdbusRule::interface(
203 "org.freedesktop.systemd1.Manager"),
204 std::bind(std::mem_fn(&Activation::unitStateChange),
205 this, std::placeholders::_1))
Saqib Khan7254f0e2017-04-10 21:45:37 -0500206 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500207 // Enable systemd signals
208 subscribeToSystemdSignals();
Saqib Khan7254f0e2017-04-10 21:45:37 -0500209 // Set Properties.
210 extendedVersion(extVersion);
Saqib Khana8ade7e2017-04-12 10:27:56 -0500211 activation(activationStatus);
Saqib Khan7254f0e2017-04-10 21:45:37 -0500212 // Emit deferred signal.
213 emit_object_added();
214 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500215
Saqib Khan2cbfa032017-08-17 14:52:37 -0500216 /** @brief Activation property get function
217 *
218 * @returns One of Activation::Activations
219 */
220 using ActivationInherit::activation;
221
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500222 /** @brief Overloaded Activation property setter function
223 *
224 * @param[in] value - One of Activation::Activations
225 *
226 * @return Success or exception thrown
227 */
228 Activations activation(Activations value) override;
229
230 /** @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 Tritz9d25b602017-06-14 14:41:43 -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 Tritz1cb127f2017-07-26 15:40:38 -0500258 /**
259 * @brief unsubscribe from the systemd signals
260 *
261 * Once the activation process has completed successfully, we can
262 * safely unsubscribe from systemd signals.
263 *
264 **/
265 void unsubscribeFromSystemdSignals();
266
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500267 /** @brief Persistent sdbusplus DBus bus connection */
268 sdbusplus::bus::bus& bus;
269
270 /** @brief Persistent DBus object path */
271 std::string path;
272
Saqib Khan81bac882017-06-08 12:17:01 -0500273 /** @brief Parent Object. */
274 ItemUpdater& parent;
275
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500276 /** @brief Version id */
277 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500278
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500279 /** @brief Persistent ActivationBlocksTransition dbus object */
280 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500281
Michael Tritz1793b642017-06-28 18:35:58 -0500282 /** @brief Persistent ActivationProgress dbus object */
283 std::unique_ptr<ActivationProgress> activationProgress;
284
Saqib Khan942df8a2017-06-01 14:09:27 -0500285 /** @brief Persistent RedundancyPriority dbus object */
286 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500287
288 /** @brief Used to subscribe to dbus systemd signals **/
289 sdbusplus::bus::match_t systemdSignals;
290
291 /** @brief Tracks whether the squashfs image has been loaded as part of
292 * the activation process. **/
293 bool squashfsLoaded = false;
294
295 /** @brief Tracks whether the read-write volumes have been created as
296 * part of the activation process. **/
297 bool rwVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500298
299 /** @brief activation status property get function
300 *
301 * @returns Activations - The activation value
302 */
303 using ActivationInherit::activation;
304
305 /** @brief Deletes the d-bus object.
306 *
307 *
308 * */
309 void delete_() override;
310
Michael Tritz1cb127f2017-07-26 15:40:38 -0500311 private:
312 /** @brief Member function for clarity & brevity at activation start */
313 void startActivation();
314
315 /** @brief Member function for clarity & brevity at activation end */
316 void finishActivation();
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500317};
318
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500319} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500320} // namespace software
321} // namespace openpower