forked from openbmc/pldm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvoker.hpp
50 lines (40 loc) · 1.1 KB
/
invoker.hpp
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
#pragma once
#include "libpldm/base.h"
#include "handler.hpp"
#include <map>
#include <memory>
namespace pldm
{
using Type = uint8_t;
namespace responder
{
class Invoker
{
public:
/** @brief Register a handler for a PLDM Type
*
* @param[in] pldmType - PLDM type code
* @param[in] handler - PLDM Type handler
*/
void registerHandler(Type pldmType, std::unique_ptr<CmdHandler> handler)
{
handlers.emplace(pldmType, std::move(handler));
}
/** @brief Invoke a PLDM command handler
*
* @param[in] pldmType - PLDM type code
* @param[in] pldmCommand - PLDM command code
* @param[in] request - PLDM request message
* @param[in] reqMsgLen - PLDM request message size
* @return PLDM response message
*/
Response handle(Type pldmType, Command pldmCommand, const pldm_msg* request,
size_t reqMsgLen)
{
return handlers.at(pldmType)->handle(pldmCommand, request, reqMsgLen);
}
private:
std::map<Type, std::unique_ptr<CmdHandler>> handlers;
};
} // namespace responder
} // namespace pldm