blob: 5827c8a9ca0927e3bf8b26fe6181291edb95648b [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"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05005#include "xyz/openbmc_project/Software/Version/server.hpp"
6
Leonel Gonzaleze4233682017-07-07 14:38:25 -05007#include <functional>
Gunnar Millsb0ce9962018-09-07 13:39:10 -05008#include <sdbusplus/bus.hpp>
Andrew Geissler9155b712020-05-16 13:04:44 -05009#include <string>
Gunnar Mills392f2942017-04-12 11:04:37 -050010
11namespace phosphor
12{
13namespace software
14{
15namespace manager
16{
17
Leonel Gonzaleze4233682017-07-07 14:38:25 -050018typedef std::function<void(std::string)> eraseFunc;
19
Gunnar Mills392f2942017-04-12 11:04:37 -050020using VersionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060021 sdbusplus::xyz::openbmc_project::Software::server::Version,
22 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khanee13e832017-10-23 12:53:11 -050023using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060024 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050025
26class Version;
27class Delete;
28
29/** @class Delete
30 * @brief OpenBMC Delete implementation.
31 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
32 * D-Bus API.
33 */
34class Delete : public DeleteInherit
35{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060036 public:
37 /** @brief Constructs Delete.
38 *
39 * @param[in] bus - The D-Bus bus object
40 * @param[in] path - The D-Bus object path
41 * @param[in] parent - Parent object.
42 */
43 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
Lei YU29d84b02020-02-13 15:13:09 +080044 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
45 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060046 {
Lei YU29d84b02020-02-13 15:13:09 +080047 // Empty
Adriana Kobylak2285fe02018-02-27 15:36:59 -060048 }
Saqib Khanee13e832017-10-23 12:53:11 -050049
Adriana Kobylak2285fe02018-02-27 15:36:59 -060050 /** @brief delete the D-Bus object. */
51 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050052
Adriana Kobylak2285fe02018-02-27 15:36:59 -060053 private:
54 /** @brief Parent Object. */
55 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050056};
Gunnar Mills392f2942017-04-12 11:04:37 -050057
58/** @class Version
59 * @brief OpenBMC version software management implementation.
60 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050061 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050062 */
63class Version : public VersionInherit
64{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060065 public:
66 /** @brief Constructs Version Software Manager
67 *
68 * @param[in] bus - The D-Bus bus object
69 * @param[in] objPath - The D-Bus object path
70 * @param[in] versionString - The version string
71 * @param[in] versionPurpose - The version purpose
72 * @param[in] filePath - The image filesystem path
73 * @param[in] callback - The eraseFunc callback
74 */
75 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
76 const std::string& versionString, VersionPurpose versionPurpose,
77 const std::string& filePath, eraseFunc callback) :
78 VersionInherit(bus, (objPath).c_str(), true),
Adriana Kobylak292159f2020-05-05 09:25:55 -050079 eraseCallback(callback), versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060080 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060081 // Set properties.
82 purpose(versionPurpose);
83 version(versionString);
84 path(filePath);
85 // Emit deferred signal.
86 emit_object_added();
87 }
Gunnar Mills392f2942017-04-12 11:04:37 -050088
Adriana Kobylak2285fe02018-02-27 15:36:59 -060089 /**
90 * @brief Read the manifest file to get the value of the key.
91 *
92 * @return The value of the key.
93 **/
94 static std::string getValue(const std::string& manifestFilePath,
95 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -050096
Adriana Kobylak2285fe02018-02-27 15:36:59 -060097 /**
98 * @brief Calculate the version id from the version string.
99 *
100 * @details The version id is a unique 8 hexadecimal digit id
101 * calculated from the version string.
102 *
103 * @param[in] version - The image's version string (e.g. v1.99.10-19).
104 *
105 * @return The id.
106 */
107 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500108
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600109 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700110 * @brief Get the active BMC machine name string.
111 *
112 * @param[in] releaseFilePath - The path to the file which contains
113 * the release machine string.
114 *
115 * @return The machine name string (e.g. romulus, tiogapass).
116 */
117 static std::string getBMCMachine(const std::string& releaseFilePath);
118
119 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600120 * @brief Get the active BMC version string.
121 *
122 * @param[in] releaseFilePath - The path to the file which contains
123 * the release version string.
124 *
125 * @return The version string (e.g. v1.99.10-19).
126 */
127 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500128
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600129 /* @brief Check if this version matches the currently running version
130 *
131 * @return - Returns true if this version matches the currently running
132 * version.
133 */
134 bool isFunctional();
Eddie James6d873712017-09-01 11:29:07 -0500135
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600136 /** @brief Persistent Delete D-Bus object */
137 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500138
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600139 /** @brief The parent's erase callback. */
140 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500141
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600142 private:
143 /** @brief This Version's version string */
144 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500145};
146
147} // namespace manager
148} // namespace software
149} // namespace phosphor