C API for BALTECH SDK
protocol.h
Go to the documentation of this file.
1 
20 #ifndef __PROTOCOL_H__
21 #define __PROTOCOL_H__
22 
23 
24 #include "common.h"
25 #include "errorcodes.h"
26 #include "protocol_ids.h"
27 #include "frames.h"
28 #include "mempool.h"
29 
30 
34 typedef struct brp_protocol_t * brp_protocol;
35 
36 
42 typedef int brp_layer_id;
43 
44 
53 typedef brp_errcode (*brp_cb_generic_t)
54 (
55  brp_protocol protocol
56 );
57 
58 
62 typedef brp_errcode (*brp_cb_generic_t)
63 (
64  brp_protocol protocol
65 );
66 
67 
71 typedef brp_errcode (*brp_cb_recv_any_frame_t)
72 (
73  brp_protocol protocol,
74  brp_time timeout
75 );
76 
77 
90 typedef size_t (*brp_cb_fmt_spec_t)
91 (
92  brp_frame frame,
93  void * context
94 );
95 
96 
100 typedef brp_errcode (*brp_cb_recv_frame_t)
101 (
102  brp_protocol protocol,
103  brp_time timeout,
104  brp_cb_fmt_spec_t fmt_spec_callback,
105  void * context
106 );
107 
108 
112 typedef brp_errcode (*brp_cb_get_id_t)
113 (
114  brp_protocol protocol,
115  char * * intf_name,
116  brp_frame instance_id
117 );
118 
119 
146 struct brp_protocol_t
147 {
148  int protocol_id;
149  brp_layer_id layer_id;
150  brp_protocol base_protocol;
151 
152  brp_cb_generic_t cb_open;
153  brp_cb_generic_t cb_close;
154  brp_cb_generic_t cb_send_frame;
155  brp_cb_recv_any_frame_t cb_recv_any_frame;
156  brp_cb_recv_frame_t cb_recv_frame;
157  brp_cb_generic_t cb_flush;
158  brp_cb_generic_t cb_destroy;
159  brp_cb_get_id_t cb_get_id;
160 
164  bool opened;
165 
170  struct brp_frame_t send_frame;
171 
176  struct brp_frame_t recv_frame;
177 
182  brp_time recv_delay;
183 
187  brp_mempool mempool;
188 } ;
189 
190 
195 BRP_LIB brp_errcode brp_send_frame
196 (
197  brp_protocol protocol
198 );
199 
200 
205 BRP_LIB brp_errcode brp_recv_any_frame
206 (
207  brp_protocol protocol,
208  brp_time timeout
209 );
210 
211 
216 BRP_LIB brp_errcode brp_recv_fix_frame
217 (
218  brp_protocol protocol,
219  brp_time timeout,
220  size_t frame_size
221 );
222 
223 
229 BRP_LIB brp_errcode brp_recv_frame
230 (
231  brp_protocol protocol,
232  brp_time timeout,
233  brp_cb_fmt_spec_t fmt_spec_callback,
234  void * context
237 );
238 
239 
258 #define BRP_FMTSPEC_EXPECT_MORE(frame_rdr, requested_byte_cnt) do { \
259  if (brp_frame_read_err(frame_rdr)) \
260  return -1; \
261  else if (brp_frame_rest(frame_rdr) < (requested_byte_cnt)) \
262  return (requested_byte_cnt) - brp_frame_rest(frame_rdr); \
263 } while (0)
264 
265 
271 #define BRP_FMTSPEC_EXPECT_END(frame_rdr) do { \
272  if (! brp_frame_read_eof(frame_rdr)) \
273  return -1; \
274 } while (0)
275 
276 
280 BRP_LIB void brp_protocol_free(brp_protocol protocol);
281 
295 BRP_LIB brp_errcode brp_open
296 (
297  brp_protocol protocol
298 );
299 
300 
309 BRP_LIB brp_errcode brp_close
310 (
311  brp_protocol protocol
312 );
313 
314 
320 
321 
344 (
345  brp_protocol protocol,
346  char * * intf_name,
347  brp_frame instance_id
348 );
353 
354 
361 
362 
363 #endif
364  // end of defgroup brp_lib
BRP_LIB brp_errcode brp_flush(brp_protocol)
Deletes all data that is waiting in input buffers for being read via brp_recv_frame() (or brp_recv_fi...
int brp_layer_id
identifies the layer of a composite protocol stack (see brp_create() or brp_create_composite().
Definition: protocol.h:42
Contains all possible error codes that could be returned by BRP library.
unsigned int brp_errcode
This type is used library-wide for passing error codes in the return value of functions.
Definition: errorcodes.h:23
Every protocol has to be identified unique by a protocol ID.
struct brp_protocol_t * brp_protocol
This is a generic handle of a protocol.
Definition: protocol.h:34
unsigned long brp_time
absolute/relative timeout/delay in ms.
Definition: common.h:67
BRP_LIB brp_errcode brp_close(brp_protocol protocol)
Closes protocol.
struct brp_mempool_object_t * brp_mempool
mempool handle.
Definition: mempool.h:27
BRP_LIB brp_errcode brp_open(brp_protocol protocol)
Set up a connection via this protocol.
BRP_LIB brp_errcode brp_destroy(brp_protocol)
Closes a protocol if opened and frees all allocated resources thereafter.
Defines frame objects that allow dynamic sized buffers to be handled easily.
BRP_LIB brp_errcode brp_get_io_id(brp_protocol protocol, char **intf_name, brp_frame instance_id)
Retrieves the instance name of the I/O-protocol of this protocol stack.
Contains the basic defines that are required throughout the BRP library.
Defines a mempool that allows centralized memory allocation.