forked from openbmc/pldm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.cpp
63 lines (54 loc) · 1.61 KB
/
registration.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
#include "registration.hpp"
#include <map>
#include <phosphor-logging/log.hpp>
using namespace phosphor::logging;
namespace pldm
{
namespace responder
{
namespace internal
{
using Command = uint8_t;
using CommandHandler = std::map<Command, Handler>;
using Type = uint8_t;
std::map<Type, CommandHandler> typeHandlers;
} // namespace internal
void registerHandler(uint8_t pldmType, uint8_t pldmCommand, Handler&& handler)
{
using namespace internal;
CommandHandler& ch = typeHandlers[pldmType];
ch.emplace(pldmCommand, std::move(handler));
}
Response invokeHandler(uint8_t pldmType, uint8_t pldmCommand,
const pldm_msg* request, size_t payloadLength)
{
using namespace internal;
Response response;
if (!(typeHandlers.end() == typeHandlers.find(pldmType)))
{
if (!((typeHandlers.at(pldmType)).end() ==
(typeHandlers.at(pldmType)).find(pldmCommand)))
{
response = typeHandlers.at(pldmType).at(pldmCommand)(request,
payloadLength);
if (response.empty())
{
log<level::ERR>("Encountered invalid response");
}
}
else
{
log<level::ERR>("Unsupported PLDM command",
entry("TYPE=0x%02x", pldmType),
entry("COMMAND=0x%02x", pldmCommand));
}
}
else
{
log<level::ERR>("Unsupported PLDM TYPE",
entry("TYPE=0x%02x", pldmType));
}
return response;
}
} // namespace responder
} // namespace pldm