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