blob: bb66341b7be933c029a58f75c4e19bda174ee303 [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"
Justin Ledford054bb0b2022-03-15 15:46:58 -07004#include "xyz/openbmc_project/Inventory/Decorator/Compatible/server.hpp"
Saqib Khanee13e832017-10-23 12:53:11 -05005#include "xyz/openbmc_project/Object/Delete/server.hpp"
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +07006#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05007#include "xyz/openbmc_project/Software/Version/server.hpp"
8
Gunnar Millsb0ce9962018-09-07 13:39:10 -05009#include <sdbusplus/bus.hpp>
Adriana Kobylak58aa7502020-06-08 11:12:11 -050010
11#include <functional>
Andrew Geissler9155b712020-05-16 13:04:44 -050012#include <string>
Justin Ledford054bb0b2022-03-15 15:46:58 -070013#include <vector>
Gunnar Mills392f2942017-04-12 11:04:37 -050014
15namespace phosphor
16{
17namespace software
18{
19namespace manager
20{
21
Leonel Gonzaleze4233682017-07-07 14:38:25 -050022typedef std::function<void(std::string)> eraseFunc;
23
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050024using VersionInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050025 sdbusplus::server::xyz::openbmc_project::software::ExtendedVersion,
26 sdbusplus::server::xyz::openbmc_project::software::Version,
27 sdbusplus::server::xyz::openbmc_project::common::FilePath,
28 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Compatible>;
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050029using DeleteInherit = sdbusplus::server::object_t<
Patrick Williams1e9a5f12023-08-23 16:53:06 -050030 sdbusplus::server::xyz::openbmc_project::object::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050031
32class Version;
33class Delete;
34
35/** @class Delete
36 * @brief OpenBMC Delete implementation.
37 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
38 * D-Bus API.
39 */
40class Delete : public DeleteInherit
41{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060042 public:
43 /** @brief Constructs Delete.
44 *
45 * @param[in] bus - The D-Bus bus object
46 * @param[in] path - The D-Bus object path
47 * @param[in] parent - Parent object.
48 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050049 Delete(sdbusplus::bus_t& bus, const std::string& path, Version& parent) :
Lei YU29d84b02020-02-13 15:13:09 +080050 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
51 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060052 {
Lei YU29d84b02020-02-13 15:13:09 +080053 // Empty
Adriana Kobylak2285fe02018-02-27 15:36:59 -060054 }
Saqib Khanee13e832017-10-23 12:53:11 -050055
Adriana Kobylak2285fe02018-02-27 15:36:59 -060056 /** @brief delete the D-Bus object. */
57 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050058
Adriana Kobylak2285fe02018-02-27 15:36:59 -060059 private:
60 /** @brief Parent Object. */
61 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050062};
Gunnar Mills392f2942017-04-12 11:04:37 -050063
64/** @class Version
65 * @brief OpenBMC version software management implementation.
66 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050067 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050068 */
69class Version : public VersionInherit
70{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060071 public:
72 /** @brief Constructs Version Software Manager
73 *
Justin Ledford054bb0b2022-03-15 15:46:58 -070074 * @param[in] bus - The D-Bus bus object
75 * @param[in] objPath - The D-Bus object path
76 * @param[in] versionString - The version string
77 * @param[in] versionPurpose - The version purpose
78 * @param[in] extVersion - The extended version
79 * @param[in] filePath - The image filesystem path
80 * @param[in] compatibleNames - The device compatibility names
81 * @param[in] callback - The eraseFunc callback
Adriana Kobylak2285fe02018-02-27 15:36:59 -060082 */
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050083 Version(sdbusplus::bus_t& bus, const std::string& objPath,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060084 const std::string& versionString, VersionPurpose versionPurpose,
Lei YUb412bd12021-03-23 20:01:28 +080085 const std::string& extVersion, const std::string& filePath,
Justin Ledford054bb0b2022-03-15 15:46:58 -070086 const std::vector<std::string>& compatibleNames, eraseFunc callback,
87 const std::string& id) :
Patrick Williams35aa9a82022-04-05 15:55:30 -050088 VersionInherit(bus, (objPath).c_str(),
89 VersionInherit::action::defer_emit),
Jagpal Singh Gillc111b932024-08-12 16:07:33 -070090 eraseCallback(std::move(callback)), id(id), objPath(objPath),
91 versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060092 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060093 // Set properties.
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070094 extendedVersion(extVersion);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060095 purpose(versionPurpose);
96 version(versionString);
97 path(filePath);
Justin Ledford054bb0b2022-03-15 15:46:58 -070098 names(compatibleNames);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060099 // Emit deferred signal.
100 emit_object_added();
101 }
Gunnar Mills392f2942017-04-12 11:04:37 -0500102
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600103 /**
104 * @brief Read the manifest file to get the value of the key.
105 *
106 * @return The value of the key.
107 **/
108 static std::string getValue(const std::string& manifestFilePath,
109 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500110
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600111 /**
Justin Ledford054bb0b2022-03-15 15:46:58 -0700112 * @brief Read the manifest file to get the values of the repeated key.
113 *
114 * @return The values of the repeated key.
115 **/
116 static std::vector<std::string>
117 getRepeatedValues(const std::string& manifestFilePath, std::string key);
118
119 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600120 * @brief Calculate the version id from the version string.
121 *
122 * @details The version id is a unique 8 hexadecimal digit id
123 * calculated from the version string.
124 *
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000125 * @param[in] versionWithSalt - The image's version string
126 * (e.g. v1.99.10-19) plus an optional salt
127 * string.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600128 *
129 * @return The id.
130 */
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000131 static std::string getId(const std::string& versionWithSalt);
Gunnar Millscebd1022017-04-17 16:10:15 -0500132
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600133 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700134 * @brief Get the active BMC machine name string.
135 *
136 * @param[in] releaseFilePath - The path to the file which contains
137 * the release machine string.
138 *
139 * @return The machine name string (e.g. romulus, tiogapass).
140 */
141 static std::string getBMCMachine(const std::string& releaseFilePath);
142
143 /**
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700144 * @brief Get the BMC Extended Version string.
145 *
146 * @param[in] releaseFilePath - The path to the file which contains
147 * the release machine string.
148 *
149 * @return The extended version string.
150 */
151 static std::string
152 getBMCExtendedVersion(const std::string& releaseFilePath);
153
154 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600155 * @brief Get the active BMC version string.
156 *
157 * @param[in] releaseFilePath - The path to the file which contains
158 * the release version string.
159 *
160 * @return The version string (e.g. v1.99.10-19).
161 */
162 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500163
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000164 /* @brief Check if this version is functional.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165 *
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000166 * @return - Returns the functional value.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600167 */
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000168 bool isFunctional() const
169 {
170 return functional;
171 }
172
173 /** @brief Set the functional value.
174 * @param[in] value - True or False
175 */
176 void setFunctional(bool value)
177 {
178 functional = value;
179 }
Eddie James6d873712017-09-01 11:29:07 -0500180
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600181 /** @brief Persistent Delete D-Bus object */
182 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500183
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600184 /** @brief The parent's erase callback. */
185 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500186
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000187 /** @brief The version ID of the object */
188 const std::string id;
189
Jagpal Singh Gillc111b932024-08-12 16:07:33 -0700190 /** @brief The path of the object */
191 std::string objPath;
192
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600193 private:
194 /** @brief This Version's version string */
195 const std::string versionStr;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000196
197 /** @brief If this version is the functional one */
198 bool functional = false;
Gunnar Mills392f2942017-04-12 11:04:37 -0500199};
200
201} // namespace manager
202} // namespace software
203} // namespace phosphor