blob: 59364e43dbb6364f8ff0757ab8292466aa45d88c [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
Lei YU91029442019-08-01 15:57:31 +08005#include "types.hpp"
6
Lei YUff83c2a2019-09-12 13:55:18 +08007#include <queue>
Lei YU01539e72019-07-31 10:57:38 +08008#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +08009#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080010#include <xyz/openbmc_project/Software/Activation/server.hpp>
Lei YU81c67722019-09-11 16:47:29 +080011#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90c8a8b2019-09-11 17:20:03 +080012#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080013#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
14
Lei YUff83c2a2019-09-12 13:55:18 +080015class TestActivation;
16
Lei YU01539e72019-07-31 10:57:38 +080017namespace phosphor
18{
19namespace software
20{
21namespace updater
22{
23
Lei YU12c9f4c2019-09-11 15:08:15 +080024namespace sdbusRule = sdbusplus::bus::match::rules;
25
Lei YU81c67722019-09-11 16:47:29 +080026using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::
28 ActivationBlocksTransition>;
29
30/** @class ActivationBlocksTransition
31 * @brief OpenBMC ActivationBlocksTransition implementation.
32 * @details A concrete implementation for
33 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
34 */
35class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
36{
37 public:
38 /** @brief Constructs ActivationBlocksTransition.
39 *
40 * @param[in] bus - The Dbus bus object
41 * @param[in] path - The Dbus object path
42 */
43 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
44 const std::string& path) :
45 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
46 bus(bus), path(path)
47 {
48 std::vector<std::string> interfaces({interface});
49 bus.emit_interfaces_added(path.c_str(), interfaces);
50 }
51
52 ~ActivationBlocksTransition()
53 {
54 std::vector<std::string> interfaces({interface});
55 bus.emit_interfaces_removed(path.c_str(), interfaces);
56 }
57
58 private:
59 // TODO Remove once openbmc/openbmc#1975 is resolved
60 static constexpr auto interface =
61 "xyz.openbmc_project.Software.ActivationBlocksTransition";
62 sdbusplus::bus::bus& bus;
63 std::string path;
64};
65
Lei YU90c8a8b2019-09-11 17:20:03 +080066using ActivationProgressInherit = sdbusplus::server::object::object<
67 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
68
69class ActivationProgress : public ActivationProgressInherit
70{
71 public:
72 /** @brief Constructs ActivationProgress.
73 *
74 * @param[in] bus - The Dbus bus object
75 * @param[in] path - The Dbus object path
76 */
77 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
78 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
79 {
80 progress(0);
81 std::vector<std::string> interfaces({interface});
82 bus.emit_interfaces_added(path.c_str(), interfaces);
83 }
84
85 ~ActivationProgress()
86 {
87 std::vector<std::string> interfaces({interface});
88 bus.emit_interfaces_removed(path.c_str(), interfaces);
89 }
90
91 private:
92 // TODO Remove once openbmc/openbmc#1975 is resolved
93 static constexpr auto interface =
94 "xyz.openbmc_project.Software.ActivationProgress";
95 sdbusplus::bus::bus& bus;
96 std::string path;
97};
98
Lei YU01539e72019-07-31 10:57:38 +080099using ActivationInherit = sdbusplus::server::object::object<
100 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +0800101 sdbusplus::xyz::openbmc_project::Software::server::Activation,
102 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +0800103
104/** @class Activation
105 * @brief OpenBMC activation software management implementation.
106 * @details A concrete implementation for
107 * xyz.openbmc_project.Software.Activation DBus API.
108 */
109class Activation : public ActivationInherit
110{
111 public:
Lei YUff83c2a2019-09-12 13:55:18 +0800112 friend class ::TestActivation;
Lei YU12c9f4c2019-09-11 15:08:15 +0800113 using Status = Activations;
Lei YUff83c2a2019-09-12 13:55:18 +0800114
Lei YU01539e72019-07-31 10:57:38 +0800115 /** @brief Constructs Activation Software Manager
116 *
117 * @param[in] bus - The Dbus bus object
118 * @param[in] path - The Dbus object path
119 * @param[in] versionId - The software version id
120 * @param[in] extVersion - The extended version
121 * @param[in] activationStatus - The status of Activation
Lei YU91029442019-08-01 15:57:31 +0800122 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +0800123 */
124 Activation(sdbusplus::bus::bus& bus, const std::string& path,
125 const std::string& versionId, const std::string& extVersion,
Lei YUff83c2a2019-09-12 13:55:18 +0800126 Status activationStatus, const AssociationList& assocs) :
Lei YU01539e72019-07-31 10:57:38 +0800127 ActivationInherit(bus, path.c_str(), true),
Lei YU12c9f4c2019-09-11 15:08:15 +0800128 versionId(versionId), bus(bus), path(path),
129 systemdSignals(
130 bus,
131 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
132 sdbusRule::path("/org/freedesktop/systemd1") +
133 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
134 std::bind(&Activation::unitStateChange, this,
135 std::placeholders::_1))
Lei YU01539e72019-07-31 10:57:38 +0800136 {
137 // Set Properties.
138 extendedVersion(extVersion);
139 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800140 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +0800141
142 // Emit deferred signal.
143 emit_object_added();
144 }
145
146 /** @brief Overloaded Activation property setter function
147 *
148 * @param[in] value - One of Activation::Activations
149 *
150 * @return Success or exception thrown
151 */
Lei YUff83c2a2019-09-12 13:55:18 +0800152 Status activation(Status value) override;
Lei YU01539e72019-07-31 10:57:38 +0800153
154 /** @brief Activation */
155 using ActivationInherit::activation;
156
157 /** @brief Overloaded requestedActivation property setter function
158 *
159 * @param[in] value - One of Activation::RequestedActivations
160 *
161 * @return Success or exception thrown
162 */
163 RequestedActivations
164 requestedActivation(RequestedActivations value) override;
165
Lei YU12c9f4c2019-09-11 15:08:15 +0800166 /** @brief Version id */
167 std::string versionId;
168
169 private:
170 /** @brief Check if systemd state change is relevant to this object
171 *
172 * Instance specific interface to handle the detected systemd state
173 * change
174 *
175 * @param[in] msg - Data associated with subscribed signal
176 *
177 */
178 void unitStateChange(sdbusplus::message::message& msg);
179
Lei YUd0bbfa92019-09-11 16:10:54 +0800180 /**
181 * @brief Delete the version from Image Manager and the
182 * untar image from image upload dir.
183 */
184 void deleteImageManagerObject();
185
Lei YUff83c2a2019-09-12 13:55:18 +0800186 /** @brief Invoke the update service for the PSU
187 *
188 * @param[in] psuInventoryPath - The PSU inventory to be updated.
189 *
190 * @return true if the update starts, and false if it fails.
191 */
192 bool doUpdate(const std::string& psuInventoryPath);
193
194 /** @brief Do PSU update one-by-one
195 *
196 * @return true if the update starts, and false if it fails.
197 */
198 bool doUpdate();
199
200 /** @brief Handle an update done event */
201 void onUpdateDone();
202
203 /** @brief Handle an update failure event */
204 void onUpdateFailed();
205
Lei YU12c9f4c2019-09-11 15:08:15 +0800206 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800207 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800208
209 /** @brief Finish PSU update */
210 void finishActivation();
211
Lei YU01539e72019-07-31 10:57:38 +0800212 /** @brief Persistent sdbusplus DBus bus connection */
213 sdbusplus::bus::bus& bus;
214
215 /** @brief Persistent DBus object path */
216 std::string path;
217
Lei YU12c9f4c2019-09-11 15:08:15 +0800218 /** @brief Used to subscribe to dbus systemd signals */
219 sdbusplus::bus::match_t systemdSignals;
220
Lei YUff83c2a2019-09-12 13:55:18 +0800221 /** @brief The queue of psu objects to be updated */
222 std::queue<std::string> psuQueue;
223
224 /** @brief The progress step for each PSU update is done */
225 uint32_t progressStep;
226
Lei YU12c9f4c2019-09-11 15:08:15 +0800227 /** @brief The PSU update systemd unit */
228 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800229
230 /** @brief Persistent ActivationBlocksTransition dbus object */
231 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800232
233 /** @brief Persistent ActivationProgress dbus object */
234 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU01539e72019-07-31 10:57:38 +0800235};
236
237} // namespace updater
238} // namespace software
239} // namespace phosphor