blob: 4c4dfde82610b9bf330fac262dddbef759fc68e9 [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
18using VersionInherit = sdbusplus::server::object::object<
Lei YU99301372019-09-29 16:27:12 +080019 sdbusplus::xyz::openbmc_project::Software::server::Version>;
Lei YU01539e72019-07-31 10:57:38 +080020using DeleteInherit = sdbusplus::server::object::object<
21 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 */
41 Delete(sdbusplus::bus::bus& bus, const std::string& path,
42 Version& version) :
Albert Zhangf356fdc2020-03-02 09:24:17 +080043 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
44 version(version)
Lei YU01539e72019-07-31 10:57:38 +080045 {
Lei YU01539e72019-07-31 10:57:38 +080046 }
47
48 /**
49 * @brief Delete the D-Bus object.
50 * Overrides the default delete function by calling
51 * Version class erase Method.
52 **/
53 void delete_() override;
54
55 private:
56 /** @brief The Version Object. */
57 Version& version;
Lei YU01539e72019-07-31 10:57:38 +080058};
59
60/** @class Version
61 * @brief OpenBMC version software management implementation.
62 * @details A concrete implementation for xyz.openbmc_project.Software.Version
63 * D-Bus API.
64 */
65class Version : public VersionInherit
66{
67 public:
68 /** @brief Constructs Version Software Manager.
69 *
70 * @param[in] bus - The D-Bus bus object
71 * @param[in] objPath - The D-Bus object path
72 * @param[in] versionId - The version Id
73 * @param[in] versionString - The version string
74 * @param[in] versionPurpose - The version purpose
Lei YU01539e72019-07-31 10:57:38 +080075 * @param[in] callback - The eraseFunc callback
76 */
77 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
78 const std::string& versionId, const std::string& versionString,
Lei YU99301372019-09-29 16:27:12 +080079 VersionPurpose versionPurpose, eraseFunc callback) :
Tang Yiwei434ae482022-04-16 13:55:21 +080080 VersionInherit(bus, (objPath).c_str(),
81 VersionInherit::action::defer_emit),
Lei YU01539e72019-07-31 10:57:38 +080082 eraseCallback(callback), bus(bus), objPath(objPath),
83 versionId(versionId), versionStr(versionString)
84 {
85 // Set properties.
86 purpose(versionPurpose);
87 version(versionString);
Lei YU01539e72019-07-31 10:57:38 +080088
89 deleteObject = std::make_unique<Delete>(bus, objPath, *this);
90
91 // Emit deferred signal.
92 emit_object_added();
93 }
94
95 /**
96 * @brief Return the version id
97 */
98 std::string getVersionId() const
99 {
100 return versionId;
101 }
102
103 /**
Lei YU58c26e32019-09-27 17:52:06 +0800104 * @brief Read the manifest file to get the values of the keys.
Lei YU01539e72019-07-31 10:57:38 +0800105 *
106 * @param[in] filePath - The path to the file which contains the value
107 * of keys.
Lei YUfda15a32019-09-19 14:43:02 +0800108 * @param[in] keys - A vector of keys.
Lei YU01539e72019-07-31 10:57:38 +0800109 *
110 * @return The map of keys with filled values.
111 **/
112 static std::map<std::string, std::string>
Lei YUfda15a32019-09-19 14:43:02 +0800113 getValues(const std::string& filePath,
114 const std::vector<std::string>& keys);
Lei YU01539e72019-07-31 10:57:38 +0800115
Lei YU58c26e32019-09-27 17:52:06 +0800116 /**
117 * @brief Read the manifest file to get the value of the key.
118 *
119 * @param[in] filePath - The path to the file which contains the value
120 * of keys.
121 * @param[in] key - The string of the key.
122 *
123 * @return The string of the value.
124 **/
125 static std::string getValue(const std::string& filePath,
126 const std::string& key);
127
Lei YU9edb7332019-09-19 14:46:19 +0800128 /** @brief Get information from extVersion
129 *
130 * @param[in] extVersion - The extended version string that contains
131 * key/value pairs separated by comma.
132 *
133 * @return The map of key/value pairs
134 */
135 static std::map<std::string, std::string>
136 getExtVersionInfo(const std::string& extVersion);
137
Lei YU01539e72019-07-31 10:57:38 +0800138 /** @brief The temUpdater's erase callback. */
139 eraseFunc eraseCallback;
140
Lei YU1517f5f2019-10-14 16:44:42 +0800141 /** @brief Get the version string. */
142 const std::string& getVersionString() const
143 {
144 return versionStr;
145 }
146
Lei YU01539e72019-07-31 10:57:38 +0800147 private:
148 /** @brief Persistent sdbusplus DBus bus connection */
149 sdbusplus::bus::bus& bus;
150
151 /** @brief Persistent DBus object path */
152 std::string objPath;
153
154 /** @brief This Version's version Id */
155 const std::string versionId;
156
157 /** @brief This Version's version string */
158 const std::string versionStr;
Lei YUf77189f2019-08-07 14:26:30 +0800159
160 /** @brief Persistent Delete D-Bus object */
161 std::unique_ptr<Delete> deleteObject;
Lei YU01539e72019-07-31 10:57:38 +0800162};
163
164} // namespace updater
165} // namespace software
166} // namespace phosphor