Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lizhongxiao
OpenXG-RAN
Commits
1eb79272
Commit
1eb79272
authored
Mar 30, 2022
by
frtabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config module enhancement, next step
parent
79b85864
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
22 deletions
+66
-22
common/config/config_load_configmodule.c
common/config/config_load_configmodule.c
+5
-2
common/config/config_load_configmodule.h
common/config/config_load_configmodule.h
+11
-7
common/config/libconfig/config_libconfig.c
common/config/libconfig/config_libconfig.c
+50
-13
No files found.
common/config/config_load_configmodule.c
View file @
1eb79272
...
...
@@ -275,7 +275,7 @@ configmodule_interface_t *load_configmodule(int argc,
/* argv[0] is the exec name, always Ok */
cfgptr
->
argv_info
[
0
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
/*
a file with config parameters as defined after all processing
will be created */
/*
When reuested _(_--OW or rtflag is 5), a file with config parameters, as defined after all processing,
will be created */
if
(
OWoptIdx
>=
0
)
{
cfgptr
->
argv_info
[
OWoptIdx
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
cfgptr
->
rtflags
|=
CONFIG_SAVERUNCFG
;
...
...
@@ -322,7 +322,10 @@ configmodule_interface_t *load_configmodule(int argc,
if
(
i
==
0
)
{
printf
(
"[CONFIG] config module %s loaded
\n
"
,
cfgmode
);
Config_Params
[
CONFIGPARAM_DEBUGFLAGS_IDX
].
uptr
=&
(
cfgptr
->
rtflags
);
int
idx
=
config_paramidx_fromname
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
),
CONFIGP_DEBUGFLAGS
);
Config_Params
[
idx
].
uptr
=&
(
cfgptr
->
rtflags
);
idx
=
config_paramidx_fromname
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
),
CONFIGP_TMPDIR
);
Config_Params
[
idx
].
strptr
=&
(
cfgptr
->
tmpdir
);
config_get
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
),
CONFIG_SECTIONNAME
);
}
else
{
fprintf
(
stderr
,
"[CONFIG] %s %d config module
\"
%s
\"
couldn't be loaded
\n
"
,
__FILE__
,
__LINE__
,
cfgmode
);
...
...
common/config/config_load_configmodule.h
View file @
1eb79272
...
...
@@ -80,6 +80,7 @@ typedef struct configmodule_interface {
uint32_t
rtflags
;
char
*
ptrs
[
CONFIG_MAX_ALLOCATEDPTRS
];
bool
ptrsAllocated
[
CONFIG_MAX_ALLOCATEDPTRS
];
char
*
tmpdir
;
}
configmodule_interface_t
;
#ifdef CONFIG_LOADCONFIG_MAIN
...
...
@@ -92,16 +93,19 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl
incp parameter can be used to define the include path used for config files (@include directive)
\n
\
defaults is set to the path of the main config file.
\n
"
;
#define CONFIG_SECTIONNAME "config"
#define CONFIGPARAM_DEBUGFLAGS_IDX 0
#define CONFIG_HELP_TMPDIR "<Repository to create temporary file>"
#define CONFIG_SECTIONNAME "config"
#define CONFIGP_DEBUGFLAGS "debugflags"
#define CONFIGP_TMPDIR "tmpdir"
static
paramdef_t
Config_Params
[]
=
{
/*-----------------------------------------------------------------------------------------------------------------------*/
/* config parameters for config module */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/*-----------------------------------------------------------------------------------------------------------------------*/
{
"debugflags"
,
config_helpstr
,
0
,
uptr
:
NULL
,
defintval
:
0
,
TYPE_MASK
,
0
},
/*--------------------------------------------------------------------------------------------------------------------------*/
/* config parameters for config module */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/*--------------------------------------------------------------------------------------------------------------------------*/
{
CONFIGP_DEBUGFLAGS
,
config_helpstr
,
0
,
uptr
:
NULL
,
defintval
:
0
,
TYPE_MASK
,
0
},
{
CONFIGP_TMPDIR
,
CONFIG_HELP_TMPDIR
,
PARAMFLAG_NOFREE
,
strptr
:
NULL
,
defstrval
:
"/tmp"
,
TYPE_STRING
,
0
},
};
#else
...
...
common/config/libconfig/config_libconfig.c
View file @
1eb79272
...
...
@@ -91,14 +91,30 @@ int read_intarray(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpat
int
config_libconfig_setparams
(
paramdef_t
*
cfgoptions
,
int
numoptions
,
config_setting_t
*
asetting
)
{
int
status
;
int
errors
=
0
;
int
notused
=
0
;
#define LIBCONFIG_NOTUSED_PARAMS "Not used? (NULL value ptr)"
for
(
int
i
=
0
;
i
<
numoptions
;
i
++
)
{
status
=
CONFIG_FALSE
;
config_setting_t
*
psetting
;
switch
(
cfgoptions
[
i
].
type
)
{
case
TYPE_STRING
:
//status=config_setting_set_string (asetting, *cfgoptions[i].strptr;
psetting
=
config_setting_add
(
asetting
,
cfgoptions
[
i
].
optname
,
CONFIG_TYPE_STRING
);
if
(
psetting
!=
NULL
)
{
char
*
value
;
if
(
cfgoptions
[
i
].
strptr
==
NULL
)
{
notused
++
;
value
=
LIBCONFIG_NOTUSED_PARAMS
;
}
else
{
if
(
cfgoptions
[
i
].
numelt
==
0
)
{
value
=
*
(
cfgoptions
[
i
].
strptr
);
}
else
{
value
=
(
char
*
)(
cfgoptions
[
i
].
strptr
);
}
}
status
=
config_setting_set_string
(
psetting
,
value
);
}
break
;
case
TYPE_STRINGLIST
:
break
;
...
...
@@ -109,12 +125,16 @@ int config_libconfig_setparams(paramdef_t *cfgoptions, int numoptions, config_se
case
TYPE_UINT32
:
case
TYPE_INT32
:
case
TYPE_MASK
:
status
=
config_setting_set_int
(
asetting
,
(
int
)
*
(
cfgoptions
[
i
].
iptr
)
);
psetting
=
config_setting_add
(
asetting
,
cfgoptions
[
i
].
optname
,
CONFIG_TYPE_INT
);
if
(
psetting
!=
NULL
)
status
=
config_setting_set_int
(
psetting
,
(
int
)
*
(
cfgoptions
[
i
].
iptr
)
);
break
;
case
TYPE_UINT64
:
case
TYPE_INT64
:
status
=
config_setting_set_int64
(
asetting
,
(
int64_t
)
*
(
cfgoptions
[
i
].
i64ptr
)
);
psetting
=
config_setting_add
(
asetting
,
cfgoptions
[
i
].
optname
,
CONFIG_TYPE_INT64
);
if
(
psetting
!=
NULL
)
status
=
config_setting_set_int64
(
psetting
,
(
int64_t
)
*
(
cfgoptions
[
i
].
i64ptr
)
);
break
;
case
TYPE_UINTARRAY
:
...
...
@@ -123,7 +143,9 @@ int config_libconfig_setparams(paramdef_t *cfgoptions, int numoptions, config_se
break
;
case
TYPE_DOUBLE
:
status
=
config_setting_set_float
(
asetting
,
(
double
)
*
(
cfgoptions
[
i
].
dblptr
)
);
psetting
=
config_setting_add
(
asetting
,
cfgoptions
[
i
].
optname
,
CONFIG_TYPE_FLOAT
);
if
(
psetting
!=
NULL
)
status
=
config_setting_set_float
(
psetting
,
(
double
)
*
(
cfgoptions
[
i
].
dblptr
)
);
break
;
case
TYPE_IPV4ADDR
:
...
...
@@ -142,8 +164,11 @@ int config_libconfig_setparams(paramdef_t *cfgoptions, int numoptions, config_se
fprintf
(
stderr
,
"[LIBCONFIG] Error creating setting %i: %s type %i
\n
"
,
i
,
cfgoptions
[
i
].
optname
,
cfgoptions
[
i
].
type
);
}
}
if
(
notused
>
0
)
printf_params
(
"[LIBCONFIG], %i settings with NULL value pointer
\n
"
,
notused
);
if
(
errors
==
0
)
{
print_params
(
"[LIBCONFIG], %i settings set successfully "
,
numoptions
);
print
f
_params
(
"[LIBCONFIG], %i settings set successfully "
,
numoptions
);
}
else
{
fprintf
(
stderr
,
"[LIBCONFIG] ...%i/%i settings creation errors
\n
"
,
errors
,
numoptions
);
}
...
...
@@ -161,29 +186,39 @@ int config_libconfig_set(paramdef_t *cfgoptions, int numoptions, char *prefix )
prefix_elem1
=
strtok_r
(
prefixbck
,
"."
,
&
tokctx1
);
}
int
n1
=
0
;
/* parse the prefix , possibly creating groups, lists and list elements */
while
(
prefix_elem1
!=
NULL
)
{
n1
+=
strlen
(
prefix_elem1
)
+
1
;
char
*
prefix_elem2
=
(
n1
<
strlen
(
prefix
)
)
?
prefix_elem1
+
n1
:
""
;
if
(
prefix_elem2
[
0
]
!=
'['
)
{
/* prefix (the path to the parameter name) may contain groups and elements from a list, which are specified with [] */
if
(
prefix_elem2
[
0
]
!=
'['
)
{
// not a list
config_setting_t
*
tmpset
=
config_setting_lookup
(
asetting
,
prefix_elem1
);
if
(
tmpset
==
NULL
)
asetting
=
config_setting_add
(
asetting
,
prefix_elem1
,
CONFIG_TYPE_GROUP
);
else
asetting
=
tmpset
;
}
else
{
}
else
{
// a list
listidx
=
(
int
)
strtol
(
prefix_elem2
,
NULL
,
10
);
config_setting_t
*
tmpset
=
config_setting_lookup
(
asetting
,
prefix_elem1
);
if
(
tmpset
==
NULL
)
asetting
=
config_setting_add
(
asetting
,
prefix_elem1
,
CONFIG_TYPE_LIST
);
else
asetting
=
tmpset
;
// tmpset =
if
(
asetting
!=
NULL
)
{
tmpset
=
config_setting_get_elem
(
asetting
,
listidx
);
if
(
tmpset
==
NULL
)
asetting
=
config_setting_add
(
asetting
,
NULL
,
CONFIG_TYPE_GROUP
);
else
asetting
=
tmpset
;
}
prefix_elem1
=
strtok_r
(
NULL
,
"."
,
&
tokctx1
);
//skip the [x] elements we already took care of it
if
(
prefix_elem1
==
NULL
)
{
fprintf
(
stderr
,
"[LICONFIG] Error parsing %s__
\n
"
,
prefix
);
break
;
}
}
if
(
asetting
==
NULL
)
{
fprintf
(
stderr
,
"[LIBCONFIG] Error creating setting %s %s %i
\n
"
,
prefix_elem1
,
prefix_elem2
,
listidx
);
break
;
}
prefix_elem1
=
strtok_r
(
NULL
,
"."
,
&
tokctx1
);
}
...
...
@@ -498,10 +533,11 @@ int config_libconfig_init(char *cfgP[], int numP) {
void
config_libconfig_end
(
void
)
{
config_destroy
(
&
(
libconfig_privdata
.
cfg
));
if
(
cfgptr
->
rtflags
&
CONFIG_SAVERUNCFG
)
{
char
*
fname
=
strdup
(
libconfig_privdata
.
configfile
);
char
*
newcfgf
=
malloc
(
strlen
(
libconfig_privdata
.
configfile
+
20
));
time_t
t
=
time
(
NULL
);
struct
tm
tm
=
*
localtime
(
&
t
);
sprintf
(
newcfgf
,
"%s
-run%d_%02d_%02d_%02d%02d"
,
libconfig_privdata
.
configfile
,
sprintf
(
newcfgf
,
"%s
/%s-run%d_%02d_%02d_%02d%02d"
,
cfgptr
->
tmpdir
,
basename
(
fname
)
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
);
if
(
config_write_file
(
&
(
libconfig_privdata
.
runtcfg
)
,
newcfgf
)
!=
CONFIG_TRUE
)
{
fprintf
(
stderr
,
"[LIBCONFIG] %s %d file %s - line %d: %s
\n
"
,
__FILE__
,
__LINE__
,
...
...
@@ -511,6 +547,7 @@ void config_libconfig_end(void ) {
printf
(
"[LIBCONFIG] file %s created successfully
\n
"
,
newcfgf
);
}
config_destroy
(
&
(
libconfig_privdata
.
runtcfg
));
free
(
fname
);
free
(
newcfgf
);
}
if
(
libconfig_privdata
.
configfile
!=
NULL
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment