Skip to content

Commit 857ba99

Browse files
zherczegyichoi
authored andcommitted
Rework JerryScript transport layer. (#2421)
Introducing jerryscript-debugger-transport.h interface, which allows chaining multiple protocols (e.g. tcp and websocket). JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 43aae19 commit 857ba99

15 files changed

+1195
-387
lines changed

docs/13.DEBUGGER-TRANSPORT.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# JerryScript debugger transport interface
2+
3+
The transport interface support allows dynamic selection of transportation
4+
layers which can encode/decode or send/receive messages transmitted between
5+
the debugger client and server.
6+
7+
# Types
8+
9+
## jerry_debugger_transport_receive_context_t
10+
11+
**Summary**
12+
13+
This context represents the current status of processing received data.
14+
The final state is returned by
15+
[jerry_debugger_transport_receive](#jerry_debugger_transport_receive)
16+
and must be passed to
17+
[jerry_debugger_transport_receive_completed](#jerry_debugger_transport_receive_completed)
18+
after the message is processed.
19+
20+
**Prototype**
21+
22+
```c
23+
typedef struct
24+
{
25+
uint8_t *buffer_p; /**< buffer for storing the received data */
26+
size_t received_length; /**< number of currently received bytes */
27+
uint8_t *message_p; /**< start of the received message */
28+
size_t message_length; /**< length of the received message */
29+
size_t message_total_length; /**< total length for datagram protocols,
30+
* 0 for stream protocols */
31+
} jerry_debugger_transport_receive_context_t;
32+
```
33+
34+
## jerry_debugger_transport_header_t
35+
36+
**Summary**
37+
38+
Shared header for each transport interface. It mostly contains callback functions
39+
used by the JerryScript debugger server.
40+
41+
**Prototype**
42+
43+
```c
44+
typedef struct jerry_debugger_transport_layer_t
45+
{
46+
/* The following fields must be filled before calling jerry_debugger_transport_add(). */
47+
jerry_debugger_transport_close_t close; /**< close connection callback */
48+
jerry_debugger_transport_send_t send; /**< send data callback */
49+
jerry_debugger_transport_receive_t receive; /**< receive data callback */
50+
51+
/* The following fields are filled by jerry_debugger_transport_add(). */
52+
struct jerry_debugger_transport_layer_t *next_p; /**< next transport layer */
53+
} jerry_debugger_transport_header_t;
54+
```
55+
56+
## jerry_debugger_transport_close_t
57+
58+
**Summary**
59+
60+
Called when the connection is closed. Must release all resources (including the
61+
memory area for the transport interface) allocated for the transport interface.
62+
63+
**Prototype**
64+
65+
```c
66+
typedef void (*jerry_debugger_transport_close_t) (struct jerry_debugger_transport_interface_t *header_p);
67+
```
68+
69+
## jerry_debugger_transport_send_t
70+
71+
**Summary**
72+
73+
Called when a message needs to be sent. Must either transmit the message or call
74+
the `header_p->next_p->send()` method.
75+
76+
**Prototype**
77+
78+
```c
79+
typedef bool (*jerry_debugger_transport_send_t) (struct jerry_debugger_transport_interface_t *header_p,
80+
uint8_t *message_p, size_t message_length);
81+
```
82+
83+
## jerry_debugger_transport_receive_t
84+
85+
**Summary**
86+
87+
Called during message processing. If messages are available it must return with
88+
the next message.
89+
90+
**Prototype**
91+
92+
```c
93+
typedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transport_interface_t *header_p,
94+
jerry_debugger_transport_receive_context_t *context_p);
95+
```
96+
97+
# Transport interface API functions
98+
99+
## jerry_debugger_transport_malloc
100+
101+
**Summary**
102+
103+
Allocates memory for the transport interface.
104+
105+
**Prototype**
106+
107+
```c
108+
void * jerry_debugger_transport_malloc (size_t size);
109+
```
110+
111+
- `size`: size of the memory block.
112+
- return value: non-NULL pointer, if the memory is successfully allocated,
113+
NULL otherwise.
114+
115+
## jerry_debugger_transport_free
116+
117+
**Summary**
118+
119+
Free memory allocated by [jerry_debugger_transport_malloc](#jerry_debugger_transport_malloc)
120+
121+
**Prototype**
122+
123+
```c
124+
void jerry_debugger_transport_free (void *mem_p, size_t size);
125+
```
126+
127+
- `header_p`: header of a transporation interface.
128+
- `size`: total size of the transportation interface.
129+
130+
## jerry_debugger_transport_add
131+
132+
**Summary**
133+
134+
Add a new interface to the transporation interface chain. The interface
135+
will be the first item of the interface chain.
136+
137+
**Prototype**
138+
139+
```c
140+
void jerry_debugger_transport_add (jerry_debugger_transport_header_t *header_p,
141+
size_t send_message_header_size, size_t max_send_message_size,
142+
size_t receive_message_header_size, size_t max_receive_message_size);
143+
```
144+
145+
- `header_p`: header of a transporation interface.
146+
- `send_message_header_size`: size of the outgoing message header, can be 0.
147+
- `max_send_message_size`: maximum outgoing message size supported by the interface.
148+
- `receive_message_header_size`: size of the incoming message header, can be 0.
149+
- `max_receive_message_size`: maximum incoming message size supported by the interface.
150+
151+
## jerry_debugger_transport_start
152+
153+
**Summary**
154+
155+
Starts the communication to the debugger client. Must be called after the
156+
connection is successfully established.
157+
158+
**Prototype**
159+
160+
```c
161+
void jerry_debugger_transport_start (void);
162+
```
163+
164+
## jerry_debugger_transport_is_connected
165+
166+
**Summary**
167+
168+
Tells whether a debugger client is connected to the debugger server.
169+
170+
**Prototype**
171+
172+
```c
173+
bool jerry_debugger_transport_is_connected (void);
174+
```
175+
176+
- return value: `true`, if a client is connected, `false` otherwise.
177+
178+
## jerry_debugger_transport_close
179+
180+
**Summary**
181+
182+
Disconnect from the current debugger client. It does nothing if a client is
183+
not connected,
184+
185+
**Prototype**
186+
187+
```c
188+
void jerry_debugger_transport_close (void);
189+
```
190+
191+
## jerry_debugger_transport_send
192+
193+
**Summary**
194+
195+
Send message to the client.
196+
197+
**Prototype**
198+
199+
```c
200+
bool jerry_debugger_transport_send (const uint8_t *message_p, size_t message_length);
201+
```
202+
203+
- `message_p`: message to be sent.
204+
- `message_length`: message length in bytes.
205+
- return value: `true`, if a client is still connected, `false` otherwise.
206+
207+
## jerry_debugger_transport_receive
208+
209+
**Summary**
210+
211+
Receive message from the client.
212+
213+
**Prototype**
214+
215+
```c
216+
bool jerry_debugger_transport_receive (jerry_debugger_transport_receive_context_t *context_p);
217+
```
218+
219+
- `context_p`: an unused [jerry_debugger_transport_receive_context_t](#jerry_debugger_transport_receive_context_t).
220+
- return value: `true`, if a client is still connected, `false` otherwise.
221+
222+
## jerry_debugger_transport_receive_completed
223+
224+
**Summary**
225+
226+
Must be called after [jerry_debugger_transport_receive](#jerry_debugger_transport_receive)
227+
returns with a valid message. Must not be called otherwise.
228+
229+
**Prototype**
230+
231+
```c
232+
void jerry_debugger_transport_receive_completed (jerry_debugger_transport_receive_context_t *context_p);
233+
```
234+
235+
- `context_p`: a [jerry_debugger_transport_receive_context_t](#jerry_debugger_transport_receive_context_t)
236+
passed to [jerry_debugger_transport_receive](#jerry_debugger_transport_receive).
237+
238+
## jerry_debugger_transport_sleep
239+
240+
**Summary**
241+
242+
Can be used to wait for incoming messages. Currently the delay is 100ms.
243+
244+
**Prototype**
245+
246+
```c
247+
void jerry_debugger_transport_sleep (void);
248+
```

0 commit comments

Comments
 (0)