blob: d22ed916082bbe27653e5e979eafd6bbdb7eeee9 [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 =
18 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,
21 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050022using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050024using RedundancyPriorityInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050026using ActivationProgressInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050028
Michael Tritzbed88af2017-07-19 16:00:06 -050029namespace sdbusRule = sdbusplus::bus::match::rules;
30
Saqib Khan4c1aec02017-07-06 11:46:13 -050031class ItemUpdater;
32class Activation;
33class RedundancyPriority;
34
35/** @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
47 * @param[in] parent - Parent object.
48 * @param[in] value - The redundancyPriority value
49 */
50 RedundancyPriority(sdbusplus::bus::bus& bus,
51 const std::string& path,
52 Activation& parent,
53 uint8_t value) :
54 RedundancyPriorityInherit(bus,
55 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050056 parent(parent),
57 bus(bus),
58 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050059 {
60 // Set Property
61 priority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -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 Khan4c1aec02017-07-06 11:46:13 -050070 }
71
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;
79
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;
Saqib Khan140fcb12017-08-07 09:06:57 -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 Khan4c1aec02017-07-06 11:46:13 -050095};
Saqib Khanb0774702017-05-23 16:02:41 -050096
97/** @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) :
Saqib Khan140fcb12017-08-07 09:06:57 -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;
Saqib Khanb0774702017-05-23 16:02:41 -0500132};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500133
Michael Tritz0edd4ad2017-07-26 14:27:42 -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) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500144 ActivationProgressInherit(bus, path.c_str(), true),
145 bus(bus),
146 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500147 {
148 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500149 std::vector<std::string> interfaces({interface});
150 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500151 }
Saqib Khan140fcb12017-08-07 09:06:57 -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 Tritz0edd4ad2017-07-26 14:27:42 -0500165};
166
Gunnar Millsded875d2017-08-28 16:44:52 -0500167// TODO: openbmc/openbmc#2086 - Add removeActiveAssociation() after
168// Delete() is implemented
Gunnar Millsec1b41c2017-05-02 12:20:36 -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 Khan4c1aec02017-07-06 11:46:13 -0500181 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500182 * @param[in] versionId - The software version id
183 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500184 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500185 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500186 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500187 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500188 std::string& versionId,
189 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500190 server::Activation::Activations activationStatus,
191 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500192 ActivationInherit(bus, path.c_str(), true),
193 bus(bus),
194 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500195 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -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))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500206 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500207 // Enable systemd signals
208 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500209 // Set Properties.
210 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500211 associations(assocs);
212
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500213 // Emit deferred signal.
214 emit_object_added();
215 }
216
Saqib Khanb0774702017-05-23 16:02:41 -0500217 /** @brief Overloaded Activation property setter function
218 *
219 * @param[in] value - One of Activation::Activations
220 *
221 * @return Success or exception thrown
222 */
223 Activations activation(Activations value) override;
224
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500225 /** @brief Activation */
226 using ActivationInherit::activation;
227
Saqib Khanb0774702017-05-23 16:02:41 -0500228 /** @brief Overloaded requestedActivation property setter function
229 *
230 * @param[in] value - One of Activation::RequestedActivations
231 *
232 * @return Success or exception thrown
233 */
234 RequestedActivations requestedActivation(RequestedActivations value)
235 override;
236
Michael Tritzbed88af2017-07-19 16:00:06 -0500237 /** @brief Check if systemd state change is relevant to this object
238 *
239 * Instance specific interface to handle the detected systemd state
240 * change
241 *
242 * @param[in] msg - Data associated with subscribed signal
243 *
244 */
245 void unitStateChange(sdbusplus::message::message& msg);
246
247 /**
248 * @brief subscribe to the systemd signals
249 *
250 * This object needs to capture when it's systemd targets complete
251 * so it can keep it's state updated
252 *
253 */
254 void subscribeToSystemdSignals();
255
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500256 /**
257 * @brief unsubscribe from the systemd signals
258 *
259 * systemd signals are only of interest during the activation process.
260 * Once complete, we want to unsubscribe to avoid unnecessary calls of
261 * unitStateChange().
262 *
263 */
264 void unsubscribeFromSystemdSignals();
265
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500266 /** @brief Persistent sdbusplus DBus bus connection */
267 sdbusplus::bus::bus& bus;
268
269 /** @brief Persistent DBus object path */
270 std::string path;
271
Saqib Khan4c1aec02017-07-06 11:46:13 -0500272 /** @brief Parent Object. */
273 ItemUpdater& parent;
274
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500275 /** @brief Version id */
276 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500277
278 /** @brief Persistent ActivationBlocksTransition dbus object */
279 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500280
281 /** @brief Persistent RedundancyPriority dbus object */
282 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500283
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500284 /** @brief Persistent ActivationProgress dbus object */
285 std::unique_ptr<ActivationProgress> activationProgress;
286
Michael Tritzbed88af2017-07-19 16:00:06 -0500287 /** @brief Used to subscribe to dbus systemd signals **/
288 sdbusplus::bus::match_t systemdSignals;
289
290 /** @brief Tracks whether the read-write volume has been created as
291 * part of the activation process. **/
292 bool rwVolumeCreated = false;
293
294 /** @brief Tracks whether the read-only volume has been created as
295 * part of the activation process. **/
296 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500297};
298
299} // namespace updater
300} // namespace software
301} // namespace phosphor