blob: 8a68cb5f7b1f95833f53f00219e319278b657e63 [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,
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +070082 eraseFunc callback) :
Adriana Kobylak2285fe02018-02-27 15:36:59 -060083 VersionInherit(bus, (objPath).c_str(), true),
Adriana Kobylak292159f2020-05-05 09:25:55 -050084 eraseCallback(callback), 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 *
109 * @param[in] version - The image's version string (e.g. v1.99.10-19).
110 *
111 * @return The id.
112 */
113 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500114
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600115 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700116 * @brief Get the active BMC machine name string.
117 *
118 * @param[in] releaseFilePath - The path to the file which contains
119 * the release machine string.
120 *
121 * @return The machine name string (e.g. romulus, tiogapass).
122 */
123 static std::string getBMCMachine(const std::string& releaseFilePath);
124
125 /**
Chanh Nguyen1fd6ddd2021-01-06 11:09:09 +0700126 * @brief Get the BMC Extended Version string.
127 *
128 * @param[in] releaseFilePath - The path to the file which contains
129 * the release machine string.
130 *
131 * @return The extended version string.
132 */
133 static std::string
134 getBMCExtendedVersion(const std::string& releaseFilePath);
135
136 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600137 * @brief Get the active BMC version string.
138 *
139 * @param[in] releaseFilePath - The path to the file which contains
140 * the release version string.
141 *
142 * @return The version string (e.g. v1.99.10-19).
143 */
144 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500145
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600146 /* @brief Check if this version matches the currently running version
147 *
148 * @return - Returns true if this version matches the currently running
149 * version.
150 */
151 bool isFunctional();
Eddie James6d873712017-09-01 11:29:07 -0500152
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600153 /** @brief Persistent Delete D-Bus object */
154 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500155
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600156 /** @brief The parent's erase callback. */
157 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500158
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600159 private:
160 /** @brief This Version's version string */
161 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500162};
163
164} // namespace manager
165} // namespace software
166} // namespace phosphor