blob: 33db8bcfe5ce6eb2f751e8d3385be3cfab0df85f [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
5#include "activation.hpp"
Lei YU7f2a2152019-09-16 16:50:18 +08006#include "association_interface.hpp"
Lei YU91029442019-08-01 15:57:31 +08007#include "types.hpp"
Lei YU5e0dcb32019-08-02 18:04:34 +08008#include "utils.hpp"
Lei YU01539e72019-07-31 10:57:38 +08009#include "version.hpp"
10
Lei YU5e0dcb32019-08-02 18:04:34 +080011#include <phosphor-logging/log.hpp>
Lei YU01539e72019-07-31 10:57:38 +080012#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080013#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080014#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
15
Lei YUf77189f2019-08-07 14:26:30 +080016class TestItemUpdater;
17
Lei YU01539e72019-07-31 10:57:38 +080018namespace phosphor
19{
20namespace software
21{
22namespace updater
23{
24
25class Version;
26
27using ItemUpdaterInherit = sdbusplus::server::object::object<
Lei YUa5c47bb2019-09-29 11:28:53 +080028 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
29
Lei YU01539e72019-07-31 10:57:38 +080030namespace MatchRules = sdbusplus::bus::match::rules;
31
32/** @class ItemUpdater
33 * @brief Manages the activation of the PSU version items.
34 */
Lei YU7f2a2152019-09-16 16:50:18 +080035class ItemUpdater : public ItemUpdaterInherit, public AssociationInterface
Lei YU01539e72019-07-31 10:57:38 +080036{
Lei YUf77189f2019-08-07 14:26:30 +080037 friend class ::TestItemUpdater;
38
Lei YU01539e72019-07-31 10:57:38 +080039 public:
40 /** @brief Constructs ItemUpdater
41 *
42 * @param[in] bus - The D-Bus bus object
43 * @param[in] path - The D-Bus path
44 */
45 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
46 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
47 versionMatch(bus,
48 MatchRules::interfacesAdded() +
49 MatchRules::path(SOFTWARE_OBJPATH),
50 std::bind(std::mem_fn(&ItemUpdater::createActivation),
51 this, std::placeholders::_1))
52 {
Lei YUad90ad52019-08-06 11:19:28 +080053 processPSUImage();
Lei YU01539e72019-07-31 10:57:38 +080054 }
55
56 /** @brief Deletes version
57 *
58 * @param[in] versionId - Id of the version to delete
59 */
Lei YUa5c47bb2019-09-29 11:28:53 +080060 void erase(const std::string& versionId);
Lei YU01539e72019-07-31 10:57:38 +080061
Lei YU91029442019-08-01 15:57:31 +080062 /** @brief Creates an active association to the
63 * newly active software image
64 *
65 * @param[in] path - The path to create the association to.
66 */
Lei YU7f2a2152019-09-16 16:50:18 +080067 void createActiveAssociation(const std::string& path) override;
Lei YU91029442019-08-01 15:57:31 +080068
Lei YUad90ad52019-08-06 11:19:28 +080069 /** @brief Add the functional association to the
Lei YU91029442019-08-01 15:57:31 +080070 * new "running" PSU images
71 *
Lei YUad90ad52019-08-06 11:19:28 +080072 * @param[in] path - The path to add the association to.
Lei YU91029442019-08-01 15:57:31 +080073 */
Lei YU7f2a2152019-09-16 16:50:18 +080074 void addFunctionalAssociation(const std::string& path) override;
Lei YU91029442019-08-01 15:57:31 +080075
76 /** @brief Removes the associations from the provided software image path
77 *
78 * @param[in] path - The path to remove the association from.
79 */
Lei YU7f2a2152019-09-16 16:50:18 +080080 void removeAssociation(const std::string& path) override;
Lei YU91029442019-08-01 15:57:31 +080081
Lei YU7f2a2152019-09-16 16:50:18 +080082 private:
Lei YU01539e72019-07-31 10:57:38 +080083 /** @brief Callback function for Software.Version match.
84 * @details Creates an Activation D-Bus object.
85 *
86 * @param[in] msg - Data associated with subscribed signal
87 */
88 void createActivation(sdbusplus::message::message& msg);
89
Lei YUa2c2cd72019-08-09 15:54:10 +080090 using Properties =
91 std::map<std::string, utils::UtilsInterface::PropertyType>;
92
Lei YUad90ad52019-08-06 11:19:28 +080093 /** @brief Callback function for PSU inventory match.
94 * @details Update an Activation D-Bus object for PSU inventory.
95 *
96 * @param[in] msg - Data associated with subscribed signal
97 */
Lei YUa2c2cd72019-08-09 15:54:10 +080098 void onPsuInventoryChangedMsg(sdbusplus::message::message& msg);
99
100 /** @brief Callback function for PSU inventory match.
101 * @details Update an Activation D-Bus object for PSU inventory.
102 *
103 * @param[in] psuPath - The PSU inventory path
104 * @param[in] properties - The updated properties
105 */
106 void onPsuInventoryChanged(const std::string& psuPath,
107 const Properties& properties);
Lei YUad90ad52019-08-06 11:19:28 +0800108
Lei YU01539e72019-07-31 10:57:38 +0800109 /** @brief Create Activation object */
110 std::unique_ptr<Activation> createActivationObject(
111 const std::string& path, const std::string& versionId,
112 const std::string& extVersion,
113 sdbusplus::xyz::openbmc_project::Software::server::Activation::
Lei YU91029442019-08-01 15:57:31 +0800114 Activations activationStatus,
Lei YU99301372019-09-29 16:27:12 +0800115 const AssociationList& assocs, const std::string& filePath);
Lei YU01539e72019-07-31 10:57:38 +0800116
117 /** @brief Create Version object */
118 std::unique_ptr<Version>
119 createVersionObject(const std::string& objPath,
120 const std::string& versionId,
121 const std::string& versionString,
122 sdbusplus::xyz::openbmc_project::Software::server::
Lei YU99301372019-09-29 16:27:12 +0800123 Version::VersionPurpose versionPurpose);
Lei YU01539e72019-07-31 10:57:38 +0800124
Lei YUbd3b0072019-08-08 13:09:50 +0800125 /** @brief Create Activation and Version object for PSU inventory
126 * @details If the same version exists for multiple PSUs, just add
127 * related association, instead of creating new objects.
128 * */
Lei YUad90ad52019-08-06 11:19:28 +0800129 void createPsuObject(const std::string& psuInventoryPath,
130 const std::string& psuVersion);
131
Lei YUbd3b0072019-08-08 13:09:50 +0800132 /** @brief Remove Activation and Version object for PSU inventory
133 * @details If the same version exists for mutliple PSUs, just remove
134 * related association.
135 * If the version has no association, the Activation and
136 * Version object will be removed
137 */
138 void removePsuObject(const std::string& psuInventoryPath);
139
Lei YUad90ad52019-08-06 11:19:28 +0800140 /**
141 * @brief Create and populate the active PSU Version.
142 */
143 void processPSUImage();
144
Lei YU01539e72019-07-31 10:57:38 +0800145 /** @brief Persistent sdbusplus D-Bus bus connection. */
146 sdbusplus::bus::bus& bus;
147
148 /** @brief Persistent map of Activation D-Bus objects and their
149 * version id */
150 std::map<std::string, std::unique_ptr<Activation>> activations;
151
152 /** @brief Persistent map of Version D-Bus objects and their
153 * version id */
154 std::map<std::string, std::unique_ptr<Version>> versions;
155
Lei YUbd3b0072019-08-08 13:09:50 +0800156 /** @brief The reference map of PSU Inventory objects and the
157 * Activation*/
158 std::map<std::string, const std::unique_ptr<Activation>&>
159 psuPathActivationMap;
160
Lei YUad90ad52019-08-06 11:19:28 +0800161 /** @brief sdbusplus signal match for PSU Software*/
Lei YU01539e72019-07-31 10:57:38 +0800162 sdbusplus::bus::match_t versionMatch;
Lei YU91029442019-08-01 15:57:31 +0800163
Lei YUad90ad52019-08-06 11:19:28 +0800164 /** @brief sdbusplus signal matches for PSU Inventory */
165 std::vector<sdbusplus::bus::match_t> psuMatches;
166
Lei YU91029442019-08-01 15:57:31 +0800167 /** @brief This entry's associations */
168 AssociationList assocs;
Lei YU01539e72019-07-31 10:57:38 +0800169};
170
171} // namespace updater
172} // namespace software
173} // namespace phosphor