blob: 7702c5214a7745b08e099868e04d8d8dd658bc8b [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"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050010
11namespace openpower
12{
13namespace software
14{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050015namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050016{
17
18using ActivationInherit = sdbusplus::server::object::object<
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050019 sdbusplus::xyz::openbmc_project::Object::server::Delete,
Saqib Khan7254f0e2017-04-10 21:45:37 -050020 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050021 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050022using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050024using RedundancyPriorityInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050026using ActivationProgressInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050028
Michael Tritz9d25b602017-06-14 14:41:43 -050029namespace sdbusRule = sdbusplus::bus::match::rules;
30
Saqib Khan81bac882017-06-08 12:17:01 -050031class ItemUpdater;
32class Activation;
33class RedundancyPriority;
34
Saqib Khan942df8a2017-06-01 14:09:27 -050035/** @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
Saqib Khan81bac882017-06-08 12:17:01 -050047 * @param[in] parent - Parent object.
48 * @param[in] value - The redundancyPriority value
Saqib Khan942df8a2017-06-01 14:09:27 -050049 */
50 RedundancyPriority(sdbusplus::bus::bus& bus,
Saqib Khan81bac882017-06-08 12:17:01 -050051 const std::string& path,
52 Activation& parent,
53 uint8_t value) :
Saqib Khan942df8a2017-06-01 14:09:27 -050054 RedundancyPriorityInherit(bus,
Saqib Khan81bac882017-06-08 12:17:01 -050055 path.c_str(), true),
Adriana Kobylaka8eda562017-07-17 15:24:29 -050056 parent(parent),
57 bus(bus),
58 path(path)
Saqib Khan942df8a2017-06-01 14:09:27 -050059 {
60 // Set Property
Saqib Khan81bac882017-06-08 12:17:01 -050061 priority(value);
Adriana Kobylaka8eda562017-07-17 15:24:29 -050062 std::vector<std::string> interfaces({interface});
63 bus.emit_interfaces_added(path.c_str(), interfaces);
64 }
65
66 ~RedundancyPriority()
67 {
68 std::vector<std::string> interfaces({interface});
69 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan942df8a2017-06-01 14:09:27 -050070 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050071
72 /** @brief Overloaded Priority property set function
73 *
74 * @param[in] value - uint8_t
75 *
76 * @return Success or exception thrown
77 */
78 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050079
80 /** @brief Priority property get function
81 *
82 * @returns uint8_t - The Priority value
83 */
84 using RedundancyPriorityInherit::priority;
85
86 /** @brief Parent Object. */
87 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -050088
89 private:
90 // TODO Remove once openbmc/openbmc#1975 is resolved
91 static constexpr auto interface =
92 "xyz.openbmc_project.Software.RedundancyPriority";
93 sdbusplus::bus::bus& bus;
94 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -050095};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050096
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050097/** @class ActivationBlocksTransition
98 * @brief OpenBMC ActivationBlocksTransition implementation.
99 * @details A concrete implementation for
100 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
101 */
102class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
103{
104 public:
105 /** @brief Constructs ActivationBlocksTransition.
106 *
107 * @param[in] bus - The Dbus bus object
108 * @param[in] path - The Dbus object path
109 */
110 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
111 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500112 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
113 bus(bus),
114 path(path)
115 {
116 std::vector<std::string> interfaces({interface});
117 bus.emit_interfaces_added(path.c_str(), interfaces);
118 }
119
120 ~ActivationBlocksTransition()
121 {
122 std::vector<std::string> interfaces({interface});
123 bus.emit_interfaces_removed(path.c_str(), interfaces);
124 }
125
126 private:
127 // TODO Remove once openbmc/openbmc#1975 is resolved
128 static constexpr auto interface =
129 "xyz.openbmc_project.Software.ActivationBlocksTransition";
130 sdbusplus::bus::bus& bus;
131 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500132};
133
Michael Tritz1793b642017-06-28 18:35:58 -0500134class ActivationProgress : public ActivationProgressInherit
135{
136 public:
137 /** @brief Constructs ActivationProgress.
138 *
139 * @param[in] bus - The Dbus bus object
140 * @param[in] path - The Dbus object path
141 */
142 ActivationProgress(sdbusplus::bus::bus& bus,
143 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500144 ActivationProgressInherit(bus, path.c_str(), true),
145 bus(bus),
146 path(path)
Michael Tritz1793b642017-06-28 18:35:58 -0500147 {
148 progress(0);
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500149 std::vector<std::string> interfaces({interface});
150 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz1793b642017-06-28 18:35:58 -0500151 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500152
153 ~ActivationProgress()
154 {
155 std::vector<std::string> interfaces({interface});
156 bus.emit_interfaces_removed(path.c_str(), interfaces);
157 }
158
159 private:
160 // TODO Remove once openbmc/openbmc#1975 is resolved
161 static constexpr auto interface =
162 "xyz.openbmc_project.Software.ActivationProgress";
163 sdbusplus::bus::bus& bus;
164 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500165};
166
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500167/** @class Activation
168 * @brief OpenBMC activation software management implementation.
169 * @details A concrete implementation for
170 * xyz.openbmc_project.Software.Activation DBus API.
171 */
172class Activation : public ActivationInherit
173{
174 public:
175 /** @brief Constructs Activation Software Manager
176 *
177 * @param[in] bus - The Dbus bus object
178 * @param[in] path - The Dbus object path
Saqib Khan81bac882017-06-08 12:17:01 -0500179 * @param[in] parent - Parent object.
Saqib Khan7254f0e2017-04-10 21:45:37 -0500180 * @param[in] versionId - The software version id
181 * @param[in] extVersion - The extended version
Saqib Khana8ade7e2017-04-12 10:27:56 -0500182 * @param[in] activationStatus - The status of Activation
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500183 */
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500184 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan81bac882017-06-08 12:17:01 -0500185 ItemUpdater& parent,
Saqib Khan7254f0e2017-04-10 21:45:37 -0500186 std::string& versionId,
Saqib Khana8ade7e2017-04-12 10:27:56 -0500187 std::string& extVersion,
188 sdbusplus::xyz::openbmc_project::Software::
189 server::Activation::Activations activationStatus) :
Saqib Khan7254f0e2017-04-10 21:45:37 -0500190 ActivationInherit(bus, path.c_str(), true),
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500191 bus(bus),
192 path(path),
Saqib Khan81bac882017-06-08 12:17:01 -0500193 parent(parent),
Michael Tritz9d25b602017-06-14 14:41:43 -0500194 versionId(versionId),
195 systemdSignals(
196 bus,
197 sdbusRule::type::signal() +
198 sdbusRule::member("JobRemoved") +
199 sdbusRule::path("/org/freedesktop/systemd1") +
200 sdbusRule::interface(
201 "org.freedesktop.systemd1.Manager"),
202 std::bind(std::mem_fn(&Activation::unitStateChange),
203 this, std::placeholders::_1))
Saqib Khan7254f0e2017-04-10 21:45:37 -0500204 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500205 // Enable systemd signals
206 subscribeToSystemdSignals();
Saqib Khan7254f0e2017-04-10 21:45:37 -0500207 // Set Properties.
208 extendedVersion(extVersion);
Saqib Khana8ade7e2017-04-12 10:27:56 -0500209 activation(activationStatus);
Saqib Khan7254f0e2017-04-10 21:45:37 -0500210 // Emit deferred signal.
211 emit_object_added();
212 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500213
214 /** @brief Overloaded Activation property setter function
215 *
216 * @param[in] value - One of Activation::Activations
217 *
218 * @return Success or exception thrown
219 */
220 Activations activation(Activations value) override;
221
222 /** @brief Overloaded requestedActivation property setter function
223 *
224 * @param[in] value - One of Activation::RequestedActivations
225 *
226 * @return Success or exception thrown
227 */
228 RequestedActivations requestedActivation(RequestedActivations value)
229 override;
230
Saqib Khan2af5c492017-07-17 16:15:13 -0500231 /** @brief Create symlinks for the current Software Version */
232 void createSymlinks();
233
Michael Tritz9d25b602017-06-14 14:41:43 -0500234 /** @brief Check if systemd state change is relevant to this object
235 *
236 * Instance specific interface to handle the detected systemd state
237 * change
238 *
239 * @param[in] msg - Data associated with subscribed signal
240 *
241 */
242 void unitStateChange(sdbusplus::message::message& msg);
243
244 /**
245 * @brief subscribe to the systemd signals
246 *
247 * This object needs to capture when it's systemd targets complete
248 * so it can keep it's state updated
249 *
250 **/
251 void subscribeToSystemdSignals();
252
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500253 /** @brief Persistent sdbusplus DBus bus connection */
254 sdbusplus::bus::bus& bus;
255
256 /** @brief Persistent DBus object path */
257 std::string path;
258
Saqib Khan81bac882017-06-08 12:17:01 -0500259 /** @brief Parent Object. */
260 ItemUpdater& parent;
261
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500262 /** @brief Version id */
263 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500264
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500265 /** @brief Persistent ActivationBlocksTransition dbus object */
266 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500267
Michael Tritz1793b642017-06-28 18:35:58 -0500268 /** @brief Persistent ActivationProgress dbus object */
269 std::unique_ptr<ActivationProgress> activationProgress;
270
Saqib Khan942df8a2017-06-01 14:09:27 -0500271 /** @brief Persistent RedundancyPriority dbus object */
272 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500273
274 /** @brief Used to subscribe to dbus systemd signals **/
275 sdbusplus::bus::match_t systemdSignals;
276
277 /** @brief Tracks whether the squashfs image has been loaded as part of
278 * the activation process. **/
279 bool squashfsLoaded = false;
280
281 /** @brief Tracks whether the read-write volumes have been created as
282 * part of the activation process. **/
283 bool rwVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500284
285 /** @brief activation status property get function
286 *
287 * @returns Activations - The activation value
288 */
289 using ActivationInherit::activation;
290
291 /** @brief Deletes the d-bus object.
292 *
293 *
294 * */
295 void delete_() override;
296
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500297};
298
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500299} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500300} // namespace software
301} // namespace openpower