Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "handler.hpp" |
| 4 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 5 | #include <libpldm/base.h> |
| 6 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <memory> |
| 9 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 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 | * |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 33 | * @param[in] tid - PLDM request TID |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 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 | */ |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 40 | Response handle(pldm_tid_t tid, Type pldmType, Command pldmCommand, |
| 41 | const pldm_msg* request, size_t reqMsgLen) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 42 | { |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 43 | return handlers.at(pldmType)->handle(tid, pldmCommand, request, |
| 44 | reqMsgLen); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | private: |
| 48 | std::map<Type, std::unique_ptr<CmdHandler>> handlers; |
| 49 | }; |
| 50 | |
| 51 | } // namespace responder |
| 52 | } // namespace pldm |