blob: 8a07ae0c3ad968f725d379a9677b4b4fddf11588 [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<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060021 sdbusplus::xyz::openbmc_project::Software::server::Version,
22 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050023using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060024 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050025
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.
Adriana Kobylak70dcb632018-02-27 15:46:52 -060035 */
Saqib Khan7f80e0b2017-10-22 11:29:07 -050036class Delete : public DeleteInherit
37{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060038 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, const std::string& path, Version& parent) :
46 DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus),
47 path(path)
48 {
49 std::vector<std::string> interfaces({interface});
50 bus.emit_interfaces_added(path.c_str(), interfaces);
51 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -050052
Adriana Kobylak70dcb632018-02-27 15:46:52 -060053 ~Delete()
54 {
55 std::vector<std::string> interfaces({interface});
56 bus.emit_interfaces_removed(path.c_str(), interfaces);
57 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -050058
Adriana Kobylak70dcb632018-02-27 15:46:52 -060059 /**
60 * @brief Delete the D-Bus object.
61 * Overrides the default delete function by calling
62 * Version class erase Method.
63 **/
64 void delete_() override;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050065
Adriana Kobylak70dcb632018-02-27 15:46:52 -060066 private:
67 /** @brief Parent Object. */
68 Version& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050069
Adriana Kobylak70dcb632018-02-27 15:46:52 -060070 // TODO Remove once openbmc/openbmc#1975 is resolved
71 static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
72 sdbusplus::bus::bus& bus;
73 std::string path;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050074};
Saqib Khance148702017-06-11 12:01:58 -050075
76/** @class Version
77 * @brief OpenBMC version software management implementation.
78 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsb78dfa52017-09-21 16:05:22 -050079 * D-Bus API.
Saqib Khance148702017-06-11 12:01:58 -050080 */
81class Version : public VersionInherit
82{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060083 public:
84 /** @brief Constructs Version Software Manager.
85 *
86 * @param[in] bus - The D-Bus bus object
87 * @param[in] objPath - The D-Bus object path
88 * @param[in] parent - Parent object.
89 * @param[in] versionId - The version Id
90 * @param[in] versionString - The version string
91 * @param[in] versionPurpose - The version purpose
92 * @param[in] filePath - The image filesystem path
93 * @param[in] callback - The eraseFunc callback
94 */
95 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
96 ItemUpdater& parent, const std::string& versionId,
97 const std::string& versionString, VersionPurpose versionPurpose,
98 const std::string& filePath, eraseFunc callback) :
99 VersionInherit(bus, (objPath).c_str(), true),
100 bus(bus), objPath(objPath), parent(parent), versionId(versionId),
101 versionStr(versionString),
102 chassisStateSignals(
103 bus,
104 sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") +
105 sdbusRule::path(CHASSIS_STATE_PATH) +
106 sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
107 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
108 std::bind(std::mem_fn(&Version::updateDeleteInterface), this,
109 std::placeholders::_1))
110 {
111 // Bind erase method
112 eraseCallback = callback;
113 // Set properties.
114 purpose(versionPurpose);
115 version(versionString);
116 path(filePath);
Saqib Khance148702017-06-11 12:01:58 -0500117
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600118 // Emit deferred signal.
119 emit_object_added();
120 }
Saqib Khan167601b2017-06-18 23:33:46 -0500121
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600122 /**
123 * @brief Update the Object.Delete interface for this activation
124 *
125 * Update the delete interface based on whether or not this
126 * activation is currently functional. A functional activation
127 * will have no Object.Delete, while a non-functional activation
128 * will have one.
129 *
130 * @param[in] msg - Data associated with subscribed signal
131 */
132 void updateDeleteInterface(sdbusplus::message::message& msg);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500133
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 /**
135 * @brief Read the manifest file to get the value of the key.
136 *
137 * @param[in] filePath - The path to the file which contains the value
138 * of keys.
139 * @param[in] keys - A map of keys with empty values.
140 *
141 * @return The map of keys with filled values.
142 **/
143 static std::map<std::string, std::string>
144 getValue(const std::string& filePath,
145 std::map<std::string, std::string> keys);
Saqib Khan167601b2017-06-18 23:33:46 -0500146
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600147 /**
148 * @brief Calculate the version id from the version string.
149 *
150 * @details The version id is a unique 8 hexadecimal digit id
151 * calculated from the version string.
152 *
153 * @param[in] version - The image version string (e.g. v1.99.10-19).
154 *
155 * @return The id.
156 */
157 static std::string getId(const std::string& version);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500158
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600159 /** @brief Persistent Delete D-Bus object */
160 std::unique_ptr<Delete> deleteObject;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500161
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600162 /** @brief The parent's erase callback. */
163 eraseFunc eraseCallback;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500164
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600165 private:
166 /** @brief Persistent sdbusplus DBus bus connection */
167 sdbusplus::bus::bus& bus;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500168
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600169 /** @brief Persistent DBus object path */
170 std::string objPath;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500171
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600172 /** @brief Parent Object. */
173 ItemUpdater& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500174
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600175 /** @brief This Version's version Id */
176 const std::string versionId;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500177
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600178 /** @brief This Version's version string */
179 const std::string versionStr;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500180
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600181 /** @brief Used to subscribe to chassis power state changes **/
182 sdbusplus::bus::match_t chassisStateSignals;
Saqib Khance148702017-06-11 12:01:58 -0500183};
184
185} // namespace updater
186} // namespace software
187} // namespace openpower