blob: 021aadd276e87730a12d994bc21b0f9b7f34d493 [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),
Lei YU01539e72019-07-31 10:57:38 +080080 eraseCallback(callback), bus(bus), objPath(objPath),
81 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 **/
110 static std::map<std::string, std::string>
Lei YUfda15a32019-09-19 14:43:02 +0800111 getValues(const std::string& filePath,
112 const std::vector<std::string>& keys);
Lei YU01539e72019-07-31 10:57:38 +0800113
Lei YU58c26e32019-09-27 17:52:06 +0800114 /**
115 * @brief Read the manifest file to get the value of the key.
116 *
117 * @param[in] filePath - The path to the file which contains the value
118 * of keys.
119 * @param[in] key - The string of the key.
120 *
121 * @return The string of the value.
122 **/
123 static std::string getValue(const std::string& filePath,
124 const std::string& key);
125
Lei YU9edb7332019-09-19 14:46:19 +0800126 /** @brief Get information from extVersion
127 *
128 * @param[in] extVersion - The extended version string that contains
129 * key/value pairs separated by comma.
130 *
131 * @return The map of key/value pairs
132 */
133 static std::map<std::string, std::string>
134 getExtVersionInfo(const std::string& extVersion);
135
Lei YU01539e72019-07-31 10:57:38 +0800136 /** @brief The temUpdater's erase callback. */
137 eraseFunc eraseCallback;
138
Lei YU1517f5f2019-10-14 16:44:42 +0800139 /** @brief Get the version string. */
140 const std::string& getVersionString() const
141 {
142 return versionStr;
143 }
144
Lei YU01539e72019-07-31 10:57:38 +0800145 private:
146 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williams374fae52022-07-22 19:26:55 -0500147 sdbusplus::bus_t& bus;
Lei YU01539e72019-07-31 10:57:38 +0800148
149 /** @brief Persistent DBus object path */
150 std::string objPath;
151
152 /** @brief This Version's version Id */
153 const std::string versionId;
154
155 /** @brief This Version's version string */
156 const std::string versionStr;
Lei YUf77189f2019-08-07 14:26:30 +0800157
158 /** @brief Persistent Delete D-Bus object */
159 std::unique_ptr<Delete> deleteObject;
Lei YU01539e72019-07-31 10:57:38 +0800160};
161
162} // namespace updater
163} // namespace software
164} // namespace phosphor