blob: e4f3e5941c2af8f0f7589b4627c93c0cdf488f8d [file] [log] [blame]
Deepak Kodihalli82c1e562016-11-28 06:06:50 -06001#include <exception>
2#include <algorithm>
3#include "defines.hpp"
4#include "write.hpp"
5#include "writefru.hpp"
6
7namespace openpower
8{
9namespace vpd
10{
11namespace inventory
12{
13
14static const std::unordered_map<std::string, Fru> supportedFrus =
15{
16 {"BMC", Fru::BMC},
17 {"ETHERNET", Fru::ETHERNET}
18};
19
20void write(const std::string& type,
21 const Store& vpdStore,
22 const std::string& path)
23{
24 // Get the enum corresponding to type, and call
25 // appropriate write FRU method.
26
27 std::string fru = type;
28 std::transform(fru.begin(), fru.end(), fru.begin(),
29 [](unsigned char c) { return std::toupper(c); });
30 auto iterator = supportedFrus.find(fru);
31 if (supportedFrus.end() == iterator)
32 {
33 throw std::runtime_error("Unsupported FRU: " + std::move(fru));
34 }
35 else
36 {
37 switch (iterator->second)
38 {
39 case Fru::BMC:
40 {
41 writeFru<Fru::BMC>(vpdStore, path);
42 break;
43 }
44
45 case Fru::ETHERNET:
46 {
47 writeFru<Fru::ETHERNET>(vpdStore, path);
48 break;
49 }
50
51 default:
52 break;
53 }
54 }
55}
56
57} // inventory
58} // namespace vpd
59} // namespace openpower