|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 | + * this software and associated documentation files (the "Software"), to deal in |
| 6 | + * the Software without restriction, including without limitation the rights to |
| 7 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 8 | + * the Software, and to permit persons to whom the Software is furnished to do so, |
| 9 | + * subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 16 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 17 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 18 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +#ifndef TRANSPORT_INTERFACE_H_ |
| 23 | +#define TRANSPORT_INTERFACE_H_ |
| 24 | + |
| 25 | +#include <stdint.h> |
| 26 | +#include <stddef.h> |
| 27 | + |
| 28 | +/** |
| 29 | + * @brief The NetworkContext is an incomplete type. An implementation of this |
| 30 | + * interface must define NetworkContext as per the requirements. This context |
| 31 | + * is passed into the network interface functions. |
| 32 | + */ |
| 33 | +struct NetworkContext; |
| 34 | +typedef struct NetworkContext NetworkContext_t; |
| 35 | + |
| 36 | +/** |
| 37 | + * @brief Transport interface for receiving data on the network. |
| 38 | + * |
| 39 | + * @param[in] pNetworkContext Implementation-defined network context. |
| 40 | + * @param[in] pBuffer Buffer to receive the data into. |
| 41 | + * @param[in] bytesToRecv Number of bytes requested from the network. |
| 42 | + * |
| 43 | + * @return The number of bytes received or a negative error code. |
| 44 | + */ |
| 45 | +typedef int32_t ( * TransportRecv_t )( const NetworkContext_t * pNetworkContext, |
| 46 | + void * pBuffer, |
| 47 | + size_t bytesToRecv ); |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Transport interface for sending data over the network. |
| 51 | + * |
| 52 | + * @param[in] pNetworkContext Implementation-defined network context. |
| 53 | + * @param[in] pBuffer Buffer containing the bytes to send over the network stack. |
| 54 | + * @param[in] bytesToSend Number of bytes to send over the network. |
| 55 | + * |
| 56 | + * @return The number of bytes sent or a negative error code. |
| 57 | + */ |
| 58 | +typedef int32_t ( * TransportSend_t )( const NetworkContext_t * pNetworkContext, |
| 59 | + const void * pBuffer, |
| 60 | + size_t bytesToSend ); |
| 61 | + |
| 62 | +/** |
| 63 | + * @brief The transport layer interface. |
| 64 | + */ |
| 65 | +typedef struct TransportInterface |
| 66 | +{ |
| 67 | + TransportRecv_t recv; /**< Transport receive interface. */ |
| 68 | + TransportSend_t send; /**< Transport send interface. */ |
| 69 | + NetworkContext_t * pNetworkContext; /**< Implementation-defined network context. */ |
| 70 | +} TransportInterface_t; |
| 71 | + |
| 72 | +#endif /* ifndef TRANSPORT_INTERFACE_H_ */ |
0 commit comments