blob: 85dccda3acddc7deb920b6095770644c3b9fb1de [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) :
Albert Zhang7f1967d2020-03-02 14:12:08 +080048 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
49 parent(parent)
Adriana Kobylak70dcb632018-02-27 15:46:52 -060050 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -060051 }
Saqib Khan7f80e0b2017-10-22 11:29:07 -050052
Adriana Kobylak70dcb632018-02-27 15:46:52 -060053 /**
54 * @brief Delete the D-Bus object.
55 * Overrides the default delete function by calling
56 * Version class erase Method.
57 **/
58 void delete_() override;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050059
Adriana Kobylak70dcb632018-02-27 15:46:52 -060060 private:
61 /** @brief Parent Object. */
62 Version& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050063};
Saqib Khance148702017-06-11 12:01:58 -050064
65/** @class Version
66 * @brief OpenBMC version software management implementation.
67 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsb78dfa52017-09-21 16:05:22 -050068 * D-Bus API.
Saqib Khance148702017-06-11 12:01:58 -050069 */
70class Version : public VersionInherit
71{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060072 public:
73 /** @brief Constructs Version Software Manager.
74 *
75 * @param[in] bus - The D-Bus bus object
76 * @param[in] objPath - The D-Bus object path
77 * @param[in] parent - Parent object.
78 * @param[in] versionId - The version Id
79 * @param[in] versionString - The version string
80 * @param[in] versionPurpose - The version purpose
81 * @param[in] filePath - The image filesystem path
82 * @param[in] callback - The eraseFunc callback
83 */
84 Version(sdbusplus::bus::bus& bus, const std::string& objPath,
85 ItemUpdater& parent, const std::string& versionId,
86 const std::string& versionString, VersionPurpose versionPurpose,
87 const std::string& filePath, eraseFunc callback) :
88 VersionInherit(bus, (objPath).c_str(), true),
Lei YU1db9adf2019-03-05 16:02:31 +080089 eraseCallback(callback), bus(bus), objPath(objPath), parent(parent),
90 versionId(versionId), versionStr(versionString),
Adriana Kobylak70dcb632018-02-27 15:46:52 -060091 chassisStateSignals(
92 bus,
93 sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") +
94 sdbusRule::path(CHASSIS_STATE_PATH) +
95 sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
96 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
97 std::bind(std::mem_fn(&Version::updateDeleteInterface), this,
98 std::placeholders::_1))
99 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600100 // Set properties.
101 purpose(versionPurpose);
102 version(versionString);
103 path(filePath);
Saqib Khance148702017-06-11 12:01:58 -0500104
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600105 // Emit deferred signal.
106 emit_object_added();
107 }
Saqib Khan167601b2017-06-18 23:33:46 -0500108
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600109 /**
110 * @brief Update the Object.Delete interface for this activation
111 *
112 * Update the delete interface based on whether or not this
113 * activation is currently functional. A functional activation
114 * will have no Object.Delete, while a non-functional activation
115 * will have one.
116 *
117 * @param[in] msg - Data associated with subscribed signal
118 */
119 void updateDeleteInterface(sdbusplus::message::message& msg);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500120
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600121 /**
122 * @brief Read the manifest file to get the value of the key.
123 *
124 * @param[in] filePath - The path to the file which contains the value
125 * of keys.
126 * @param[in] keys - A map of keys with empty values.
127 *
128 * @return The map of keys with filled values.
129 **/
130 static std::map<std::string, std::string>
131 getValue(const std::string& filePath,
132 std::map<std::string, std::string> keys);
Saqib Khan167601b2017-06-18 23:33:46 -0500133
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 /**
Lei YUdec8cf92019-02-21 17:47:05 +0800135 * @brief Get version and extended version from VERSION partition string.
136 *
137 * @param[in] versionPart - The string containing the VERSION partition.
138 *
139 * @return The pair contains the version and extended version.
140 **/
141 static std::pair<std::string, std::string>
142 getVersions(const std::string& versionPart);
143
144 /**
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600145 * @brief Calculate the version id from the version string.
146 *
147 * @details The version id is a unique 8 hexadecimal digit id
148 * calculated from the version string.
149 *
150 * @param[in] version - The image version string (e.g. v1.99.10-19).
151 *
152 * @return The id.
153 */
154 static std::string getId(const std::string& version);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500155
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600156 /** @brief Persistent Delete D-Bus object */
157 std::unique_ptr<Delete> deleteObject;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500158
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600159 /** @brief The parent's erase callback. */
160 eraseFunc eraseCallback;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500161
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600162 private:
163 /** @brief Persistent sdbusplus DBus bus connection */
164 sdbusplus::bus::bus& bus;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500165
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600166 /** @brief Persistent DBus object path */
167 std::string objPath;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500168
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600169 /** @brief Parent Object. */
170 ItemUpdater& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500171
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600172 /** @brief This Version's version Id */
173 const std::string versionId;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500174
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600175 /** @brief This Version's version string */
176 const std::string versionStr;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500177
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600178 /** @brief Used to subscribe to chassis power state changes **/
179 sdbusplus::bus::match_t chassisStateSignals;
Saqib Khance148702017-06-11 12:01:58 -0500180};
181
182} // namespace updater
183} // namespace software
184} // namespace openpower