Libtrap: Internal development docs  1.16.1
Macros
Nemea module macros

Macros

#define TRAP_DEFAULT_SIGNAL_HANDLER(stop_cmd)
 Define default signal handler function Defines function to handle SIGTERM and SIGINT signals. When a signal is received, it runs the specified command and calls trap_terminate(). Place this macro before your main function. More...
 
#define TRAP_REGISTER_DEFAULT_SIGNAL_HANDLER()
 Register default signal handler. Register function defined by TRAP_DEFAULT_SIGNAL_HANDLER as handler of SIGTERM and SIGINT signals. Place this macro between TRAP initialization and the main loop. More...
 
#define TRAP_DEFAULT_INITIALIZATION(argc, argv, module_info)
 Initialize TRAP using command-line parameters and handle errors. Generates code that parses command-line parameters using trap_parse_params, intializes TRAP library using trap_init and handle possible errors. It calls exit(1) when an error has occured. Place this macro at the beginning of your main function. More...
 
#define TRAP_DEFAULT_FINALIZATION()   trap_finalize();
 Generate TRAP cleanup code. Only calls trap_finalize function. Place this macro at the end of your main function. More...
 
#define TRAP_DEFAULT_GET_DATA_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd)
 Handle possible errors after call to trap_recv(). More...
 
#define TRAP_DEFAULT_RECV_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd)
 Handle possible errors after call to trap_recv. More...
 
#define TRAP_DEFAULT_SEND_DATA_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd)
 Handle possible errors after call to trap_send_data. More...
 
#define TRAP_DEFAULT_SEND_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd)
 Handle possible errors after call to trap_send. More...
 

Detailed Description

Set of preprocessor macros for rapid NEMEA module development.

Macro Definition Documentation

◆ TRAP_DEFAULT_FINALIZATION

#define TRAP_DEFAULT_FINALIZATION ( )    trap_finalize();

Generate TRAP cleanup code. Only calls trap_finalize function. Place this macro at the end of your main function.

Definition at line 954 of file trap.h.

◆ TRAP_DEFAULT_GET_DATA_ERROR_HANDLING

#define TRAP_DEFAULT_GET_DATA_ERROR_HANDLING (   ret_code,
  timeout_cmd,
  error_cmd 
)
Value:
if ((ret_code) != TRAP_E_OK) {\
if ((ret_code) == TRAP_E_TIMEOUT) {\
timeout_cmd;\
} else if ((ret_code) == TRAP_E_TERMINATED) {\
error_cmd;\
} else if (ret_code == TRAP_E_FORMAT_CHANGED) { \
/* Nothing to do here, TRAP_E_FORMAT_CHANGED has to be skipped by this macro */ \
/* (module can perform some special operations with templates after trap_recv() signals format change) */ \
} else if (ret_code == TRAP_E_FORMAT_MISMATCH) { \
fprintf(stderr, "trap_recv() error: output and input interfaces data formats or data specifiers mismatch.\n"); \
error_cmd; \
} else if (ret_code == TRAP_E_NEGOTIATION_FAILED) { \
fprintf(stderr, "trap_recv() error: interface negotiation failed (caused by invalid reply from a remote module, corrupted file or an unknown error).\n"); \
error_cmd; \
} else {\
fprintf(stderr, "Error: trap_recv() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
error_cmd;\
}\
}
#define TRAP_E_OK
Success, no error.
Definition: trap.h:87
#define TRAP_E_FORMAT_CHANGED
Returned by trap_recv when format or format spec of the receivers interface has been changed...
Definition: trap.h:100
const char * trap_last_error_msg
Human-readable message about last error.
Definition: trap.c:125
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing.
Definition: trap.h:94
#define TRAP_E_NEGOTIATION_FAILED
Returned by trap_recv when negotiation of the output and input interfaces failed. ...
Definition: trap.h:102
#define TRAP_E_FORMAT_MISMATCH
Returned by trap_recv when data format or data specifier of the output and input interfaces doesn't m...
Definition: trap.h:101
#define TRAP_E_TIMEOUT
Read or write operation timeout.
Definition: trap.h:88

Handle possible errors after call to trap_recv().

Parameters
[in]ret_codeReturn code of trap_recv().
timeout_cmdCommand to run when a timeout has occured, e.g. "continue".
error_cmdCommand to run when an error has occured or interface was terminated, e.g. "break".
Deprecated:
This macro should be replaced by TRAP_DEFAULT_RECV_ERROR_HANDLING.

Definition at line 964 of file trap.h.

◆ TRAP_DEFAULT_INITIALIZATION

#define TRAP_DEFAULT_INITIALIZATION (   argc,
  argv,
  module_info 
)
Value:
{\
trap_ifc_spec_t ifc_spec;\
int ret = trap_parse_params(&argc, argv, &ifc_spec);\
if (ret != TRAP_E_OK) {\
if (ret == TRAP_E_HELP) {\
trap_print_help(&module_info);\
FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
return 0;\
}\
trap_free_ifc_spec(ifc_spec);\
fprintf(stderr, "ERROR in parsing of parameters for TRAP: %s\n", trap_last_error_msg);\
FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
return 1;\
}\
ret = trap_init(&module_info, ifc_spec);\
if (ret != TRAP_E_OK) {\
trap_free_ifc_spec(ifc_spec);\
fprintf(stderr, "ERROR in TRAP initialization: %s\n", trap_last_error_msg);\
FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
return 1;\
}\
trap_free_ifc_spec(ifc_spec);\
}
#define TRAP_E_OK
Success, no error.
Definition: trap.h:87
const char * trap_last_error_msg
Human-readable message about last error.
Definition: trap.c:125
#define TRAP_E_HELP
Returned by parse_parameters when help is requested.
Definition: trap.h:97
int trap_init(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec)
Definition: trap.c:526
int trap_parse_params(int *argc, char **argv, trap_ifc_spec_t *ifc_spec)
Definition: trap.c:339

