blob: 8a85ba922d292b0f659feeeec07255867031a1e8 [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),
Adriana Kobylak59b640b2022-01-21 19:45:22 +000090 eraseCallback(callback), id(id), versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060091 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060092 // Set properties.
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070093 extendedVersion(extVersion);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060094 purpose(versionPurpose);
95 version(versionString);
96 path(filePath);
Justin Ledford054bb0b2022-03-15 15:46:58 -070097 names(compatibleNames);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060098 // Emit deferred signal.
99 emit_object_added();
100 }
Gunnar Mills392f2942017-04-12 11:04:37 -0500101
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600102 /**
103 * @brief Read the manifest file to get the value of the key.
104 *
105 * @return The value of the key.
106 **/
107 static std::string getValue(const std::string& manifestFilePath,
108 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500109
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600110 /**
Justin Ledford054bb0b2022-03-15 15:46:58 -0700111 * @brief Read the manifest file to get the values of the repeated key.
112 *
113 * @return The values of the repeated key.
114 **/
115 static std::vector<std::string>
116 getRepeatedValues(const std::string& manifestFilePath, std::string key);
117
118 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600119 * @brief Calculate the version id from the version string.
120 *
121 * @details The version id is a unique 8 hexadecimal digit id
122 * calculated from the version string.
123 *
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000124 * @param[in] versionWithSalt - The image's version string
125 * (e.g. v1.99.10-19) plus an optional salt
126 * string.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600127 *
128 * @return The id.
129 */
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000130 static std::string getId(const std::string& versionWithSalt);
Gunnar Millscebd1022017-04-17 16:10:15 -0500131
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600132 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700133 * @brief Get the active BMC machine name string.
134 *
135 * @param[in] releaseFilePath - The path to the file which contains
136 * the release machine string.
137 *
138 * @return The machine name string (e.g. romulus, tiogapass).
139 */
140 static std::string getBMCMachine(const std::string& releaseFilePath);
141
142 /**
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700143 * @brief Get the BMC Extended Version string.
144 *
145 * @param[in] releaseFilePath - The path to the file which contains
146 * the release machine string.
147 *
148 * @return The extended version string.
149 */
150 static std::string
151 getBMCExtendedVersion(const std::string& releaseFilePath);
152
153 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600154 * @brief Get the active BMC version string.
155 *
156 * @param[in] releaseFilePath - The path to the file which contains
157 * the release version string.
158 *
159 * @return The version string (e.g. v1.99.10-19).
160 */
161 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500162
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000163 /* @brief Check if this version is functional.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600164 *
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000165 * @return - Returns the functional value.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600166 */
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000167 bool isFunctional() const
168 {
169 return functional;
170 }
171
172 /** @brief Set the functional value.
173 * @param[in] value - True or False
174 */
175 void setFunctional(bool value)
176 {
177 functional = value;
178 }
Eddie James6d873712017-09-01 11:29:07 -0500179
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600180 /** @brief Persistent Delete D-Bus object */
181 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500182
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600183 /** @brief The parent's erase callback. */
184 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500185
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000186 /** @brief The version ID of the object */
187 const std::string id;
188
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600189 private:
190 /** @brief This Version's version string */
191 const std::string versionStr;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000192
193 /** @brief If this version is the functional one */
194 bool functional = false;
Gunnar Mills392f2942017-04-12 11:04:37 -0500195};
196
197} // namespace manager
198} // namespace software
199} // namespace phosphor