blob: eeacdf83bb9733669e390114c6555c01f4d745cc [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
5#include "activation.hpp"
Lei YU91029442019-08-01 15:57:31 +08006#include "types.hpp"
Lei YU5e0dcb32019-08-02 18:04:34 +08007#include "utils.hpp"
Lei YU01539e72019-07-31 10:57:38 +08008#include "version.hpp"
9
Lei YU5e0dcb32019-08-02 18:04:34 +080010#include <phosphor-logging/log.hpp>
Lei YU01539e72019-07-31 10:57:38 +080011#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080012#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080013#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
14
Lei YUf77189f2019-08-07 14:26:30 +080015class TestItemUpdater;
16
Lei YU01539e72019-07-31 10:57:38 +080017namespace phosphor
18{
19namespace software
20{
21namespace updater
22{
23
24class Version;
25
26using ItemUpdaterInherit = sdbusplus::server::object::object<
Lei YU91029442019-08-01 15:57:31 +080027 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Lei YU01539e72019-07-31 10:57:38 +080028 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
29namespace MatchRules = sdbusplus::bus::match::rules;
30
31/** @class ItemUpdater
32 * @brief Manages the activation of the PSU version items.
33 */
34class ItemUpdater : public ItemUpdaterInherit
35{
Lei YUf77189f2019-08-07 14:26:30 +080036 friend class ::TestItemUpdater;
37
Lei YU01539e72019-07-31 10:57:38 +080038 public:
39 /** @brief Constructs ItemUpdater
40 *
41 * @param[in] bus - The D-Bus bus object
42 * @param[in] path - The D-Bus path
43 */
44 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
45 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
46 versionMatch(bus,
47 MatchRules::interfacesAdded() +
48 MatchRules::path(SOFTWARE_OBJPATH),
49 std::bind(std::mem_fn(&ItemUpdater::createActivation),
50 this, std::placeholders::_1))
51 {
Lei YUad90ad52019-08-06 11:19:28 +080052 processPSUImage();
Lei YU01539e72019-07-31 10:57:38 +080053 }
54
55 /** @brief Deletes version
56 *
57 * @param[in] versionId - Id of the version to delete
58 */
59 void erase(std::string versionId);
60
61 /**
62 * @brief Erases any non-active versions.
63 */
64 void deleteAll();
65
66 private:
Lei YU91029442019-08-01 15:57:31 +080067 /** @brief Creates an active association to the
68 * newly active software image
69 *
70 * @param[in] path - The path to create the association to.
71 */
72 void createActiveAssociation(const std::string& path);
73
Lei YUad90ad52019-08-06 11:19:28 +080074 /** @brief Add the functional association to the
Lei YU91029442019-08-01 15:57:31 +080075 * new "running" PSU images
76 *
Lei YUad90ad52019-08-06 11:19:28 +080077 * @param[in] path - The path to add the association to.
Lei YU91029442019-08-01 15:57:31 +080078 */
Lei YUad90ad52019-08-06 11:19:28 +080079 void addFunctionalAssociation(const std::string& path);
Lei YU91029442019-08-01 15:57:31 +080080
81 /** @brief Removes the associations from the provided software image path
82 *
83 * @param[in] path - The path to remove the association from.
84 */
85 void removeAssociation(const std::string& path);
86
Lei YU01539e72019-07-31 10:57:38 +080087 /** @brief Callback function for Software.Version match.
88 * @details Creates an Activation D-Bus object.
89 *
90 * @param[in] msg - Data associated with subscribed signal
91 */
92 void createActivation(sdbusplus::message::message& msg);
93
Lei YUad90ad52019-08-06 11:19:28 +080094 /** @brief Callback function for PSU inventory match.
95 * @details Update an Activation D-Bus object for PSU inventory.
96 *
97 * @param[in] msg - Data associated with subscribed signal
98 */
99 void onPsuInventoryChanged(sdbusplus::message::message& msg);
100
Lei YU01539e72019-07-31 10:57:38 +0800101 /** @brief Create Activation object */
102 std::unique_ptr<Activation> createActivationObject(
103 const std::string& path, const std::string& versionId,
104 const std::string& extVersion,
105 sdbusplus::xyz::openbmc_project::Software::server::Activation::
Lei YU91029442019-08-01 15:57:31 +0800106 Activations activationStatus,
107 const AssociationList& assocs);
Lei YU01539e72019-07-31 10:57:38 +0800108
109 /** @brief Create Version object */
110 std::unique_ptr<Version>
111 createVersionObject(const std::string& objPath,
112 const std::string& versionId,
113 const std::string& versionString,
114 sdbusplus::xyz::openbmc_project::Software::server::
115 Version::VersionPurpose versionPurpose,
116 const std::string& filePath);
117
Lei YUbd3b0072019-08-08 13:09:50 +0800118 /** @brief Create Activation and Version object for PSU inventory
119 * @details If the same version exists for multiple PSUs, just add
120 * related association, instead of creating new objects.
121 * */
Lei YUad90ad52019-08-06 11:19:28 +0800122 void createPsuObject(const std::string& psuInventoryPath,
123 const std::string& psuVersion);
124
Lei YUbd3b0072019-08-08 13:09:50 +0800125 /** @brief Remove Activation and Version object for PSU inventory
126 * @details If the same version exists for mutliple PSUs, just remove
127 * related association.
128 * If the version has no association, the Activation and
129 * Version object will be removed
130 */
131 void removePsuObject(const std::string& psuInventoryPath);
132
Lei YUad90ad52019-08-06 11:19:28 +0800133 /**
134 * @brief Create and populate the active PSU Version.
135 */
136 void processPSUImage();
137
Lei YU01539e72019-07-31 10:57:38 +0800138 /** @brief Persistent sdbusplus D-Bus bus connection. */
139 sdbusplus::bus::bus& bus;
140
141 /** @brief Persistent map of Activation D-Bus objects and their
142 * version id */
143 std::map<std::string, std::unique_ptr<Activation>> activations;
144
145 /** @brief Persistent map of Version D-Bus objects and their
146 * version id */
147 std::map<std::string, std::unique_ptr<Version>> versions;
148
Lei YUbd3b0072019-08-08 13:09:50 +0800149 /** @brief The reference map of PSU Inventory objects and the
150 * Activation*/
151 std::map<std::string, const std::unique_ptr<Activation>&>
152 psuPathActivationMap;
153
154 /** @brief A struct to hold the PSU present status and version */
155 struct psuStatus
156 {
157 bool present;
158 std::string version;
159 };
160
161 /** @brief The map of PSU inventory path and the psuStatus */
162 std::map<std::string, psuStatus> psuStatusMap;
163
Lei YUad90ad52019-08-06 11:19:28 +0800164 /** @brief sdbusplus signal match for PSU Software*/
Lei YU01539e72019-07-31 10:57:38 +0800165 sdbusplus::bus::match_t versionMatch;
Lei YU91029442019-08-01 15:57:31 +0800166
Lei YUad90ad52019-08-06 11:19:28 +0800167 /** @brief sdbusplus signal matches for PSU Inventory */
168 std::vector<sdbusplus::bus::match_t> psuMatches;
169
Lei YU91029442019-08-01 15:57:31 +0800170 /** @brief This entry's associations */
171 AssociationList assocs;
Lei YU01539e72019-07-31 10:57:38 +0800172};
173
174} // namespace updater
175} // namespace software
176} // namespace phosphor