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