blob: ddfb99de63814f490e1087ea9ca5a6388b7737f0 [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 *
Delphine CC Chiud2e48992023-12-05 16:29:51 +080033 * @param[in] tid - PLDM request TID
Deepak Kodihallibc669f12019-11-28 08:52:07 -060034 * @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 */
Delphine CC Chiud2e48992023-12-05 16:29:51 +080040 Response handle(pldm_tid_t tid, Type pldmType, Command pldmCommand,
41 const pldm_msg* request, size_t reqMsgLen)
Deepak Kodihallibc669f12019-11-28 08:52:07 -060042 {
Delphine CC Chiud2e48992023-12-05 16:29:51 +080043 return handlers.at(pldmType)->handle(tid, pldmCommand, request,
44 reqMsgLen);
Deepak Kodihallibc669f12019-11-28 08:52:07 -060045 }
46
47 private:
48 std::map<Type, std::unique_ptr<CmdHandler>> handlers;
49};
50
51} // namespace responder
52} // namespace pldm