blob: e26e4eb6d0e80ca9f31da255f364ff1b1e7d6bff [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),
79 versionStr(versionString)
80 {
81 // Bind erase method
82 eraseCallback = callback;
83 // Set properties.
84 purpose(versionPurpose);
85 version(versionString);
86 path(filePath);
87 // Emit deferred signal.
88 emit_object_added();
89 }
Gunnar Mills392f2942017-04-12 11:04:37 -050090
Adriana Kobylak2285fe02018-02-27 15:36:59 -060091 /**
92 * @brief Read the manifest file to get the value of the key.
93 *
94 * @return The value of the key.
95 **/
96 static std::string getValue(const std::string& manifestFilePath,
97 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -050098
Adriana Kobylak2285fe02018-02-27 15:36:59 -060099 /**
100 * @brief Calculate the version id from the version string.
101 *
102 * @details The version id is a unique 8 hexadecimal digit id
103 * calculated from the version string.
104 *
105 * @param[in] version - The image's version string (e.g. v1.99.10-19).
106 *
107 * @return The id.
108 */
109 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500110
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600111 /**
Vijay Khemkab7c062e2019-09-18 17:15:57 -0700112 * @brief Get the active BMC machine name string.
113 *
114 * @param[in] releaseFilePath - The path to the file which contains
115 * the release machine string.
116 *
117 * @return The machine name string (e.g. romulus, tiogapass).
118 */
119 static std::string getBMCMachine(const std::string& releaseFilePath);
120
121 /**
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600122 * @brief Get the active BMC version string.
123 *
124 * @param[in] releaseFilePath - The path to the file which contains
125 * the release version string.
126 *
127 * @return The version string (e.g. v1.99.10-19).
128 */
129 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500130
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600131 /* @brief Check if this version matches the currently running version
132 *
133 * @return - Returns true if this version matches the currently running
134 * version.
135 */
136 bool isFunctional();
Eddie James6d873712017-09-01 11:29:07 -0500137
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600138 /** @brief Persistent Delete D-Bus object */
139 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500140
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600141 /** @brief The parent's erase callback. */
142 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500143
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600144 private:
145 /** @brief This Version's version string */
146 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500147};
148
149} // namespace manager
150} // namespace software
151} // namespace phosphor