1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef JERRYSCRIPT_DEBUGGER_TRANSPORT_H
17425bb815Sopenharmony_ci#define JERRYSCRIPT_DEBUGGER_TRANSPORT_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci#include <stdbool.h>
20425bb815Sopenharmony_ci#include <stddef.h>
21425bb815Sopenharmony_ci#include <stdint.h>
22425bb815Sopenharmony_ci
23425bb815Sopenharmony_ci#ifdef __cplusplus
24425bb815Sopenharmony_ciextern "C"
25425bb815Sopenharmony_ci{
26425bb815Sopenharmony_ci#endif /* __cplusplus */
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ci/** \addtogroup jerry-debugger-transport Jerry engine debugger interface - transport control
29425bb815Sopenharmony_ci * @{
30425bb815Sopenharmony_ci */
31425bb815Sopenharmony_ci
32425bb815Sopenharmony_ci/**
33425bb815Sopenharmony_ci * Maximum number of bytes transmitted or received.
34425bb815Sopenharmony_ci */
35425bb815Sopenharmony_ci#define JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE 128
36425bb815Sopenharmony_ci
37425bb815Sopenharmony_ci/**
38425bb815Sopenharmony_ci * Receive message context.
39425bb815Sopenharmony_ci */
40425bb815Sopenharmony_citypedef struct
41425bb815Sopenharmony_ci{
42425bb815Sopenharmony_ci  uint8_t *buffer_p; /**< buffer for storing the received data */
43425bb815Sopenharmony_ci  size_t received_length; /**< number of currently received bytes */
44425bb815Sopenharmony_ci  uint8_t *message_p; /**< start of the received message */
45425bb815Sopenharmony_ci  size_t message_length; /**< length of the received message */
46425bb815Sopenharmony_ci  size_t message_total_length; /**< total length for datagram protocols,
47425bb815Sopenharmony_ci                                *   0 for stream protocols */
48425bb815Sopenharmony_ci} jerry_debugger_transport_receive_context_t;
49425bb815Sopenharmony_ci
50425bb815Sopenharmony_ci/**
51425bb815Sopenharmony_ci * Forward definition of jerry_debugger_transport_header_t.
52425bb815Sopenharmony_ci */
53425bb815Sopenharmony_cistruct jerry_debugger_transport_interface_t;
54425bb815Sopenharmony_ci
55425bb815Sopenharmony_ci/**
56425bb815Sopenharmony_ci * Close connection callback.
57425bb815Sopenharmony_ci */
58425bb815Sopenharmony_citypedef void (*jerry_debugger_transport_close_t) (struct jerry_debugger_transport_interface_t *header_p);
59425bb815Sopenharmony_ci
60425bb815Sopenharmony_ci/**
61425bb815Sopenharmony_ci * Send data callback.
62425bb815Sopenharmony_ci */
63425bb815Sopenharmony_citypedef bool (*jerry_debugger_transport_send_t) (struct jerry_debugger_transport_interface_t *header_p,
64425bb815Sopenharmony_ci                                                 uint8_t *message_p, size_t message_length);
65425bb815Sopenharmony_ci
66425bb815Sopenharmony_ci/**
67425bb815Sopenharmony_ci * Receive data callback.
68425bb815Sopenharmony_ci */
69425bb815Sopenharmony_citypedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transport_interface_t *header_p,
70425bb815Sopenharmony_ci                                                    jerry_debugger_transport_receive_context_t *context_p);
71425bb815Sopenharmony_ci
72425bb815Sopenharmony_ci/**
73425bb815Sopenharmony_ci * Transport layer header.
74425bb815Sopenharmony_ci */
75425bb815Sopenharmony_citypedef struct jerry_debugger_transport_interface_t
76425bb815Sopenharmony_ci{
77425bb815Sopenharmony_ci  /* The following fields must be filled before calling jerry_debugger_transport_add(). */
78425bb815Sopenharmony_ci  jerry_debugger_transport_close_t close; /**< close connection callback */
79425bb815Sopenharmony_ci  jerry_debugger_transport_send_t send;  /**< send data callback */
80425bb815Sopenharmony_ci  jerry_debugger_transport_receive_t receive; /**< receive data callback */
81425bb815Sopenharmony_ci
82425bb815Sopenharmony_ci  /* The following fields are filled by jerry_debugger_transport_add(). */
83425bb815Sopenharmony_ci  struct jerry_debugger_transport_interface_t *next_p; /**< next transport layer */
84425bb815Sopenharmony_ci} jerry_debugger_transport_header_t;
85425bb815Sopenharmony_ci
86425bb815Sopenharmony_civoid jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p,
87425bb815Sopenharmony_ci                                   size_t send_message_header_size, size_t max_send_message_size,
88425bb815Sopenharmony_ci                                   size_t receive_message_header_size, size_t max_receive_message_size);
89425bb815Sopenharmony_civoid jerry_debugger_transport_start (void);
90425bb815Sopenharmony_ci
91425bb815Sopenharmony_cibool jerry_debugger_transport_is_connected (void);
92425bb815Sopenharmony_civoid jerry_debugger_transport_close (void);
93425bb815Sopenharmony_ci
94425bb815Sopenharmony_cibool jerry_debugger_transport_send (const uint8_t *message_p, size_t message_length);
95425bb815Sopenharmony_cibool jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p);
96425bb815Sopenharmony_civoid jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p);
97425bb815Sopenharmony_ci
98425bb815Sopenharmony_civoid jerry_debugger_transport_sleep (void);
99425bb815Sopenharmony_ci
100425bb815Sopenharmony_ci/**
101425bb815Sopenharmony_ci * @}
102425bb815Sopenharmony_ci */
103425bb815Sopenharmony_ci
104425bb815Sopenharmony_ci#ifdef __cplusplus
105425bb815Sopenharmony_ci}
106425bb815Sopenharmony_ci#endif /* __cplusplus */
107425bb815Sopenharmony_ci#endif /* !JERRYSCRIPT_DEBUGGER_TRANSPORT_H */
108