blob: b3ec44be6ec0c1042395d7eb73e8eb6bdf3b0467 [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),
52 parent(parent)
53 {
54 // Set Property
55 priority(value);
56 // Emit deferred signal.
57 emit_object_added();
58 }
59
60 /** @brief Overloaded Priority property set function
61 *
62 * @param[in] value - uint8_t
63 *
64 * @return Success or exception thrown
65 */
66 uint8_t priority(uint8_t value) override;
67
68 /** @brief Priority property get function
69 *
70 * @returns uint8_t - The Priority value
71 */
72 using RedundancyPriorityInherit::priority;
73
74 /** @brief Parent Object. */
75 Activation& parent;
76};
Saqib Khanb0774702017-05-23 16:02:41 -050077
78/** @class ActivationBlocksTransition
79 * @brief OpenBMC ActivationBlocksTransition implementation.
80 * @details A concrete implementation for
81 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
82 */
83class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
84{
85 public:
86 /** @brief Constructs ActivationBlocksTransition.
87 *
88 * @param[in] bus - The Dbus bus object
89 * @param[in] path - The Dbus object path
90 */
91 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
92 const std::string& path) :
93 ActivationBlocksTransitionInherit(bus, path.c_str()) {}
94};
Gunnar Millsec1b41c2017-05-02 12:20:36 -050095
Michael Tritz0edd4ad2017-07-26 14:27:42 -050096class ActivationProgress : public ActivationProgressInherit
97{
98 public:
99 /** @brief Constructs ActivationProgress.
100 *
101 * @param[in] bus - The Dbus bus object
102 * @param[in] path - The Dbus object path
103 */
104 ActivationProgress(sdbusplus::bus::bus& bus,
105 const std::string& path) :
106 ActivationProgressInherit(bus, path.c_str(), true)
107 {
108 progress(0);
109 emit_object_added();
110 }
111};
112
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500113/** @class Activation
114 * @brief OpenBMC activation software management implementation.
115 * @details A concrete implementation for
116 * xyz.openbmc_project.Software.Activation DBus API.
117 */
118class Activation : public ActivationInherit
119{
120 public:
121 /** @brief Constructs Activation Software Manager
122 *
123 * @param[in] bus - The Dbus bus object
124 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500125 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500126 * @param[in] versionId - The software version id
127 * @param[in] activationStatus - The status of Activation
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500128 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500129 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500130 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500131 std::string& versionId,
132 sdbusplus::xyz::openbmc_project::Software::
133 server::Activation::Activations activationStatus) :
134 ActivationInherit(bus, path.c_str(), true),
135 bus(bus),
136 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500137 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500138 versionId(versionId),
139 systemdSignals(
140 bus,
141 sdbusRule::type::signal() +
142 sdbusRule::member("JobRemoved") +
143 sdbusRule::path("/org/freedesktop/systemd1") +
144 sdbusRule::interface(
145 "org.freedesktop.systemd1.Manager"),
146 std::bind(std::mem_fn(&Activation::unitStateChange),
147 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500148 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500149 // Enable systemd signals
150 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500151 // Set Properties.
152 activation(activationStatus);
153 // Emit deferred signal.
154 emit_object_added();
155 }
156
Saqib Khanb0774702017-05-23 16:02:41 -0500157 /** @brief Overloaded Activation property setter function
158 *
159 * @param[in] value - One of Activation::Activations
160 *
161 * @return Success or exception thrown
162 */
163 Activations activation(Activations value) override;
164
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500165 /** @brief Activation */
166 using ActivationInherit::activation;
167
Saqib Khanb0774702017-05-23 16:02:41 -0500168 /** @brief Overloaded requestedActivation property setter function
169 *
170 * @param[in] value - One of Activation::RequestedActivations
171 *
172 * @return Success or exception thrown
173 */
174 RequestedActivations requestedActivation(RequestedActivations value)
175 override;
176
Michael Tritzbed88af2017-07-19 16:00:06 -0500177 /** @brief Check if systemd state change is relevant to this object
178 *
179 * Instance specific interface to handle the detected systemd state
180 * change
181 *
182 * @param[in] msg - Data associated with subscribed signal
183 *
184 */
185 void unitStateChange(sdbusplus::message::message& msg);
186
187 /**
188 * @brief subscribe to the systemd signals
189 *
190 * This object needs to capture when it's systemd targets complete
191 * so it can keep it's state updated
192 *
193 */
194 void subscribeToSystemdSignals();
195
Michael Tritzf2b5e0d2017-07-25 14:39:34 -0500196 /**
197 * @brief unsubscribe from the systemd signals
198 *
199 * systemd signals are only of interest during the activation process.
200 * Once complete, we want to unsubscribe to avoid unnecessary calls of
201 * unitStateChange().
202 *
203 */
204 void unsubscribeFromSystemdSignals();
205
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500206 /** @brief Persistent sdbusplus DBus bus connection */
207 sdbusplus::bus::bus& bus;
208
209 /** @brief Persistent DBus object path */
210 std::string path;
211
Saqib Khan4c1aec02017-07-06 11:46:13 -0500212 /** @brief Parent Object. */
213 ItemUpdater& parent;
214
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500215 /** @brief Version id */
216 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500217
218 /** @brief Persistent ActivationBlocksTransition dbus object */
219 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500220
221 /** @brief Persistent RedundancyPriority dbus object */
222 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500223
Michael Tritz0edd4ad2017-07-26 14:27:42 -0500224 /** @brief Persistent ActivationProgress dbus object */
225 std::unique_ptr<ActivationProgress> activationProgress;
226
Michael Tritzbed88af2017-07-19 16:00:06 -0500227 /** @brief Used to subscribe to dbus systemd signals **/
228 sdbusplus::bus::match_t systemdSignals;
229
230 /** @brief Tracks whether the read-write volume has been created as
231 * part of the activation process. **/
232 bool rwVolumeCreated = false;
233
234 /** @brief Tracks whether the read-only volume has been created as
235 * part of the activation process. **/
236 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500237};
238
239} // namespace updater
240} // namespace software
241} // namespace phosphor