blob: 4af7c44fdc3f86e4e45ee87652346785459daa77 [file] [log] [blame]
Tom Joseph4d8d5772021-08-17 07:35:05 -07001#pragma once
2
Tom Joseph4d8d5772021-08-17 07:35:05 -07003#include <sdbusplus/bus.hpp>
4#include <xyz/openbmc_project/Object/Delete/server.hpp>
5#include <xyz/openbmc_project/Software/Activation/server.hpp>
6#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
7
8#include <string>
9
10namespace pldm
11{
12
13namespace fw_update
14{
15
Andrew Jefferyf106a2c2024-07-25 21:45:41 +093016class UpdateManager;
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 */
Andrew Jefferyf106a2c2024-07-25 21:45:41 +093066 void delete_() override;
Tom Joseph4d8d5772021-08-17 07:35:05 -070067
68 private:
69 UpdateManager* updateManager;
70};
71
72/** @class Activation
73 *
74 * Concrete implementation of xyz.openbmc_project.Object.Activation D-Bus
75 * interface
76 */
77class Activation : public ActivationIntf
78{
79 public:
80 /** @brief Constructor
81 *
82 * @param[in] bus - Bus to attach to
83 * @param[in] objPath - D-Bus object path
84 * @param[in] updateManager - Reference to FW update manager
85 */
Patrick Williams84b790c2022-07-22 19:26:56 -050086 Activation(sdbusplus::bus_t& bus, std::string objPath,
Tom Joseph4d8d5772021-08-17 07:35:05 -070087 Activations activationStatus, UpdateManager* updateManager) :
Patrick Williams357b72d2022-04-13 09:01:35 -050088 ActivationIntf(bus, objPath.c_str(),
89 ActivationIntf::action::defer_emit),
Tom Joseph4d8d5772021-08-17 07:35:05 -070090 bus(bus), objPath(objPath), updateManager(updateManager)
91 {
92 activation(activationStatus);
93 deleteImpl = std::make_unique<Delete>(bus, objPath, updateManager);
94 emit_object_added();
95 }
96
97 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
98 activation;
99 using sdbusplus::xyz::openbmc_project::Software::server::Activation::
100 requestedActivation;
101
102 /** @brief Overriding Activation property setter function
103 */
Andrew Jefferyf106a2c2024-07-25 21:45:41 +0930104 Activations activation(Activations value) override;
Tom Joseph4d8d5772021-08-17 07:35:05 -0700105
106 /** @brief Overriding RequestedActivations property setter function
107 */
108 RequestedActivations
109 requestedActivation(RequestedActivations value) override
110 {
111 if ((value == RequestedActivations::Active) &&
112 (requestedActivation() != RequestedActivations::Active))
113 {
114 if ((ActivationIntf::activation() == Activations::Ready))
115 {
116 activation(Activations::Activating);
117 }
118 }
119 return ActivationIntf::requestedActivation(value);
120 }
121
122 private:
Patrick Williams84b790c2022-07-22 19:26:56 -0500123 sdbusplus::bus_t& bus;
Tom Joseph4d8d5772021-08-17 07:35:05 -0700124 const std::string objPath;
125 UpdateManager* updateManager;
126 std::unique_ptr<Delete> deleteImpl;
127};
128
129} // namespace fw_update
130
131} // namespace pldm