Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & |
| 3 | * AFFILIATES. All rights reserved. |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <OcpMctpVdm.hpp> |
| 10 | #include <boost/asio/generic/datagram_protocol.hpp> |
| 11 | #include <boost/asio/io_context.hpp> |
| 12 | #include <boost/asio/steady_timer.hpp> |
| 13 | |
| 14 | #include <cstddef> |
| 15 | #include <cstdint> |
| 16 | #include <functional> |
| 17 | #include <span> |
| 18 | |
| 19 | namespace mctp |
| 20 | { |
| 21 | class MctpRequester |
| 22 | { |
| 23 | public: |
| 24 | MctpRequester() = delete; |
| 25 | |
| 26 | MctpRequester(const MctpRequester&) = delete; |
| 27 | |
| 28 | MctpRequester(MctpRequester&&) = delete; |
| 29 | |
| 30 | MctpRequester& operator=(const MctpRequester&) = delete; |
| 31 | |
| 32 | MctpRequester& operator=(MctpRequester&&) = delete; |
| 33 | |
| 34 | explicit MctpRequester(boost::asio::io_context& ctx); |
| 35 | |
| 36 | void sendRecvMsg(uint8_t eid, std::span<const uint8_t> reqMsg, |
| 37 | std::span<uint8_t> respMsg, |
| 38 | std::move_only_function<void(int)> callback); |
| 39 | |
| 40 | private: |
| 41 | void processRecvMsg(uint8_t eid, std::span<const uint8_t> reqMsg, |
| 42 | std::span<uint8_t> respMsg, |
| 43 | const boost::system::error_code& ec, size_t length); |
| 44 | |
| 45 | void handleSendMsgCompletion(uint8_t eid, std::span<const uint8_t> reqMsg, |
| 46 | std::span<uint8_t> respMsg, |
| 47 | const boost::system::error_code& ec, |
| 48 | size_t length); |
| 49 | |
| 50 | boost::asio::generic::datagram_protocol::socket mctpSocket; |
| 51 | |
| 52 | static constexpr size_t maxMessageSize = 65536 + 256; |
| 53 | |
| 54 | boost::asio::generic::datagram_protocol::endpoint sendEndPoint; |
| 55 | |
| 56 | boost::asio::generic::datagram_protocol::endpoint recvEndPoint; |
| 57 | |
| 58 | boost::asio::steady_timer expiryTimer; |
| 59 | |
| 60 | std::move_only_function<void(int)> completionCallback; |
| 61 | |
| 62 | static constexpr uint8_t msgType = ocp::accelerator_management::messageType; |
| 63 | }; |
| 64 | } // namespace mctp |