blob: 96006f42752707ef1a2bb81c047932fbb4f44aaa [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 YU01539e72019-07-31 10:57:38 +08007#include "version.hpp"
8
9#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080010#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080011#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
12
13namespace phosphor
14{
15namespace software
16{
17namespace updater
18{
19
20class Version;
21
22using ItemUpdaterInherit = sdbusplus::server::object::object<
Lei YU91029442019-08-01 15:57:31 +080023 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Lei YU01539e72019-07-31 10:57:38 +080024 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
25namespace MatchRules = sdbusplus::bus::match::rules;
26
27/** @class ItemUpdater
28 * @brief Manages the activation of the PSU version items.
29 */
30class ItemUpdater : public ItemUpdaterInherit
31{
32 public:
33 /** @brief Constructs ItemUpdater
34 *
35 * @param[in] bus - The D-Bus bus object
36 * @param[in] path - The D-Bus path
37 */
38 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
39 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
40 versionMatch(bus,
41 MatchRules::interfacesAdded() +
42 MatchRules::path(SOFTWARE_OBJPATH),
43 std::bind(std::mem_fn(&ItemUpdater::createActivation),
44 this, std::placeholders::_1))
45 {
46 }
47
48 /** @brief Deletes version
49 *
50 * @param[in] versionId - Id of the version to delete
51 */
52 void erase(std::string versionId);
53
54 /**
55 * @brief Erases any non-active versions.
56 */
57 void deleteAll();
58
59 private:
Lei YU91029442019-08-01 15:57:31 +080060 /** @brief Creates an active association to the
61 * newly active software image
62 *
63 * @param[in] path - The path to create the association to.
64 */
65 void createActiveAssociation(const std::string& path);
66
67 /** @brief Updates the functional association to the
68 * new "running" PSU images
69 *
70 * @param[in] versionId - The id of the image to update the association to.
71 */
72 void updateFunctionalAssociation(const std::string& versionId);
73
74 /** @brief Removes the associations from the provided software image path
75 *
76 * @param[in] path - The path to remove the association from.
77 */
78 void removeAssociation(const std::string& path);
79
Lei YU01539e72019-07-31 10:57:38 +080080 /** @brief Callback function for Software.Version match.
81 * @details Creates an Activation D-Bus object.
82 *
83 * @param[in] msg - Data associated with subscribed signal
84 */
85 void createActivation(sdbusplus::message::message& msg);
86
87 /** @brief Create Activation object */
88 std::unique_ptr<Activation> createActivationObject(
89 const std::string& path, const std::string& versionId,
90 const std::string& extVersion,
91 sdbusplus::xyz::openbmc_project::Software::server::Activation::
Lei YU91029442019-08-01 15:57:31 +080092 Activations activationStatus,
93 const AssociationList& assocs);
Lei YU01539e72019-07-31 10:57:38 +080094
95 /** @brief Create Version object */
96 std::unique_ptr<Version>
97 createVersionObject(const std::string& objPath,
98 const std::string& versionId,
99 const std::string& versionString,
100 sdbusplus::xyz::openbmc_project::Software::server::
101 Version::VersionPurpose versionPurpose,
102 const std::string& filePath);
103
104 /** @brief Persistent sdbusplus D-Bus bus connection. */
105 sdbusplus::bus::bus& bus;
106
107 /** @brief Persistent map of Activation D-Bus objects and their
108 * version id */
109 std::map<std::string, std::unique_ptr<Activation>> activations;
110
111 /** @brief Persistent map of Version D-Bus objects and their
112 * version id */
113 std::map<std::string, std::unique_ptr<Version>> versions;
114
115 /** @brief sdbusplus signal match for Software.Version */
116 sdbusplus::bus::match_t versionMatch;
Lei YU91029442019-08-01 15:57:31 +0800117
118 /** @brief This entry's associations */
119 AssociationList assocs;
Lei YU01539e72019-07-31 10:57:38 +0800120};
121
122} // namespace updater
123} // namespace software
124} // namespace phosphor