blob: 831b20175e228aec21766f5b79a84955292732c1 [file] [log] [blame]
Saqib Khance148702017-06-11 12:01:58 -05001#pragma once
2
Gunnar Millsf6ed5892018-09-07 17:08:02 -05003#include "config.h"
4
Saqib Khance148702017-06-11 12:01:58 -05005#include "xyz/openbmc_project/Common/FilePath/server.hpp"
Saqib Khan7f80e0b2017-10-22 11:29:07 -05006#include "xyz/openbmc_project/Object/Delete/server.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05007#include "xyz/openbmc_project/Software/Version/server.hpp"
8
9#include <sdbusplus/bus.hpp>
Saqib Khance148702017-06-11 12:01:58 -050010
11namespace openpower
12{
13namespace software
14{
15namespace updater
16{
17
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050018class ItemUpdater;
19
Saqib Khan7f80e0b2017-10-22 11:29:07 -050020typedef std::function<void(std::string)> eraseFunc;
21
Saqib Khance148702017-06-11 12:01:58 -050022using VersionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060023 sdbusplus::xyz::openbmc_project::Software::server::Version,
24 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050025using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060026 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050027
28namespace sdbusRule = sdbusplus::bus::match::rules;
29
30class Delete;
31class Version;
32
33/** @class Delete
34 * @brief OpenBMC Delete implementation.
35 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
36 * D-Bus API.
Adriana Kobylak70dcb632018-02-27 15:46:52 -060037 */
Saqib Khan7f80e0b2017-10-22 11:29:07 -050038class Delete : public DeleteInherit
39{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060040 public:
41 /** @brief Constructs Delete.
42 *
43 * @param[in] bus - The D-Bus bus object
44 * @param[in] path - The D-Bus object path
45 * @param[in] parent - Parent object.
46 */
47 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
48 DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus),
49 path(path)
50 {
51 std::vector<std::string> interfaces({interface});
52 bus.emit_interfaces_added(path.c_str(), interfaces);
53 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -050054
Adriana Kobylak70dcb632018-02-27 15:46:52 -060055 ~Delete()
56 {
57 std::vector<std::string> interfaces({interface});
58 bus.emit_interfaces_removed(path.c_str(), interfaces);
59 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -050060
Adriana Kobylak70dcb632018-02-27 15:46:52 -060061 /**
62 * @brief Delete the D-Bus object.
63 * Overrides the default delete function by calling
64 * Version class erase Method.
65 **/
66 void delete_() override;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050067
Adriana Kobylak70dcb632018-02-27 15:46:52 -060068 private:
69 /** @brief Parent Object. */
70 Version& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050071
Adriana Kobylak70dcb632018-02-27 15:46:52 -060072 // TODO Remove once openbmc/openbmc#1975 is resolved
73 static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
74 sdbusplus::bus::bus& bus;
75 std::string path;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050076};
Saqib Khance148702017-06-11 12:01:58 -050077
78/** @class Version
79 * @brief OpenBMC version software management implementation.
80 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsb78dfa52017-09-21 16:05:22 -050081 * D-Bus API.
Saqib Khance148702017-06-11 12:01:58 -050082 */
83class Version : public VersionInherit
84{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060085 public:
86 /** @brief Constructs Version Software Manager.
87 *
88 * @param[in] bus - The D-Bus bus object
89 * @param[in] objPath - The D-Bus object path
90 * @param[in] parent - Parent object.
91 * @param[in] versionId - The version Id
92 * @param[in] versionString - The version string
93 * @param[in] versionPurpose - The version purpose
94 * @param[in] filePath - The image filesystem path
95 * @param[in] callback - The eraseFunc callback
96 */
97 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
98 ItemUpdater& parent, const std::string& versionId,
99 const std::string& versionString, VersionPurpose versionPurpose,
100 const std::string& filePath, eraseFunc callback) :
101 VersionInherit(bus, (objPath).c_str(), true),
102 bus(bus), objPath(objPath), parent(parent), versionId(versionId),
103 versionStr(versionString),
104 chassisStateSignals(
105 bus,
106 sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") +
107 sdbusRule::path(CHASSIS_STATE_PATH) +
108 sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
109 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
110 std::bind(std::mem_fn(&Version::updateDeleteInterface), this,
111 std::placeholders::_1))
112 {
113 // Bind erase method
114 eraseCallback = callback;
115 // Set properties.
116 purpose(versionPurpose);
117 version(versionString);
118 path(filePath);
Saqib Khance148702017-06-11 12:01:58 -0500119
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600120 // Emit deferred signal.
121 emit_object_added();
122 }
Saqib Khan167601b2017-06-18 23:33:46 -0500123
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600124 /**
125 * @brief Update the Object.Delete interface for this activation
126 *
127 * Update the delete interface based on whether or not this
128 * activation is currently functional. A functional activation
129 * will have no Object.Delete, while a non-functional activation
130 * will have one.
131 *
132 * @param[in] msg - Data associated with subscribed signal
133 */
134 void updateDeleteInterface(sdbusplus::message::message& msg);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500135
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600136 /**
137 * @brief Read the manifest file to get the value of the key.
138 *
139 * @param[in] filePath - The path to the file which contains the value
140 * of keys.
141 * @param[in] keys - A map of keys with empty values.
142 *
143 * @return The map of keys with filled values.
144 **/
145 static std::map<std::string, std::string>
146 getValue(const std::string& filePath,
147 std::map<std::string, std::string> keys);
Saqib Khan167601b2017-06-18 23:33:46 -0500148
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600149 /**
Lei YUdec8cf92019-02-21 17:47:05 +0800150 * @brief Get version and extended version from VERSION partition string.
151 *
152 * @param[in] versionPart - The string containing the VERSION partition.
153 *
154 * @return The pair contains the version and extended version.
155 **/
156 static std::pair<std::string, std::string>
157 getVersions(const std::string& versionPart);
158
159 /**
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600160 * @brief Calculate the version id from the version string.
161 *
162 * @details The version id is a unique 8 hexadecimal digit id
163 * calculated from the version string.
164 *
165 * @param[in] version - The image version string (e.g. v1.99.10-19).
166 *
167 * @return The id.
168 */
169 static std::string getId(const std::string& version);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500170
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 /** @brief Persistent Delete D-Bus object */
172 std::unique_ptr<Delete> deleteObject;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500173
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600174 /** @brief The parent's erase callback. */
175 eraseFunc eraseCallback;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500176
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600177 private:
178 /** @brief Persistent sdbusplus DBus bus connection */
179 sdbusplus::bus::bus& bus;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500180
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600181 /** @brief Persistent DBus object path */
182 std::string objPath;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500183
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600184 /** @brief Parent Object. */
185 ItemUpdater& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500186
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600187 /** @brief This Version's version Id */
188 const std::string versionId;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500189
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600190 /** @brief This Version's version string */
191 const std::string versionStr;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500192
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600193 /** @brief Used to subscribe to chassis power state changes **/
194 sdbusplus::bus::match_t chassisStateSignals;
Saqib Khance148702017-06-11 12:01:58 -0500195};
196
197} // namespace updater
198} // namespace software
199} // namespace openpower