blob: 8972ed6cfa8487e720dda843821417d732399c01 [file] [log] [blame]
Deepak Kodihallibc669f12019-11-28 08:52:07 -06001#pragma once
2
George Liu6492f522020-06-16 10:34:05 +08003#include "libpldm/base.h"
4
Deepak Kodihallibc669f12019-11-28 08:52:07 -06005#include "handler.hpp"
6
7#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