blob: 8dab2f8a9d258460c8a587bd4671844e3f9a41e1 [file] [log] [blame]
Anupama B R445819f2025-09-18 11:00:25 -05001#pragma once
2
3#include "types.hpp"
4
5#include <nlohmann/json.hpp>
6
7#include <string>
8
9/**
10 * @brief Class to prime system blueprint.
11 *
12 * This class will be used for priming the system, by traversing the system
13 * config JSON and primes all the FRU paths which qualifies for priming and
14 * publishes inventory object paths on the DBus.
15 */
16class PrimeInventory
17{
18 public:
19 /**
20 * Deleted methods
21 */
22 PrimeInventory(const PrimeInventory&) = delete;
23 PrimeInventory& operator=(const PrimeInventory&) = delete;
24 PrimeInventory& operator=(PrimeInventory&&) = delete;
25 PrimeInventory(PrimeInventory&&) = delete;
26
27 /**
28 * Contructor
29 *
30 * @throw std::exception
31 */
32 PrimeInventory();
33
34 /**
35 * @brief API to prime system blueprint.
36 *
37 * The API will traverse the system config JSON and will prime all the FRU
38 * paths which qualifies for priming.
39 *
40 */
41 void primeSystemBlueprint() const noexcept;
42
43 private:
44 /**
45 * @brief API to check if priming is required.
46 *
47 * The API will traverse the system config JSON and counts the FRU
48 * paths which qualifies for priming and compares with count of object paths
49 * found under PIM which hosts the "xyz.openbmc_project.Common.Progress"
50 * interface. If the dbus count is equal to or greater than the count from
51 * JSON config consider as priming is not required.
52 *
53 * @return true if priming is required, false otherwise.
54 */
55 bool isPrimingRequired() const noexcept;
56
57 /**
58 * @brief API to prime inventory Objects.
59 *
60 * @param[in] i_vpdFilePath - EEPROM file path.
61 *
62 * @return true if the prime inventory is success, false otherwise.
63 */
64 bool primeInventory(const std::string& i_vpdFilePath) const noexcept;
65
66 /**
67 * @brief API to populate all required interface for a FRU.
68 *
69 * @param[in] i_interfaceJson - JSON containing interfaces to be populated.
70 * @param[in,out] io_interfaceMap - Map to hold populated interfaces.
71 * @param[in] i_parsedVpdMap - Parsed VPD as a map.
72 */
73 void populateInterfaces(
74 const nlohmann::json& i_interfaceJson,
75 vpd::types::InterfaceMap& io_interfaceMap,
76 const vpd::types::VPDMapVariant& i_parsedVpdMap) const noexcept;
77
78 /**
79 * @brief API to check if present property should be handled for given FRU.
80 *
81 * vpd-manager should update present property for a FRU if and only if it's
82 * not synthesized and vpd-manager handles present property for the FRU.
83 * This API assumes "handlePresence" tag is a subset of "synthesized" tag.
84 *
85 * @param[in] i_fru - JSON block for a single FRU.
86 *
87 * @return true if present property should be handled, false otherwise.
88 */
89 inline bool isPresentPropertyHandlingRequired(
90 const nlohmann::json& i_fru) const noexcept
91 {
92 return !i_fru.value("synthesized", false) &&
93 i_fru.value("handlePresence", true);
94 }
95
96 /**
97 * @brief API to update "Functional" property.
98 *
99 * The API sets the default value for "Functional" property once if the
100 * property is not yet populated over DBus. As the property value is not
101 * controlled by the VPD-Collection process, if it is found already
102 * populated, the functions skips re-populating the property so that already
103 * existing value can be retained.
104 *
105 * @param[in] i_inventoryObjPath - Inventory path as read from config JSON.
106 * @param[in,out] io_interfaces - Map to hold all the interfaces for the
107 * FRU.
108 */
109 void processFunctionalProperty(
110 const std::string& i_inventoryObjPath,
111 vpd::types::InterfaceMap& io_interfaces) const noexcept;
112
113 /**
114 * @brief API to update "enabled" property.
115 *
116 * The API sets the default value for "enabled" property once if the
117 * property is not yet populated over DBus. As the property value is not
118 * controlled by the VPD-Collection process, if it is found already
119 * populated, the functions skips re-populating the property so that already
120 * existing value can be retained.
121 *
122 * @param[in] i_inventoryObjPath - Inventory path as read from config JSON.
123 * @param[in,out] io_interfaces - Map to hold all the interfaces for the
124 * FRU.
125 */
126 void processEnabledProperty(
127 const std::string& i_inventoryObjPath,
128 vpd::types::InterfaceMap& io_interfaces) const noexcept;
129
130 // Parsed JSON file.
131 nlohmann::json m_sysCfgJsonObj{};
132};