blob: ed216d806216e3d116eba62d6e74182e00dbea1a [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
18using ActivationIntf = sdbusplus::server::object::object<
19 sdbusplus::xyz::openbmc_project::Software::server::Activation>;
20using ActivationProgressIntf = sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
22using DeleteIntf = sdbusplus::server::object::object<
23 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 */
38 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& objPath) :
39 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 */
59 Delete(sdbusplus::bus::bus& bus, const std::string& objPath,
60 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 */
89 Activation(sdbusplus::bus::bus& bus, std::string objPath,
90 Activations activationStatus, UpdateManager* updateManager) :
91 ActivationIntf(bus, objPath.c_str(), true),
92 bus(bus), objPath(objPath), updateManager(updateManager)
93 {
94 activation(activationStatus);
95 deleteImpl = std::make_unique<Delete>(bus, objPath, updateManager);
96 emit_object_added();
97 }
98
99 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
100 activation;
101 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
102 requestedActivation;
103
104 /** @brief Overriding Activation property setter function
105 */
106 Activations activation(Activations value) override
107 {
108 if (value == Activations::Activating)
109 {
110 deleteImpl.reset();
111 updateManager->activatePackage();
112 }
113 else if (value == Activations::Active || value == Activations::Failed)
114 {
115 if (!deleteImpl)
116 {
117 deleteImpl =
118 std::make_unique<Delete>(bus, objPath, updateManager);
119 }
120 }
121
122 return ActivationIntf::activation(value);
123 }
124
125 /** @brief Overriding RequestedActivations property setter function
126 */
127 RequestedActivations
128 requestedActivation(RequestedActivations value) override
129 {
130 if ((value == RequestedActivations::Active) &&
131 (requestedActivation() != RequestedActivations::Active))
132 {
133 if ((ActivationIntf::activation() == Activations::Ready))
134 {
135 activation(Activations::Activating);
136 }
137 }
138 return ActivationIntf::requestedActivation(value);
139 }
140
141 private:
142 sdbusplus::bus::bus& bus;
143 const std::string objPath;
144 UpdateManager* updateManager;
145 std::unique_ptr<Delete> deleteImpl;
146};
147
148} // namespace fw_update
149
150} // namespace pldm