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