Initialize TRAP using command-line parameters and handle errors. Generates code that parses command-line parameters using trap_parse_params, intializes TRAP library using trap_init and handle possible errors. It calls exit(1) when an error has occured. Place this macro at the beginning of your main function.

Parameters
[in,out]argcNumber of command-line parameters.
[in,out]argvList of command-line parameters.
[in]module_infotrap_module_info_t structure containing information about the module.

Definition at line 925 of file trap.h.

◆ TRAP_DEFAULT_RECV_ERROR_HANDLING

#define TRAP_DEFAULT_RECV_ERROR_HANDLING (   ret_code,
  timeout_cmd,
  error_cmd 
)
Value:
if ((ret_code) != TRAP_E_OK) {\
if ((ret_code) == TRAP_E_TIMEOUT) {\
timeout_cmd;\
} else if ((ret_code) == TRAP_E_TERMINATED) {\
error_cmd;\
} else if (ret_code == TRAP_E_FORMAT_CHANGED) { \
/* Nothing to do here, TRAP_E_FORMAT_CHANGED has to be skipped by this macro */ \
/* (module can perform some special operations with templates after trap_recv() signals format change) */ \
} else if (ret_code == TRAP_E_FORMAT_MISMATCH) { \
fprintf(stderr, "trap_recv() error: output and input interfaces data formats or data specifiers mismatch.\n"); \
error_cmd; \
} else if (ret_code == TRAP_E_NEGOTIATION_FAILED) { \
fprintf(stderr, "trap_recv() error: interface negotiation failed (caused by invalid reply from a remote module, corrupted file or an unknown error).\n"); \
error_cmd; \
} else {\
fprintf(stderr, "Error: trap_recv() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
error_cmd;\
}\
}
#define TRAP_E_OK
Success, no error.
Definition: trap.h:87
#define TRAP_E_FORMAT_CHANGED
Returned by trap_recv when format or format spec of the receivers interface has been changed...
Definition: trap.h:100
const char * trap_last_error_msg
Human-readable message about last error.
Definition: trap.c:125
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing.
Definition: trap.h:94
#define TRAP_E_NEGOTIATION_FAILED
Returned by trap_recv when negotiation of the output and input interfaces failed. ...
Definition: trap.h:102
#define TRAP_E_FORMAT_MISMATCH
Returned by trap_recv when data format or data specifier of the output and input interfaces doesn't m...
Definition: trap.h:101
#define TRAP_E_TIMEOUT
Read or write operation timeout.
Definition: trap.h:88

Handle possible errors after call to trap_recv.

Parameters
[in]ret_codeReturn code of trap_recv.
timeout_cmdCommand to run when a timeout has occured, e.g. "continue".
error_cmdCommand to run when an error has occured or interface was terminated, e.g. "break".

Definition at line 991 of file trap.h.

◆ TRAP_DEFAULT_SEND_DATA_ERROR_HANDLING

#define TRAP_DEFAULT_SEND_DATA_ERROR_HANDLING (   ret_code,
  timeout_cmd,
  error_cmd 
)
Value:
if ((ret_code) != TRAP_E_OK) {\
if ((ret_code) == TRAP_E_TIMEOUT) {\
timeout_cmd;\
} else if ((ret_code) == TRAP_E_TERMINATED) {\
error_cmd;\
} else {\
fprintf(stderr, "Error: trap_send_data() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
error_cmd;\
}\
}
#define TRAP_E_OK
Success, no error.
Definition: trap.h:87
const char * trap_last_error_msg
Human-readable message about last error.
Definition: trap.c:125
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing.
Definition: trap.h:94
#define TRAP_E_TIMEOUT
Read or write operation timeout.
Definition: trap.h:88

Handle possible errors after call to trap_send_data.

Parameters
[in]ret_codeReturn code of trap_send_data.
timeout_cmdCommand to run when a timeout has occured, e.g. "0" to do nothing.
error_cmdCommand to run when an error has occured or interface was terminated, e.g. "break".
Deprecated:
This macro should be replaced by TRAP_DEFAULT_SEND_ERROR_HANDLING.

Definition at line 1021 of file trap.h.

◆ TRAP_DEFAULT_SEND_ERROR_HANDLING

#define TRAP_DEFAULT_SEND_ERROR_HANDLING (   ret_code,
  timeout_cmd,
  error_cmd 
)
Value:
if ((ret_code) != TRAP_E_OK) {\
if ((ret_code) == TRAP_E_TIMEOUT) {\
timeout_cmd;\
} else if ((ret_code) == TRAP_E_TERMINATED) {\
error_cmd;\
} else {\
fprintf(stderr, "Error: trap_send() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
error_cmd;\
}\
}
#define TRAP_E_OK
Success, no error.
Definition: trap.h:87
const char * trap_last_error_msg
Human-readable message about last error.
Definition: trap.c:125
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing.
Definition: trap.h:94
#define TRAP_E_TIMEOUT
Read or write operation timeout.
Definition: trap.h:88

Handle possible errors after call to trap_send.

Parameters
[in]ret_codeReturn code of trap_send.
timeout_cmdCommand to run when a timeout has occured, e.g. "0" to do nothing.
error_cmdCommand to run when an error has occured or interface was terminated, e.g. "break".

Definition at line 1040 of file trap.h.

◆ TRAP_DEFAULT_SIGNAL_HANDLER

#define TRAP_DEFAULT_SIGNAL_HANDLER (   stop_cmd)
Value:
void trap_default_signal_handler(int signal)\
{\
if (signal == SIGTERM || signal == SIGINT) { \
stop_cmd;\
trap_terminate();\
}\
}

Define default signal handler function Defines function to handle SIGTERM and SIGINT signals. When a signal is received, it runs the specified command and calls trap_terminate(). Place this macro before your main function.

Parameters
[in]stop_cmdCommand which stops operation of a module. Usually setting a variable which is tested in module's main loop.

Definition at line 872 of file trap.h.

◆ TRAP_REGISTER_DEFAULT_SIGNAL_HANDLER

#define TRAP_REGISTER_DEFAULT_SIGNAL_HANDLER ( )
Value:
do {\
printf("Setting signal handler for SIGINT and SIGTERM using 'signal' function.\n");\
signal(SIGTERM, trap_default_signal_handler);\
signal(SIGINT, trap_default_signal_handler);\
} while(0)
int trap_get_verbose_level()
Definition: trap.c:663

Register default signal handler. Register function defined by TRAP_DEFAULT_SIGNAL_HANDLER as handler of SIGTERM and SIGINT signals. Place this macro between TRAP initialization and the main loop.

Definition at line 904 of file trap.h.