VPD tool : dumpInventory & dumpObject

VPD tool has four options.

a) Dump Complete Inventory - no additional arguments are needed.
b) Dump Specific Object - by providing the object name.
c) Read the keyword - by providing the object name, record name and keyword to be read.
d) Write/Update the keyword - by providing the object name,  record name, keyword and the value to be updated.

{value - in ascii or hex & all the other arguments in string}

"--help" option provides details on how to use the above mentioned options.

This commit has implementation of dump inventory and dump specific object.

Output:

---------Dump Inventory---------
Not displaying the complete output.

root@rainier:/tmp# ./vpd-tool -i
[
    {
        "/system": {
            "LocationCode": "U9105.22A.SIMP10R",
            "Model": "9105-22A",
            "SerialNumber": "SIMP10R",
            "type": "xyz.openbmc_project.Inventory.Item.System"
        },
        "/system/chassis": {
            "LocationCode": "U78DA.ND1.1234567",
            "type": "xyz.openbmc_project.Inventory.Item.Chassis"
        },
        .
        .
        .
        .
       and so on..
]

---------Dump Object----------

root@rainier:/tmp# ./vpd-tool -o -O /system/chassis/motherboard/ebmc_card_bmc
[
    {
        "/system/chassis/motherboard/ebmc_card_bmc": {
            "CC": "6B58",
            "DR": "EBMC            ",
            "FN": "F191014",
            "LocationCode": "U78DA.ND1.1234567-P0-C5",
            "PN": "PN12345",
            "SN": "YL6B58010000",
            "type": "xyz.openbmc_project.Inventory.Item.Bmc"
        }
    }
]

Flag to enable VPD tool:
There is no seperate flag for VPD tool.
ibm-parser flag will generate the vpd-tool binary.

Steps to build and generate the executable using meson:
meson -Denabled=ibm-parser build
ninja -C build

Test:
Tested on simics.

Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: I712f7ad4303eefa68f232685b6b0e53646f859f5
diff --git a/vpd_tool_impl.hpp b/vpd_tool_impl.hpp
new file mode 100644
index 0000000..378ece2
--- /dev/null
+++ b/vpd_tool_impl.hpp
@@ -0,0 +1,136 @@
+#include "config.h"
+
+#include "types.hpp"
+
+#include <nlohmann/json.hpp>
+
+using json = nlohmann::json;
+
+class VpdTool
+{
+  private:
+    const std::string fruPath;
+
+    /**
+     * @brief Debugger
+     * Displays the output in JSON.
+     *
+     * @param[in] output - json output to be displayed
+     */
+    void debugger(json output);
+
+    /**
+     * @brief make Dbus Call
+     *
+     * @param[in] objectName - dbus Object
+     * @param[in] interface - dbus Interface
+     * @param[in] kw - keyword under the interface
+     *
+     * @return dbus call response
+     */
+    auto makeDBusCall(const std::string& objectName,
+                      const std::string& interface, const std::string& kw);
+
+    /**
+     * @brief Adds FRU type and Location Code
+     * Appends the type of the FRU and location code to the output
+     *
+     * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
+     * @param[in] object - The D-Bus object to read the location code from
+     * @param[out] kwVal - JSON object into which the FRU type and location code
+     * are placed
+     */
+    void addFruTypeAndLocation(json exIntf, const std::string& object,
+                               json& kwVal);
+
+    /**
+     * @brief Get VINI properties
+     * Making a dbus call for properties [SN, PN, CC, FN, DR]
+     * under VINI interface.
+     *
+     * @param[in] invPath - Value of inventory Path
+     * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
+     *
+     * @return json output which gives the properties under invPath's VINI
+     * interface
+     */
+    json getVINIProperties(std::string invPath, json exIntf);
+
+    /**
+     * @brief Get ExtraInterface Properties
+     * Making a dbus call for those properties under extraInterfaces.
+     *
+     * @param[in] invPath - Value of inventory path
+     * @param[in] extraInterface - One of the invPath's extraInterfaces whose
+     * value is not null
+     * @param[in] prop - All properties of the extraInterface.
+     *
+     * @return json output which gives the properties under invPath's
+     *         extraInterface.
+     */
+    void getExtraInterfaceProperties(std::string invPath,
+                                     std::string extraInterface, json prop,
+                                     json exIntf, json& output);
+
+    /**
+     * @brief Interface Decider
+     * Decides whether to make the dbus call for
+     * getting properites from extraInterface or from
+     * VINI interface, depending on the value of
+     * extraInterfaces object in the inventory json.
+     *
+     * @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
+     *
+     * @return json output for one of the EEPROM objects.
+     */
+    json interfaceDecider(json& itemEEPROM);
+
+    /**
+     * @brief Parse Inventory JSON
+     * Parses the complete inventory json and depending upon
+     * the user option makes the dbuscall for the frus
+     * via interfaceDecider function.
+     *
+     * @param[in] jsObject - Inventory json object
+     * @param[in] flag - flag which tells about the user option(either
+     * dumpInventory or dumpObject)
+     * @param[in] fruPath - fruPath is empty for dumpInventory option and holds
+     *                      valid fruPath for dumpObject option.
+     *
+     * @return output json
+     */
+    json parseInvJson(const json& jsObject, char flag, std::string fruPath);
+
+  public:
+    /**
+     * @brief Dump the complete inventory in JSON format
+     *
+     * @param[in] jsObject - Inventory JSON specified in configure file.
+     */
+    void dumpInventory(const nlohmann::basic_json<>& jsObject);
+
+    /**
+     * @brief Dump the given inventory object in JSON format
+     *
+     * @param[in] jsObject - Inventory JSON specified in configure file.
+     */
+    void dumpObject(const nlohmann::basic_json<>& jsObject);
+
+    /**
+     * @brief A Constructor
+     * Constructor is called during the
+     * object instantiation for dumpInventory option.
+     */
+    VpdTool()
+    {
+    }
+
+    /**
+     * @brief Constructor
+     * Constructor is called during the
+     * object instantiation for dumpObject option.
+     */
+    VpdTool(const std::string&& fru) : fruPath(std::move(fru))
+    {
+    }
+};