blob: f04cce261386adf1781ff028678e190725230678 [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>
Gunnar Mills392f2942017-04-12 11:04:37 -05009
10namespace phosphor
11{
12namespace software
13{
14namespace manager
15{
16
Leonel Gonzaleze4233682017-07-07 14:38:25 -050017typedef std::function<void(std::string)> eraseFunc;
18
Gunnar Mills392f2942017-04-12 11:04:37 -050019using VersionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060020 sdbusplus::xyz::openbmc_project::Software::server::Version,
21 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khanee13e832017-10-23 12:53:11 -050022using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060023 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050024
25class Version;
26class Delete;
27
28/** @class Delete
29 * @brief OpenBMC Delete implementation.
30 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
31 * D-Bus API.
32 */
33class Delete : public DeleteInherit
34{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060035 public:
36 /** @brief Constructs Delete.
37 *
38 * @param[in] bus - The D-Bus bus object
39 * @param[in] path - The D-Bus object path
40 * @param[in] parent - Parent object.
41 */
42 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
Lei YU29d84b02020-02-13 15:13:09 +080043 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
44 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060045 {
Lei YU29d84b02020-02-13 15:13:09 +080046 // Empty
Adriana Kobylak2285fe02018-02-27 15:36:59 -060047 }
Saqib Khanee13e832017-10-23 12:53:11 -050048
Adriana Kobylak2285fe02018-02-27 15:36:59 -060049 /** @brief delete the D-Bus object. */
50 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050051
Adriana Kobylak2285fe02018-02-27 15:36:59 -060052 private:
53 /** @brief Parent Object. */
54 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050055};
Gunnar Mills392f2942017-04-12 11:04:37 -050056
57/** @class Version
58 * @brief OpenBMC version software management implementation.
59 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050060 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050061 */
62class Version : public VersionInherit
63{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060064 public:
65 /** @brief Constructs Version Software Manager
66 *
67 * @param[in] bus - The D-Bus bus object
68 * @param[in] objPath - The D-Bus object path
69 * @param[in] versionString - The version string
70 * @param[in] versionPurpose - The version purpose
71 * @param[in] filePath - The image filesystem path
72 * @param[in] callback - The eraseFunc callback
73 */
74 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
75 const std::string& versionString, VersionPurpose versionPurpose,
76 const std::string& filePath, eraseFunc callback) :
77 VersionInherit(bus, (objPath).c_str(), true),
78 versionStr(versionString)
79 {
80 // Bind erase method
81 eraseCallback = callback;
82 // Set properties.
83 purpose(versionPurpose);
84 version(versionString);
85 path(filePath);
86 // Emit deferred signal.
87 emit_object_added();
88 }
Gunnar Mills392f2942017-04-12 11:04:37 -050089
Adriana Kobylak2285fe02018-02-27 15:36:59 -060090 /**
91 * @brief Read the manifest file to get the value of the key.
92 *
93 * @return The value of the key.
94 **/
95 static std::string getValue(const std::string& manifestFilePath,
96 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -050097
Adriana Kobylak2285fe02018-02-27 15:36:59 -060098 /**
99 * @brief Calculate the version id from the version string.
100 *
101 * @details The version id is a unique 8 hexadecimal digit id
102 * calculated from the version string.
103 *
104 * @param[in] version - The image's version string (e.g. v1.99.10-19).
105 *
106 * @return The id.
107 */
108 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500109
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600110 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700111 * @brief Get the active BMC machine name string.
112 *
113 * @param[in] releaseFilePath - The path to the file which contains
114 * the release machine string.
115 *
116 * @return The machine name string (e.g. romulus, tiogapass).
117 */
118 static std::string getBMCMachine(const std::string& releaseFilePath);
119
120 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600121 * @brief Get the active BMC version string.
122 *
123 * @param[in] releaseFilePath - The path to the file which contains
124 * the release version string.
125 *
126 * @return The version string (e.g. v1.99.10-19).
127 */
128 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500129
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600130 /* @brief Check if this version matches the currently running version
131 *
132 * @return - Returns true if this version matches the currently running
133 * version.
134 */
135 bool isFunctional();
Eddie James6d873712017-09-01 11:29:07 -0500136
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600137 /** @brief Persistent Delete D-Bus object */
138 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500139
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600140 /** @brief The parent's erase callback. */
141 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500142
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600143 private:
144 /** @brief This Version's version string */
145 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500146};
147
148} // namespace manager
149} // namespace software
150} // namespace phosphor