xref: /openbmc/pldm/pldmd/invoker.hpp (revision 4d99c311)
1 #pragma once
2 
3 #include "handler.hpp"
4 
5 #include <libpldm/base.h>
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] tid - PLDM request TID
34      *  @param[in] pldmType - PLDM type code
35      *  @param[in] pldmCommand - PLDM command code
36      *  @param[in] request - PLDM request message
37      *  @param[in] reqMsgLen - PLDM request message size
38      *  @return PLDM response message
39      */
40     Response handle(pldm_tid_t tid, Type pldmType, Command pldmCommand,
41                     const pldm_msg* request, size_t reqMsgLen)
42     {
43         return handlers.at(pldmType)->handle(tid, pldmCommand, request,
44                                              reqMsgLen);
45     }
46 
47   private:
48     std::map<Type, std::unique_ptr<CmdHandler>> handlers;
49 };
50 
51 } // namespace responder
52 } // namespace pldm
53