Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 1 | #include "write.hpp" |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 2 | |
| 3 | #include "defines.hpp" |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 4 | #include "writefru.hpp" |
| 5 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 6 | #include <algorithm> |
| 7 | #include <exception> |
| 8 | |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 9 | namespace openpower |
| 10 | { |
| 11 | namespace vpd |
| 12 | { |
| 13 | namespace inventory |
| 14 | { |
| 15 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 16 | static const std::unordered_map<std::string, Fru> supportedFrus = { |
| 17 | {"BMC", Fru::BMC}, {"ETHERNET", Fru::ETHERNET}}; |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 18 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 19 | void write(const std::string& type, const Store& vpdStore, |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 20 | 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 Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 55 | } // namespace inventory |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 56 | } // namespace vpd |
| 57 | } // namespace openpower |