blob: b7efe44cc5037771a001c416a1b34e71d62b9d9d [file] [log] [blame]
Gunnar Mills392f2942017-04-12 11:04:37 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/Software/Version/server.hpp"
Gunnar Millsef4781f2017-04-19 11:28:24 -05005#include "xyz/openbmc_project/Common/FilePath/server.hpp"
Saqib Khanee13e832017-10-23 12:53:11 -05006#include "xyz/openbmc_project/Object/Delete/server.hpp"
Leonel Gonzaleze4233682017-07-07 14:38:25 -05007#include <functional>
Gunnar Mills392f2942017-04-12 11:04:37 -05008
9namespace phosphor
10{
11namespace software
12{
13namespace manager
14{
15
Leonel Gonzaleze4233682017-07-07 14:38:25 -050016typedef std::function<void(std::string)> eraseFunc;
17
Gunnar Mills392f2942017-04-12 11:04:37 -050018using VersionInherit = sdbusplus::server::object::object<
Gunnar Millsa4fcb682017-10-06 13:14:12 -050019 sdbusplus::xyz::openbmc_project::Software::server::Version,
20 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khanee13e832017-10-23 12:53:11 -050021using DeleteInherit = sdbusplus::server::object::object<
22 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
23
24class Version;
25class Delete;
26
27/** @class Delete
28 * @brief OpenBMC Delete implementation.
29 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
30 * D-Bus API.
31 */
32class Delete : public DeleteInherit
33{
34 public:
35 /** @brief Constructs Delete.
36 *
37 * @param[in] bus - The D-Bus bus object
38 * @param[in] path - The D-Bus object path
39 * @param[in] parent - Parent object.
40 */
41 Delete(sdbusplus::bus::bus& bus,
42 const std::string& path,
43 Version& parent) :
44 DeleteInherit(bus, path.c_str(), true),
45 parent(parent),
46 bus(bus),
47 path(path)
48 {
49 std::vector<std::string> interfaces({interface});
50 bus.emit_interfaces_added(path.c_str(), interfaces);
51 }
52
53 ~Delete()
54 {
55 std::vector<std::string> interfaces({interface});
56 bus.emit_interfaces_removed(path.c_str(), interfaces);
57 }
58
59 /** @brief delete the D-Bus object. */
60 void delete_() override;
61
62 private:
63
64 /** @brief Parent Object. */
65 Version& parent;
66
67 // TODO Remove once openbmc/openbmc#1975 is resolved
68 static constexpr auto interface =
69 "xyz.openbmc_project.Object.Delete";
70 sdbusplus::bus::bus& bus;
71 std::string path;
72};
Gunnar Mills392f2942017-04-12 11:04:37 -050073
74/** @class Version
75 * @brief OpenBMC version software management implementation.
76 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050077 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050078 */
79class Version : public VersionInherit
80{
81 public:
82 /** @brief Constructs Version Software Manager
83 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -050084 * @param[in] bus - The D-Bus bus object
85 * @param[in] objPath - The D-Bus object path
86 * @param[in] versionString - The version string
Gunnar Millscebd1022017-04-17 16:10:15 -050087 * @param[in] versionPurpose - The version purpose
Gunnar Millsef4781f2017-04-19 11:28:24 -050088 * @param[in] filePath - The image filesystem path
Saqib Khanee13e832017-10-23 12:53:11 -050089 * @param[in] callback - The eraseFunc callback
Gunnar Mills392f2942017-04-12 11:04:37 -050090 */
91 Version(sdbusplus::bus::bus& bus,
92 const std::string& objPath,
Gunnar Millsa4fcb682017-10-06 13:14:12 -050093 const std::string& versionString,
Gunnar Millsef4781f2017-04-19 11:28:24 -050094 VersionPurpose versionPurpose,
Saqib Khanee13e832017-10-23 12:53:11 -050095 const std::string& filePath,
96 eraseFunc callback) : VersionInherit(
Gunnar Millsa4fcb682017-10-06 13:14:12 -050097 bus, (objPath).c_str(), true),
98 versionStr(versionString)
Gunnar Mills392f2942017-04-12 11:04:37 -050099 {
Saqib Khanee13e832017-10-23 12:53:11 -0500100 // Bind erase method
101 eraseCallback = callback;
Gunnar Mills392f2942017-04-12 11:04:37 -0500102 // Set properties.
Gunnar Millscebd1022017-04-17 16:10:15 -0500103 purpose(versionPurpose);
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500104 version(versionString);
Gunnar Millsef4781f2017-04-19 11:28:24 -0500105 path(filePath);
Gunnar Mills392f2942017-04-12 11:04:37 -0500106 // Emit deferred signal.
107 emit_object_added();
108 }
109
110 /**
Gunnar Millscebd1022017-04-17 16:10:15 -0500111 * @brief Read the manifest file to get the value of the key.
Gunnar Mills392f2942017-04-12 11:04:37 -0500112 *
Gunnar Millscebd1022017-04-17 16:10:15 -0500113 * @return The value of the key.
Gunnar Mills392f2942017-04-12 11:04:37 -0500114 **/
Gunnar Millscebd1022017-04-17 16:10:15 -0500115 static std::string getValue(const std::string& manifestFilePath,
116 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500117
118 /**
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500119 * @brief Calculate the version id from the version string.
120 *
121 * @details The version id is a unique 8 hexadecimal digit id
122 * calculated from the version string.
123 *
124 * @param[in] version - The image's version string (e.g. v1.99.10-19).
Gunnar Mills392f2942017-04-12 11:04:37 -0500125 *
126 * @return The id.
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500127 */
Gunnar Mills392f2942017-04-12 11:04:37 -0500128 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500129
Saqib Khanba239882017-05-26 08:41:54 -0500130 /**
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500131 * @brief Get the active BMC version string.
Saqib Khanba239882017-05-26 08:41:54 -0500132 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500133 * @param[in] releaseFilePath - The path to the file which contains
134 * the release version string.
Saqib Khan1eef62d2017-08-10 15:29:34 -0500135 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -0500136 * @return The version string (e.g. v1.99.10-19).
Saqib Khanba239882017-05-26 08:41:54 -0500137 */
Saqib Khan1eef62d2017-08-10 15:29:34 -0500138 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -0500139
140 /* @brief Check if this version matches the currently running version
141 *
142 * @return - Returns true if this version matches the currently running
143 * version.
144 */
145 bool isFunctional();
146
Saqib Khanee13e832017-10-23 12:53:11 -0500147 /** @brief Persistent Delete D-Bus object */
148 std::unique_ptr<Delete> deleteObject;
149
150 /** @brief The parent's erase callback. */
151 eraseFunc eraseCallback;
152
Eddie James6d873712017-09-01 11:29:07 -0500153 private:
Saqib Khanee13e832017-10-23 12:53:11 -0500154
Eddie James6d873712017-09-01 11:29:07 -0500155 /** @brief This Version's version string */
156 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -0500157};
158
159} // namespace manager
160} // namespace software
161} // namespace phosphor