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