-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathversion.hpp
203 lines (177 loc) · 6.14 KB
/
version.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#pragma once
#include "xyz/openbmc_project/Common/FilePath/server.hpp"
#include "xyz/openbmc_project/Inventory/Decorator/Compatible/server.hpp"
#include "xyz/openbmc_project/Object/Delete/server.hpp"
#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
#include "xyz/openbmc_project/Software/Version/server.hpp"
#include <sdbusplus/bus.hpp>
#include <functional>
#include <string>
#include <vector>
namespace phosphor
{
namespace software
{
namespace manager
{
typedef std::function<void(std::string)> eraseFunc;
using VersionInherit = sdbusplus::server::object_t<
sdbusplus::server::xyz::openbmc_project::software::ExtendedVersion,
sdbusplus::server::xyz::openbmc_project::software::Version,
sdbusplus::server::xyz::openbmc_project::common::FilePath,
sdbusplus::server::xyz::openbmc_project::inventory::decorator::Compatible>;
using DeleteInherit = sdbusplus::server::object_t<
sdbusplus::server::xyz::openbmc_project::object::Delete>;
class Version;
class Delete;
/** @class Delete
* @brief OpenBMC Delete implementation.
* @details A concrete implementation for xyz.openbmc_project.Object.Delete
* D-Bus API.
*/
class Delete : public DeleteInherit
{
public:
/** @brief Constructs Delete.
*
* @param[in] bus - The D-Bus bus object
* @param[in] path - The D-Bus object path
* @param[in] parent - Parent object.
*/
Delete(sdbusplus::bus_t& bus, const std::string& path, Version& parent) :
DeleteInherit(bus, path.c_str(), action::emit_interface_added),
parent(parent)
{
// Empty
}
/** @brief delete the D-Bus object. */
void delete_() override;
private:
/** @brief Parent Object. */
Version& parent;
};
/** @class Version
* @brief OpenBMC version software management implementation.
* @details A concrete implementation for xyz.openbmc_project.Software.Version
* D-Bus API.
*/
class Version : public VersionInherit
{
public:
/** @brief Constructs Version Software Manager
*
* @param[in] bus - The D-Bus bus object
* @param[in] objPath - The D-Bus object path
* @param[in] versionString - The version string
* @param[in] versionPurpose - The version purpose
* @param[in] extVersion - The extended version
* @param[in] filePath - The image filesystem path
* @param[in] compatibleNames - The device compatibility names
* @param[in] callback - The eraseFunc callback
*/
Version(sdbusplus::bus_t& bus, const std::string& objPath,
const std::string& versionString, VersionPurpose versionPurpose,
const std::string& extVersion, const std::string& filePath,
const std::vector<std::string>& compatibleNames, eraseFunc callback,
const std::string& id) :
VersionInherit(bus, (objPath).c_str(),
VersionInherit::action::defer_emit),
eraseCallback(std::move(callback)), id(id), objPath(objPath),
versionStr(versionString)
{
// Set properties.
extendedVersion(extVersion);
purpose(versionPurpose);
version(versionString);
path(filePath);
names(compatibleNames);
// Emit deferred signal.
emit_object_added();
}
/**
* @brief Read the manifest file to get the value of the key.
*
* @return The value of the key.
**/
static std::string getValue(const std::string& manifestFilePath,
std::string key);
/**
* @brief Read the manifest file to get the values of the repeated key.
*
* @return The values of the repeated key.
**/
static std::vector<std::string>
getRepeatedValues(const std::string& manifestFilePath, std::string key);
/**
* @brief Calculate the version id from the version string.
*
* @details The version id is a unique 8 hexadecimal digit id
* calculated from the version string.
*
* @param[in] versionWithSalt - The image's version string
* (e.g. v1.99.10-19) plus an optional salt
* string.
*
* @return The id.
*/
static std::string getId(const std::string& versionWithSalt);
/**
* @brief Get the active BMC machine name string.
*
* @param[in] releaseFilePath - The path to the file which contains
* the release machine string.
*
* @return The machine name string (e.g. romulus, tiogapass).
*/
static std::string getBMCMachine(const std::string& releaseFilePath);
/**
* @brief Get the BMC Extended Version string.
*
* @param[in] releaseFilePath - The path to the file which contains
* the release machine string.
*
* @return The extended version string.
*/
static std::string
getBMCExtendedVersion(const std::string& releaseFilePath);
/**
* @brief Get the active BMC version string.
*
* @param[in] releaseFilePath - The path to the file which contains
* the release version string.
*
* @return The version string (e.g. v1.99.10-19).
*/
static std::string getBMCVersion(const std::string& releaseFilePath);
/* @brief Check if this version is functional.
*
* @return - Returns the functional value.
*/
bool isFunctional() const
{
return functional;
}
/** @brief Set the functional value.
* @param[in] value - True or False
*/
void setFunctional(bool value)
{
functional = value;
}
/** @brief Persistent Delete D-Bus object */
std::unique_ptr<Delete> deleteObject;
/** @brief The parent's erase callback. */
eraseFunc eraseCallback;
/** @brief The version ID of the object */
const std::string id;
/** @brief The path of the object */
std::string objPath;
private:
/** @brief This Version's version string */
const std::string versionStr;
/** @brief If this version is the functional one */
bool functional = false;
};
} // namespace manager
} // namespace software
} // namespace phosphor