summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2016-11-28 05:00:44 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2016-12-08 12:40:08 -0600
commit51748cfbe0c811573d51594a7030991ef5432430 (patch)
treee044748d2141b5f9fabae509d44fce9e921401e2
parent0361e3f16ce09b48ad8d35ae76b12cd65a92199c (diff)
downloadopenpower-vpd-parser-51748cfbe0c811573d51594a7030991ef5432430.tar.gz
openpower-vpd-parser-51748cfbe0c811573d51594a7030991ef5432430.zip
Add main application
Add main program to read OpenPOWER VPD, parse it and then to write it to the inventory. The program needs as input - VPD file, FRU type and FRU object path. Change-Id: Iaebc0d5a99f5c12e408de893bd1f310145b4b360 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--app.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/app.cpp b/app.cpp
new file mode 100644
index 0000000..876cf61
--- /dev/null
+++ b/app.cpp
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <iterator>
+#include <exception>
+#include "defines.hpp"
+#include "write.hpp"
+#include "args.hpp"
+#include "parser.hpp"
+
+int main(int argc, char** argv)
+{
+ int rc = 0;
+
+ try
+ {
+ using namespace openpower::vpd;
+
+ args::Args arguments = args::parse(argc, argv);
+
+ // We need vpd file, FRU type and object path
+ if ((arguments.end() != arguments.find("vpd")) &&
+ (arguments.end() != arguments.find("fru")) &&
+ (arguments.end() != arguments.find("object")))
+ {
+ // Read binary VPD file
+ auto file = arguments.at("vpd")[0];
+ std::ifstream vpdFile(file, std::ios::binary);
+ Binary vpd((std::istreambuf_iterator<char>(vpdFile)),
+ std::istreambuf_iterator<char>());
+
+ // Parse vpd
+ auto vpdStore = parse(std::move(vpd));
+
+ using argList = std::vector<std::string>;
+ argList frus = std::move(arguments.at("fru"));
+ argList objects = std::move(arguments.at("object"));
+
+ if (frus.size() != objects.size())
+ {
+ std::cerr << "Unequal number of FRU types and object paths "
+ "specified\n";
+ rc = -1;
+ }
+ else
+ {
+ // Write VPD to FRU inventory
+ for (std::size_t index = 0; index < frus.size(); ++index)
+ {
+ inventory::write(
+ frus[index],
+ vpdStore,
+ objects[index]);
+ }
+ }
+ }
+ else
+ {
+ std::cerr << "Need VPD file, FRU type and object path\n";
+ rc = -1;
+ }
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << e.what() << "\n";
+ }
+
+ return rc;
+}
OpenPOWER on IntegriCloud