blob: ef0eef3b84683187c5e5c6a3240fc189c1abca7c [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) :
43 DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus),
44 path(path)
45 {
46 std::vector<std::string> interfaces({interface});
47 bus.emit_interfaces_added(path.c_str(), interfaces);
48 }
Saqib Khanee13e832017-10-23 12:53:11 -050049
Adriana Kobylak2285fe02018-02-27 15:36:59 -060050 ~Delete()
51 {
52 std::vector<std::string> interfaces({interface});
53 bus.emit_interfaces_removed(path.c_str(), interfaces);
54 }
Saqib Khanee13e832017-10-23 12:53:11 -050055
Adriana Kobylak2285fe02018-02-27 15:36:59 -060056 /** @brief delete the D-Bus object. */
57 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050058
Adriana Kobylak2285fe02018-02-27 15:36:59 -060059 private:
60 /** @brief Parent Object. */
61 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050062
Adriana Kobylak2285fe02018-02-27 15:36:59 -060063 // TODO Remove once openbmc/openbmc#1975 is resolved
64 static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
65 sdbusplus::bus::bus& bus;
66 std::string path;
Saqib Khanee13e832017-10-23 12:53:11 -050067};
Gunnar Mills392f2942017-04-12 11:04:37 -050068
69/** @class Version
70 * @brief OpenBMC version software management implementation.
71 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050072 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050073 */
74class Version : public VersionInherit
75{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060076 public:
77 /** @brief Constructs Version Software Manager
78 *
79 * @param[in] bus - The D-Bus bus object
80 * @param[in] objPath - The D-Bus object path
81 * @param[in] versionString - The version string
82 * @param[in] versionPurpose - The version purpose
83 * @param[in] filePath - The image filesystem path
84 * @param[in] callback - The eraseFunc callback
85 */
86 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
87 const std::string& versionString, VersionPurpose versionPurpose,
88 const std::string& filePath, eraseFunc callback) :
89 VersionInherit(bus, (objPath).c_str(), true),
90 versionStr(versionString)
91 {
92 // Bind erase method
93 eraseCallback = callback;
94 // Set properties.
95 purpose(versionPurpose);
96 version(versionString);
97 path(filePath);
98 // Emit deferred signal.
99 emit_object_added();
100 }
Gunnar Mills392f2942017-04-12 11:04:37 -0500101
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600102 /**
103 * @brief Read the manifest file to get the value of the key.
104 *
105 * @return The value of the key.
106 **/
107 static std::string getValue(const std::string& manifestFilePath,
108 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500109
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600110 /**
111 * @brief Calculate the version id from the version string.
112 *
113 * @details The version id is a unique 8 hexadecimal digit id
114 * calculated from the version string.
115 *
116 * @param[in] version - The image's version string (e.g. v1.99.10-19).
117 *
118 * @return The id.
119 */
120 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500121
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600122 /**
123 * @brief Get the active BMC version string.
124 *
125 * @param[in] releaseFilePath - The path to the file which contains
126 * the release version string.
127 *
128 * @return The version string (e.g. v1.99.10-19).
129 */
130 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500131
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600132 /* @brief Check if this version matches the currently running version
133 *
134 * @return - Returns true if this version matches the currently running
135 * version.
136 */
137 bool isFunctional();
Eddie James6d873712017-09-01 11:29:07 -0500138
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600139 /** @brief Persistent Delete D-Bus object */
140 std::unique_ptr<Delete> deleteObject;
Saqib Khanee13e832017-10-23 12:53:11 -0500141
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600142 /** @brief The parent's erase callback. */
143 eraseFunc eraseCallback;
Saqib Khanee13e832017-10-23 12:53:11 -0500144
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600145 private:
146 /** @brief This Version's version string */
147 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500148};
149
150} // namespace manager
151} // namespace software
152} // namespace phosphor