UniRec  2.9.3
Macros
Helpers for libtrap

Macros

#define TRAP_RECEIVE(ifc_num, data, data_size, tmplt)   TRAP_CTX_RECEIVE(trap_get_global_ctx(), ifc_num, data, data_size, tmplt);
 Receive data from interface Receive data with specified template from libtrap interface. If the receiving template is subset of sending template, it will define new fields and expand receiving template. More...
 
#define TRAP_CTX_RECEIVE(ctx, ifc_num, data, data_size, tmplt)
 Receive data from interface with given context Receive data with specified template from libtrap interface with specified context. If the receiving template is subset of sending template, it will define new fields and expand receiving template. More...
 

Detailed Description

This module defines useful macros for handling data receive. When data format is changed, these macros create new UniRec template.

Macro Definition Documentation

◆ TRAP_CTX_RECEIVE

#define TRAP_CTX_RECEIVE (   ctx,
  ifc_num,
  data,
  data_size,
  tmplt 
)
Value:
__extension__ \
({\
int ret = trap_ctx_recv(ctx, ifc_num, &data, &data_size);\
if (ret == TRAP_E_FORMAT_CHANGED) {\
const char *spec = NULL;\
uint8_t data_fmt;\
if (trap_ctx_get_data_fmt(ctx, TRAPIFC_INPUT, ifc_num, &data_fmt, &spec) != TRAP_E_OK) {\
fprintf(stderr, "Data format was not loaded.\n");\
} else {\
tmplt = ur_define_fields_and_update_template(spec, tmplt);\
if (tmplt == NULL) {\
fprintf(stderr, "Template could not be edited.\n");\
} else {\
if (tmplt->direction == UR_TMPLT_DIRECTION_BI) {\
char * spec_cpy = ur_cpy_string(spec);\
if (spec_cpy == NULL) {\
fprintf(stderr, "Memory allocation problem.\n");\
} else {\
trap_ctx_set_data_fmt(ctx, tmplt->ifc_out, TRAP_FMT_UNIREC, spec_cpy);\
}\
}\
}\
}\
}\
ret;\
})
char * ur_cpy_string(const char *str)
Duplicates given string. Helper function which returns pointer to duplicated string. New string has to be freed by user.
Definition: unirec.c:1655
bidirection
Definition: unirec.h:133
ur_template_t * ur_define_fields_and_update_template(const char *ifc_data_fmt, ur_template_t *tmplt)
Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields)...
Definition: unirec.c:610

Receive data from interface with given context Receive data with specified template from libtrap interface with specified context. If the receiving template is subset of sending template, it will define new fields and expand receiving template.

Parameters
[in]ctxcontext
[in]ifc_numindex of libtrap interface
[in]datapointer to memory where the data will be stored
[in]data_sizesize of allocated space for data
[in]tmpltpointer to input template
Returns
return value of trap_ctx_recv

Definition at line 233 of file unirec.h.

◆ TRAP_RECEIVE

#define TRAP_RECEIVE (   ifc_num,
  data,
  data_size,
  tmplt 
)    TRAP_CTX_RECEIVE(trap_get_global_ctx(), ifc_num, data, data_size, tmplt);

Receive data from interface Receive data with specified template from libtrap interface. If the receiving template is subset of sending template, it will define new fields and expand receiving template.

Parameters
[in]ifc_numindex of libtrap interface
[in]datapointer to memory where the data will be stored
[in]data_sizesize of allocated space for data
[in]tmpltpointer to input template
Returns
return value of trap_recv

Definition at line 219 of file unirec.h.