blob: 9903e7fc2314b903aa9ecd874588b21117785c47 [file] [log] [blame]
Deepak Kodihallibc669f12019-11-28 08:52:07 -06001#pragma once
2
3#include "handler.hpp"
4
George Liuc453e162022-12-21 17:16:23 +08005#include <libpldm/base.h>
6
Deepak Kodihallibc669f12019-11-28 08:52:07 -06007#include <map>
8#include <memory>
9
Deepak Kodihallibc669f12019-11-28 08:52:07 -060010namespace pldm
11{
12
13using Type = uint8_t;
14
15namespace responder
16{
17
18class Invoker
19{
20 public:
21 /** @brief Register a handler for a PLDM Type
22 *
23 * @param[in] pldmType - PLDM type code
24 * @param[in] handler - PLDM Type handler
25 */
26 void registerHandler(Type pldmType, std::unique_ptr<CmdHandler> handler)
27 {
28 handlers.emplace(pldmType, std::move(handler));
29 }
30
31 /** @brief Invoke a PLDM command handler
32 *
33 * @param[in] pldmType - PLDM type code
34 * @param[in] pldmCommand - PLDM command code
35 * @param[in] request - PLDM request message
36 * @param[in] reqMsgLen - PLDM request message size
37 * @return PLDM response message
38 */
39 Response handle(Type pldmType, Command pldmCommand, const pldm_msg* request,
40 size_t reqMsgLen)
41 {
42 return handlers.at(pldmType)->handle(pldmCommand, request, reqMsgLen);
43 }
44
45 private:
46 std::map<Type, std::unique_ptr<CmdHandler>> handlers;
47};
48
49} // namespace responder
50} // namespace pldm