blob: d7880f625920ef7a4b10ecf0bf893058368ef2f0 [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 YU01539e72019-07-31 10:57:38 +08007#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +08008#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +08009#include <xyz/openbmc_project/Software/Activation/server.hpp>
Lei YU81c67722019-09-11 16:47:29 +080010#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90c8a8b2019-09-11 17:20:03 +080011#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080012#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
13
14namespace phosphor
15{
16namespace software
17{
18namespace updater
19{
20
Lei YU12c9f4c2019-09-11 15:08:15 +080021namespace sdbusRule = sdbusplus::bus::match::rules;
22
Lei YU81c67722019-09-11 16:47:29 +080023using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
24 sdbusplus::xyz::openbmc_project::Software::server::
25 ActivationBlocksTransition>;
26
27/** @class ActivationBlocksTransition
28 * @brief OpenBMC ActivationBlocksTransition implementation.
29 * @details A concrete implementation for
30 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
31 */
32class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
33{
34 public:
35 /** @brief Constructs ActivationBlocksTransition.
36 *
37 * @param[in] bus - The Dbus bus object
38 * @param[in] path - The Dbus object path
39 */
40 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
41 const std::string& path) :
42 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
43 bus(bus), path(path)
44 {
45 std::vector<std::string> interfaces({interface});
46 bus.emit_interfaces_added(path.c_str(), interfaces);
47 }
48
49 ~ActivationBlocksTransition()
50 {
51 std::vector<std::string> interfaces({interface});
52 bus.emit_interfaces_removed(path.c_str(), interfaces);
53 }
54
55 private:
56 // TODO Remove once openbmc/openbmc#1975 is resolved
57 static constexpr auto interface =
58 "xyz.openbmc_project.Software.ActivationBlocksTransition";
59 sdbusplus::bus::bus& bus;
60 std::string path;
61};
62
Lei YU90c8a8b2019-09-11 17:20:03 +080063using ActivationProgressInherit = sdbusplus::server::object::object<
64 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
65
66class ActivationProgress : public ActivationProgressInherit
67{
68 public:
69 /** @brief Constructs ActivationProgress.
70 *
71 * @param[in] bus - The Dbus bus object
72 * @param[in] path - The Dbus object path
73 */
74 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
75 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
76 {
77 progress(0);
78 std::vector<std::string> interfaces({interface});
79 bus.emit_interfaces_added(path.c_str(), interfaces);
80 }
81
82 ~ActivationProgress()
83 {
84 std::vector<std::string> interfaces({interface});
85 bus.emit_interfaces_removed(path.c_str(), interfaces);
86 }
87
88 private:
89 // TODO Remove once openbmc/openbmc#1975 is resolved
90 static constexpr auto interface =
91 "xyz.openbmc_project.Software.ActivationProgress";
92 sdbusplus::bus::bus& bus;
93 std::string path;
94};
95
Lei YU01539e72019-07-31 10:57:38 +080096using ActivationInherit = sdbusplus::server::object::object<
97 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +080098 sdbusplus::xyz::openbmc_project::Software::server::Activation,
99 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +0800100
101/** @class Activation
102 * @brief OpenBMC activation software management implementation.
103 * @details A concrete implementation for
104 * xyz.openbmc_project.Software.Activation DBus API.
105 */
106class Activation : public ActivationInherit
107{
108 public:
Lei YU12c9f4c2019-09-11 15:08:15 +0800109 using Status = Activations;
Lei YU01539e72019-07-31 10:57:38 +0800110 /** @brief Constructs Activation Software Manager
111 *
112 * @param[in] bus - The Dbus bus object
113 * @param[in] path - The Dbus object path
114 * @param[in] versionId - The software version id
115 * @param[in] extVersion - The extended version
116 * @param[in] activationStatus - The status of Activation
Lei YU91029442019-08-01 15:57:31 +0800117 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +0800118 */
119 Activation(sdbusplus::bus::bus& bus, const std::string& path,
120 const std::string& versionId, const std::string& extVersion,
121 sdbusplus::xyz::openbmc_project::Software::server::Activation::
Lei YU91029442019-08-01 15:57:31 +0800122 Activations activationStatus,
123 const AssociationList& assocs) :
Lei YU01539e72019-07-31 10:57:38 +0800124 ActivationInherit(bus, path.c_str(), true),
Lei YU12c9f4c2019-09-11 15:08:15 +0800125 versionId(versionId), bus(bus), path(path),
126 systemdSignals(
127 bus,
128 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
129 sdbusRule::path("/org/freedesktop/systemd1") +
130 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
131 std::bind(&Activation::unitStateChange, this,
132 std::placeholders::_1))
Lei YU01539e72019-07-31 10:57:38 +0800133 {
134 // Set Properties.
135 extendedVersion(extVersion);
136 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800137 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +0800138
139 // Emit deferred signal.
140 emit_object_added();
141 }
142
143 /** @brief Overloaded Activation property setter function
144 *
145 * @param[in] value - One of Activation::Activations
146 *
147 * @return Success or exception thrown
148 */
149 Activations activation(Activations value) override;
150
151 /** @brief Activation */
152 using ActivationInherit::activation;
153
154 /** @brief Overloaded requestedActivation property setter function
155 *
156 * @param[in] value - One of Activation::RequestedActivations
157 *
158 * @return Success or exception thrown
159 */
160 RequestedActivations
161 requestedActivation(RequestedActivations value) override;
162
Lei YU12c9f4c2019-09-11 15:08:15 +0800163 /** @brief Version id */
164 std::string versionId;
165
166 private:
167 /** @brief Check if systemd state change is relevant to this object
168 *
169 * Instance specific interface to handle the detected systemd state
170 * change
171 *
172 * @param[in] msg - Data associated with subscribed signal
173 *
174 */
175 void unitStateChange(sdbusplus::message::message& msg);
176
Lei YUd0bbfa92019-09-11 16:10:54 +0800177 /**
178 * @brief Delete the version from Image Manager and the
179 * untar image from image upload dir.
180 */
181 void deleteImageManagerObject();
182
Lei YU12c9f4c2019-09-11 15:08:15 +0800183 /** @brief Start PSU update */
184 void startActivation();
185
186 /** @brief Finish PSU update */
187 void finishActivation();
188
Lei YU01539e72019-07-31 10:57:38 +0800189 /** @brief Persistent sdbusplus DBus bus connection */
190 sdbusplus::bus::bus& bus;
191
192 /** @brief Persistent DBus object path */
193 std::string path;
194
Lei YU12c9f4c2019-09-11 15:08:15 +0800195 /** @brief Used to subscribe to dbus systemd signals */
196 sdbusplus::bus::match_t systemdSignals;
197
198 /** @brief The PSU update systemd unit */
199 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800200
201 /** @brief Persistent ActivationBlocksTransition dbus object */
202 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800203
204 /** @brief Persistent ActivationProgress dbus object */
205 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU01539e72019-07-31 10:57:38 +0800206};
207
208} // namespace updater
209} // namespace software
210} // namespace phosphor