blob: 3a061b144c9397a2b8eeafe0a2b2486b0e497a70 [file] [log] [blame]
Tom Joseph4d8d5772021-08-17 07:35:05 -07001#pragma once
2
3#include "fw-update/update_manager.hpp"
4
5#include <sdbusplus/bus.hpp>
6#include <xyz/openbmc_project/Object/Delete/server.hpp>
7#include <xyz/openbmc_project/Software/Activation/server.hpp>
8#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
9
10#include <string>
11
12namespace pldm
13{
14
15namespace fw_update
16{
17
Patrick Williams84b790c2022-07-22 19:26:56 -050018using ActivationIntf = sdbusplus::server::object_t<
Tom Joseph4d8d5772021-08-17 07:35:05 -070019 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
Patrick Williams84b790c2022-07-22 19:26:56 -050020using ActivationProgressIntf = sdbusplus::server::object_t<
Tom Joseph4d8d5772021-08-17 07:35:05 -070021 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Patrick Williams84b790c2022-07-22 19:26:56 -050022using DeleteIntf = sdbusplus::server::object_t<
Tom Joseph4d8d5772021-08-17 07:35:05 -070023 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
24
25/** @class ActivationProgress
26 *
27 * Concrete implementation of xyz.openbmc_project.Software.ActivationProgress
28 * D-Bus interface
29 */
30class ActivationProgress : public ActivationProgressIntf
31{
32 public:
33 /** @brief Constructor
34 *
35 * @param[in] bus - Bus to attach to
36 * @param[in] objPath - D-Bus object path
37 */
Patrick Williams84b790c2022-07-22 19:26:56 -050038 ActivationProgress(sdbusplus::bus_t& bus, const std::string& objPath) :
Tom Joseph4d8d5772021-08-17 07:35:05 -070039 ActivationProgressIntf(bus, objPath.c_str(),
40 action::emit_interface_added)
41 {
42 progress(0);
43 }
44};
45
46/** @class Delete
47 *
48 * Concrete implementation of xyz.openbmc_project.Object.Delete D-Bus interface
49 */
50class Delete : public DeleteIntf
51{
52 public:
53 /** @brief Constructor
54 *
55 * @param[in] bus - Bus to attach to
56 * @param[in] objPath - D-Bus object path
57 * @param[in] updateManager - Reference to FW update manager
58 */
Patrick Williams84b790c2022-07-22 19:26:56 -050059 Delete(sdbusplus::bus_t& bus, const std::string& objPath,
Tom Joseph4d8d5772021-08-17 07:35:05 -070060 UpdateManager* updateManager) :
61 DeleteIntf(bus, objPath.c_str(), action::emit_interface_added),
62 updateManager(updateManager)
63 {}
64
65 /** @brief Delete the Activation D-Bus object for the FW update package */
66 void delete_() override
67 {
68 updateManager->clearActivationInfo();
69 }
70
71 private:
72 UpdateManager* updateManager;
73};
74
75/** @class Activation
76 *
77 * Concrete implementation of xyz.openbmc_project.Object.Activation D-Bus
78 * interface
79 */
80class Activation : public ActivationIntf
81{
82 public:
83 /** @brief Constructor
84 *
85 * @param[in] bus - Bus to attach to
86 * @param[in] objPath - D-Bus object path
87 * @param[in] updateManager - Reference to FW update manager
88 */
Patrick Williams84b790c2022-07-22 19:26:56 -050089 Activation(sdbusplus::bus_t& bus, std::string objPath,
Tom Joseph4d8d5772021-08-17 07:35:05 -070090 Activations activationStatus, UpdateManager* updateManager) :
Patrick Williams357b72d2022-04-13 09:01:35 -050091 ActivationIntf(bus, objPath.c_str(),
92 ActivationIntf::action::defer_emit),
Tom Joseph4d8d5772021-08-17 07:35:05 -070093 bus(bus), objPath(objPath), updateManager(updateManager)
94 {
95 activation(activationStatus);
96 deleteImpl = std::make_unique<Delete>(bus, objPath, updateManager);
97 emit_object_added();
98 }
99
100 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
101 activation;
102 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
103 requestedActivation;
104
105 /** @brief Overriding Activation property setter function
106 */
107 Activations activation(Activations value) override
108 {
109 if (value == Activations::Activating)
110 {
111 deleteImpl.reset();
112 updateManager->activatePackage();
113 }
114 else if (value == Activations::Active || value == Activations::Failed)
115 {
116 if (!deleteImpl)
117 {
118 deleteImpl =
119 std::make_unique<Delete>(bus, objPath, updateManager);
120 }
121 }
122
123 return ActivationIntf::activation(value);
124 }
125
126 /** @brief Overriding RequestedActivations property setter function
127 */
128 RequestedActivations
129 requestedActivation(RequestedActivations value) override
130 {
131 if ((value == RequestedActivations::Active) &&
132 (requestedActivation() != RequestedActivations::Active))
133 {
134 if ((ActivationIntf::activation() == Activations::Ready))
135 {
136 activation(Activations::Activating);
137 }
138 }
139 return ActivationIntf::requestedActivation(value);
140 }
141
142 private:
Patrick Williams84b790c2022-07-22 19:26:56 -0500143 sdbusplus::bus_t& bus;
Tom Joseph4d8d5772021-08-17 07:35:05 -0700144 const std::string objPath;
145 UpdateManager* updateManager;
146 std::unique_ptr<Delete> deleteImpl;
147};
148
149} // namespace fw_update
150
151} // namespace pldm