Skip to content

Commit

Permalink
Initial setup for vpd-tool APIs (ibm-openbmc#501)
Browse files Browse the repository at this point in the history
This commit includes changes and new source code files required for
implementation of vpd-tool APIs.

Change-Id: I821777237a3080d390e2bba151cd685ef8994bf9
Signed-off-by: Souvik Roy <[email protected]>
  • Loading branch information
Souvik Roy committed Dec 2, 2024
1 parent bda78ab commit 3e2f9fb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vpd-tool/include/tool_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ constexpr auto inventoryManagerService =
"xyz.openbmc_project.Inventory.Manager";
constexpr auto baseInventoryPath = "/xyz/openbmc_project/inventory";
constexpr auto ipzVpdInfPrefix = "com.ibm.ipzvpd.";
constexpr auto inventoryItemInf = "xyz.openbmc_project.Inventory.Item";
constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI";
constexpr auto locationCodeInf = "com.ibm.ipzvpd.Location";
constexpr auto assetInf = "xyz.openbmc_project.Inventory.Decorator.Asset";
} // namespace constants
} // namespace vpd
53 changes: 53 additions & 0 deletions vpd-tool/include/tool_json_utility.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <nlohmann/json.hpp>

#include <fstream>

namespace vpd
{
namespace jsonUtility
{

/**
* @brief API to parse respective JSON.
*
* Exception is thrown in case of JSON parse error.
*
* @param[in] i_pathToJson - Path to JSON.
* @return Parsed JSON.
* @throw std::runtime_error
*/
inline nlohmann::json getParsedJson(const std::string& i_pathToJson)
{
if (i_pathToJson.empty())
{
throw std::runtime_error("Path to JSON is missing");
}

if (!std::filesystem::exists(i_pathToJson) ||
std::filesystem::is_empty(i_pathToJson))
{
throw std::runtime_error("Incorrect File Path or empty file = " +
i_pathToJson);
}

std::ifstream jsonFile(i_pathToJson);
if (!jsonFile)
{
throw std::runtime_error("Failed to access Json path = " +
i_pathToJson);
}

try
{
return nlohmann::json::parse(jsonFile);
}
catch (const nlohmann::json::parse_error& e)
{
throw std::runtime_error("Failed to parse JSON file");
}
}

} // namespace jsonUtility
} // namespace vpd
1 change: 1 addition & 0 deletions vpd-tool/include/tool_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "tool_constants.hpp"
#include "tool_types.hpp"

#include <nlohmann/json.hpp>
Expand Down
5 changes: 5 additions & 0 deletions vpd-tool/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ endif
sdbusplus = dependency('sdbusplus', fallback: [ 'sdbusplus', 'sdbusplus_dep' ])
dependency_list = [CLI11_dep, sdbusplus]

conf_data = configuration_data()
conf_data.set_quoted('INVENTORY_JSON_SYM_LINK', get_option('INVENTORY_JSON_SYM_LINK'))
configure_file(output: 'config.h',
configuration : conf_data)

sources = ['src/vpd_tool_main.cpp',
'src/vpd_tool.cpp']

Expand Down
1 change: 1 addition & 0 deletions vpd-tool/meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('INVENTORY_JSON_SYM_LINK', type: 'string', value: '/var/lib/vpd/vpd_inventory.json', description: 'Symbolic link to vpd inventory json.')

0 comments on commit 3e2f9fb

Please sign in to comment.