Skip to content

Commit 0f3f57f

Browse files
committed
Rework JerryScript transport layer.
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 0c6b5ea commit 0f3f57f

15 files changed

+1177
-387
lines changed

docs/13.DEBUGGER-TRANSPORT.md

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

0 commit comments

Comments
 (0)