blob: f550e375fa440ebc3fbb94cbfce20eb3eb76478e [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"
Gunnar Millsec1b41c2017-05-02 12:20:36 -05007
8namespace phosphor
9{
10namespace software
11{
12namespace updater
13{
14
15using ActivationInherit = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
Saqib Khanb0774702017-05-23 16:02:41 -050017using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
18 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan4c1aec02017-07-06 11:46:13 -050019using RedundancyPriorityInherit = sdbusplus::server::object::object<
20 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
21
Michael Tritzbed88af2017-07-19 16:00:06 -050022namespace sdbusRule = sdbusplus::bus::match::rules;
23
Saqib Khan4c1aec02017-07-06 11:46:13 -050024class ItemUpdater;
25class Activation;
26class RedundancyPriority;
27
28/** @class RedundancyPriority
29 * @brief OpenBMC RedundancyPriority implementation
30 * @details A concrete implementation for
31 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
32 */
33class RedundancyPriority : public RedundancyPriorityInherit
34{
35 public:
36 /** @brief Constructs RedundancyPriority.
37 *
38 * @param[in] bus - The Dbus bus object
39 * @param[in] path - The Dbus object path
40 * @param[in] parent - Parent object.
41 * @param[in] value - The redundancyPriority value
42 */
43 RedundancyPriority(sdbusplus::bus::bus& bus,
44 const std::string& path,
45 Activation& parent,
46 uint8_t value) :
47 RedundancyPriorityInherit(bus,
48 path.c_str(), true),
49 parent(parent)
50 {
51 // Set Property
52 priority(value);
53 // Emit deferred signal.
54 emit_object_added();
55 }
56
57 /** @brief Overloaded Priority property set function
58 *
59 * @param[in] value - uint8_t
60 *
61 * @return Success or exception thrown
62 */
63 uint8_t priority(uint8_t value) override;
64
65 /** @brief Priority property get function
66 *
67 * @returns uint8_t - The Priority value
68 */
69 using RedundancyPriorityInherit::priority;
70
71 /** @brief Parent Object. */
72 Activation& parent;
73};
Saqib Khanb0774702017-05-23 16:02:41 -050074
75/** @class ActivationBlocksTransition
76 * @brief OpenBMC ActivationBlocksTransition implementation.
77 * @details A concrete implementation for
78 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
79 */
80class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
81{
82 public:
83 /** @brief Constructs ActivationBlocksTransition.
84 *
85 * @param[in] bus - The Dbus bus object
86 * @param[in] path - The Dbus object path
87 */
88 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
89 const std::string& path) :
90 ActivationBlocksTransitionInherit(bus, path.c_str()) {}
91};
Gunnar Millsec1b41c2017-05-02 12:20:36 -050092
93/** @class Activation
94 * @brief OpenBMC activation software management implementation.
95 * @details A concrete implementation for
96 * xyz.openbmc_project.Software.Activation DBus API.
97 */
98class Activation : public ActivationInherit
99{
100 public:
101 /** @brief Constructs Activation Software Manager
102 *
103 * @param[in] bus - The Dbus bus object
104 * @param[in] path - The Dbus object path
Saqib Khan4c1aec02017-07-06 11:46:13 -0500105 * @param[in] parent - Parent object.
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500106 * @param[in] versionId - The software version id
107 * @param[in] activationStatus - The status of Activation
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500108 */
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500109 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan4c1aec02017-07-06 11:46:13 -0500110 ItemUpdater& parent,
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500111 std::string& versionId,
112 sdbusplus::xyz::openbmc_project::Software::
113 server::Activation::Activations activationStatus) :
114 ActivationInherit(bus, path.c_str(), true),
115 bus(bus),
116 path(path),
Saqib Khan4c1aec02017-07-06 11:46:13 -0500117 parent(parent),
Michael Tritzbed88af2017-07-19 16:00:06 -0500118 versionId(versionId),
119 systemdSignals(
120 bus,
121 sdbusRule::type::signal() +
122 sdbusRule::member("JobRemoved") +
123 sdbusRule::path("/org/freedesktop/systemd1") +
124 sdbusRule::interface(
125 "org.freedesktop.systemd1.Manager"),
126 std::bind(std::mem_fn(&Activation::unitStateChange),
127 this, std::placeholders::_1))
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500128 {
Michael Tritzbed88af2017-07-19 16:00:06 -0500129 // Enable systemd signals
130 subscribeToSystemdSignals();
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500131 // Set Properties.
132 activation(activationStatus);
133 // Emit deferred signal.
134 emit_object_added();
135 }
136
Saqib Khanb0774702017-05-23 16:02:41 -0500137 /** @brief Overloaded Activation property setter function
138 *
139 * @param[in] value - One of Activation::Activations
140 *
141 * @return Success or exception thrown
142 */
143 Activations activation(Activations value) override;
144
145 /** @brief Overloaded requestedActivation property setter function
146 *
147 * @param[in] value - One of Activation::RequestedActivations
148 *
149 * @return Success or exception thrown
150 */
151 RequestedActivations requestedActivation(RequestedActivations value)
152 override;
153
Michael Tritzbed88af2017-07-19 16:00:06 -0500154 /** @brief Check if systemd state change is relevant to this object
155 *
156 * Instance specific interface to handle the detected systemd state
157 * change
158 *
159 * @param[in] msg - Data associated with subscribed signal
160 *
161 */
162 void unitStateChange(sdbusplus::message::message& msg);
163
164 /**
165 * @brief subscribe to the systemd signals
166 *
167 * This object needs to capture when it's systemd targets complete
168 * so it can keep it's state updated
169 *
170 */
171 void subscribeToSystemdSignals();
172
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500173 /** @brief Persistent sdbusplus DBus bus connection */
174 sdbusplus::bus::bus& bus;
175
176 /** @brief Persistent DBus object path */
177 std::string path;
178
Saqib Khan4c1aec02017-07-06 11:46:13 -0500179 /** @brief Parent Object. */
180 ItemUpdater& parent;
181
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500182 /** @brief Version id */
183 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500184
185 /** @brief Persistent ActivationBlocksTransition dbus object */
186 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500187
188 /** @brief Persistent RedundancyPriority dbus object */
189 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500190
191 /** @brief Used to subscribe to dbus systemd signals **/
192 sdbusplus::bus::match_t systemdSignals;
193
194 /** @brief Tracks whether the read-write volume has been created as
195 * part of the activation process. **/
196 bool rwVolumeCreated = false;
197
198 /** @brief Tracks whether the read-only volume has been created as
199 * part of the activation process. **/
200 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500201};
202
203} // namespace updater
204} // namespace software
205} // namespace phosphor