44 #ifndef _TRAP_MODULE_INFO_H_ 45 #define _TRAP_MODULE_INFO_H_ 161 #define GEN_LONG_OPT_STRUCT_LINE(p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) {p_long_opt, p_required_argument, 0, p_short_opt}, 165 #define GEN_LONG_OPT_STRUCT(PARAMS) \ 166 static struct option long_options[] __attribute__((used)) = { \ 167 PARAMS(GEN_LONG_OPT_STRUCT_LINE) \ 179 #define ALLOCATE_BASIC_INFO_2(module_info, p_name, p_description, p_input, p_output) \ 180 if (module_info != NULL) { \ 181 if (p_name != NULL) { \ 182 module_info->name = strdup(p_name); \ 184 module_info->name = NULL; \ 186 if (p_description != NULL) { \ 187 module_info->description = strdup(p_description); \ 189 module_info->description = NULL; \ 191 module_info->num_ifc_in = p_input; \ 192 module_info->num_ifc_out = p_output; \ 202 #define ALLOCATE_BASIC_INFO(p_name, p_description, p_input, p_output) \ 203 ALLOCATE_BASIC_INFO_2(module_info, p_name, p_description, p_input, p_output) 215 #define ALLOCATE_PARAM_ITEMS_2(m, param_id, p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) \ 217 if (m->params[param_id] == NULL) { \ 218 m->params[param_id] = (trap_module_info_parameter_t *) calloc(1, sizeof(trap_module_info_parameter_t)); \ 220 if (m->params[param_id] != NULL) { \ 221 if (p_short_opt != 0) { \ 222 m->params[param_id]->short_opt = p_short_opt; \ 224 m->params[param_id]->short_opt = 0; \ 226 if (p_long_opt != NULL) { \ 227 m->params[param_id]->long_opt = strdup(p_long_opt); \ 229 m->params[param_id]->long_opt = strdup(""); \ 231 if (p_description != NULL) { \ 232 m->params[param_id]->description = strdup(p_description); \ 234 m->params[param_id]->description = strdup(""); \ 236 if (p_required_argument == 1) { \ 237 m->params[param_id]->param_required_argument = p_required_argument; \ 239 m->params[param_id]->param_required_argument = 0; \ 241 if (p_argument_type != NULL) { \ 242 m->params[param_id]->argument_type = strdup(p_argument_type); \ 244 m->params[param_id]->argument_type = strdup(""); \ 257 #define ALLOCATE_PARAM_ITEMS(p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) \ 258 ALLOCATE_PARAM_ITEMS_2(module_info, trap_module_params_cnt, p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) \ 259 trap_module_params_cnt++; 263 #define FREE_BASIC_INFO(p_name, p_description, p_input, p_output) \ 264 if (module_info->name != NULL) { \ 265 free(module_info->name); \ 266 module_info->name = NULL; \ 268 if (module_info->description != NULL) { \ 269 free(module_info->description); \ 270 module_info->description = NULL; \ 275 #define FREE_PARAM_ITEMS(p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) \ 276 if (module_info->params[trap_module_params_cnt] != NULL) { \ 277 if (module_info->params[trap_module_params_cnt]->long_opt != NULL) { \ 278 free(module_info->params[trap_module_params_cnt]->long_opt); \ 279 module_info->params[trap_module_params_cnt]->long_opt= NULL; \ 281 if (module_info->params[trap_module_params_cnt]->description != NULL) { \ 282 free(module_info->params[trap_module_params_cnt]->description); \ 283 module_info->params[trap_module_params_cnt]->description= NULL; \ 285 if (module_info->params[trap_module_params_cnt]->argument_type != NULL) { \ 286 free(module_info->params[trap_module_params_cnt]->argument_type); \ 287 module_info->params[trap_module_params_cnt]->argument_type= NULL; \ 289 if (module_info->params[trap_module_params_cnt] != NULL) { \ 290 free(module_info->params[trap_module_params_cnt]); \ 292 trap_module_params_cnt++; \ 295 #define GENERATE_GETOPT_STRING(p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) \ 296 if (module_getopt_string_size <= (strlen(module_getopt_string) + 2)) { \ 297 module_getopt_string_size += module_getopt_string_size/2; \ 298 module_getopt_string = (char *) realloc(module_getopt_string, module_getopt_string_size * sizeof(char)); \ 299 memset(module_getopt_string + (2*module_getopt_string_size)/3, 0, module_getopt_string_size/3); \ 301 module_getopt_string[strlen(module_getopt_string)] = p_short_opt; \ 302 if (p_required_argument == required_argument) { \ 303 module_getopt_string[strlen(module_getopt_string)] = ':'; \ 308 #define COUNT_MODULE_PARAMS(p_short_opt, p_long_opt, p_description, p_required_argument, p_argument_type) trap_module_params_cnt++; 315 #define INIT_MODULE_INFO_STRUCT(BASIC, PARAMS) \ 316 int trap_module_params_cnt = 0; \ 317 size_t module_getopt_string_size = 50; \ 318 char * module_getopt_string = (char *) calloc(module_getopt_string_size, sizeof(char)); \ 319 module_info = (trap_module_info_t *) calloc(1, sizeof(trap_module_info_t)); \ 320 GEN_LONG_OPT_STRUCT(PARAMS); \ 321 BASIC(ALLOCATE_BASIC_INFO) \ 322 PARAMS(COUNT_MODULE_PARAMS) \ 323 if (module_info != NULL) { \ 324 module_info->params = (trap_module_info_parameter_t **) calloc(trap_module_params_cnt + 1, sizeof(trap_module_info_parameter_t *)); \ 325 if (module_info->params != NULL) { \ 326 trap_module_params_cnt = 0; \ 327 PARAMS(ALLOCATE_PARAM_ITEMS) \ 328 PARAMS(GENERATE_GETOPT_STRING) \ 361 #define FREE_MODULE_INFO_STRUCT(BASIC, PARAMS) \ 362 if (module_info != NULL) { \ 363 trap_module_params_cnt = 0; \ 364 BASIC(FREE_BASIC_INFO) \ 365 if (module_info->params != NULL) { \ 366 PARAMS(FREE_PARAM_ITEMS) \ 367 free(module_info->params); \ 368 module_info->params = NULL; \ 371 module_info = NULL; \ 372 if (module_getopt_string != NULL) { \ 373 free(module_getopt_string); \
int param_required_argument
char * name
Name of the module (short string)
int num_ifc_out
Number of output interfaces.
trap_module_info_t * trap_create_module_info(const char *mname, const char *mdesc, int8_t i_ifcs, int8_t o_ifcs, uint16_t param_count)
trap_module_info_parameter_t ** params
struct trap_module_info_s trap_module_info_t
struct trap_module_info_parameter_s trap_module_info_parameter_t
int trap_update_module_param(trap_module_info_t *m, uint16_t param_id, char shortopt, const char *longopt, const char *desc, int req_arg, const char *arg_type)
int num_ifc_in
Number of input interfaces.