Commit 32786cc7 authored by Francois TABURET's avatar Francois TABURET

Integration of configuration module. Temporarily keep the legacy mode.

lte-softmodem -O <config file> will trigger legacy config mode
ltesoftmodem  -O libconfig:<config file> will trigger configuration module usage.
parent 293bcf13
...@@ -37,43 +37,73 @@ ...@@ -37,43 +37,73 @@
int processoption(paramdef_t *cfgoptions, char *value) int processoption(paramdef_t *cfgoptions, char *value)
{ {
int ret = 0; int optisset=0;
int noarg=0;
if ((cfgoptions->paramflags &PARAMFLAG_BOOL) == 0) {
if (value == NULL) {
noarg=1;
} else if ( value[0] == '-') {
noarg = 1;
}
if (noarg == 1) {
fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
return 0;
}
}
switch(cfgoptions->type) switch(cfgoptions->type)
{ {
case TYPE_STRING: case TYPE_STRING:
check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *)); config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
check_valptr(cfgoptions, cfgoptions->strptr, strlen(value+1)); config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(value+1));
sprintf(*(cfgoptions->strptr), "%s",value); sprintf(*(cfgoptions->strptr), "%s",value);
printf_cmdl("[LIBCONFIG] %s set to %s from command line\n", cfgoptions->optname, value); printf_cmdl("[CONFIG] %s set to %s from command line\n", cfgoptions->optname, value);
ret++; optisset=1;
break; break;
case TYPE_STRINGLIST:
break;
case TYPE_UINT: case TYPE_STRINGLIST:
case TYPE_INT: break;
case TYPE_UINT32:
case TYPE_INT32:
case TYPE_UINT16:
case TYPE_INT16:
case TYPE_UINT8:
case TYPE_INT8:
config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t));
config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(value,NULL,0));
optisset=1;
break;
case TYPE_UINT64: case TYPE_UINT64:
case TYPE_INT64: case TYPE_INT64:
check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t)); config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t));
*(cfgoptions->uptr) =strtol(value,NULL,0); *(cfgoptions->i64ptr)=strtoll(value,NULL,0);
printf_cmdl("[LIBCONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr)); printf_cmdl("[CONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr));
ret++; optisset=1;
break; break;
case TYPE_UINTARRAY: case TYPE_UINTARRAY:
case TYPE_INTARRAY: case TYPE_INTARRAY:
break; break;
case TYPE_DOUBLE:
config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double));
*(cfgoptions->dblptr) = strtof(value,NULL);
printf_cmdl("[CONFIG] %s set to %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr));
optisset=1;
break;
case TYPE_IPV4ADDR: case TYPE_IPV4ADDR:
break; break;
default: default:
fprintf(stderr,"[LIBCONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type); fprintf(stderr,"[CONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type);
break; break;
} /* switch on param type */ } /* switch on param type */
return ret; if (optisset == 1) {
cfgoptions->paramflags = cfgoptions->paramflags | PARAMFLAG_PARAMSET;
}
return optisset;
} }
int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix)
...@@ -101,9 +131,13 @@ char *cfgpath; ...@@ -101,9 +131,13 @@ char *cfgpath;
if ( ( cfgoptions[i].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) { if ( ( cfgoptions[i].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) {
continue; continue;
} }
sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname); if (prefix != NULL) {
if ( strcmp(*p + 1,cfgoptions[i].shortopt) == 0 || sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
strcmp(*p + 2,cfgpath ) == 0 ) { } else {
sprintf(cfgpath,"%s",cfgoptions[i].optname);
}
if ( ((strlen(*p) > 1) && (strcmp(*p + 1,cfgoptions[i].shortopt) == 0)) ||
((strlen(*p) > 2) && (strcmp(*p + 2,cfgpath ) == 0 )) ) {
p++; p++;
j =+ processoption(&(cfgoptions[i]), *p); j =+ processoption(&(cfgoptions[i]), *p);
c--; c--;
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include "config_userapi.h" #include "config_userapi.h"
#define CONFIG_SHAREDLIBFORMAT "libparams_%s.so" #define CONFIG_SHAREDLIBFORMAT "libparams_%s.so"
int load_config_sharedlib(char *cfgmode, char *cfgP[], int numP, configmodule_interface_t *cfgptr) int load_config_sharedlib(configmodule_interface_t *cfgptr)
{ {
void *lib_handle; void *lib_handle;
char fname[128]; char fname[128];
...@@ -50,46 +50,46 @@ char libname[FILENAME_MAX]; ...@@ -50,46 +50,46 @@ char libname[FILENAME_MAX];
int st; int st;
st=0; st=0;
sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgmode); sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode);
lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
if (!lib_handle) { if (!lib_handle) {
fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror()); fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror());
st = -1; st = -1;
} else { } else {
sprintf (fname,"config_%s_init",cfgmode); sprintf (fname,"config_%s_init",cfgptr->cfgmode);
cfgptr->init = dlsym(lib_handle,fname); cfgptr->init = dlsym(lib_handle,fname);
if (cfgptr->init == NULL ) { if (cfgptr->init == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n", printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode); __FILE__, __LINE__,fname, cfgptr->cfgmode);
} else { } else {
st=cfgptr->init(cfgP,numP); st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP);
printf("[CONFIG] function %s returned %i\n", printf("[CONFIG] function %s returned %i\n",
fname, st); fname, st);
} }
sprintf (fname,"config_%s_get",cfgmode); sprintf (fname,"config_%s_get",cfgptr->cfgmode);
cfgptr->get = dlsym(lib_handle,fname); cfgptr->get = dlsym(lib_handle,fname);
if (cfgptr->get == NULL ) { if (cfgptr->get == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n", printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode); __FILE__, __LINE__,fname, cfgptr->cfgmode);
st = -1; st = -1;
} }
sprintf (fname,"config_%s_getlist",cfgmode); sprintf (fname,"config_%s_getlist",cfgptr->cfgmode);
cfgptr->getlist = dlsym(lib_handle,fname); cfgptr->getlist = dlsym(lib_handle,fname);
if (cfgptr->getlist == NULL ) { if (cfgptr->getlist == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n", printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode); __FILE__, __LINE__,fname, cfgptr->cfgmode);
st = -1; st = -1;
} }
sprintf (fname,"config_%s_end",cfgmode); sprintf (fname,"config_%s_end",cfgptr->cfgmode);
cfgptr->end = dlsym(lib_handle,fname); cfgptr->end = dlsym(lib_handle,fname);
if (cfgptr->getlist == NULL ) { if (cfgptr->getlist == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n", printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode); __FILE__, __LINE__,fname, cfgptr->cfgmode);
} }
} }
...@@ -105,16 +105,11 @@ char *cfgparam=NULL; ...@@ -105,16 +105,11 @@ char *cfgparam=NULL;
char *modeparams=NULL; char *modeparams=NULL;
char *cfgmode=NULL; char *cfgmode=NULL;
char *strtokctx=NULL; char *strtokctx=NULL;
char *cfgP[CONFIG_MAX_OOPT_PARAMS]; char *atoken;
int i;
int p;
int i;
for(i=0; i<CONFIG_MAX_OOPT_PARAMS ; i++) {
cfgP[i]=NULL;
}
/* first parse the command line to look for the -O option */ /* first parse the command line to look for the -O option */
opterr=0; opterr=0;
while ((i = getopt(argc, argv, "O:")) != -1) { while ((i = getopt(argc, argv, "O:")) != -1) {
...@@ -122,6 +117,8 @@ int p; ...@@ -122,6 +117,8 @@ int p;
cfgparam = optarg; cfgparam = optarg;
} }
} }
optind=1;
/* look for the OAI_CONFIGMODULE environement variable */ /* look for the OAI_CONFIGMODULE environement variable */
if ( cfgparam == NULL ) { if ( cfgparam == NULL ) {
cfgparam = getenv("OAI_CONFIGMODULE"); cfgparam = getenv("OAI_CONFIGMODULE");
...@@ -138,36 +135,47 @@ int p; ...@@ -138,36 +135,47 @@ int p;
return NULL; return NULL;
} }
else if ( i == 1 ) { else if ( i == 1 ) {
/* -O argument doesn't contain ":" separator, legacy -O <conf file> option, default cfgmode to libconfig
with one parameter, the path to the configuration file */
modeparams=cfgmode; modeparams=cfgmode;
cfgmode=strdup("libconfig"); cfgmode=strdup("libconfig");
} }
cfgptr = malloc(sizeof(configmodule_interface_t)); cfgptr = malloc(sizeof(configmodule_interface_t));
memset(cfgptr,0,sizeof(configmodule_interface_t));
p=0; /* temporary, legacy mode */
cfgP[p]=strtok_r(modeparams,":",&strtokctx); if (i==1) cfgptr->rtflags = cfgptr->rtflags | CONFIG_LEGACY;
while ( p< CONFIG_MAX_OOPT_PARAMS && cfgP[p] != NULL) { /*--*/
cfgptr->argc = argc;
cfgptr->argv = argv;
cfgptr->cfgmode=strdup(cfgmode);
cfgptr->num_cfgP=0;
atoken=strtok_r(modeparams,":",&strtokctx);
while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) {
/* look for debug level in the config parameters, it is commom to all config mode
and will be removed frome the parameter array passed to the shared module */
char *aptr; char *aptr;
aptr=strcasestr(cfgP[p],"dbgl"); aptr=strcasestr(atoken,"dbgl");
if (aptr != NULL) { if (aptr != NULL) {
cfgptr->rtflags = strtol(aptr+4,NULL,0); cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0);
Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].paramflags = Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].paramflags | PARAMFLAG_DONOTREAD;
for (int j=p; j<(CONFIG_MAX_OOPT_PARAMS-1); j++) cfgP[j] = cfgP[j+1]; } else {
p--; cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken);
cfgptr->num_cfgP++;
} }
p++; atoken = strtok_r(NULL,":",&strtokctx);
cfgP[p] = strtok_r(NULL,":",&strtokctx);
} }
printf("[CONFIG] get parameters from %s ",cfgmode); printf("[CONFIG] get parameters from %s ",cfgmode);
for (i=0;i<p; i++) { for (i=0;i<cfgptr->num_cfgP; i++) {
printf("%s ",cfgP[i]); printf("%s ",cfgptr->cfgP[i]);
} }
printf("\n"); printf("\n");
i=load_config_sharedlib(cfgmode, cfgP,p,cfgptr); i=load_config_sharedlib(cfgptr);
if (i< 0) { if (i< 0) {
fprintf(stderr,"[CONFIG] %s %d config module %s couldn't be loaded\n", __FILE__, __LINE__,cfgmode); fprintf(stderr,"[CONFIG] %s %d config module %s couldn't be loaded\n", __FILE__, __LINE__,cfgmode);
return NULL; return NULL;
...@@ -180,26 +188,30 @@ int p; ...@@ -180,26 +188,30 @@ int p;
if (modeparams != NULL) free(modeparams); if (modeparams != NULL) free(modeparams);
if (cfgmode != NULL) free(cfgmode); if (cfgmode != NULL) free(cfgmode);
optind=1;
cfgptr->argc = argc;
cfgptr->argv = argv;
return cfgptr; return cfgptr;
} }
void end_configmodule() void end_configmodule()
{ {
if (cfgptr != NULL) { if (cfgptr != NULL) {
printf ("[CONFIG] free %u pointers\n",cfgptr->numptrs); if (cfgptr->end != NULL) {
printf ("[CONFIG] calling config module end function...\n");
cfgptr->end();
}
if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP);
for (int i=0; i<cfgptr->num_cfgP; i++) {
if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
}
printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs);
for(int i=0; i<cfgptr->numptrs ; i++) { for(int i=0; i<cfgptr->numptrs ; i++) {
if (cfgptr->ptrs[i] != NULL) { if (cfgptr->ptrs[i] != NULL) {
free(cfgptr->ptrs[i]); free(cfgptr->ptrs[i]);
} }
cfgptr->ptrs[i]=NULL; cfgptr->ptrs[i]=NULL;
} }
if (cfgptr->end != NULL) {
printf ("[CONFIG] calling config module end function...\n");
cfgptr->end();
}
free(cfgptr); free(cfgptr);
cfgptr=NULL; cfgptr=NULL;
} }
......
...@@ -38,28 +38,34 @@ ...@@ -38,28 +38,34 @@
#include <stdlib.h> #include <stdlib.h>
#include "common/config/config_paramdesc.h" #include "common/config/config_paramdesc.h"
#define CONFIG_MAX_OOPT_PARAMS 10 // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2... #define CONFIG_MAX_OOPT_PARAMS 10 // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2...
#define CONFIG_MAX_ALLOCATEDPTRS 1024 // maximum number of parameters that can be dynamicaly alloted in the config module #define CONFIG_MAX_ALLOCATEDPTRS 1024 // maximum number of parameters that can be dynamicaly allocated in the config module
/* rtflags bit position definitions */ /* rtflags bit position definitions */
#define CONFIG_PRINTPARAMS 1 // print parameters values while processing #define CONFIG_PRINTPARAMS 1 // print parameters values while processing
#define CONFIG_DEBUGPTR 2 // print memory allocation/free debug messages #define CONFIG_DEBUGPTR 2 // print memory allocation/free debug messages
#define CONFIG_DEBUGCMDLINE 4 // print command line processing messages #define CONFIG_DEBUGCMDLINE 4 // print command line processing messages
/* temporary flag to be able to use legacy config mechanism */
#define CONFIG_LEGACY (1 << 10)
typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP); typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix); typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix);
typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix); typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix);
typedef void(*configmodule_endfunc_t)(void); typedef void(*configmodule_endfunc_t)(void);
typedef struct configmodule_interface typedef struct configmodule_interface
{ {
int argc; int argc;
char **argv; char **argv;
char *cfgmode;
int num_cfgP;
char *cfgP[CONFIG_MAX_OOPT_PARAMS];
configmodule_initfunc_t init; configmodule_initfunc_t init;
configmodule_getfunc_t get; configmodule_getfunc_t get;
configmodule_getlistfunc_t getlist; configmodule_getlistfunc_t getlist;
configmodule_endfunc_t end; configmodule_endfunc_t end;
uint32_t numptrs; uint32_t numptrs;
uint32_t rtflags; uint32_t rtflags;
char *ptrs[CONFIG_MAX_ALLOCATEDPTRS]; char *ptrs[CONFIG_MAX_ALLOCATEDPTRS];
} configmodule_interface_t; } configmodule_interface_t;
#ifdef CONFIG_LOADCONFIG_MAIN #ifdef CONFIG_LOADCONFIG_MAIN
...@@ -75,7 +81,7 @@ static char config_helpstr [] =" \ ...@@ -75,7 +81,7 @@ static char config_helpstr [] =" \
#define CONFIGPARAM_DEBUGFLAGS_IDX 0 #define CONFIGPARAM_DEBUGFLAGS_IDX 0
static paramdef_t Config_Params[] = { static paramdef_t Config_Params[] = {
{"debugflags", "", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_UINT, 0}, {"debugflags", "", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0},
}; };
#else #else
......
...@@ -42,51 +42,64 @@ ...@@ -42,51 +42,64 @@
/* parameter flags definitions */ /* parameter flags definitions */
/* Flags to be used by calling modules in their parameters definitions: */ /* Flags to be used by calling modules in their parameters definitions to modify config module behavior*/
#define PARAMFLAG_DISABLECMDLINE (1 << 0) // parameter can bet set from comand line #define PARAMFLAG_MANDATORY (1 << 0) // parameter must be explicitely set, default value ignored
#define PARAMFLAG_DISABLECMDLINE (1 << 1) // parameter cannot bet set from comand line
#define PARAMFLAG_DONOTREAD (1 << 2) // parameter must be ignored in get function
#define PARAMFLAG_NOFREE (1 << 3) // don't free parameter in end function
#define PARAMFLAG_BOOL (1 << 4) // integer param can be 0 or 1
/* Flags used by config modules: */
/* flags to be used by caller modules when defining parameters */
#define PARAMFLAG_MANDATORY (1 << 1) // parameter must be explicitely set, default value ignored
/* flags used by config modules, at runtime to manage memory allocations */ /* Flags used by config modules to return info to calling modules and/or to for internal usage*/
#define PARAMFLAG_MALLOCINCONFIG (1 << 15) // parameter allocated in config module #define PARAMFLAG_MALLOCINCONFIG (1 << 15) // parameter allocated in config module
#define PARAMFLAG_NOFREE (1 << 14) // don't free parameter in end function #define PARAMFLAG_PARAMSET (1 << 16) // parameter has been explicitely set in get functions
#define PARAMFLAG_PARAMSETDEF (1 << 17) // parameter has been set to default value in get functions
/* flags to be used by caller modules to modify get behavior */
#define PARAMFLAG_DONOTREAD (1 << 20) // parameter must be ignored in get function
typedef struct paramdef typedef struct paramdef
{ {
char optname[MAX_OPTNAME_SIZE]; char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */
char shortopt[MAX_SHORTOPT_SIZE]; char shortopt[MAX_SHORTOPT_SIZE]; /* short command line option */
char *helpstr; char *helpstr; /* help string */
unsigned int paramflags; unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */
union { union { /* pointer to the parameter value, completed by the config module */
char **strptr; char **strptr;
char **strlistptr; char **strlistptr;
uint32_t *uptr; uint8_t *u8ptr;
int32_t *iptr; char *i8ptr;
uint64_t *u64ptr; uint16_t *u16ptr;
int64_t *i64ptr; int16_t *i16ptr;
uint32_t *uptr;
int32_t *iptr;
uint64_t *u64ptr;
int64_t *i64ptr;
double *dblptr;
} ; } ;
union { union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
char *defstrval; char *defstrval;
char **defstrlistval; char **defstrlistval;
uint32_t defuintval; uint32_t defuintval;
int defintval; int defintval;
uint64_t defint64val; uint64_t defint64val;
int *defintarrayval; int *defintarrayval;
double defdblval;
} ; } ;
char type; char type; /* parameter value type, as listed below as TYPE_XXXX macro */
int numelt; int numelt; /* number of elements in a list or array parameters or max size of string value */
} paramdef_t; } paramdef_t;
#define TYPE_INT TYPE_INT32
#define TYPE_UINT TYPE_UINT32
#define TYPE_STRING 1 #define TYPE_STRING 1
#define TYPE_INT 2 #define TYPE_INT8 2
#define TYPE_UINT 3 #define TYPE_UINT8 3
#define TYPE_INT64 4 #define TYPE_INT16 4
#define TYPE_UINT64 5 #define TYPE_UINT16 5
#define TYPE_INT32 6
#define TYPE_UINT32 7
#define TYPE_INT64 8
#define TYPE_UINT64 9
#define TYPE_MASK 10
#define TYPE_DOUBLE 16
#define TYPE_IPV4ADDR 20 #define TYPE_IPV4ADDR 20
...@@ -94,7 +107,7 @@ typedef struct paramdef ...@@ -94,7 +107,7 @@ typedef struct paramdef
#define TYPE_INTARRAY 51 #define TYPE_INTARRAY 51
#define TYPE_UINTARRAY 52 #define TYPE_UINTARRAY 52
#define TYPE_LIST 55 #define TYPE_LIST 55
#define NO_UINTDEFAULT ((int)(-1))
#define ANY_IPV4ADDR_STRING "0.0.0.0" #define ANY_IPV4ADDR_STRING "0.0.0.0"
typedef struct paramlist_def { typedef struct paramlist_def {
......
...@@ -47,7 +47,7 @@ configmodule_interface_t *config_get_if(void) ...@@ -47,7 +47,7 @@ configmodule_interface_t *config_get_if(void)
return cfgptr; return cfgptr;
} }
char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length) char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length)
{ {
printf_ptrs("-- %s 0x%08lx %i\n",cfgoptions->optname,(uintptr_t)(*ptr),length); printf_ptrs("-- %s 0x%08lx %i\n",cfgoptions->optname,(uintptr_t)(*ptr),length);
...@@ -60,13 +60,54 @@ char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ...@@ -60,13 +60,54 @@ char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length)
config_get_if()->numptrs++; config_get_if()->numptrs++;
} }
} else { } else {
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__); fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
exit(-1); exit(-1);
} }
} }
return *ptr; return *ptr;
} }
void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val)
{
int tmpval=val;
if ( ((cfgoptions->paramflags &PARAMFLAG_BOOL) != 0) && tmpval >1) {
tmpval =1;
}
switch (cfgoptions->type) {
case TYPE_UINT8:
*(cfgoptions->u8ptr) = (uint8_t)tmpval;
printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval);
break;
case TYPE_INT8:
*(cfgoptions->i8ptr) = (int8_t)tmpval;
printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval);
break;
case TYPE_UINT16:
*(cfgoptions->u16ptr) = (uint16_t)tmpval;
printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval);
break;
case TYPE_INT16:
*(cfgoptions->i16ptr) = (int16_t)tmpval;
printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval);
break;
case TYPE_UINT32:
*(cfgoptions->uptr) = (uint32_t)tmpval;
printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval);
break;
case TYPE_MASK:
*(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval;
printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval);
break;
case TYPE_INT32:
*(cfgoptions->iptr) = (int32_t)tmpval;
printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval);
break;
default:
fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname);
break;
}
}
void config_printhelp(paramdef_t *params,int numparams) void config_printhelp(paramdef_t *params,int numparams)
{ {
for (int i=0 ; i<numparams ; i++) { for (int i=0 ; i<numparams ; i++) {
...@@ -80,12 +121,21 @@ int config_get(paramdef_t *params,int numparams, char *prefix) ...@@ -80,12 +121,21 @@ int config_get(paramdef_t *params,int numparams, char *prefix)
{ {
int ret= -1; int ret= -1;
configmodule_interface_t *cfgif = config_get_if(); configmodule_interface_t *cfgif = config_get_if();
if (cfgif != NULL) { if (cfgif != NULL) {
ret = config_get_if()->get(params, numparams,prefix); ret = config_get_if()->get(params, numparams,prefix);
if (ret >= 0) { if (ret >= 0) {
config_process_cmdline(params,numparams,prefix); config_process_cmdline(params,numparams,prefix);
} }
return ret;
}
return ret; return ret;
} }
return ret;
int config_isparamset(paramdef_t *params,int paramidx)
{
if ((params[paramidx].paramflags & PARAMFLAG_PARAMSET) != 0) {
return 1;
} else {
return 0;
}
} }
...@@ -38,12 +38,19 @@ ...@@ -38,12 +38,19 @@
extern "C" extern "C"
{ {
#endif #endif
#define CONFIG_GETSOURCE ( (config_get_if()==NULL) ? NULL : config_get_if()->cfgmode )
#define CONFIG_GETNUMP ( (config_get_if()==NULL) ? 0 : config_get_if()->num_cfgP )
#define CONFIG_GETP(P) ( (config_get_if()==NULL) ? NULL : config_get_if()->cfgP[P] )
#define CONFIG_ISFLAGSET(P) ( (config_get_if()==NULL) ? 0 : !!(config_get_if()->rtflags & P))
extern configmodule_interface_t *config_get_if(void); extern configmodule_interface_t *config_get_if(void);
extern char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ; extern char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
extern void config_printhelp(paramdef_t *,int numparams); extern void config_printhelp(paramdef_t *,int numparams);
extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix); extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix);
extern int config_get(paramdef_t *params,int numparams, char *prefix);