blob: 67ad4716d00ed9e4c329f432189d0b6a0efe63cc [file] [log] [blame]
Deepak Kodihallibc669f12019-11-28 08:52:07 -06001#pragma once
2
3#include <functional>
4#include <map>
5
6#include "libpldm/base.h"
7
8namespace pldm
9{
10
11using Command = uint8_t;
12
13namespace responder
14{
15
16using Response = std::vector<uint8_t>;
17class CmdHandler;
18using HandlerFunc =
19 std::function<Response(const pldm_msg* request, size_t reqMsgLen)>;
20
21class 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