blob: 2b0af134ba8928276d2d67a54120d17be1ac5b60 [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
5#include <sdbusplus/bus.hpp>
Lei YU01539e72019-07-31 10:57:38 +08006#include <xyz/openbmc_project/Object/Delete/server.hpp>
7#include <xyz/openbmc_project/Software/Version/server.hpp>
8
9namespace phosphor
10{
11namespace software
12{
13namespace updater
14{
15
16using eraseFunc = std::function<void(std::string)>;
17
Patrick Williams374fae52022-07-22 19:26:55 -050018using VersionInherit = sdbusplus::server::object_t<
Lei YU99301372019-09-29 16:27:12 +080019 sdbusplus::xyz::openbmc_project::Software::server::Version>;
Patrick Williams374fae52022-07-22 19:26:55 -050020using DeleteInherit = sdbusplus::server::object_t<
Lei YU01539e72019-07-31 10:57:38 +080021 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
22
23namespace sdbusRule = sdbusplus::bus::match::rules;
24
25class Version;
26
27/** @class Delete
28 * @brief OpenBMC Delete implementation.
29 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
30 * D-Bus API.
31 */
32class Delete : public DeleteInherit
33{
34 public:
35 /** @brief Constructs Delete.
36 *
37 * @param[in] bus - The D-Bus bus object
38 * @param[in] path - The D-Bus object path
39 * @param[in] version - The Version object.
40 */
Patrick Williams374fae52022-07-22 19:26:55 -050041 Delete(sdbusplus::bus_t& bus, const std::string& path, Version& version) :
Albert Zhangf356fdc2020-03-02 09:24:17 +080042 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
43 version(version)
Patrick Williams5670b182023-05-10 07:50:50 -050044 {}
Lei YU01539e72019-07-31 10:57:38 +080045
46 /**
47 * @brief Delete the D-Bus object.
48 * Overrides the default delete function by calling
49 * Version class erase Method.
50 **/
51 void delete_() override;
52
53 private:
54 /** @brief The Version Object. */
55 Version& version;
Lei YU01539e72019-07-31 10:57:38 +080056};
57
58/** @class Version
59 * @brief OpenBMC version software management implementation.
60 * @details A concrete implementation for xyz.openbmc_project.Software.Version
61 * D-Bus API.
62 */
63class Version : public VersionInherit
64{
65 public:
66 /** @brief Constructs Version Software Manager.
67 *
68 * @param[in] bus - The D-Bus bus object
69 * @param[in] objPath - The D-Bus object path
70 * @param[in] versionId - The version Id
71 * @param[in] versionString - The version string
72 * @param[in] versionPurpose - The version purpose
Lei YU01539e72019-07-31 10:57:38 +080073 * @param[in] callback - The eraseFunc callback
74 */
Patrick Williams374fae52022-07-22 19:26:55 -050075 Version(sdbusplus::bus_t& bus, const std::string& objPath,
Lei YU01539e72019-07-31 10:57:38 +080076 const std::string& versionId, const std::string& versionString,
Lei YU99301372019-09-29 16:27:12 +080077 VersionPurpose versionPurpose, eraseFunc callback) :
Tang Yiwei434ae482022-04-16 13:55:21 +080078 VersionInherit(bus, (objPath).c_str(),
79 VersionInherit::action::defer_emit),
George Liua31e5682024-08-23 14:59:57 +080080 eraseCallback(std::move(callback)), bus(bus), objPath(objPath),
Lei YU01539e72019-07-31 10:57:38 +080081 versionId(versionId), versionStr(versionString)
82 {
83 // Set properties.
84 purpose(versionPurpose);
85 version(versionString);
Lei YU01539e72019-07-31 10:57:38 +080086
87 deleteObject = std::make_unique<Delete>(bus, objPath, *this);
88
89 // Emit deferred signal.
90 emit_object_added();
91 }
92
93 /**
94 * @brief Return the version id
95 */
96 std::string getVersionId() const
97 {
98 return versionId;
99 }
100
101 /**
Lei YU58c26e32019-09-27 17:52:06 +0800102 * @brief Read the manifest file to get the values of the keys.
Lei YU01539e72019-07-31 10:57:38 +0800103 *
104 * @param[in] filePath - The path to the file which contains the value
105 * of keys.
Lei YUfda15a32019-09-19 14:43:02 +0800106 * @param[in] keys - A vector of keys.
Lei YU01539e72019-07-31 10:57:38 +0800107 *
108 * @return The map of keys with filled values.
109 **/
Patrick Williamsbab5ed92024-08-16 15:20:54 -0400110 static std::map<std::string, std::string> getValues(
111 const std::string& filePath, const std::vector<std::string>& keys);
Lei YU01539e72019-07-31 10:57:38 +0800112
Lei YU58c26e32019-09-27 17:52:06 +0800113 /**
114 * @brief Read the manifest file to get the value of the key.
115 *
116 * @param[in] filePath - The path to the file which contains the value
117 * of keys.
118 * @param[in] key - The string of the key.
119 *
120 * @return The string of the value.
121 **/
122 static std::string getValue(const std::string& filePath,
123 const std::string& key);
124
Lei YU9edb7332019-09-19 14:46:19 +0800125 /** @brief Get information from extVersion
126 *
127 * @param[in] extVersion - The extended version string that contains
128 * key/value pairs separated by comma.
129 *
130 * @return The map of key/value pairs
131 */
132 static std::map<std::string, std::string>
133 getExtVersionInfo(const std::string& extVersion);
134
Lei YU01539e72019-07-31 10:57:38 +0800135 /** @brief The temUpdater's erase callback. */
136 eraseFunc eraseCallback;
137
Lei YU1517f5f2019-10-14 16:44:42 +0800138 /** @brief Get the version string. */
139 const std::string& getVersionString() const
140 {
141 return versionStr;
142 }
143
Lei YU01539e72019-07-31 10:57:38 +0800144 private:
145 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williams374fae52022-07-22 19:26:55 -0500146 sdbusplus::bus_t& bus;
Lei YU01539e72019-07-31 10:57:38 +0800147
148 /** @brief Persistent DBus object path */
149 std::string objPath;
150
151 /** @brief This Version's version Id */
152 const std::string versionId;
153
154 /** @brief This Version's version string */
155 const std::string versionStr;
Lei YUf77189f2019-08-07 14:26:30 +0800156
157 /** @brief Persistent Delete D-Bus object */
158 std::unique_ptr<Delete> deleteObject;
Lei YU01539e72019-07-31 10:57:38 +0800159};
160
161} // namespace updater
162} // namespace software
163} // namespace phosphor