blob: b6f91720329bd2efc160e7c0d726004284e27a89 [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
Gunnar Mills392f2942017-04-12 11:04:37 -050024using VersionInherit = sdbusplus::server::object::object<
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070025 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Adriana Kobylak2285fe02018-02-27 15:36:59 -060026 sdbusplus::xyz::openbmc_project::Software::server::Version,
Justin Ledford054bb0b2022-03-15 15:46:58 -070027 sdbusplus::xyz::openbmc_project::Common::server::FilePath,
28 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Compatible>;
Saqib Khanee13e832017-10-23 12:53:11 -050029using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060030 sdbusplus::xyz::openbmc_project::Object::server::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 */
49 Delete(sdbusplus::bus::bus& 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 */
83 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
84 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) :
Adriana Kobylak2285fe02018-02-27 15:36:59 -060088 VersionInherit(bus, (objPath).c_str(), true),
Adriana Kobylak59b640b2022-01-21 19:45:22 +000089 eraseCallback(callback), id(id), versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060090 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060091 // Set properties.
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070092 extendedVersion(extVersion);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060093 purpose(versionPurpose);
94 version(versionString);
95 path(filePath);
Justin Ledford054bb0b2022-03-15 15:46:58 -070096 names(compatibleNames);
Adriana Kobylak2285fe02018-02-27 15:36:59 -060097 // Emit deferred signal.
98 emit_object_added();
99 }
Gunnar Mills392f2942017-04-12 11:04:37 -0500100
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600101 /**
102 * @brief Read the manifest file to get the value of the key.
103 *
104 * @return The value of the key.
105 **/
106 static std::string getValue(const std::string& manifestFilePath,
107 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500108
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600109 /**
Justin Ledford054bb0b2022-03-15 15:46:58 -0700110 * @brief Read the manifest file to get the values of the repeated key.
111 *
112 * @return The values of the repeated key.
113 **/
114 static std::vector<std::string>
115 getRepeatedValues(const std::string& manifestFilePath, std::string key);
116
117 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600118 * @brief Calculate the version id from the version string.
119 *
120 * @details The version id is a unique 8 hexadecimal digit id
121 * calculated from the version string.
122 *
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000123 * @param[in] versionWithSalt - The image's version string
124 * (e.g. v1.99.10-19) plus an optional salt
125 * string.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600126 *
127 * @return The id.
128 */
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000129 static std::string getId(const std::string& versionWithSalt);
Gunnar Millscebd1022017-04-17 16:10:15 -0500130
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600131 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700132 * @brief Get the active BMC machine name string.
133 *
134 * @param[in] releaseFilePath - The path to the file which contains
135 * the release machine string.
136 *
137 * @return The machine name string (e.g. romulus, tiogapass).
138 */
139 static std::string getBMCMachine(const std::string& releaseFilePath);
140
141 /**
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700142 * @brief Get the BMC Extended Version string.
143 *
144 * @param[in] releaseFilePath - The path to the file which contains
145 * the release machine string.
146 *
147 * @return The extended version string.
148 */
149 static std::string
150 getBMCExtendedVersion(const std::string& releaseFilePath);
151
152 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600153 * @brief Get the active BMC version string.
154 *
155 * @param[in] releaseFilePath - The path to the file which contains
156 * the release version string.
157 *
158 * @return The version string (e.g. v1.99.10-19).
159 */
160 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500161
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000162 /* @brief Check if this version is functional.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600163 *
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000164 * @return - Returns the functional value.
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600165 */
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000166 bool isFunctional() const
167 {
168 return functional;
169 }
170
171 /** @brief Set the functional value.
172 * @param[in] value - True or False
173 */
174 void setFunctional(bool value)
175 {
176 functional = value;
177 }
Eddie James6d873712017-09-01 11:29:07 -0500178
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600179 /** @brief Persistent Delete D-Bus object */
180 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500181
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600182 /** @brief The parent's erase callback. */
183 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500184
Adriana Kobylak59b640b2022-01-21 19:45:22 +0000185 /** @brief The version ID of the object */
186 const std::string id;
187
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600188 private:
189 /** @brief This Version's version string */
190 const std::string versionStr;
Adriana Kobylak1e81f232022-01-18 22:28:47 +0000191
192 /** @brief If this version is the functional one */
193 bool functional = false;
Gunnar Mills392f2942017-04-12 11:04:37 -0500194};
195
196} // namespace manager
197} // namespace software
198} // namespace phosphor