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