blob: bc86af1f517efdc9b2340bdc99af5f72ce11ae3f [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
5#include "activation.hpp"
6#include "version.hpp"
7
8#include <sdbusplus/server.hpp>
9#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
10
11namespace phosphor
12{
13namespace software
14{
15namespace updater
16{
17
18class Version;
19
20using ItemUpdaterInherit = sdbusplus::server::object::object<
21 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
22namespace MatchRules = sdbusplus::bus::match::rules;
23
24/** @class ItemUpdater
25 * @brief Manages the activation of the PSU version items.
26 */
27class ItemUpdater : public ItemUpdaterInherit
28{
29 public:
30 /** @brief Constructs ItemUpdater
31 *
32 * @param[in] bus - The D-Bus bus object
33 * @param[in] path - The D-Bus path
34 */
35 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
36 ItemUpdaterInherit(bus, path.c_str()), bus(bus),
37 versionMatch(bus,
38 MatchRules::interfacesAdded() +
39 MatchRules::path(SOFTWARE_OBJPATH),
40 std::bind(std::mem_fn(&ItemUpdater::createActivation),
41 this, std::placeholders::_1))
42 {
43 }
44
45 /** @brief Deletes version
46 *
47 * @param[in] versionId - Id of the version to delete
48 */
49 void erase(std::string versionId);
50
51 /**
52 * @brief Erases any non-active versions.
53 */
54 void deleteAll();
55
56 private:
57 /** @brief Callback function for Software.Version match.
58 * @details Creates an Activation D-Bus object.
59 *
60 * @param[in] msg - Data associated with subscribed signal
61 */
62 void createActivation(sdbusplus::message::message& msg);
63
64 /** @brief Create Activation object */
65 std::unique_ptr<Activation> createActivationObject(
66 const std::string& path, const std::string& versionId,
67 const std::string& extVersion,
68 sdbusplus::xyz::openbmc_project::Software::server::Activation::
69 Activations activationStatus);
70
71 /** @brief Create Version object */
72 std::unique_ptr<Version>
73 createVersionObject(const std::string& objPath,
74 const std::string& versionId,
75 const std::string& versionString,
76 sdbusplus::xyz::openbmc_project::Software::server::
77 Version::VersionPurpose versionPurpose,
78 const std::string& filePath);
79
80 /** @brief Persistent sdbusplus D-Bus bus connection. */
81 sdbusplus::bus::bus& bus;
82
83 /** @brief Persistent map of Activation D-Bus objects and their
84 * version id */
85 std::map<std::string, std::unique_ptr<Activation>> activations;
86
87 /** @brief Persistent map of Version D-Bus objects and their
88 * version id */
89 std::map<std::string, std::unique_ptr<Version>> versions;
90
91 /** @brief sdbusplus signal match for Software.Version */
92 sdbusplus::bus::match_t versionMatch;
93};
94
95} // namespace updater
96} // namespace software
97} // namespace phosphor