blob: 0a98b85738b05468b35026185ef0eae8c5130658 [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 Millsec1b41c2017-05-02 12:20:36 -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 Khan4c1aec02017-07-06 11:46:13 -0500179 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500180 * @param[in] versionId - The software version id
181 * @param[in] activationStatus - The status of Activation
Gunnar Millsb60add12017-08-24 16:41:42 -0500182 * @param[in] assocs - Association objects
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500183 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500184 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500185 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500186 std::string& versionId,
187 sdbusplus::xyz::openbmc_project::Software::
Gunnar Millsb60add12017-08-24 16:41:42 -0500188 server::Activation::Activations activationStatus,
189 AssociationList& assocs) :
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500190 ActivationInherit(bus, path.c_str(), true),
191 bus(bus),
192 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500193 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -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))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500204 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500205 // Enable systemd signals
206 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500207 // Set Properties.
208 activation(activationStatus);
Gunnar Millsb60add12017-08-24 16:41:42 -0500209 associations(assocs);
210
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500211 // Emit deferred signal.
212 emit_object_added();
213 }
214
Saqib Khanb0774702017-05-23 16:02:41 -0500215 /** @brief Overloaded Activation property setter function
216 *
217 * @param[in] value - One of Activation::Activations
218 *
219 * @return Success or exception thrown
220 */
221 Activations activation(Activations value) override;
222
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500223 /** @brief Activation */
224 using ActivationInherit::activation;
225
Saqib Khanb0774702017-05-23 16:02:41 -0500226 /** @brief Overloaded requestedActivation property setter function
227 *
228 * @param[in] value - One of Activation::RequestedActivations
229 *
230 * @return Success or exception thrown
231 */
232 RequestedActivations requestedActivation(RequestedActivations value)
233 override;
234
Michael Tritzbed88af2017-07-19 16:00:06 -0500235 /** @brief Check if systemd state change is relevant to this object
236 *
237 * Instance specific interface to handle the detected systemd state
238 * change
239 *
240 * @param[in] msg - Data associated with subscribed signal
241 *
242 */
243 void unitStateChange(sdbusplus::message::message& msg);
244
245 /**
246 * @brief subscribe to the systemd signals
247 *
248 * This object needs to capture when it's systemd targets complete
249 * so it can keep it's state updated
250 *
251 */
252 void subscribeToSystemdSignals();
253
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500254 /**
255 * @brief unsubscribe from the systemd signals
256 *
257 * systemd signals are only of interest during the activation process.
258 * Once complete, we want to unsubscribe to avoid unnecessary calls of
259 * unitStateChange().
260 *
261 */
262 void unsubscribeFromSystemdSignals();
263
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500264 /** @brief Persistent sdbusplus DBus bus connection */
265 sdbusplus::bus::bus& bus;
266
267 /** @brief Persistent DBus object path */
268 std::string path;
269
Saqib Khan4c1aec02017-07-06 11:46:13 -0500270 /** @brief Parent Object. */
271 ItemUpdater& parent;
272
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500273 /** @brief Version id */
274 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500275
276 /** @brief Persistent ActivationBlocksTransition dbus object */
277 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500278
279 /** @brief Persistent RedundancyPriority dbus object */
280 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500281
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500282 /** @brief Persistent ActivationProgress dbus object */
283 std::unique_ptr<ActivationProgress> activationProgress;
284
Michael Tritzbed88af2017-07-19 16:00:06 -0500285 /** @brief Used to subscribe to dbus systemd signals **/
286 sdbusplus::bus::match_t systemdSignals;
287
288 /** @brief Tracks whether the read-write volume has been created as
289 * part of the activation process. **/
290 bool rwVolumeCreated = false;
291
292 /** @brief Tracks whether the read-only volume has been created as
293 * part of the activation process. **/
294 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500295};
296
297} // namespace updater
298} // namespace software
299} // namespace phosphor