blob: 75d9f8bb45f487d7a0158c3352fabc0722a92026 [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<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060019 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<
Adriana Kobylak2285fe02018-02-27 15:36:59 -060022 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khanee13e832017-10-23 12:53:11 -050023
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{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060034 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, const std::string& path, Version& parent) :
42 DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus),
43 path(path)
44 {
45 std::vector<std::string> interfaces({interface});
46 bus.emit_interfaces_added(path.c_str(), interfaces);
47 }
Saqib Khanee13e832017-10-23 12:53:11 -050048
Adriana Kobylak2285fe02018-02-27 15:36:59 -060049 ~Delete()
50 {
51 std::vector<std::string> interfaces({interface});
52 bus.emit_interfaces_removed(path.c_str(), interfaces);
53 }
Saqib Khanee13e832017-10-23 12:53:11 -050054
Adriana Kobylak2285fe02018-02-27 15:36:59 -060055 /** @brief delete the D-Bus object. */
56 void delete_() override;
Saqib Khanee13e832017-10-23 12:53:11 -050057
Adriana Kobylak2285fe02018-02-27 15:36:59 -060058 private:
59 /** @brief Parent Object. */
60 Version& parent;
Saqib Khanee13e832017-10-23 12:53:11 -050061
Adriana Kobylak2285fe02018-02-27 15:36:59 -060062 // TODO Remove once openbmc/openbmc#1975 is resolved
63 static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
64 sdbusplus::bus::bus& bus;
65 std::string path;
Saqib Khanee13e832017-10-23 12:53:11 -050066};
Gunnar Mills392f2942017-04-12 11:04:37 -050067
68/** @class Version
69 * @brief OpenBMC version software management implementation.
70 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050071 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050072 */
73class Version : public VersionInherit
74{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060075 public:
76 /** @brief Constructs Version Software Manager
77 *
78 * @param[in] bus - The D-Bus bus object
79 * @param[in] objPath - The D-Bus object path
80 * @param[in] versionString - The version string
81 * @param[in] versionPurpose - The version purpose
82 * @param[in] filePath - The image filesystem path
83 * @param[in] callback - The eraseFunc callback
84 */
85 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
86 const std::string& versionString, VersionPurpose versionPurpose,
87 const std::string& filePath, eraseFunc callback) :
88 VersionInherit(bus, (objPath).c_str(), true),
89 versionStr(versionString)
90 {
91 // Bind erase method
92 eraseCallback = callback;
93 // Set properties.
94 purpose(versionPurpose);
95 version(versionString);
96 path(filePath);
97 // Emit deferred signal.
98 emit_object_added();
99 }
Gunnar Mills392f2942017-04-12 11:04:37 -0500100
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600101 /**
102 * @brief Read the manifest file to get the value of the key.
103 *
104 * @return The value of the key.
105 **/
106 static std::string getValue(const std::string& manifestFilePath,
107 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -0500108
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600109 /**
110 * @brief Calculate the version id from the version string.
111 *
112 * @details The version id is a unique 8 hexadecimal digit id
113 * calculated from the version string.
114 *
115 * @param[in] version - The image's version string (e.g. v1.99.10-19).
116 *
117 * @return The id.
118 */
119 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -0500120
Adriana Kobylak2285fe02018-02-27 15:36:59 -0600121 /**
122 * @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