Editor implementation for VPD manager
This commit implements editor class for VPD manager app.
This calss holds responsibility of handling and editing
vpd data related requests on behalf of manager app and
updating the cache with new data if required.
This commit also changes parser class to implement api
needed to validate vpd header file in case of write call.
Steps to build:
meson <build_directory>
ninja -C <directory_path>
-Tested with sample json and sample vpd file
sample command to test
busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager
com.ibm.VPD.Manager WriteKeyword sssay
<"inventory_path"> <"Record_Name"> <"Keyword_Name">
<no. of bytes to update> <array_of_bytes>
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I569f03e329b0f62937c6e143a344d8e4ff02db6f
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index ce8bea5..79ab5a5 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -5,11 +5,8 @@
#include "const.hpp"
#include "parser.hpp"
-#include <exception>
-#include <fstream>
-#include <iostream>
-#include <nlohmann/json.hpp>
-#include <vector>
+using namespace openpower::vpd::constants;
+using namespace openpower::vpd::manager::editor;
namespace openpower
{
@@ -79,7 +76,49 @@
const std::string recordName,
const std::string keyword, const Binary value)
{
- // implement the interface to write keyword VPD data
+ try
+ {
+ if (frus.find(path) == frus.end())
+ {
+ throw std::runtime_error("Inventory path not found");
+ }
+
+ inventory::Path vpdFilePath = frus.find(path)->second;
+ std::ifstream vpdStream(vpdFilePath, std::ios::binary);
+ if (!vpdStream)
+ {
+ throw std::runtime_error("file not found");
+ }
+
+ Byte data;
+ vpdStream.seekg(IPZ_DATA_START, std::ios::beg);
+ vpdStream.get(*(reinterpret_cast<char*>(&data)));
+
+ // implies it is IPZ VPD
+ if (data == KW_VAL_PAIR_START_TAG)
+ {
+ Binary vpdHeader(lengths::VHDR_RECORD_LENGTH +
+ lengths::VHDR_ECC_LENGTH);
+ vpdStream.seekg(0);
+ vpdStream.read(reinterpret_cast<char*>(vpdHeader.data()),
+ vpdHeader.capacity());
+
+ // check if header is valid
+ openpower::vpd::keyword::editor::processHeader(
+ std::move(vpdHeader));
+
+ // instantiate editor class to update the data
+ EditorImpl edit(vpdFilePath, recordName, keyword);
+ edit.updateKeyword(value);
+
+ return;
+ }
+ throw std::runtime_error("Invalid VPD file type");
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << e.what() << std::endl;
+ }
}
std::vector<sdbusplus::message::object_path>