blob: 41d055e307111468257f6efc4e1ecaca6641017b [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
Leonel Gonzaleze4233682017-07-07 14:38:25 -0500145 /** @brief Activation */
146 using ActivationInherit::activation;
147
Saqib Khanb0774702017-05-23 16:02:41 -0500148 /** @brief Overloaded requestedActivation property setter function
149 *
150 * @param[in] value - One of Activation::RequestedActivations
151 *
152 * @return Success or exception thrown
153 */
154 RequestedActivations requestedActivation(RequestedActivations value)
155 override;
156
Michael Tritzbed88af2017-07-19 16:00:06 -0500157 /** @brief Check if systemd state change is relevant to this object
158 *
159 * Instance specific interface to handle the detected systemd state
160 * change
161 *
162 * @param[in] msg - Data associated with subscribed signal
163 *
164 */
165 void unitStateChange(sdbusplus::message::message& msg);
166
167 /**
168 * @brief subscribe to the systemd signals
169 *
170 * This object needs to capture when it's systemd targets complete
171 * so it can keep it's state updated
172 *
173 */
174 void subscribeToSystemdSignals();
175
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500176 /** @brief Persistent sdbusplus DBus bus connection */
177 sdbusplus::bus::bus& bus;
178
179 /** @brief Persistent DBus object path */
180 std::string path;
181
Saqib Khan4c1aec02017-07-06 11:46:13 -0500182 /** @brief Parent Object. */
183 ItemUpdater& parent;
184
Gunnar Mills2ce7da22017-05-04 15:37:56 -0500185 /** @brief Version id */
186 std::string versionId;
Saqib Khanb0774702017-05-23 16:02:41 -0500187
188 /** @brief Persistent ActivationBlocksTransition dbus object */
189 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan4c1aec02017-07-06 11:46:13 -0500190
191 /** @brief Persistent RedundancyPriority dbus object */
192 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritzbed88af2017-07-19 16:00:06 -0500193
194 /** @brief Used to subscribe to dbus systemd signals **/
195 sdbusplus::bus::match_t systemdSignals;
196
197 /** @brief Tracks whether the read-write volume has been created as
198 * part of the activation process. **/
199 bool rwVolumeCreated = false;
200
201 /** @brief Tracks whether the read-only volume has been created as
202 * part of the activation process. **/
203 bool roVolumeCreated = false;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500204};
205
206} // namespace updater
207} // namespace software
208} // namespace phosphor