blob: 9cf76daa890920c9455abfbc1a16d06fa407a921 [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
Gunnar Millsb0ce9962018-09-07 13:39:10 -05007#include <sdbusplus/bus.hpp>
Adriana Kobylak58aa7502020-06-08 11:12:11 -05008
9#include <functional>
Andrew Geissler9155b712020-05-16 13:04:44 -050010#include <string>
Gunnar Mills392f2942017-04-12 11:04:37 -050011
12namespace phosphor
13{
14namespace software
15{
16namespace manager
17{
18
Leonel Gonzaleze4233682017-07-07 14:38:25 -050019typedef std::function<void(std::string)> eraseFunc;
20
Gunnar Mills392f2942017-04-12 11:04:37 -050021using VersionInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060022 sdbusplus::xyz::openbmc_project::Software::server::Version,
23 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khanee13e832017-10-23 12:53:11 -050024using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060025 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050026
27class Version;
28class Delete;
29
30/** @class Delete
31 * @brief OpenBMC Delete implementation.
32 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
33 * D-Bus API.
34 */
35class Delete : public DeleteInherit
36{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060037 public:
38 /** @brief Constructs Delete.
39 *
40 * @param[in] bus - The D-Bus bus object
41 * @param[in] path - The D-Bus object path
42 * @param[in] parent - Parent object.
43 */
44 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
Lei YU29d84b02020-02-13 15:13:09 +080045 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
46 parent(parent)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060047 {
Lei YU29d84b02020-02-13 15:13:09 +080048 // Empty
Adriana Kobylak2285fe02018-02-27 15:36:59 -060049 }
Saqib Khanee13e832017-10-23 12:53:11 -050050
Adriana Kobylak2285fe02018-02-27 15:36:59 -060051 /** @brief delete the D-Bus object. */
52 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050053
Adriana Kobylak2285fe02018-02-27 15:36:59 -060054 private:
55 /** @brief Parent Object. */
56 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050057};
Gunnar Mills392f2942017-04-12 11:04:37 -050058
59/** @class Version
60 * @brief OpenBMC version software management implementation.
61 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050062 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050063 */
64class Version : public VersionInherit
65{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060066 public:
67 /** @brief Constructs Version Software Manager
68 *
69 * @param[in] bus - The D-Bus bus object
70 * @param[in] objPath - The D-Bus object path
71 * @param[in] versionString - The version string
72 * @param[in] versionPurpose - The version purpose
73 * @param[in] filePath - The image filesystem path
74 * @param[in] callback - The eraseFunc callback
75 */
76 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
77 const std::string& versionString, VersionPurpose versionPurpose,
78 const std::string& filePath, eraseFunc callback) :
79 VersionInherit(bus, (objPath).c_str(), true),
Adriana Kobylak292159f2020-05-05 09:25:55 -050080 eraseCallback(callback), versionStr(versionString)
Adriana Kobylak2285fe02018-02-27 15:36:59 -060081 {
Adriana Kobylak2285fe02018-02-27 15:36:59 -060082 // 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