From 51748cfbe0c811573d51594a7030991ef5432430 Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Mon, 28 Nov 2016 05:00:44 -0600 Subject: 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 --- app.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app.cpp 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 +#include +#include +#include +#include +#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(vpdFile)), + std::istreambuf_iterator()); + + // Parse vpd + auto vpdStore = parse(std::move(vpd)); + + using argList = std::vector; + 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; +} -- cgit v1.2.1