xref: /openbmc/pldm/fw-update/aggregate_update_manager.hpp (revision ee2bd8ad3979dac8c41afa643e0eb24b31e70683)
1 #pragma once
2 
3 #include "update_manager.hpp"
4 
5 namespace pldm::fw_update
6 {
7 
8 class AggregateUpdateManager : public UpdateManager
9 {
10   public:
11     AggregateUpdateManager() = delete;
12     AggregateUpdateManager(const AggregateUpdateManager&) = delete;
13     AggregateUpdateManager(AggregateUpdateManager&&) = delete;
14     AggregateUpdateManager& operator=(const AggregateUpdateManager&) = delete;
15     AggregateUpdateManager& operator=(AggregateUpdateManager&&) = delete;
16 
17     /**
18      * @brief Constructor for AggregateUpdateManager
19      *
20      * @param[in] event - Reference to the PLDM daemon's main event loop
21      * @param[in] handler - PLDM request handler
22      * @param[in] instanceIdDb - Reference to the instance ID database
23      * @param[in] descriptorMap - Descriptor map for the update manager
24      * @param[in] componentInfoMap - Component information map for the update
25      * manager
26      */
AggregateUpdateManager(Event & event,pldm::requester::Handler<pldm::requester::Request> & handler,InstanceIdDb & instanceIdDb,const DescriptorMap & descriptorMap,const ComponentInfoMap & componentInfoMap)27     explicit AggregateUpdateManager(
28         Event& event,
29         pldm::requester::Handler<pldm::requester::Request>& handler,
30         InstanceIdDb& instanceIdDb, const DescriptorMap& descriptorMap,
31         const ComponentInfoMap& componentInfoMap) :
32         UpdateManager(event, handler, instanceIdDb, descriptorMap,
33                       componentInfoMap)
34     {}
35 
36     /**
37      * @brief Handle PLDM requests for the aggregate update manager
38      *
39      * This function processes incoming PLDM requests and dispatches them to the
40      * appropriate update manager based on the software identifier.
41      *
42      * @param[in] eid - Remote MCTP Endpoint ID
43      * @param[in] command - PLDM command code
44      * @param[in] request - PLDM request message
45      * @param[in] reqMsgLen - PLDM request message length
46      * @return PLDM response message
47      */
48     Response handleRequest(mctp_eid_t eid, uint8_t command,
49                            const pldm_msg* request, size_t reqMsgLen) override;
50 
51     /**
52      * @brief Create a new UpdateManager instance for a specific software
53      * identifier
54      *
55      * This function creates and stores a new UpdateManager instance associated
56      * with the given software identifier, along with its corresponding
57      * descriptor and component information maps.
58      *
59      * @param[in] softwareIdentifier - The software identifier (pair of eid and
60      * component identifier)
61      * @param[in] descriptors - The descriptors associated with the software
62      * identifier
63      * @param[in] componentInfo - The component information associated with the
64      * software identifier
65      * @param[in] updateObjPath - The D-Bus object path for the update manager
66      */
67     void createUpdateManager(const SoftwareIdentifier& softwareIdentifier,
68                              const Descriptors& descriptors,
69                              const ComponentInfo& componentInfo,
70                              const std::string& updateObjPath);
71 
72     /**
73      * @brief Erase an existing UpdateManager instance associated with a
74      * specific software identifier
75      *
76      * This function removes the UpdateManager instance and its associated
77      * descriptor and component information maps from the internal storage based
78      * on the provided software identifier.
79      *
80      * @param[in] softwareIdentifier - The software identifier (pair of eid and
81      * component identifier)
82      */
83     void eraseUpdateManager(const SoftwareIdentifier& softwareIdentifier);
84 
85     /**
86      * @brief Erase UpdateManager instances that satisfy a given predicate
87      *
88      * This function iterates through the stored UpdateManager instances and
89      * removes those that satisfy the provided predicate function. It also
90      * removes the associated descriptor and component information maps.
91      *
92      * @param[in] predicate - A function that takes a SoftwareIdentifier and
93      * returns true if the corresponding UpdateManager should be erased
94      */
95     void eraseUpdateManagerIf(
96         std::function<bool(const SoftwareIdentifier&)>&& predicate);
97 
98   private:
99     /**
100      * @brief Map of UpdateManager instances keyed by software identifier
101      */
102     std::map<SoftwareIdentifier, std::unique_ptr<UpdateManager>> updateManagers;
103 
104     /**
105      * @brief Map of descriptor maps keyed by software identifier
106      */
107     std::map<SoftwareIdentifier, std::unique_ptr<Descriptors>> descriptorMap;
108 
109     /**
110      * @brief Map of component information maps keyed by software identifier
111      */
112     std::map<SoftwareIdentifier, std::unique_ptr<ComponentInfo>>
113         componentInfoMap;
114 };
115 
116 } // namespace pldm::fw_update
117