blob: a15a0a71e344cd4ff5ec7b6826f229635c8c3eec [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 YU01539e72019-07-31 10:57:38 +080011#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
12
13namespace phosphor
14{
15namespace software
16{
17namespace updater
18{
19
Lei YU12c9f4c2019-09-11 15:08:15 +080020namespace sdbusRule = sdbusplus::bus::match::rules;
21
Lei YU81c67722019-09-11 16:47:29 +080022using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Software::server::
24 ActivationBlocksTransition>;
25
26/** @class ActivationBlocksTransition
27 * @brief OpenBMC ActivationBlocksTransition implementation.
28 * @details A concrete implementation for
29 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
30 */
31class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
32{
33 public:
34 /** @brief Constructs ActivationBlocksTransition.
35 *
36 * @param[in] bus - The Dbus bus object
37 * @param[in] path - The Dbus object path
38 */
39 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
40 const std::string& path) :
41 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
42 bus(bus), path(path)
43 {
44 std::vector<std::string> interfaces({interface});
45 bus.emit_interfaces_added(path.c_str(), interfaces);
46 }
47
48 ~ActivationBlocksTransition()
49 {
50 std::vector<std::string> interfaces({interface});
51 bus.emit_interfaces_removed(path.c_str(), interfaces);
52 }
53
54 private:
55 // TODO Remove once openbmc/openbmc#1975 is resolved
56 static constexpr auto interface =
57 "xyz.openbmc_project.Software.ActivationBlocksTransition";
58 sdbusplus::bus::bus& bus;
59 std::string path;
60};
61
Lei YU01539e72019-07-31 10:57:38 +080062using ActivationInherit = sdbusplus::server::object::object<
63 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +080064 sdbusplus::xyz::openbmc_project::Software::server::Activation,
65 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +080066
67/** @class Activation
68 * @brief OpenBMC activation software management implementation.
69 * @details A concrete implementation for
70 * xyz.openbmc_project.Software.Activation DBus API.
71 */
72class Activation : public ActivationInherit
73{
74 public:
Lei YU12c9f4c2019-09-11 15:08:15 +080075 using Status = Activations;
Lei YU01539e72019-07-31 10:57:38 +080076 /** @brief Constructs Activation Software Manager
77 *
78 * @param[in] bus - The Dbus bus object
79 * @param[in] path - The Dbus object path
80 * @param[in] versionId - The software version id
81 * @param[in] extVersion - The extended version
82 * @param[in] activationStatus - The status of Activation
Lei YU91029442019-08-01 15:57:31 +080083 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +080084 */
85 Activation(sdbusplus::bus::bus& bus, const std::string& path,
86 const std::string& versionId, const std::string& extVersion,
87 sdbusplus::xyz::openbmc_project::Software::server::Activation::
Lei YU91029442019-08-01 15:57:31 +080088 Activations activationStatus,
89 const AssociationList& assocs) :
Lei YU01539e72019-07-31 10:57:38 +080090 ActivationInherit(bus, path.c_str(), true),
Lei YU12c9f4c2019-09-11 15:08:15 +080091 versionId(versionId), bus(bus), path(path),
92 systemdSignals(
93 bus,
94 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
95 sdbusRule::path("/org/freedesktop/systemd1") +
96 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
97 std::bind(&Activation::unitStateChange, this,
98 std::placeholders::_1))
Lei YU01539e72019-07-31 10:57:38 +080099 {
100 // Set Properties.
101 extendedVersion(extVersion);
102 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800103 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +0800104
105 // Emit deferred signal.
106 emit_object_added();
107 }
108
109 /** @brief Overloaded Activation property setter function
110 *
111 * @param[in] value - One of Activation::Activations
112 *
113 * @return Success or exception thrown
114 */
115 Activations activation(Activations value) override;
116
117 /** @brief Activation */
118 using ActivationInherit::activation;
119
120 /** @brief Overloaded requestedActivation property setter function
121 *
122 * @param[in] value - One of Activation::RequestedActivations
123 *
124 * @return Success or exception thrown
125 */
126 RequestedActivations
127 requestedActivation(RequestedActivations value) override;
128
Lei YU12c9f4c2019-09-11 15:08:15 +0800129 /** @brief Version id */
130 std::string versionId;
131
132 private:
133 /** @brief Check if systemd state change is relevant to this object
134 *
135 * Instance specific interface to handle the detected systemd state
136 * change
137 *
138 * @param[in] msg - Data associated with subscribed signal
139 *
140 */
141 void unitStateChange(sdbusplus::message::message& msg);
142
Lei YUd0bbfa92019-09-11 16:10:54 +0800143 /**
144 * @brief Delete the version from Image Manager and the
145 * untar image from image upload dir.
146 */
147 void deleteImageManagerObject();
148
Lei YU12c9f4c2019-09-11 15:08:15 +0800149 /** @brief Start PSU update */
150 void startActivation();
151
152 /** @brief Finish PSU update */
153 void finishActivation();
154
Lei YU01539e72019-07-31 10:57:38 +0800155 /** @brief Persistent sdbusplus DBus bus connection */
156 sdbusplus::bus::bus& bus;
157
158 /** @brief Persistent DBus object path */
159 std::string path;
160
Lei YU12c9f4c2019-09-11 15:08:15 +0800161 /** @brief Used to subscribe to dbus systemd signals */
162 sdbusplus::bus::match_t systemdSignals;
163
164 /** @brief The PSU update systemd unit */
165 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800166
167 /** @brief Persistent ActivationBlocksTransition dbus object */
168 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU01539e72019-07-31 10:57:38 +0800169};
170
171} // namespace updater
172} // namespace software
173} // namespace phosphor