| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | #ifndef _ESP_TRANSPORT_H_
 | 
					
						
							|  |  |  | #define _ESP_TRANSPORT_H_
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <esp_err.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | typedef struct esp_transport_list_t* esp_transport_list_handle_t; | 
					
						
							|  |  |  | typedef struct esp_transport_item_t* esp_transport_handle_t; | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | typedef int (*connect_func)(esp_transport_handle_t t, const char *host, int port, int timeout_ms); | 
					
						
							|  |  |  | typedef int (*io_func)(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms); | 
					
						
							|  |  |  | typedef int (*io_read_func)(esp_transport_handle_t t, char *buffer, int len, int timeout_ms); | 
					
						
							|  |  |  | typedef int (*trans_func)(esp_transport_handle_t t); | 
					
						
							|  |  |  | typedef int (*poll_func)(esp_transport_handle_t t, int timeout_ms); | 
					
						
							|  |  |  | typedef int (*connect_async_func)(esp_transport_handle_t t, const char *host, int port, int timeout_ms); | 
					
						
							|  |  |  | typedef esp_transport_handle_t (*payload_transfer_func)(esp_transport_handle_t); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Create transport list | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     A handle can hold all transports | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_transport_list_handle_t esp_transport_list_init(); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Cleanup and free all transports, include itself, | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  |  *             this function will invoke esp_transport_destroy of every transport have added this the list | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  list  The list | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_FAIL | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_list_destroy(esp_transport_list_handle_t list); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Add a transport to the list, and define a scheme to indentify this transport in the list | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  list    The list | 
					
						
							|  |  |  |  * @param[in]  t       The Transport | 
					
						
							|  |  |  |  * @param[in]  scheme  The scheme | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_list_add(esp_transport_list_handle_t list, esp_transport_handle_t t, const char *scheme); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      This function will remove all transport from the list, | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  |  *             invoke esp_transport_destroy of every transport have added this the list | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  list  The list | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_ERR_INVALID_ARG | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_list_clean(esp_transport_list_handle_t list); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  |  * @brief      Get the transport by scheme, which has been defined when calling function `esp_transport_list_add` | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  list  The list | 
					
						
							|  |  |  |  * @param[in]  tag   The tag | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     The transport handle | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_transport_handle_t esp_transport_list_get_transport(esp_transport_list_handle_t list, const char *scheme); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Initialize a transport handle object | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     The transport handle | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_transport_handle_t esp_transport_init(); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Cleanup and free memory the transport | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t     The transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_FAIL | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_destroy(esp_transport_handle_t t); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Get default port number used by this transport | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t     The transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     the port number | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_get_default_port(esp_transport_handle_t t); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Set default port number that can be used by this transport | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t     The transport handle | 
					
						
							|  |  |  |  * @param[in]  port  The port number | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_FAIL | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_set_default_port(esp_transport_handle_t t, int port); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Transport connection function, to make a connection to server | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param      t           The transport handle | 
					
						
							|  |  |  |  * @param[in]  host        Hostname | 
					
						
							|  |  |  |  * @param[in]  port        Port | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  * - socket for will use by this transport | 
					
						
							|  |  |  |  * - (-1) if there are any errors, should check errno | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 23:26:59 +05:30
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Non-blocking transport connection function, to make a connection to server | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param      t           The transport handle | 
					
						
							|  |  |  |  * @param[in]  host        Hostname | 
					
						
							|  |  |  |  * @param[in]  port        Port | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  * - socket for will use by this transport | 
					
						
							|  |  |  |  * - (-1) if there are any errors, should check errno | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_connect_async(esp_transport_handle_t t, const char *host, int port, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2018-08-07 23:26:59 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Transport read function | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param      t           The transport handle | 
					
						
							|  |  |  |  * @param      buffer      The buffer | 
					
						
							|  |  |  |  * @param[in]  len         The length | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *  - Number of bytes was read | 
					
						
							|  |  |  |  *  - (-1) if there are any errors, should check errno | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_read(esp_transport_handle_t t, char *buffer, int len, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Poll the transport until readable or timeout | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t           The transport handle | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - 0      Timeout | 
					
						
							|  |  |  |  *     - (-1)   If there are any errors, should check errno | 
					
						
							|  |  |  |  *     - other  The transport can read | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_poll_read(esp_transport_handle_t t, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Transport write function | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param      t           The transport handle | 
					
						
							|  |  |  |  * @param      buffer      The buffer | 
					
						
							|  |  |  |  * @param[in]  len         The length | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *  - Number of bytes was written | 
					
						
							|  |  |  |  *  - (-1) if there are any errors, should check errno | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Poll the transport until writeable or timeout | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t           The transport handle | 
					
						
							|  |  |  |  * @param[in]  timeout_ms  The timeout milliseconds | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - 0      Timeout | 
					
						
							|  |  |  |  *     - (-1)   If there are any errors, should check errno | 
					
						
							|  |  |  |  *     - other  The transport can write | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_poll_write(esp_transport_handle_t t, int timeout_ms); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Transport close | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param      t     The transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  * - 0 if ok | 
					
						
							|  |  |  |  * - (-1) if there are any errors, should check errno | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | int esp_transport_close(esp_transport_handle_t t); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Get user data context of this transport | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t        The transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     The user data context | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | void *esp_transport_get_context_data(esp_transport_handle_t t); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 16:59:03 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Get transport handle of underlying protocol | 
					
						
							|  |  |  |  *             which can access this protocol payload directly | 
					
						
							|  |  |  |  *             (used for receiving longer msg multiple times) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t        The transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return     Payload transport handle | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_transport_handle_t esp_transport_get_payload_transport_handle(esp_transport_handle_t t); | 
					
						
							| 
									
										
										
										
											2018-07-24 16:59:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Set the user context data for this transport | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t        The transport handle | 
					
						
							|  |  |  |  * @param      data     The user data context | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_set_context_data(esp_transport_handle_t t, void *data); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Set transport functions for the transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t            The transport handle | 
					
						
							|  |  |  |  * @param[in]  _connect     The connect function pointer | 
					
						
							|  |  |  |  * @param[in]  _read        The read function pointer | 
					
						
							|  |  |  |  * @param[in]  _write       The write function pointer | 
					
						
							|  |  |  |  * @param[in]  _close       The close function pointer | 
					
						
							|  |  |  |  * @param[in]  _poll_read   The poll read function pointer | 
					
						
							|  |  |  |  * @param[in]  _poll_write  The poll write function pointer | 
					
						
							|  |  |  |  * @param[in]  _destroy     The destroy function pointer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_set_func(esp_transport_handle_t t, | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  |                              connect_func _connect, | 
					
						
							|  |  |  |                              io_read_func _read, | 
					
						
							|  |  |  |                              io_func _write, | 
					
						
							|  |  |  |                              trans_func _close, | 
					
						
							|  |  |  |                              poll_func _poll_read, | 
					
						
							|  |  |  |                              poll_func _poll_write, | 
					
						
							| 
									
										
										
										
											2018-10-02 15:19:46 +02:00
										 |  |  |                              trans_func _destroy); | 
					
						
							| 
									
										
										
										
											2018-08-07 23:26:59 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Set transport functions for the transport handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t                    The transport handle | 
					
						
							|  |  |  |  * @param[in]  _connect_async_func  The connect_async function pointer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_FAIL | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | esp_err_t esp_transport_set_async_connect_func(esp_transport_handle_t t, connect_async_func _connect_async_func); | 
					
						
							| 
									
										
										
										
											2018-08-07 23:26:59 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 15:19:46 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief      Set parent transport function to the handle | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param[in]  t                    The transport handle | 
					
						
							|  |  |  |  * @param[in]  _parent_transport    The underlying transport getter pointer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *     - ESP_OK | 
					
						
							|  |  |  |  *     - ESP_FAIL | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | esp_err_t esp_transport_set_parent_transport_func(esp_transport_handle_t t, payload_transfer_func _parent_transport); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:16:20 +07:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-09-26 11:56:47 +02:00
										 |  |  | #endif /* _ESP_TRANSPORT_ */
 |