blob: 458034c966d3b0025842803686720bbd893f8cf1 [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"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05009
10namespace openpower
11{
12namespace software
13{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050014namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050015{
16
17using ActivationInherit = sdbusplus::server::object::object<
Saqib Khan7254f0e2017-04-10 21:45:37 -050018 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050020using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050022using RedundancyPriorityInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050024using ActivationProgressInherit = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050026
Michael Tritz9d25b602017-06-14 14:41:43 -050027namespace sdbusRule = sdbusplus::bus::match::rules;
28
Saqib Khan81bac882017-06-08 12:17:01 -050029class ItemUpdater;
30class Activation;
31class RedundancyPriority;
32
Saqib Khan942df8a2017-06-01 14:09:27 -050033/** @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
Saqib Khan81bac882017-06-08 12:17:01 -050045 * @param[in] parent - Parent object.
46 * @param[in] value - The redundancyPriority value
Saqib Khan942df8a2017-06-01 14:09:27 -050047 */
48 RedundancyPriority(sdbusplus::bus::bus& bus,
Saqib Khan81bac882017-06-08 12:17:01 -050049 const std::string& path,
50 Activation& parent,
51 uint8_t value) :
Saqib Khan942df8a2017-06-01 14:09:27 -050052 RedundancyPriorityInherit(bus,
Saqib Khan81bac882017-06-08 12:17:01 -050053 path.c_str(), true),
Adriana Kobylaka8eda562017-07-17 15:24:29 -050054 parent(parent),
55 bus(bus),
56 path(path)
Saqib Khan942df8a2017-06-01 14:09:27 -050057 {
58 // Set Property
Saqib Khan81bac882017-06-08 12:17:01 -050059 priority(value);
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Khan942df8a2017-06-01 14:09:27 -050068 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050069
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;
Saqib Khan81bac882017-06-08 12:17:01 -050077
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;
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Khan942df8a2017-06-01 14:09:27 -050093};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050094
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050095/** @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) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -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;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500130};
131
Michael Tritz1793b642017-06-28 18:35:58 -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) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500142 ActivationProgressInherit(bus, path.c_str(), true),
143 bus(bus),
144 path(path)
Michael Tritz1793b642017-06-28 18:35:58 -0500145 {
146 progress(0);
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500147 std::vector<std::string> interfaces({interface});
148 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz1793b642017-06-28 18:35:58 -0500149 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -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 Tritz1793b642017-06-28 18:35:58 -0500163};
164
Adriana Kobylak2d8fa222017-03-15 12:34:32 -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 Khan81bac882017-06-08 12:17:01 -0500177 * @param[in] parent - Parent object.
Saqib Khan7254f0e2017-04-10 21:45:37 -0500178 * @param[in] versionId - The software version id
179 * @param[in] extVersion - The extended version
Saqib Khana8ade7e2017-04-12 10:27:56 -0500180 * @param[in] activationStatus - The status of Activation
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500181 */
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500182 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan81bac882017-06-08 12:17:01 -0500183 ItemUpdater& parent,
Saqib Khan7254f0e2017-04-10 21:45:37 -0500184 std::string& versionId,
Saqib Khana8ade7e2017-04-12 10:27:56 -0500185 std::string& extVersion,
186 sdbusplus::xyz::openbmc_project::Software::
187 server::Activation::Activations activationStatus) :
Saqib Khan7254f0e2017-04-10 21:45:37 -0500188 ActivationInherit(bus, path.c_str(), true),
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500189 bus(bus),
190 path(path),
Saqib Khan81bac882017-06-08 12:17:01 -0500191 parent(parent),
Michael Tritz9d25b602017-06-14 14:41:43 -0500192 versionId(versionId),
193 systemdSignals(
194 bus,
195 sdbusRule::type::signal() +
196 sdbusRule::member("JobRemoved") +
197 sdbusRule::path("/org/freedesktop/systemd1") +
198 sdbusRule::interface(
199 "org.freedesktop.systemd1.Manager"),
200 std::bind(std::mem_fn(&Activation::unitStateChange),
201 this, std::placeholders::_1))
Saqib Khan7254f0e2017-04-10 21:45:37 -0500202 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500203 // Enable systemd signals
204 subscribeToSystemdSignals();
Saqib Khan7254f0e2017-04-10 21:45:37 -0500205 // Set Properties.
206 extendedVersion(extVersion);
Saqib Khana8ade7e2017-04-12 10:27:56 -0500207 activation(activationStatus);
Saqib Khan7254f0e2017-04-10 21:45:37 -0500208 // Emit deferred signal.
209 emit_object_added();
210 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500211
212 /** @brief Overloaded Activation property setter function
213 *
214 * @param[in] value - One of Activation::Activations
215 *
216 * @return Success or exception thrown
217 */
218 Activations activation(Activations value) override;
219
220 /** @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 Tritz9d25b602017-06-14 14:41:43 -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
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500248 /** @brief Persistent sdbusplus DBus bus connection */
249 sdbusplus::bus::bus& bus;
250
251 /** @brief Persistent DBus object path */
252 std::string path;
253
Saqib Khan81bac882017-06-08 12:17:01 -0500254 /** @brief Parent Object. */
255 ItemUpdater& parent;
256
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500257 /** @brief Version id */
258 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500259
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500260 /** @brief Persistent ActivationBlocksTransition dbus object */
261 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500262
Michael Tritz1793b642017-06-28 18:35:58 -0500263 /** @brief Persistent ActivationProgress dbus object */
264 std::unique_ptr<ActivationProgress> activationProgress;
265
Saqib Khan942df8a2017-06-01 14:09:27 -0500266 /** @brief Persistent RedundancyPriority dbus object */
267 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500268
269 /** @brief Used to subscribe to dbus systemd signals **/
270 sdbusplus::bus::match_t systemdSignals;
271
272 /** @brief Tracks whether the squashfs image has been loaded as part of
273 * the activation process. **/
274 bool squashfsLoaded = false;
275
276 /** @brief Tracks whether the read-write volumes have been created as
277 * part of the activation process. **/
278 bool rwVolumesCreated = false;
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500279};
280
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500281} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500282} // namespace software
283} // namespace openpower