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