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