Skip to content

Commit

Permalink
Merge pull request #501 from souvik1914581/sr_vpdToolDumpStub
Browse files Browse the repository at this point in the history
Implement vpd-tool dumpObject stub
  • Loading branch information
SunnySrivastava1984 authored Jan 2, 2025
2 parents b86a972 + ce7e4e1 commit f92c478
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
4 changes: 4 additions & 0 deletions vpd-tool/include/tool_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ constexpr auto ipzVpdInfPrefix = "com.ibm.ipzvpd.";
constexpr auto vpdManagerService = "com.ibm.VPD.Manager";
constexpr auto vpdManagerObjectPath = "/com/ibm/VPD/Manager";
constexpr auto vpdManagerInfName = "com.ibm.VPD.Manager";
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
35 changes: 35 additions & 0 deletions vpd-tool/include/vpd_tool.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <nlohmann/json.hpp>

#include <string>

namespace vpd
Expand All @@ -17,6 +19,25 @@ namespace vpd
*/
class VpdTool
{
private:
/**
* @brief Get specific properties of a FRU in JSON format.
*
* For a given object path of a FRU, this API returns the following
* properties of the FRU in JSON format:
* - Present property, Pretty Name, Location Code, Sub Model
* - SN, PN, CC, FN, DR keywords under VINI record.
*
* @param[in] i_fruPath - DBus object path
*
* @return On success, returns the properties of the FRU in JSON format,
* otherwise throws a std::runtime_error exception.
* Note: The caller of this API should handle this exception.
*
* @throw std::runtime_error
*/
nlohmann::json getFruProperties(const std::string& i_fruPath) const;

public:
/**
* @brief Read keyword value.
Expand All @@ -39,5 +60,19 @@ class VpdTool
const std::string& i_recordName,
const std::string& i_keywordName, const bool i_onHardware,
const std::string& i_fileToSave = {});

/**
* @brief Dump the given inventory object in JSON format to console.
*
* For a given object path of a FRU, this API dumps the following properties
* of the FRU in JSON format to console:
* - Present property, Pretty Name, Location Code, Sub Model
* - SN, PN, CC, FN, DR keywords under VINI record.
*
* @param[in] i_fruPath - DBus object path.
*
* @return On success returns 0, otherwise returns -1.
*/
int dumpObject(const std::string& i_fruPath) const noexcept;
};
} // namespace vpd
29 changes: 29 additions & 0 deletions vpd-tool/src/vpd_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,33 @@ int VpdTool::readKeyword(const std::string& i_vpdPath,
}
return l_rc;
}

int VpdTool::dumpObject(const std::string& i_fruPath) const noexcept
{
int l_rc{constants::FAILURE};
try
{
const nlohmann::json l_resultJson = getFruProperties(i_fruPath);

utils::printJson(l_resultJson);
l_rc = constants::SUCCESS;
}
catch (std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
// std::cerr << "Dump Object failed for FRU: " << i_fruPath
// << " Error: " << l_ex.what() << std::endl;
}
return l_rc;
}

nlohmann::json VpdTool::getFruProperties(const std::string& i_fruPath) const
{
nlohmann::json l_resultInJson = nlohmann::json::array({});

// TODO: Implement getFruProperties
(void)i_fruPath;
return l_resultInJson;
}

} // namespace vpd
16 changes: 15 additions & 1 deletion vpd-tool/src/vpd_tool_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ int main(int argc, char** argv)
" On hardware: "
"vpd-tool -w -H -O <EEPROM Path> -R <Record Name> -K <Keyword Name> -V <Keyword Value>\n"
" On hardware, take keyword value from file:\n"
" vpd-tool -w -H -O <EEPROM Path> -R <Record Name> -K <Keyword Name> --file <File Path>");
" vpd-tool -w -H -O <EEPROM Path> -R <Record Name> -K <Keyword Name> --file <File Path>\n"
"Dump Object:\n"
" From DBus to console: "
"vpd-tool -o -O <DBus Object Path>");

auto l_objectOption = l_app.add_option("--object, -O", l_vpdPath,
"File path");
Expand Down Expand Up @@ -71,6 +74,12 @@ int main(int argc, char** argv)
->needs(l_recordOption)
->needs(l_keywordOption);

auto l_dumpObjFlag =
l_app
.add_flag("--dumpObject, -o",
"Dump specific properties of an inventory object")
->needs(l_objectOption);

// ToDo: Take offset value from user for hardware path.

CLI11_PARSE(l_app, argc, argv);
Expand Down Expand Up @@ -178,6 +187,11 @@ int main(int argc, char** argv)

// ToDo: implementation of write keyword
}
else if (!l_dumpObjFlag->empty())
{
vpd::VpdTool l_vpdToolObj;
l_rc = l_vpdToolObj.dumpObject(l_vpdPath);
}
else
{
std::cout << l_app.help() << std::endl;
Expand Down

0 comments on commit f92c478

Please sign in to comment.