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