blob: 13b42ea37b1a109e989ef33994d3f277f678dfcb [file] [log] [blame]
Saqib Khance148702017-06-11 12:01:58 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/Software/Version/server.hpp"
5#include "xyz/openbmc_project/Common/FilePath/server.hpp"
Saqib Khan7f80e0b2017-10-22 11:29:07 -05006#include "xyz/openbmc_project/Object/Delete/server.hpp"
7#include "config.h"
Saqib Khance148702017-06-11 12:01:58 -05008
9namespace openpower
10{
11namespace software
12{
13namespace updater
14{
15
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050016class ItemUpdater;
17
Saqib Khan7f80e0b2017-10-22 11:29:07 -050018typedef std::function<void(std::string)> eraseFunc;
19
Saqib Khance148702017-06-11 12:01:58 -050020using VersionInherit = sdbusplus::server::object::object<
Gunnar Millsb78dfa52017-09-21 16:05:22 -050021 sdbusplus::xyz::openbmc_project::Software::server::Version,
Gunnar Millsb78dfa52017-09-21 16:05:22 -050022 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050023using DeleteInherit = sdbusplus::server::object::object<
24 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
25
26namespace sdbusRule = sdbusplus::bus::match::rules;
27
28class Delete;
29class Version;
30
31/** @class Delete
32 * @brief OpenBMC Delete implementation.
33 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
34 * D-Bus API.
35*/
36class Delete : public DeleteInherit
37{
38 public:
39 /** @brief Constructs Delete.
40 *
41 * @param[in] bus - The D-Bus bus object
42 * @param[in] path - The D-Bus object path
43 * @param[in] parent - Parent object.
44 */
45 Delete(sdbusplus::bus::bus& bus,
46 const std::string& path,
47 Version& parent) :
48 DeleteInherit(bus, path.c_str(), true),
49 parent(parent),
50 bus(bus),
51 path(path)
52 {
53 std::vector<std::string> interfaces({interface});
54 bus.emit_interfaces_added(path.c_str(), interfaces);
55 }
56
57 ~Delete()
58 {
59 std::vector<std::string> interfaces({interface});
60 bus.emit_interfaces_removed(path.c_str(), interfaces);
61 }
62
63 /**
64 * @brief Delete the D-Bus object.
65 * Overrides the default delete function by calling
66 * Version class erase Method.
67 **/
68 void delete_() override;
69
70 private:
71
72 /** @brief Parent Object. */
73 Version& parent;
74
75 // TODO Remove once openbmc/openbmc#1975 is resolved
76 static constexpr auto interface =
77 "xyz.openbmc_project.Object.Delete";
78 sdbusplus::bus::bus& bus;
79 std::string path;
80};
Saqib Khance148702017-06-11 12:01:58 -050081
82/** @class Version
83 * @brief OpenBMC version software management implementation.
84 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsb78dfa52017-09-21 16:05:22 -050085 * D-Bus API.
Saqib Khance148702017-06-11 12:01:58 -050086 */
87class Version : public VersionInherit
88{
89 public:
90 /** @brief Constructs Version Software Manager.
91 *
Gunnar Millsb78dfa52017-09-21 16:05:22 -050092 * @param[in] bus - The D-Bus bus object
93 * @param[in] objPath - The D-Bus object path
Saqib Khan7f80e0b2017-10-22 11:29:07 -050094 * @param[in] parent - Parent object.
95 * @param[in] versionId - The version Id
Gunnar Millsb78dfa52017-09-21 16:05:22 -050096 * @param[in] versionString - The version string
Saqib Khance148702017-06-11 12:01:58 -050097 * @param[in] versionPurpose - The version purpose
98 * @param[in] filePath - The image filesystem path
Saqib Khan7f80e0b2017-10-22 11:29:07 -050099 * @param[in] callback - The eraseFunc callback
Saqib Khance148702017-06-11 12:01:58 -0500100 */
101 Version(sdbusplus::bus::bus& bus,
102 const std::string& objPath,
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500103 ItemUpdater& parent,
104 const std::string& versionId,
Gunnar Millsb78dfa52017-09-21 16:05:22 -0500105 const std::string& versionString,
Saqib Khance148702017-06-11 12:01:58 -0500106 VersionPurpose versionPurpose,
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500107 const std::string& filePath, eraseFunc callback) :
108 VersionInherit(bus, (objPath).c_str(), true),
109 bus(bus),
110 objPath(objPath),
111 parent(parent),
112 versionId(versionId),
113 versionStr(versionString),
114 chassisStateSignals(
115 bus,
116 sdbusRule::type::signal() +
117 sdbusRule::member("PropertiesChanged") +
118 sdbusRule::path(CHASSIS_STATE_PATH) +
119 sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
120 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
121 std::bind(std::mem_fn(
122 &Version::updateDeleteInterface), this,
123 std::placeholders::_1))
Saqib Khance148702017-06-11 12:01:58 -0500124 {
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500125 // Bind erase method
126 eraseCallback = callback;
Saqib Khance148702017-06-11 12:01:58 -0500127 // Set properties.
128 purpose(versionPurpose);
Gunnar Millsb78dfa52017-09-21 16:05:22 -0500129 version(versionString);
Saqib Khance148702017-06-11 12:01:58 -0500130 path(filePath);
131
132 // Emit deferred signal.
133 emit_object_added();
134 }
Saqib Khan167601b2017-06-18 23:33:46 -0500135
136 /**
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500137 * @brief Update the Object.Delete interface for this activation
138 *
139 * Update the delete interface based on whether or not this
140 * activation is currently functional. A functional activation
141 * will have no Object.Delete, while a non-functional activation
142 * will have one.
143 *
144 * @param[in] msg - Data associated with subscribed signal
145 */
146 void updateDeleteInterface(sdbusplus::message::message& msg);
147
148 /**
Saqib Khan167601b2017-06-18 23:33:46 -0500149 * @brief Read the manifest file to get the value of the key.
150 *
Gunnar Millsb78dfa52017-09-21 16:05:22 -0500151 * @param[in] filePath - The path to the file which contains the value
Saqib Khan167601b2017-06-18 23:33:46 -0500152 * of keys.
153 * @param[in] keys - A map of keys with empty values.
154 *
155 * @return The map of keys with filled values.
156 **/
157 static std::map<std::string, std::string> getValue(
158 const std::string& filePath,
159 std::map<std::string, std::string> keys);
160
161 /**
Gunnar Millsb78dfa52017-09-21 16:05:22 -0500162 * @brief Calculate the version id from the version string.
Saqib Khan167601b2017-06-18 23:33:46 -0500163 *
Gunnar Millsb78dfa52017-09-21 16:05:22 -0500164 * @details The version id is a unique 8 hexadecimal digit id
165 * calculated from the version string.
166 *
167 * @param[in] version - The image version string (e.g. v1.99.10-19).
Saqib Khan167601b2017-06-18 23:33:46 -0500168 *
169 * @return The id.
170 */
171 static std::string getId(const std::string& version);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500172
173 /** @brief Persistent Delete D-Bus object */
174 std::unique_ptr<Delete> deleteObject;
175
176 /** @brief The parent's erase callback. */
177 eraseFunc eraseCallback;
178
179 private:
180 /** @brief Persistent sdbusplus DBus bus connection */
181 sdbusplus::bus::bus& bus;
182
183 /** @brief Persistent DBus object path */
184 std::string objPath;
185
186 /** @brief Parent Object. */
187 ItemUpdater& parent;
188
189 /** @brief This Version's version Id */
190 const std::string versionId;
191
192 /** @brief This Version's version string */
193 const std::string versionStr;
194
195 /** @brief Used to subscribe to chassis power state changes **/
196 sdbusplus::bus::match_t chassisStateSignals;
197
Saqib Khance148702017-06-11 12:01:58 -0500198};
199
200} // namespace updater
201} // namespace software
202} // namespace openpower