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