xref: /openbmc/pldm/pldmd/invoker.hpp (revision 6e51e373)
1 #pragma once
2 
3 #include "libpldm/base.h"
4 
5 #include "handler.hpp"
6 
7 #include <map>
8 #include <memory>
9 
10 namespace pldm
11 {
12 
13 using Type = uint8_t;
14 
15 namespace responder
16 {
17 
18 class 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
51