Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <functional> |
| 4 | #include <map> |
| 5 | |
| 6 | #include "libpldm/base.h" |
| 7 | |
| 8 | namespace pldm |
| 9 | { |
| 10 | |
| 11 | using Command = uint8_t; |
| 12 | |
| 13 | namespace responder |
| 14 | { |
| 15 | |
| 16 | using Response = std::vector<uint8_t>; |
| 17 | class CmdHandler; |
| 18 | using HandlerFunc = |
| 19 | std::function<Response(const pldm_msg* request, size_t reqMsgLen)>; |
| 20 | |
| 21 | class CmdHandler |
| 22 | { |
| 23 | public: |
| 24 | /** @brief Invoke a PLDM command handler |
| 25 | * |
| 26 | * @param[in] pldmCommand - PLDM command code |
| 27 | * @param[in] request - PLDM request message |
| 28 | * @param[in] reqMsgLen - PLDM request message size |
| 29 | * @return PLDM response message |
| 30 | */ |
| 31 | Response handle(Command pldmCommand, const pldm_msg* request, |
| 32 | size_t reqMsgLen) |
| 33 | { |
| 34 | return handlers.at(pldmCommand)(request, reqMsgLen); |
| 35 | } |
| 36 | |
| 37 | protected: |
| 38 | /** @brief map of PLDM command code to handler - to be populated by derived |
| 39 | * classes. |
| 40 | */ |
| 41 | std::map<Command, HandlerFunc> handlers; |
| 42 | }; |
| 43 | |
| 44 | } // namespace responder |
| 45 | } // namespace pldm |