Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 1 | #include "args.hpp" |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame^] | 2 | #include "defines.hpp" |
Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 3 | #include "parser.hpp" |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame^] | 4 | #include "write.hpp" |
| 5 | |
| 6 | #include <exception> |
| 7 | #include <fstream> |
| 8 | #include <iostream> |
| 9 | #include <iterator> |
| 10 | #include <string> |
| 11 | #include <vector> |
Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 12 | |
| 13 | int main(int argc, char** argv) |
| 14 | { |
| 15 | int rc = 0; |
| 16 | |
| 17 | try |
| 18 | { |
| 19 | using namespace openpower::vpd; |
| 20 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame^] | 21 | args::Args arguments = args::parse(argc, argv); |
Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 22 | |
| 23 | // We need vpd file, FRU type and object path |
| 24 | if ((arguments.end() != arguments.find("vpd")) && |
| 25 | (arguments.end() != arguments.find("fru")) && |
| 26 | (arguments.end() != arguments.find("object"))) |
| 27 | { |
| 28 | // Read binary VPD file |
| 29 | auto file = arguments.at("vpd")[0]; |
| 30 | std::ifstream vpdFile(file, std::ios::binary); |
| 31 | Binary vpd((std::istreambuf_iterator<char>(vpdFile)), |
| 32 | std::istreambuf_iterator<char>()); |
| 33 | |
| 34 | // Parse vpd |
| 35 | auto vpdStore = parse(std::move(vpd)); |
| 36 | |
| 37 | using argList = std::vector<std::string>; |
| 38 | argList frus = std::move(arguments.at("fru")); |
| 39 | argList objects = std::move(arguments.at("object")); |
| 40 | |
| 41 | if (frus.size() != objects.size()) |
| 42 | { |
| 43 | std::cerr << "Unequal number of FRU types and object paths " |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame^] | 44 | "specified\n"; |
Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 45 | rc = -1; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | // Write VPD to FRU inventory |
| 50 | for (std::size_t index = 0; index < frus.size(); ++index) |
| 51 | { |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame^] | 52 | inventory::write(frus[index], vpdStore, objects[index]); |
Deepak Kodihalli | 51748cf | 2016-11-28 05:00:44 -0600 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | std::cerr << "Need VPD file, FRU type and object path\n"; |
| 59 | rc = -1; |
| 60 | } |
| 61 | } |
| 62 | catch (std::exception& e) |
| 63 | { |
| 64 | std::cerr << e.what() << "\n"; |
| 65 | } |
| 66 | |
| 67 | return rc; |
| 68 | } |