blob: 7cd2be7884022ff3280c56f7d0e86af2abb87854 [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>
Brad Bishop8facccf2020-11-04 09:44:58 -050010
Andrew Geisslerab139ce2020-05-16 13:22:09 -050011#include <string>
Saqib Khance148702017-06-11 12:01:58 -050012
13namespace openpower
14{
15namespace software
16{
17namespace updater
18{
19
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -050020class ItemUpdater;
21
Saqib Khan7f80e0b2017-10-22 11:29:07 -050022typedef std::function<void(std::string)> eraseFunc;
23
Saqib Khance148702017-06-11 12:01:58 -050024using VersionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060025 sdbusplus::xyz::openbmc_project::Software::server::Version,
26 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050027using DeleteInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060028 sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050029
30namespace sdbusRule = sdbusplus::bus::match::rules;
31
32class Delete;
33class Version;
34
35/** @class Delete
36 * @brief OpenBMC Delete implementation.
37 * @details A concrete implementation for xyz.openbmc_project.Object.Delete
38 * D-Bus API.
Adriana Kobylak70dcb632018-02-27 15:46:52 -060039 */
Saqib Khan7f80e0b2017-10-22 11:29:07 -050040class Delete : public DeleteInherit
41{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060042 public:
43 /** @brief Constructs Delete.
44 *
45 * @param[in] bus - The D-Bus bus object
46 * @param[in] path - The D-Bus object path
47 * @param[in] parent - Parent object.
48 */
49 Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
Albert Zhang7f1967d2020-03-02 14:12:08 +080050 DeleteInherit(bus, path.c_str(), action::emit_interface_added),
51 parent(parent)
Brad Bishop8facccf2020-11-04 09:44:58 -050052 {}
Saqib Khan7f80e0b2017-10-22 11:29:07 -050053
Adriana Kobylak70dcb632018-02-27 15:46:52 -060054 /**
55 * @brief Delete the D-Bus object.
56 * Overrides the default delete function by calling
57 * Version class erase Method.
58 **/
59 void delete_() override;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050060
Adriana Kobylak70dcb632018-02-27 15:46:52 -060061 private:
62 /** @brief Parent Object. */
63 Version& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -050064};
Saqib Khance148702017-06-11 12:01:58 -050065
66/** @class Version
67 * @brief OpenBMC version software management implementation.
68 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsb78dfa52017-09-21 16:05:22 -050069 * D-Bus API.
Saqib Khance148702017-06-11 12:01:58 -050070 */
71class Version : public VersionInherit
72{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060073 public:
74 /** @brief Constructs Version Software Manager.
75 *
76 * @param[in] bus - The D-Bus bus object
77 * @param[in] objPath - The D-Bus object path
78 * @param[in] parent - Parent object.
79 * @param[in] versionId - The version Id
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 ItemUpdater& parent, const std::string& versionId,
87 const std::string& versionString, VersionPurpose versionPurpose,
88 const std::string& filePath, eraseFunc callback) :
Patrick Williams9c887d12022-04-05 21:39:40 -050089 VersionInherit(bus, (objPath).c_str(),
90 VersionInherit::action::defer_emit),
Lei YU1db9adf2019-03-05 16:02:31 +080091 eraseCallback(callback), bus(bus), objPath(objPath), parent(parent),
92 versionId(versionId), versionStr(versionString),
Adriana Kobylak70dcb632018-02-27 15:46:52 -060093 chassisStateSignals(
94 bus,
95 sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") +
96 sdbusRule::path(CHASSIS_STATE_PATH) +
97 sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
98 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
99 std::bind(std::mem_fn(&Version::updateDeleteInterface), this,
100 std::placeholders::_1))
101 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600102 // Set properties.
103 purpose(versionPurpose);
104 version(versionString);
105 path(filePath);
Saqib Khance148702017-06-11 12:01:58 -0500106
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600107 // Emit deferred signal.
108 emit_object_added();
109 }
Saqib Khan167601b2017-06-18 23:33:46 -0500110
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600111 /**
112 * @brief Update the Object.Delete interface for this activation
113 *
114 * Update the delete interface based on whether or not this
115 * activation is currently functional. A functional activation
116 * will have no Object.Delete, while a non-functional activation
117 * will have one.
118 *
119 * @param[in] msg - Data associated with subscribed signal
120 */
121 void updateDeleteInterface(sdbusplus::message::message& msg);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500122
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600123 /**
124 * @brief Read the manifest file to get the value of the key.
125 *
126 * @param[in] filePath - The path to the file which contains the value
127 * of keys.
128 * @param[in] keys - A map of keys with empty values.
129 *
130 * @return The map of keys with filled values.
131 **/
132 static std::map<std::string, std::string>
133 getValue(const std::string& filePath,
134 std::map<std::string, std::string> keys);
Saqib Khan167601b2017-06-18 23:33:46 -0500135
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600136 /**
Lei YUdec8cf92019-02-21 17:47:05 +0800137 * @brief Get version and extended version from VERSION partition string.
138 *
139 * @param[in] versionPart - The string containing the VERSION partition.
140 *
141 * @return The pair contains the version and extended version.
142 **/
143 static std::pair<std::string, std::string>
144 getVersions(const std::string& versionPart);
145
146 /**
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600147 * @brief Calculate the version id from the version string.
148 *
149 * @details The version id is a unique 8 hexadecimal digit id
150 * calculated from the version string.
151 *
152 * @param[in] version - The image version string (e.g. v1.99.10-19).
153 *
154 * @return The id.
155 */
156 static std::string getId(const std::string& version);
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500157
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600158 /** @brief Persistent Delete D-Bus object */
159 std::unique_ptr<Delete> deleteObject;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500160
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600161 /** @brief The parent's erase callback. */
162 eraseFunc eraseCallback;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500163
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600164 private:
165 /** @brief Persistent sdbusplus DBus bus connection */
166 sdbusplus::bus::bus& bus;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500167
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600168 /** @brief Persistent DBus object path */
169 std::string objPath;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500170
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 /** @brief Parent Object. */
172 ItemUpdater& parent;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500173
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600174 /** @brief This Version's version Id */
175 const std::string versionId;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500176
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600177 /** @brief This Version's version string */
178 const std::string versionStr;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500179
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600180 /** @brief Used to subscribe to chassis power state changes **/
181 sdbusplus::bus::match_t chassisStateSignals;
Saqib Khance148702017-06-11 12:01:58 -0500182};
183
184} // namespace updater
185} // namespace software
186} // namespace openpower