blob: 69f52b758aafebc585f1dfc560c57d715dde0940 [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 Millsec1b41c2017-05-02 12:20:36 -05008
9namespace phosphor
10{
11namespace software
12{
13namespace updater
14{
15
16using ActivationInherit = sdbusplus::server::object::object<
17 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
Saqib Khanb0774702017-05-23 16:02:41 -050018using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
19 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050020using RedundancyPriorityInherit = sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050022using ActivationProgressInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050024
Michael Tritzbed88af2017-07-19 16:00:06 -050025namespace sdbusRule = sdbusplus::bus::match::rules;
26
Saqib Khan4c1aec02017-07-06 11:46:13 -050027class ItemUpdater;
28class Activation;
29class RedundancyPriority;
30
31/** @class RedundancyPriority
32 * @brief OpenBMC RedundancyPriority implementation
33 * @details A concrete implementation for
34 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
35 */
36class RedundancyPriority : public RedundancyPriorityInherit
37{
38 public:
39 /** @brief Constructs RedundancyPriority.
40 *
41 * @param[in] bus - The Dbus bus object
42 * @param[in] path - The Dbus object path
43 * @param[in] parent - Parent object.
44 * @param[in] value - The redundancyPriority value
45 */
46 RedundancyPriority(sdbusplus::bus::bus& bus,
47 const std::string& path,
48 Activation& parent,
49 uint8_t value) :
50 RedundancyPriorityInherit(bus,
51 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050052 parent(parent),
53 bus(bus),
54 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050055 {
56 // Set Property
57 priority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050058 std::vector<std::string> interfaces({interface});
59 bus.emit_interfaces_added(path.c_str(), interfaces);
60 }
61
62 ~RedundancyPriority()
63 {
64 std::vector<std::string> interfaces({interface});
65 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050066 }
67
68 /** @brief Overloaded Priority property set function
69 *
70 * @param[in] value - uint8_t
71 *
72 * @return Success or exception thrown
73 */
74 uint8_t priority(uint8_t value) override;
75
76 /** @brief Priority property get function
77 *
78 * @returns uint8_t - The Priority value
79 */
80 using RedundancyPriorityInherit::priority;
81
82 /** @brief Parent Object. */
83 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -050084
85 private:
86 // TODO Remove once openbmc/openbmc#1975 is resolved
87 static constexpr auto interface =
88 "xyz.openbmc_project.Software.RedundancyPriority";
89 sdbusplus::bus::bus& bus;
90 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -050091};
Saqib Khanb0774702017-05-23 16:02:41 -050092
93/** @class ActivationBlocksTransition
94 * @brief OpenBMC ActivationBlocksTransition implementation.
95 * @details A concrete implementation for
96 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
97 */
98class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
99{
100 public:
101 /** @brief Constructs ActivationBlocksTransition.
102 *
103 * @param[in] bus - The Dbus bus object
104 * @param[in] path - The Dbus object path
105 */
106 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
107 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500108 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
109 bus(bus),
110 path(path)
111 {
112 std::vector<std::string> interfaces({interface});
113 bus.emit_interfaces_added(path.c_str(), interfaces);
114 }
115
116 ~ActivationBlocksTransition()
117 {
118 std::vector<std::string> interfaces({interface});
119 bus.emit_interfaces_removed(path.c_str(), interfaces);
120 }
121
122 private:
123 // TODO Remove once openbmc/openbmc#1975 is resolved
124 static constexpr auto interface =
125 "xyz.openbmc_project.Software.ActivationBlocksTransition";
126 sdbusplus::bus::bus& bus;
127 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500128};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500129
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500130class ActivationProgress : public ActivationProgressInherit
131{
132 public:
133 /** @brief Constructs ActivationProgress.
134 *
135 * @param[in] bus - The Dbus bus object
136 * @param[in] path - The Dbus object path
137 */
138 ActivationProgress(sdbusplus::bus::bus& bus,
139 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500140 ActivationProgressInherit(bus, path.c_str(), true),
141 bus(bus),
142 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500143 {
144 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500145 std::vector<std::string> interfaces({interface});
146 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500147 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500148
149 ~ActivationProgress()
150 {
151 std::vector<std::string> interfaces({interface});
152 bus.emit_interfaces_removed(path.c_str(), interfaces);
153 }
154
155 private:
156 // TODO Remove once openbmc/openbmc#1975 is resolved
157 static constexpr auto interface =
158 "xyz.openbmc_project.Software.ActivationProgress";
159 sdbusplus::bus::bus& bus;
160 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500161};
162
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500163/** @class Activation
164 * @brief OpenBMC activation software management implementation.
165 * @details A concrete implementation for
166 * xyz.openbmc_project.Software.Activation DBus API.
167 */
168class Activation : public ActivationInherit
169{
170 public:
171 /** @brief Constructs Activation Software Manager
172 *
173 * @param[in] bus - The Dbus bus object
174 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500175 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500176 * @param[in] versionId - The software version id
177 * @param[in] activationStatus - The status of Activation
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500178 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500179 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500180 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500181 std::string& versionId,
182 sdbusplus::xyz::openbmc_project::Software::
183 server::Activation::Activations activationStatus) :
184 ActivationInherit(bus, path.c_str(), true),
185 bus(bus),
186 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500187 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500188 versionId(versionId),
189 systemdSignals(
190 bus,
191 sdbusRule::type::signal() +
192 sdbusRule::member("JobRemoved") +
193 sdbusRule::path("/org/freedesktop/systemd1") +
194 sdbusRule::interface(
195 "org.freedesktop.systemd1.Manager"),
196 std::bind(std::mem_fn(&Activation::unitStateChange),
197 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500198 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500199 // Enable systemd signals
200 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500201 // Set Properties.
202 activation(activationStatus);
203 // Emit deferred signal.
204 emit_object_added();
205 }
206
Saqib Khanb0774702017-05-23 16:02:41 -0500207 /** @brief Overloaded Activation property setter function
208 *
209 * @param[in] value - One of Activation::Activations
210 *
211 * @return Success or exception thrown
212 */
213 Activations activation(Activations value) override;
214
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500215 /** @brief Activation */
216 using ActivationInherit::activation;
217
Saqib Khanb0774702017-05-23 16:02:41 -0500218 /** @brief Overloaded requestedActivation property setter function
219 *
220 * @param[in] value - One of Activation::RequestedActivations
221 *
222 * @return Success or exception thrown
223 */
224 RequestedActivations requestedActivation(RequestedActivations value)
225 override;
226
Michael Tritzbed88af2017-07-19 16:00:06 -0500227 /** @brief Check if systemd state change is relevant to this object
228 *
229 * Instance specific interface to handle the detected systemd state
230 * change
231 *
232 * @param[in] msg - Data associated with subscribed signal
233 *
234 */
235 void unitStateChange(sdbusplus::message::message& msg);
236
237 /**
238 * @brief subscribe to the systemd signals
239 *
240 * This object needs to capture when it's systemd targets complete
241 * so it can keep it's state updated
242 *
243 */
244 void subscribeToSystemdSignals();
245
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500246 /**
247 * @brief unsubscribe from the systemd signals
248 *
249 * systemd signals are only of interest during the activation process.
250 * Once complete, we want to unsubscribe to avoid unnecessary calls of
251 * unitStateChange().
252 *
253 */
254 void unsubscribeFromSystemdSignals();
255
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500256 /** @brief Persistent sdbusplus DBus bus connection */
257 sdbusplus::bus::bus& bus;
258
259 /** @brief Persistent DBus object path */
260 std::string path;
261
Saqib Khan4c1aec02017-07-06 11:46:13 -0500262 /** @brief Parent Object. */
263 ItemUpdater& parent;
264
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500265 /** @brief Version id */
266 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500267
268 /** @brief Persistent ActivationBlocksTransition dbus object */
269 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500270
271 /** @brief Persistent RedundancyPriority dbus object */
272 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500273
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500274 /** @brief Persistent ActivationProgress dbus object */
275 std::unique_ptr<ActivationProgress> activationProgress;
276
Michael Tritzbed88af2017-07-19 16:00:06 -0500277 /** @brief Used to subscribe to dbus systemd signals **/
278 sdbusplus::bus::match_t systemdSignals;
279
280 /** @brief Tracks whether the read-write volume has been created as
281 * part of the activation process. **/
282 bool rwVolumeCreated = false;
283
284 /** @brief Tracks whether the read-only volume has been created as
285 * part of the activation process. **/
286 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500287};
288
289} // namespace updater
290} // namespace software
291} // namespace phosphor