forked from ibm-openbmc/openpower-vpd-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup for vpd-tool APIs (ibm-openbmc#501)
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
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |