xref: /openbmc/pldm/libpldmresponder/base.hpp (revision a13bf143)
1 #pragma once
2 
3 #include "libpldmresponder/platform.hpp"
4 
5 #include <libpldm/base.h>
6 #include <stdint.h>
7 
8 #include <sdeventplus/source/event.hpp>
9 
10 #include <vector>
11 
12 using namespace pldm::responder;
13 
14 namespace pldm
15 {
16 namespace responder
17 {
18 namespace base
19 {
20 class Handler : public CmdHandler
21 {
22   public:
23     Handler(sdeventplus::Event& event,
24             pldm::responder::oem_platform::Handler* oemPlatformHandler) :
25         event(event),
26         oemPlatformHandler(oemPlatformHandler)
27     {
28         handlers.emplace(
29             PLDM_GET_PLDM_TYPES,
30             [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
31             return this->getPLDMTypes(request, payloadLength);
32         });
33         handlers.emplace(
34             PLDM_GET_PLDM_COMMANDS,
35             [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
36             return this->getPLDMCommands(request, payloadLength);
37         });
38         handlers.emplace(
39             PLDM_GET_PLDM_VERSION,
40             [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
41             return this->getPLDMVersion(request, payloadLength);
42         });
43         handlers.emplace(
44             PLDM_GET_TID,
45             [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
46             return this->getTID(request, payloadLength);
47         });
48     }
49 
50     /** @brief Handler for getPLDMTypes
51      *
52      *  @param[in] request - Request message payload
53      *  @param[in] payload_length - Request message payload length
54      *  @param[return] Response - PLDM Response message
55      */
56     Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
57 
58     /** @brief Handler for getPLDMCommands
59      *
60      *  @param[in] request - Request message payload
61      *  @param[in] payload_length - Request message payload length
62      *  @param[return] Response - PLDM Response message
63      */
64     Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
65 
66     /** @brief Handler for getPLDMCommands
67      *
68      *  @param[in] request - Request message payload
69      *  @param[in] payload_length - Request message payload length
70      *  @param[return] Response - PLDM Response message
71      */
72     Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
73 
74     /** @brief _processSetEventReceiver does the actual work that needs
75      *  to be carried out for setEventReceiver command. This is deferred
76      *  after sending response for getTID command to the host
77      *
78      *  @param[in] source - sdeventplus event source
79      */
80     void _processSetEventReceiver(sdeventplus::source::EventBase& source);
81 
82     /** @brief Handler for getTID
83      *
84      *  @param[in] request - Request message payload
85      *  @param[in] payload_length - Request message payload length
86      *  @param[return] Response - PLDM Response message
87      */
88     Response getTID(const pldm_msg* request, size_t payloadLength);
89 
90   private:
91     /** @brief reference of main event loop of pldmd, primarily used to schedule
92      *  work
93      */
94     sdeventplus::Event& event;
95 
96     /** @brief OEM platform handler */
97     pldm::responder::oem_platform::Handler* oemPlatformHandler;
98 
99     /** @brief sdeventplus event source */
100     std::unique_ptr<sdeventplus::source::Defer> survEvent;
101 };
102 
103 } // namespace base
104 } // namespace responder
105 } // namespace pldm
106