1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef JERRYSCRIPT_DEBUGGER_TRANSPORT_H 17#define JERRYSCRIPT_DEBUGGER_TRANSPORT_H 18 19#include <stdbool.h> 20#include <stddef.h> 21#include <stdint.h> 22 23#ifdef __cplusplus 24extern "C" 25{ 26#endif /* __cplusplus */ 27 28/** \addtogroup jerry-debugger-transport Jerry engine debugger interface - transport control 29 * @{ 30 */ 31 32/** 33 * Maximum number of bytes transmitted or received. 34 */ 35#define JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE 128 36 37/** 38 * Receive message context. 39 */ 40typedef struct 41{ 42 uint8_t *buffer_p; /**< buffer for storing the received data */ 43 size_t received_length; /**< number of currently received bytes */ 44 uint8_t *message_p; /**< start of the received message */ 45 size_t message_length; /**< length of the received message */ 46 size_t message_total_length; /**< total length for datagram protocols, 47 * 0 for stream protocols */ 48} jerry_debugger_transport_receive_context_t; 49 50/** 51 * Forward definition of jerry_debugger_transport_header_t. 52 */ 53struct jerry_debugger_transport_interface_t; 54 55/** 56 * Close connection callback. 57 */ 58typedef void (*jerry_debugger_transport_close_t) (struct jerry_debugger_transport_interface_t *header_p); 59 60/** 61 * Send data callback. 62 */ 63typedef bool (*jerry_debugger_transport_send_t) (struct jerry_debugger_transport_interface_t *header_p, 64 uint8_t *message_p, size_t message_length); 65 66/** 67 * Receive data callback. 68 */ 69typedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transport_interface_t *header_p, 70 jerry_debugger_transport_receive_context_t *context_p); 71 72/** 73 * Transport layer header. 74 */ 75typedef struct jerry_debugger_transport_interface_t 76{ 77 /* The following fields must be filled before calling jerry_debugger_transport_add(). */ 78 jerry_debugger_transport_close_t close; /**< close connection callback */ 79 jerry_debugger_transport_send_t send; /**< send data callback */ 80 jerry_debugger_transport_receive_t receive; /**< receive data callback */ 81 82 /* The following fields are filled by jerry_debugger_transport_add(). */ 83 struct jerry_debugger_transport_interface_t *next_p; /**< next transport layer */ 84} jerry_debugger_transport_header_t; 85 86void jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p, 87 size_t send_message_header_size, size_t max_send_message_size, 88 size_t receive_message_header_size, size_t max_receive_message_size); 89void jerry_debugger_transport_start (void); 90 91bool jerry_debugger_transport_is_connected (void); 92void jerry_debugger_transport_close (void); 93 94bool jerry_debugger_transport_send (const uint8_t *message_p, size_t message_length); 95bool jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p); 96void jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p); 97 98void jerry_debugger_transport_sleep (void); 99 100/** 101 * @} 102 */ 103 104#ifdef __cplusplus 105} 106#endif /* __cplusplus */ 107#endif /* !JERRYSCRIPT_DEBUGGER_TRANSPORT_H */ 108