blob: a67fc82e3ad5836dc44302fe5a511a6cd2728f13 [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
5#include <sdbusplus/bus.hpp>
6#include <xyz/openbmc_project/Common/FilePath/server.hpp>
7#include <xyz/openbmc_project/Object/Delete/server.hpp>
8#include <xyz/openbmc_project/Software/Version/server.hpp>
9
10namespace phosphor
11{
12namespace software
13{
14namespace updater
15{
16
17using eraseFunc = std::function<void(std::string)>;
18
19using VersionInherit = sdbusplus::server::object::object<
20 sdbusplus::xyz::openbmc_project::Software::server::Version,
21 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
22using DeleteInherit = sdbusplus::server::object::object<
23 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
24
25namespace sdbusRule = sdbusplus::bus::match::rules;
26
27class Version;
28
29/** @class Delete
30 * @brief OpenBMC Delete implementation.
31 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
32 * D-Bus API.
33 */
34class Delete : public DeleteInherit
35{
36 public:
37 /** @brief Constructs Delete.
38 *
39 * @param[in] bus - The D-Bus bus object
40 * @param[in] path - The D-Bus object path
41 * @param[in] version - The Version object.
42 */
43 Delete(sdbusplus::bus::bus& bus, const std::string& path,
44 Version& version) :
45 DeleteInherit(bus, path.c_str(), true),
46 version(version), bus(bus), path(path)
47 {
48 std::vector<std::string> interfaces({interface});
49 bus.emit_interfaces_added(path.c_str(), interfaces);
50 }
51
52 ~Delete()
53 {
54 std::vector<std::string> interfaces({interface});
55 bus.emit_interfaces_removed(path.c_str(), interfaces);
56 }
57
58 /**
59 * @brief Delete the D-Bus object.
60 * Overrides the default delete function by calling
61 * Version class erase Method.
62 **/
63 void delete_() override;
64
65 private:
66 /** @brief The Version Object. */
67 Version& version;
68
69 static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
70 sdbusplus::bus::bus& bus;
71 std::string path;
72};
73
74/** @class Version
75 * @brief OpenBMC version software management implementation.
76 * @details A concrete implementation for xyz.openbmc_project.Software.Version
77 * D-Bus API.
78 */
79class Version : public VersionInherit
80{
81 public:
82 /** @brief Constructs Version Software Manager.
83 *
84 * @param[in] bus - The D-Bus bus object
85 * @param[in] objPath - The D-Bus object path
86 * @param[in] versionId - The version Id
87 * @param[in] versionString - The version string
88 * @param[in] versionPurpose - The version purpose
89 * @param[in] filePath - The image filesystem path
90 * @param[in] callback - The eraseFunc callback
91 */
92 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
93 const std::string& versionId, const std::string& versionString,
94 VersionPurpose versionPurpose, const std::string& filePath,
95 eraseFunc callback) :
96 VersionInherit(bus, (objPath).c_str(), true),
97 eraseCallback(callback), bus(bus), objPath(objPath),
98 versionId(versionId), versionStr(versionString)
99 {
100 // Set properties.
101 purpose(versionPurpose);
102 version(versionString);
103 path(filePath);
104
105 deleteObject = std::make_unique<Delete>(bus, objPath, *this);
106
107 // Emit deferred signal.
108 emit_object_added();
109 }
110
111 /**
112 * @brief Return the version id
113 */
114 std::string getVersionId() const
115 {
116 return versionId;
117 }
118
119 /**
120 * @brief Read the manifest file to get the value of the key.
121 *
122 * @param[in] filePath - The path to the file which contains the value
123 * of keys.
124 * @param[in] keys - A map of keys with empty values.
125 *
126 * @return The map of keys with filled values.
127 **/
128 static std::map<std::string, std::string>
129 getValue(const std::string& filePath,
130 std::map<std::string, std::string> keys);
131
Lei YU01539e72019-07-31 10:57:38 +0800132 /** @brief The temUpdater's erase callback. */
133 eraseFunc eraseCallback;
134
135 private:
136 /** @brief Persistent sdbusplus DBus bus connection */
137 sdbusplus::bus::bus& bus;
138
139 /** @brief Persistent DBus object path */
140 std::string objPath;
141
142 /** @brief This Version's version Id */
143 const std::string versionId;
144
145 /** @brief This Version's version string */
146 const std::string versionStr;
Lei YUf77189f2019-08-07 14:26:30 +0800147
148 /** @brief Persistent Delete D-Bus object */
149 std::unique_ptr<Delete> deleteObject;
Lei YU01539e72019-07-31 10:57:38 +0800150};
151
152} // namespace updater
153} // namespace software
154} // namespace phosphor