blob: b6269e0c85cda32bd7e208c5b8cff7a1fe805bdc [file] [log] [blame]
Gunnar Mills392f2942017-04-12 11:04:37 -05001#pragma once
2
Gunnar Millsef4781f2017-04-19 11:28:24 -05003#include "xyz/openbmc_project/Common/FilePath/server.hpp"
Saqib Khanee13e832017-10-23 12:53:11 -05004#include "xyz/openbmc_project/Object/Delete/server.hpp"
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +07005#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05006#include "xyz/openbmc_project/Software/Version/server.hpp"
7
Gunnar Millsb0ce9962018-09-07 13:39:10 -05008#include <sdbusplus/bus.hpp>
Adriana Kobylak58aa7502020-06-08 11:12:11 -05009
10#include <functional>
Andrew Geissler9155b712020-05-16 13:04:44 -050011#include <string>
Gunnar Mills392f2942017-04-12 11:04:37 -050012
13namespace phosphor
14{
15namespace software
16{
17namespace manager
18{
19
Leonel Gonzaleze4233682017-07-07 14:38:25 -050020typedef std::function<void(std::string)> eraseFunc;
21
Gunnar Mills392f2942017-04-12 11:04:37 -050022using VersionInherit = sdbusplus::server::object::object<
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070023 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060024 sdbusplus::xyz::openbmc_project::Software::server::Version,
25 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khanee13e832017-10-23 12:53:11 -050026using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060027 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050028
29class Version;
30class Delete;
31
32/** @class Delete
33 * @brief OpenBMC Delete implementation.
34 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
35 * D-Bus API.
36 */
37class Delete : public DeleteInherit
38{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060039 public:
40 /** @brief Constructs Delete.
41 *
42 * @param[in] bus - The D-Bus bus object
43 * @param[in] path - The D-Bus object path
44 * @param[in] parent - Parent object.
45 */
46 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
Lei YU29d84b02020-02-13 15:13:09 +080047 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
48 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060049 {
Lei YU29d84b02020-02-13 15:13:09 +080050 // Empty
Adriana Kobylak2285fe02018-02-27 15:36:59 -060051 }
Saqib Khanee13e832017-10-23 12:53:11 -050052
Adriana Kobylak2285fe02018-02-27 15:36:59 -060053 /** @brief delete the D-Bus object. */
54 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050055
Adriana Kobylak2285fe02018-02-27 15:36:59 -060056 private:
57 /** @brief Parent Object. */
58 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050059};
Gunnar Mills392f2942017-04-12 11:04:37 -050060
61/** @class Version
62 * @brief OpenBMC version software management implementation.
63 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050064 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050065 */
66class Version : public VersionInherit
67{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060068 public:
69 /** @brief Constructs Version Software Manager
70 *
71 * @param[in] bus - The D-Bus bus object
72 * @param[in] objPath - The D-Bus object path
73 * @param[in] versionString - The version string
74 * @param[in] versionPurpose - The version purpose
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070075 * @param[in] extVersion - The extended version
Adriana Kobylak2285fe02018-02-27 15:36:59 -060076 * @param[in] filePath - The image filesystem path
77 * @param[in] callback - The eraseFunc callback
78 */
79 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
80 const std::string& versionString, VersionPurpose versionPurpose,
Lei YUb412bd12021-03-23 20:01:28 +080081 const std::string& extVersion, const std::string& filePath,
Adriana Kobylak59b640b2022-01-21 19:45:22 +000082 eraseFunc callback, const std::string& id) :
Adriana Kobylak2285fe02018-02-27 15:36:59 -060083 VersionInherit(bus, (objPath).c_str(), true),
Adriana Kobylak59b640b2022-01-21 19:45:22 +000084 eraseCallback(callback), id(id), versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060085 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060086 // Set properties.
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070087 extendedVersion(extVersion);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060088 purpose(versionPurpose);
89 version(versionString);
90 path(filePath);
91 // Emit deferred signal.
92 emit_object_added();
93 }
Gunnar Mills392f2942017-04-12 11:04:37 -050094
Adriana Kobylak2285fe02018-02-27 15:36:59 -060095 /**
96 * @brief Read the manifest file to get the value of the key.
97 *
98 * @return The value of the key.
99 **/
100 static std::string getValue(const std::string& manifestFilePath,
101 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500102
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600103 /**
104 * @brief Calculate the version id from the version string.
105 *
106 * @details The version id is a unique 8 hexadecimal digit id
107 * calculated from the version string.
108 *
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000109 * @param[in] versionWithSalt - The image's version string
110 * (e.g. v1.99.10-19) plus an optional salt
111 * string.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600112 *
113 * @return The id.
114 */
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000115 static std::string getId(const std::string& versionWithSalt);
Gunnar Millscebd1022017-04-17 16:10:15 -0500116
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600117 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700118 * @brief Get the active BMC machine name string.
119 *
120 * @param[in] releaseFilePath - The path to the file which contains
121 * the release machine string.
122 *
123 * @return The machine name string (e.g. romulus, tiogapass).
124 */
125 static std::string getBMCMachine(const std::string& releaseFilePath);
126
127 /**
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700128 * @brief Get the BMC Extended Version string.
129 *
130 * @param[in] releaseFilePath - The path to the file which contains
131 * the release machine string.
132 *
133 * @return The extended version string.
134 */
135 static std::string
136 getBMCExtendedVersion(const std::string& releaseFilePath);
137
138 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600139 * @brief Get the active BMC version string.
140 *
141 * @param[in] releaseFilePath - The path to the file which contains
142 * the release version string.
143 *
144 * @return The version string (e.g. v1.99.10-19).
145 */
146 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500147
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000148 /* @brief Check if this version is functional.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600149 *
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000150 * @return - Returns the functional value.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600151 */
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000152 bool isFunctional() const
153 {
154 return functional;
155 }
156
157 /** @brief Set the functional value.
158 * @param[in] value - True or False
159 */
160 void setFunctional(bool value)
161 {
162 functional = value;
163 }
Eddie James6d873712017-09-01 11:29:07 -0500164
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165 /** @brief Persistent Delete D-Bus object */
166 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500167
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600168 /** @brief The parent's erase callback. */
169 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500170
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000171 /** @brief The version ID of the object */
172 const std::string id;
173
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600174 private:
175 /** @brief This Version's version string */
176 const std::string versionStr;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000177
178 /** @brief If this version is the functional one */
179 bool functional = false;
Gunnar Mills392f2942017-04-12 11:04:37 -0500180};
181
182} // namespace manager
183} // namespace software
184} // namespace phosphor