xref: /openbmc/pldm/fw-update/firmware_inventory_manager.hpp (revision 7ad45b401134e3b3a05a75200dbba00afd5aee46)
1 #pragma once
2 
3 #include "common/types.hpp"
4 #include "firmware_inventory.hpp"
5 
6 class FirmwareInventoryManagerTest;
7 
8 namespace pldm::fw_update
9 {
10 
11 using ObjectPath = pldm::dbus::ObjectPath;
12 using SoftwareMap =
13     std::map<SoftwareIdentifier, std::unique_ptr<FirmwareInventory>>;
14 
15 /**
16  * @brief Get the Board path from Entity Manager for the given inventory path
17  * @param[in] path - Inventory path
18  * @param[in] handler - D-Bus handler for querying ancestors
19  * @return Board path if found, std::nullopt otherwise
20  */
21 std::optional<std::filesystem::path> getBoardPath(
22     const pldm::utils::DBusHandler& handler, const InventoryPath& path);
23 
24 class FirmwareInventoryManager
25 {
26   public:
27     friend class ::FirmwareInventoryManagerTest;
28     FirmwareInventoryManager() = delete;
29     FirmwareInventoryManager(const FirmwareInventoryManager&) = delete;
30     FirmwareInventoryManager(FirmwareInventoryManager&&) = delete;
31     FirmwareInventoryManager& operator=(const FirmwareInventoryManager&) =
32         delete;
33     FirmwareInventoryManager& operator=(FirmwareInventoryManager&&) = delete;
34     ~FirmwareInventoryManager() = default;
35 
36     /**
37      * @brief Constructor
38      * @param[in] configurations - Reference to the EM configurations for MCTP
39      * endpoints
40      */
FirmwareInventoryManager(const pldm::utils::DBusHandler * dbusHandler,const Configurations & config)41     explicit FirmwareInventoryManager(
42         const pldm::utils::DBusHandler* dbusHandler,
43         const Configurations& config) :
44         dbusHandler(dbusHandler), configurations(config)
45     {}
46 
47     /**
48      * @brief Creates a firmware inventory entry for the given software
49      * identifier
50      * @param[in] softwareIdentifier - Software identifier containing EID and
51      *                                 component identifier
52      * @param[in] softwareName - Name of the firmware device
53      * @param[in] activeVersion - Active version of the firmware
54      * @param[in] descriptors - Descriptors associated with the firmware
55      * @param[in] componentInfo - Component information associated with the
56      * firmware
57      */
58     void createFirmwareEntry(
59         const SoftwareIdentifier& softwareIdentifier,
60         const SoftwareName& softwareName, const std::string& activeVersion,
61         const Descriptors& descriptors, const ComponentInfo& componentInfo);
62 
63     /**
64      * @brief Deletes the firmware inventory entry for the given EID
65      * @param[in] eid - MCTP endpoint ID for which the firmware inventory entry
66      *                  needs to be deleted
67      */
68     void deleteFirmwareEntry(const pldm::eid& eid);
69 
70   private:
71     /**
72      * @brief Get the inventory path associated with the given EID
73      * @param[in] eid - MCTP endpoint ID
74      * @return Inventory path if found, std::nullopt otherwise
75      */
76     std::optional<InventoryPath> getInventoryPath(const pldm::eid& eid) const;
77 
78     /**
79      * @brief D-Bus Handler
80      */
81     const pldm::utils::DBusHandler* dbusHandler;
82 
83     /**
84      * @brief Map of software identifier to FirmwareInventory instances
85      *        This map maintains the firmware inventory entries created for
86      *        different firmware components identified by their software
87      *        identifiers (EID and component identifier).
88      */
89     SoftwareMap softwareMap;
90 
91     /**
92      * @brief Reference to the EM configurations for MCTP endpoints
93      *        This is used to retrieve the associated endpoint information
94      *        when creating firmware inventory entries.
95      *        It is expected that the configurations are provided during
96      *        the initialization of the FirmwareInventoryManager.
97      */
98     const Configurations& configurations;
99 };
100 
101 } // namespace pldm::fw_update
102