blob: 89269bd4619ccf84ed0dba87b3b448c1ed3eabba [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
17using ActivationInherit = sdbusplus::server::object::object<
Gunnar Millsf5eaf392017-08-22 16:36:55 -050018 sdbusplus::xyz::openbmc_project::Software::server::Activation,
19 sdbusplus::org::openbmc::server::Associations>;
Saqib Khanb0774702017-05-23 16:02:41 -050020using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050022using RedundancyPriorityInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz0edd4ad2017-07-26 14:27:42 -050024using ActivationProgressInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050026
Michael Tritzbed88af2017-07-19 16:00:06 -050027namespace sdbusRule = sdbusplus::bus::match::rules;
28
Saqib Khan4c1aec02017-07-06 11:46:13 -050029class ItemUpdater;
30class Activation;
31class RedundancyPriority;
32
33/** @class RedundancyPriority
34 * @brief OpenBMC RedundancyPriority implementation
35 * @details A concrete implementation for
36 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
37 */
38class RedundancyPriority : public RedundancyPriorityInherit
39{
40 public:
41 /** @brief Constructs RedundancyPriority.
42 *
43 * @param[in] bus - The Dbus bus object
44 * @param[in] path - The Dbus object path
45 * @param[in] parent - Parent object.
46 * @param[in] value - The redundancyPriority value
47 */
48 RedundancyPriority(sdbusplus::bus::bus& bus,
49 const std::string& path,
50 Activation& parent,
51 uint8_t value) :
52 RedundancyPriorityInherit(bus,
53 path.c_str(), true),
Saqib Khan140fcb12017-08-07 09:06:57 -050054 parent(parent),
55 bus(bus),
56 path(path)
Saqib Khan4c1aec02017-07-06 11:46:13 -050057 {
58 // Set Property
59 priority(value);
Saqib Khan140fcb12017-08-07 09:06:57 -050060 std::vector<std::string> interfaces({interface});
61 bus.emit_interfaces_added(path.c_str(), interfaces);
62 }
63
64 ~RedundancyPriority()
65 {
66 std::vector<std::string> interfaces({interface});
67 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan4c1aec02017-07-06 11:46:13 -050068 }
69
70 /** @brief Overloaded Priority property set function
71 *
72 * @param[in] value - uint8_t
73 *
74 * @return Success or exception thrown
75 */
76 uint8_t priority(uint8_t value) override;
77
78 /** @brief Priority property get function
79 *
80 * @returns uint8_t - The Priority value
81 */
82 using RedundancyPriorityInherit::priority;
83
84 /** @brief Parent Object. */
85 Activation& parent;
Saqib Khan140fcb12017-08-07 09:06:57 -050086
87 private:
88 // TODO Remove once openbmc/openbmc#1975 is resolved
89 static constexpr auto interface =
90 "xyz.openbmc_project.Software.RedundancyPriority";
91 sdbusplus::bus::bus& bus;
92 std::string path;
Saqib Khan4c1aec02017-07-06 11:46:13 -050093};
Saqib Khanb0774702017-05-23 16:02:41 -050094
95/** @class ActivationBlocksTransition
96 * @brief OpenBMC ActivationBlocksTransition implementation.
97 * @details A concrete implementation for
98 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
99 */
100class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
101{
102 public:
103 /** @brief Constructs ActivationBlocksTransition.
104 *
105 * @param[in] bus - The Dbus bus object
106 * @param[in] path - The Dbus object path
107 */
108 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
109 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500110 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
111 bus(bus),
112 path(path)
113 {
114 std::vector<std::string> interfaces({interface});
115 bus.emit_interfaces_added(path.c_str(), interfaces);
116 }
117
118 ~ActivationBlocksTransition()
119 {
120 std::vector<std::string> interfaces({interface});
121 bus.emit_interfaces_removed(path.c_str(), interfaces);
122 }
123
124 private:
125 // TODO Remove once openbmc/openbmc#1975 is resolved
126 static constexpr auto interface =
127 "xyz.openbmc_project.Software.ActivationBlocksTransition";
128 sdbusplus::bus::bus& bus;
129 std::string path;
Saqib Khanb0774702017-05-23 16:02:41 -0500130};
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500131
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500132class ActivationProgress : public ActivationProgressInherit
133{
134 public:
135 /** @brief Constructs ActivationProgress.
136 *
137 * @param[in] bus - The Dbus bus object
138 * @param[in] path - The Dbus object path
139 */
140 ActivationProgress(sdbusplus::bus::bus& bus,
141 const std::string& path) :
Saqib Khan140fcb12017-08-07 09:06:57 -0500142 ActivationProgressInherit(bus, path.c_str(), true),
143 bus(bus),
144 path(path)
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500145 {
146 progress(0);
Saqib Khan140fcb12017-08-07 09:06:57 -0500147 std::vector<std::string> interfaces({interface});
148 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500149 }
Saqib Khan140fcb12017-08-07 09:06:57 -0500150
151 ~ActivationProgress()
152 {
153 std::vector<std::string> interfaces({interface});
154 bus.emit_interfaces_removed(path.c_str(), interfaces);
155 }
156
157 private:
158 // TODO Remove once openbmc/openbmc#1975 is resolved
159 static constexpr auto interface =
160 "xyz.openbmc_project.Software.ActivationProgress";
161 sdbusplus::bus::bus& bus;
162 std::string path;
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500163};
164
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500165/** @class Activation
166 * @brief OpenBMC activation software management implementation.
167 * @details A concrete implementation for
168 * xyz.openbmc_project.Software.Activation DBus API.
169 */
170class Activation : public ActivationInherit
171{
172 public:
173 /** @brief Constructs Activation Software Manager
174 *
175 * @param[in] bus - The Dbus bus object
176 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500177 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500178 * @param[in] versionId - The software version id
179 * @param[in] activationStatus - The status of Activation
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500180 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500181 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500182 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500183 std::string& versionId,
184 sdbusplus::xyz::openbmc_project::Software::
185 server::Activation::Activations activationStatus) :
186 ActivationInherit(bus, path.c_str(), true),
187 bus(bus),
188 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500189 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500190 versionId(versionId),
191 systemdSignals(
192 bus,
193 sdbusRule::type::signal() +
194 sdbusRule::member("JobRemoved") +
195 sdbusRule::path("/org/freedesktop/systemd1") +
196 sdbusRule::interface(
197 "org.freedesktop.systemd1.Manager"),
198 std::bind(std::mem_fn(&Activation::unitStateChange),
199 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500200 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500201 // Enable systemd signals
202 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500203 // Set Properties.
204 activation(activationStatus);
205 // Emit deferred signal.
206 emit_object_added();
207 }
208
Saqib Khanb0774702017-05-23 16:02:41 -0500209 /** @brief Overloaded Activation property setter function
210 *
211 * @param[in] value - One of Activation::Activations
212 *
213 * @return Success or exception thrown
214 */
215 Activations activation(Activations value) override;
216
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500217 /** @brief Activation */
218 using ActivationInherit::activation;
219
Saqib Khanb0774702017-05-23 16:02:41 -0500220 /** @brief Overloaded requestedActivation property setter function
221 *
222 * @param[in] value - One of Activation::RequestedActivations
223 *
224 * @return Success or exception thrown
225 */
226 RequestedActivations requestedActivation(RequestedActivations value)
227 override;
228
Michael Tritzbed88af2017-07-19 16:00:06 -0500229 /** @brief Check if systemd state change is relevant to this object
230 *
231 * Instance specific interface to handle the detected systemd state
232 * change
233 *
234 * @param[in] msg - Data associated with subscribed signal
235 *
236 */
237 void unitStateChange(sdbusplus::message::message& msg);
238
239 /**
240 * @brief subscribe to the systemd signals
241 *
242 * This object needs to capture when it's systemd targets complete
243 * so it can keep it's state updated
244 *
245 */
246 void subscribeToSystemdSignals();
247
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500248 /**
249 * @brief unsubscribe from the systemd signals
250 *
251 * systemd signals are only of interest during the activation process.
252 * Once complete, we want to unsubscribe to avoid unnecessary calls of
253 * unitStateChange().
254 *
255 */
256 void unsubscribeFromSystemdSignals();
257
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500258 /** @brief Persistent sdbusplus DBus bus connection */
259 sdbusplus::bus::bus& bus;
260
261 /** @brief Persistent DBus object path */
262 std::string path;
263
Saqib Khan4c1aec02017-07-06 11:46:13 -0500264 /** @brief Parent Object. */
265 ItemUpdater& parent;
266
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500267 /** @brief Version id */
268 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500269
270 /** @brief Persistent ActivationBlocksTransition dbus object */
271 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500272
273 /** @brief Persistent RedundancyPriority dbus object */
274 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500275
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500276 /** @brief Persistent ActivationProgress dbus object */
277 std::unique_ptr<ActivationProgress> activationProgress;
278
Michael Tritzbed88af2017-07-19 16:00:06 -0500279 /** @brief Used to subscribe to dbus systemd signals **/
280 sdbusplus::bus::match_t systemdSignals;
281
282 /** @brief Tracks whether the read-write volume has been created as
283 * part of the activation process. **/
284 bool rwVolumeCreated = false;
285
286 /** @brief Tracks whether the read-only volume has been created as
287 * part of the activation process. **/
288 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500289};
290
291} // namespace updater
292} // namespace software
293} // namespace phosphor