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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
OpenXG
OpenXG-RAN
Commits
55732deb
Commit
55732deb
authored
Nov 22, 2018
by
Raphael Defosseux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Astyling the common files
Signed-off-by:
Raphael Defosseux
<
raphael.defosseux@eurecom.fr
>
parent
df5fe4ff
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1420 additions
and
1333 deletions
+1420
-1333
common/config/config_cmdline.c
common/config/config_cmdline.c
+220
-199
common/config/config_load_configmodule.c
common/config/config_load_configmodule.c
+255
-234
common/config/config_load_configmodule.h
common/config/config_load_configmodule.h
+12
-13
common/config/config_paramdesc.h
common/config/config_paramdesc.h
+70
-71
common/config/config_userapi.c
common/config/config_userapi.c
+308
-268
common/config/config_userapi.h
common/config/config_userapi.h
+3
-3
common/utils/LOG/log.c
common/utils/LOG/log.c
+286
-340
common/utils/LOG/log.h
common/utils/LOG/log.h
+174
-170
common/utils/T/genids.c
common/utils/T/genids.c
+92
-35
No files found.
common/config/config_cmdline.c
View file @
55732deb
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
*/
*/
/*! \file common/config/cmdline/config_libconfig.c
/*! \file common/config/cmdline/config_libconfig.c
* \brief configuration module, command line parsing implementation
* \brief configuration module, command line parsing implementation
* \author Francois TABURET
* \author Francois TABURET
* \date 2017
* \date 2017
* \version 0.1
* \version 0.1
...
@@ -39,223 +39,244 @@
...
@@ -39,223 +39,244 @@
#include "config_userapi.h"
#include "config_userapi.h"
int
parse_stringlist
(
paramdef_t
*
cfgoptions
,
char
*
val
)
int
parse_stringlist
(
paramdef_t
*
cfgoptions
,
char
*
val
)
{
{
char
*
atoken
;
char
*
atoken
;
char
*
tokctx
;
char
*
tokctx
;
char
*
tmpval
=
strdup
(
val
)
;
char
*
tmpval
=
strdup
(
val
)
;
int
numelt
=
0
;
int
numelt
=
0
;
cfgoptions
->
numelt
=
0
;
atoken
=
strtok_r
(
tmpval
,
","
,
&
tokctx
);
cfgoptions
->
numelt
=
0
;
while
(
atoken
!=
NULL
)
{
atoken
=
strtok_r
(
tmpval
,
","
,
&
tokctx
)
;
numelt
++
;
while
(
atoken
!=
NULL
)
{
atoken
=
strtok_r
(
NULL
,
","
,
&
tokctx
);
numelt
++
;
}
atoken
=
strtok_r
(
NULL
,
","
,
&
tokctx
);
}
free
(
tmpval
);
free
(
tmpval
);
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
strlistptr
),
sizeof
(
char
*
)
*
numelt
);
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
strlistptr
),
sizeof
(
char
*
)
*
numelt
)
;
cfgoptions
->
numelt
=
numelt
;
cfgoptions
->
numelt
=
numelt
;
atoken
=
strtok_r
(
val
,
","
,
&
tokctx
)
;
atoken
=
strtok_r
(
val
,
","
,
&
tokctx
);
for
(
int
i
=
0
;
i
<
cfgoptions
->
numelt
&&
atoken
!=
NULL
;
i
++
)
{
for
(
int
i
=
0
;
i
<
cfgoptions
->
numelt
&&
atoken
!=
NULL
;
i
++
)
{
config_check_valptr
(
cfgoptions
,
&
(
cfgoptions
->
strlistptr
[
i
]),
strlen
(
atoken
)
+
1
);
config_check_valptr
(
cfgoptions
,
&
(
cfgoptions
->
strlistptr
[
i
]),
strlen
(
atoken
)
+
1
);
sprintf
(
cfgoptions
->
strlistptr
[
i
],
"%s"
,
atoken
);
sprintf
(
cfgoptions
->
strlistptr
[
i
],
"%s"
,
atoken
);
printf_params
(
"[LIBCONFIG] %s[%i]: %s
\n
"
,
cfgoptions
->
optname
,
i
,
cfgoptions
->
strlistptr
[
i
]
);
printf_params
(
"[LIBCONFIG] %s[%i]: %s
\n
"
,
cfgoptions
->
optname
,
i
,
cfgoptions
->
strlistptr
[
i
]
);
atoken
=
strtok_r
(
NULL
,
","
,
&
tokctx
);
atoken
=
strtok_r
(
NULL
,
","
,
&
tokctx
);
}
}
return
(
cfgoptions
->
numelt
>
0
);
return
(
cfgoptions
->
numelt
>
0
);
}
}
int
processoption
(
paramdef_t
*
cfgoptions
,
char
*
value
)
int
processoption
(
paramdef_t
*
cfgoptions
,
char
*
value
)
{
{
char
*
tmpval
=
value
;
char
*
tmpval
=
value
;
int
optisset
=
0
;
int
optisset
=
0
;
char
defbool
[
2
]
=
"1"
;
char
defbool
[
2
]
=
"1"
;
if
(
value
==
NULL
)
{
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_BOOL
)
==
0
)
{
/* not a boolean, argument required */
if
(
value
==
NULL
)
{
fprintf
(
stderr
,
"[CONFIG] command line, option %s requires an argument
\n
"
,
cfgoptions
->
optname
);
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_BOOL
)
==
0
)
{
/* not a boolean, argument required */
return
0
;
fprintf
(
stderr
,
"[CONFIG] command line, option %s requires an argument
\n
"
,
cfgoptions
->
optname
);
}
else
{
/* boolean value option without argument, set value to true*/
return
0
;
tmpval
=
defbool
;
}
else
{
/* boolean value option without argument, set value to true*/
}
tmpval
=
defbool
;
}
}
}
switch
(
cfgoptions
->
type
)
{
switch
(
cfgoptions
->
type
)
case
TYPE_STRING
:
{
if
(
cfgoptions
->
numelt
==
0
)
{
case
TYPE_STRING
:
config_check_valptr
(
cfgoptions
,
cfgoptions
->
strptr
,
strlen
(
tmpval
)
+
1
);
if
(
cfgoptions
->
numelt
==
0
)
{
sprintf
(
*
(
cfgoptions
->
strptr
),
"%s"
,
tmpval
);
config_check_valptr
(
cfgoptions
,
cfgoptions
->
strptr
,
strlen
(
tmpval
)
+
1
);
}
else
{
sprintf
(
*
(
cfgoptions
->
strptr
),
"%s"
,
tmpval
);
sprintf
(
(
char
*
)(
cfgoptions
->
strptr
),
"%s"
,
tmpval
);
}
else
{
}
sprintf
(
(
char
*
)(
cfgoptions
->
strptr
),
"%s"
,
tmpval
);
}
printf_cmdl
(
"[CONFIG] %s set to %s from command line
\n
"
,
cfgoptions
->
optname
,
tmpval
);
printf_cmdl
(
"[CONFIG] %s set to %s from command line
\n
"
,
cfgoptions
->
optname
,
tmpval
);
optisset
=
1
;
optisset
=
1
;
break
;
break
;
case
TYPE_STRINGLIST
:
case
TYPE_STRINGLIST
:
optisset
=
parse_stringlist
(
cfgoptions
,
tmpval
);
optisset
=
parse_stringlist
(
cfgoptions
,
tmpval
);
break
;
break
;
case
TYPE_UINT32
:
case
TYPE_UINT32
:
case
TYPE_INT32
:
case
TYPE_INT32
:
case
TYPE_UINT16
:
case
TYPE_UINT16
:
case
TYPE_INT16
:
case
TYPE_INT16
:
case
TYPE_UINT8
:
case
TYPE_UINT8
:
case
TYPE_INT8
:
case
TYPE_INT8
:
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
iptr
),
sizeof
(
int32_t
));
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
iptr
),
sizeof
(
int32_t
));
config_assign_int
(
cfgoptions
,
cfgoptions
->
optname
,(
int32_t
)
strtol
(
tmpval
,
NULL
,
0
));
config_assign_int
(
cfgoptions
,
cfgoptions
->
optname
,(
int32_t
)
strtol
(
tmpval
,
NULL
,
0
));
optisset
=
1
;
optisset
=
1
;
break
;
break
;
case
TYPE_UINT64
:
case
TYPE_INT64
:
case
TYPE_UINT64
:
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
i64ptr
),
sizeof
(
uint64_t
));
case
TYPE_INT64
:
*
(
cfgoptions
->
i64ptr
)
=
strtoll
(
tmpval
,
NULL
,
0
);
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
i64ptr
),
sizeof
(
uint64_t
));
printf_cmdl
(
"[CONFIG] %s set to %lli from command line
\n
"
,
cfgoptions
->
optname
,
(
long
long
)
*
(
cfgoptions
->
i64ptr
));
*
(
cfgoptions
->
i64ptr
)
=
strtoll
(
tmpval
,
NULL
,
0
);
optisset
=
1
;
printf_cmdl
(
"[CONFIG] %s set to %lli from command line
\n
"
,
cfgoptions
->
optname
,
(
long
long
)
*
(
cfgoptions
->
i64ptr
));
break
;
optisset
=
1
;
case
TYPE_UINTARRAY
:
break
;
case
TYPE_INTARRAY
:
case
TYPE_UINTARRAY
:
break
;
case
TYPE_INTARRAY
:
case
TYPE_DOUBLE
:
break
;
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
dblptr
),
sizeof
(
double
));
*
(
cfgoptions
->
dblptr
)
=
strtof
(
tmpval
,
NULL
);
case
TYPE_DOUBLE
:
printf_cmdl
(
"[CONFIG] %s set to %lf from command line
\n
"
,
cfgoptions
->
optname
,
*
(
cfgoptions
->
dblptr
));
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
dblptr
),
sizeof
(
double
));
optisset
=
1
;
*
(
cfgoptions
->
dblptr
)
=
strtof
(
tmpval
,
NULL
);
break
;
printf_cmdl
(
"[CONFIG] %s set to %lf from command line
\n
"
,
cfgoptions
->
optname
,
*
(
cfgoptions
->
dblptr
));
optisset
=
1
;
case
TYPE_IPV4ADDR
:
break
;
break
;
case
TYPE_IPV4ADDR
:
break
;
default:
fprintf
(
stderr
,
"[CONFIG] command line, %s type %i not supported
\n
"
,
cfgoptions
->
optname
,
cfgoptions
->
type
);
default:
break
;
fprintf
(
stderr
,
"[CONFIG] command line, %s type %i not supported
\n
"
,
cfgoptions
->
optname
,
cfgoptions
->
type
);
}
/* switch on param type */
break
;
if
(
optisset
==
1
)
{
}
/* switch on param type */
cfgoptions
->
paramflags
=
cfgoptions
->
paramflags
|
PARAMFLAG_PARAMSET
;
}
if
(
optisset
==
1
)
{
return
optisset
;
cfgoptions
->
paramflags
=
cfgoptions
->
paramflags
|
PARAMFLAG_PARAMSET
;
}
return
optisset
;
}
}
int
config_check_cmdlineopt
(
char
*
prefix
)
int
config_check_cmdlineopt
(
char
*
prefix
)
{
{
int
unknowndetected
=
0
;
int
unknowndetected
=
0
;
char
testprefix
[
CONFIG_MAXOPTLENGTH
]
=
""
;
char
testprefix
[
CONFIG_MAXOPTLENGTH
]
=
""
;
int
finalcheck
=
0
;
int
finalcheck
=
0
;
if
(
prefix
!=
NULL
)
{
if
(
prefix
!=
NULL
)
{
if
(
strcmp
(
prefix
,
CONFIG_CHECKALLSECTIONS
)
==
0
)
if
(
strcmp
(
prefix
,
CONFIG_CHECKALLSECTIONS
)
==
0
)
finalcheck
=
1
;
finalcheck
=
1
;
else
if
(
strlen
(
prefix
)
>
0
)
{
else
if
(
strlen
(
prefix
)
>
0
)
{
sprintf
(
testprefix
,
"--%s."
,
prefix
);
sprintf
(
testprefix
,
"--%s."
,
prefix
);
}
}
for
(
int
i
=
1
;
i
<
config_get_if
()
->
argc
;
i
++
)
{
if
(
!
finalcheck
&&
strstr
(
config_get_if
()
->
argv
[
i
],
testprefix
)
==
NULL
)
continue
;
if
(
!
finalcheck
&&
testprefix
[
0
]
==
0
&&
index
(
config_get_if
()
->
argv
[
i
],
'.'
)
!=
NULL
)
continue
;
if
(
!
finalcheck
&&
config_get_if
()
->
argv
[
i
][
0
]
==
'-'
&&
isdigit
(
config_get_if
()
->
argv
[
i
][
1
]))
continue
;
if
(
(
config_get_if
()
->
argv_info
[
i
]
&
CONFIG_CMDLINEOPT_PROCESSED
)
==
0
)
{
fprintf
(
stderr
,
"[CONFIG] unknown option: %s
\n
"
,
config_get_if
()
->
argv
[
i
]
);
unknowndetected
++
;
}
}
}
}
for
(
int
i
=
1
;
i
<
config_get_if
()
->
argc
;
i
++
)
{
if
(
!
finalcheck
&&
strstr
(
config_get_if
()
->
argv
[
i
],
testprefix
)
==
NULL
)
continue
;
if
(
!
finalcheck
&&
testprefix
[
0
]
==
0
&&
index
(
config_get_if
()
->
argv
[
i
],
'.'
)
!=
NULL
)
continue
;
if
(
!
finalcheck
&&
config_get_if
()
->
argv
[
i
][
0
]
==
'-'
&&
isdigit
(
config_get_if
()
->
argv
[
i
][
1
]))
continue
;
if
(
(
config_get_if
()
->
argv_info
[
i
]
&
CONFIG_CMDLINEOPT_PROCESSED
)
==
0
)
{
fprintf
(
stderr
,
"[CONFIG] unknown option: %s
\n
"
,
config_get_if
()
->
argv
[
i
]
);
unknowndetected
++
;
}
}
printf_cmdl
(
"[CONFIG] %i unknown option(s) in command line starting with %s (section %s)
\n
"
,
printf_cmdl
(
"[CONFIG] %i unknown option(s) in command line starting with %s (section %s)
\n
"
,
unknowndetected
,
testprefix
,((
prefix
==
NULL
)
?
""
:
prefix
));
unknowndetected
,
testprefix
,((
prefix
==
NULL
)
?
""
:
prefix
));
return
unknowndetected
;
return
unknowndetected
;
}
/* parse_cmdline*/
}
/* parse_cmdline*/
int
config_process_cmdline
(
paramdef_t
*
cfgoptions
,
int
numoptions
,
char
*
prefix
)
int
config_process_cmdline
(
paramdef_t
*
cfgoptions
,
int
numoptions
,
char
*
prefix
)
{
{
int
c
=
config_get_if
()
->
argc
;
int
c
=
config_get_if
()
->
argc
;
int
i
,
j
;
int
i
,
j
;
char
*
pp
;
char
*
pp
;
char
cfgpath
[
CONFIG_MAXOPTLENGTH
];
char
cfgpath
[
CONFIG_MAXOPTLENGTH
];
j
=
0
;
j
=
0
;
i
=
0
;
i
=
0
;
while
(
c
>
0
)
{
char
*
oneargv
=
strdup
(
config_get_if
()
->
argv
[
i
]);
/* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */
while
(
c
>
0
)
{
/* first check help options, either --help, -h or --help_<section> */
char
*
oneargv
=
strdup
(
config_get_if
()
->
argv
[
i
]);
/* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */
if
(
strncmp
(
oneargv
,
"-h"
,
2
)
==
0
||
strncmp
(
oneargv
,
"--help"
,
6
)
==
0
)
{
char
*
tokctx
;
/* first check help options, either --help, -h or --help_<section> */
pp
=
strtok_r
(
oneargv
,
"_"
,
&
tokctx
);
if
(
strncmp
(
oneargv
,
"-h"
,
2
)
==
0
||
strncmp
(
oneargv
,
"--help"
,
6
)
==
0
)
{
char
*
tokctx
;
pp
=
strtok_r
(
oneargv
,
"_"
,
&
tokctx
);
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
pp
==
NULL
||
strcasecmp
(
pp
,
config_get_if
()
->
argv
[
i
]
)
==
0
)
{
if
(
prefix
==
NULL
)
{
config_printhelp
(
cfgoptions
,
numoptions
);
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOEXITONHELP
)))
exit_fun
(
"[CONFIG] Exiting after displaying help
\n
"
);
}
}
else
{
pp
=
strtok_r
(
NULL
,
" "
,
&
tokctx
);
if
(
prefix
!=
NULL
&&
pp
!=
NULL
&&
strncasecmp
(
prefix
,
pp
,
strlen
(
pp
))
==
0
)
{
printf
(
"Help for %s section:
\n
"
,
prefix
);
config_printhelp
(
cfgoptions
,
numoptions
);
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOEXITONHELP
)))
{
fprintf
(
stderr
,
"[CONFIG] %s %i section %s:"
,
__FILE__
,
__LINE__
,
prefix
);
exit_fun
(
" Exiting after displaying help
\n
"
);
}
}
}
}
/* now, check for non help options */
if
(
oneargv
[
0
]
==
'-'
)
{
for
(
int
n
=
0
;
n
<
numoptions
;
n
++
)
{
if
(
(
cfgoptions
[
n
].
paramflags
&
PARAMFLAG_DISABLECMDLINE
)
!=
0
)
{
continue
;
}
if
(
prefix
!=
NULL
)
{
sprintf
(
cfgpath
,
"%s.%s"
,
prefix
,
cfgoptions
[
n
].
optname
);
}
else
{
sprintf
(
cfgpath
,
"%s"
,
cfgoptions
[
n
].
optname
);
}
if
(
((
strlen
(
oneargv
)
==
2
)
&&
(
strcmp
(
oneargv
+
1
,
cfgpath
)
==
0
))
||
/* short option, one "-" */
((
strlen
(
oneargv
)
>
2
)
&&
(
strcmp
(
oneargv
+
2
,
cfgpath
)
==
0
))
)
{
char
*
valptr
=
NULL
;
int
ret
;
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
c
>
0
)
{
pp
=
config_get_if
()
->
argv
[
i
+
1
];
if
(
pp
!=
NULL
)
{
ret
=
strlen
(
pp
);
if
(
ret
>
0
)
{
if
(
pp
[
0
]
!=
'-'
)
valptr
=
pp
;
else
if
(
ret
>
1
&&
pp
[
0
]
==
'-'
&&
isdigit
(
pp
[
1
])
)
valptr
=
pp
;
}
}
}
j
+=
processoption
(
&
(
cfgoptions
[
n
]),
valptr
);
if
(
valptr
!=
NULL
)
{
i
++
;
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
pp
==
NULL
||
strcasecmp
(
pp
,
config_get_if
()
->
argv
[
i
]
)
==
0
)
{
c
--
;
if
(
prefix
==
NULL
)
{
}
config_printhelp
(
cfgoptions
,
numoptions
);
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOEXITONHELP
)))
break
;
exit_fun
(
"[CONFIG] Exiting after displaying help
\n
"
);
}
}
else
{
pp
=
strtok_r
(
NULL
,
" "
,
&
tokctx
);
if
(
prefix
!=
NULL
&&
pp
!=
NULL
&&
strncasecmp
(
prefix
,
pp
,
strlen
(
pp
))
==
0
)
{
printf
(
"Help for %s section:
\n
"
,
prefix
);
config_printhelp
(
cfgoptions
,
numoptions
);
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOEXITONHELP
)))
{
fprintf
(
stderr
,
"[CONFIG] %s %i section %s:"
,
__FILE__
,
__LINE__
,
prefix
);
exit_fun
(
" Exiting after displaying help
\n
"
);
}
}
}
}
}
}
/* for n... */
}
/* if (oneargv[0] == '-') */
free
(
oneargv
);
i
++
;
c
--
;
}
/* fin du while */
/* now, check for non help options */
if
(
oneargv
[
0
]
==
'-'
)
{
for
(
int
n
=
0
;
n
<
numoptions
;
n
++
)
{
if
(
(
cfgoptions
[
n
].
paramflags
&
PARAMFLAG_DISABLECMDLINE
)
!=
0
)
{
continue
;
}
if
(
prefix
!=
NULL
)
{
sprintf
(
cfgpath
,
"%s.%s"
,
prefix
,
cfgoptions
[
n
].
optname
);
}
else
{
sprintf
(
cfgpath
,
"%s"
,
cfgoptions
[
n
].
optname
);
}
if
(
((
strlen
(
oneargv
)
==
2
)
&&
(
strcmp
(
oneargv
+
1
,
cfgpath
)
==
0
))
||
/* short option, one "-" */
((
strlen
(
oneargv
)
>
2
)
&&
(
strcmp
(
oneargv
+
2
,
cfgpath
)
==
0
))
)
{
char
*
valptr
=
NULL
;
int
ret
;
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
c
>
0
)
{
pp
=
config_get_if
()
->
argv
[
i
+
1
];
if
(
pp
!=
NULL
)
{
ret
=
strlen
(
pp
);
if
(
ret
>
0
)
{
if
(
pp
[
0
]
!=
'-'
)
valptr
=
pp
;
else
if
(
ret
>
1
&&
pp
[
0
]
==
'-'
&&
isdigit
(
pp
[
1
])
)
valptr
=
pp
;
}
}
}
j
+=
processoption
(
&
(
cfgoptions
[
n
]),
valptr
);
if
(
valptr
!=
NULL
)
{
i
++
;
config_get_if
()
->
argv_info
[
i
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
c
--
;
}
break
;
}
}
/* for n... */
}
/* if (oneargv[0] == '-') */
free
(
oneargv
);
i
++
;
c
--
;
}
/* fin du while */
printf_cmdl
(
"[CONFIG] %s %i options set from command line
\n
"
,((
prefix
==
NULL
)
?
"(root)"
:
prefix
),
j
);
printf_cmdl
(
"[CONFIG] %s %i options set from command line
\n
"
,((
prefix
==
NULL
)
?
"(root)"
:
prefix
),
j
);
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOCHECKUNKOPT
))
)
{
if
(
!
(
CONFIG_ISFLAGSET
(
CONFIG_NOCHECKUNKOPT
))
)
{
i
=
config_check_cmdlineopt
(
prefix
);
i
=
config_check_cmdlineopt
(
prefix
);
if
(
i
>
0
)
{
fprintf
(
stderr
,
"[CONFIG] %i unknown options for section %s detected in command line
\n
"
,
if
(
i
>
0
)
{
i
,((
prefix
==
NULL
)
?
"
\"
root section
\"
"
:
prefix
));
fprintf
(
stderr
,
"[CONFIG] %i unknown options for section %s detected in command line
\n
"
,
exit_fun
(
" Exiting after detecting errors in command line
\n
"
);
i
,((
prefix
==
NULL
)
?
"
\"
root section
\"
"
:
prefix
));
}
exit_fun
(
" Exiting after detecting errors in command line
\n
"
);
}
}
}
return
j
;
return
j
;
}
/* parse_cmdline*/
}
/* parse_cmdline*/
common/config/config_load_configmodule.c
View file @
55732deb
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
*/
*/
/*! \file common/config/config_load_configmodule.c
/*! \file common/config/config_load_configmodule.c
* \brief configuration module, load the shared library implementing the configuration module
* \brief configuration module, load the shared library implementing the configuration module
* \author Francois TABURET
* \author Francois TABURET
* \date 2017
* \date 2017
* \version 0.1
* \version 0.1
...
@@ -42,293 +42,314 @@
...
@@ -42,293 +42,314 @@
#include "config_userapi.h"
#include "config_userapi.h"
#define CONFIG_SHAREDLIBFORMAT "libparams_%s.so"
#define CONFIG_SHAREDLIBFORMAT "libparams_%s.so"
int
load_config_sharedlib
(
configmodule_interface_t
*
cfgptr
)
int
load_config_sharedlib
(
configmodule_interface_t
*
cfgptr
)
{
{
void
*
lib_handle
;
void
*
lib_handle
;
char
fname
[
128
];
char
fname
[
128
];
char
libname
[
FILENAME_MAX
];
char
libname
[
FILENAME_MAX
];
int
st
;
int
st
;
st
=
0
;
sprintf
(
libname
,
CONFIG_SHAREDLIBFORMAT
,
cfgptr
->
cfgmode
);
lib_handle
=
dlopen
(
libname
,
RTLD_NOW
|
RTLD_GLOBAL
|
RTLD_NODELETE
);
if
(
!
lib_handle
)
{
fprintf
(
stderr
,
"[CONFIG] %s %d Error calling dlopen(%s): %s
\n
"
,
__FILE__
,
__LINE__
,
libname
,
dlerror
());
st
=
-
1
;
}
else
{
sprintf
(
fname
,
"config_%s_init"
,
cfgptr
->
cfgmode
);
cfgptr
->
init
=
dlsym
(
lib_handle
,
fname
);
if
(
cfgptr
->
init
==
NULL
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
}
else
{
st
=
cfgptr
->
init
(
cfgptr
->
cfgP
,
cfgptr
->
num_cfgP
);
printf
(
"[CONFIG] function %s returned %i
\n
"
,
fname
,
st
);
}
st
=
0
;
sprintf
(
fname
,
"config_%s_get"
,
cfgptr
->
cfgmode
);
sprintf
(
libname
,
CONFIG_SHAREDLIBFORMAT
,
cfgptr
->
cfgmod
e
);
cfgptr
->
get
=
dlsym
(
lib_handle
,
fnam
e
);
lib_handle
=
dlopen
(
libname
,
RTLD_NOW
|
RTLD_GLOBAL
|
RTLD_NODELETE
);
if
(
cfgptr
->
get
==
NULL
)
{
if
(
!
lib_handle
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
fprintf
(
stderr
,
"[CONFIG] %s %d Error calling dlopen(%s): %s
\n
"
,
__FILE__
,
__LINE__
,
libname
,
dlerror
()
);
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
st
=
-
1
;
st
=
-
1
;
}
else
{
}
sprintf
(
fname
,
"config_%s_init"
,
cfgptr
->
cfgmode
);
cfgptr
->
init
=
dlsym
(
lib_handle
,
fname
);
if
(
cfgptr
->
init
==
NULL
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
}
else
{
st
=
cfgptr
->
init
(
cfgptr
->
cfgP
,
cfgptr
->
num_cfgP
);
printf
(
"[CONFIG] function %s returned %i
\n
"
,
fname
,
st
);
}
sprintf
(
fname
,
"config_%s_get"
,
cfgptr
->
cfgmode
);
sprintf
(
fname
,
"config_%s_getlist"
,
cfgptr
->
cfgmode
);
cfgptr
->
get
=
dlsym
(
lib_handle
,
fname
);
cfgptr
->
getlist
=
dlsym
(
lib_handle
,
fname
);
if
(
cfgptr
->
get
==
NULL
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
if
(
cfgptr
->
getlist
==
NULL
)
{
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
st
=
-
1
;
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
}
st
=
-
1
;
}
sprintf
(
fname
,
"config_%s_getlist"
,
cfgptr
->
cfgmode
);
cfgptr
->
getlist
=
dlsym
(
lib_handle
,
fname
);
if
(
cfgptr
->
getlist
==
NULL
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
st
=
-
1
;
}
sprintf
(
fname
,
"config_%s_end"
,
cfgptr
->
cfgmode
);
sprintf
(
fname
,
"config_%s_end"
,
cfgptr
->
cfgmode
);
cfgptr
->
end
=
dlsym
(
lib_handle
,
fname
);
cfgptr
->
end
=
dlsym
(
lib_handle
,
fname
);
if
(
cfgptr
->
getlist
==
NULL
)
{
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
if
(
cfgptr
->
getlist
==
NULL
)
{
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
printf
(
"[CONFIG] %s %d no function %s for config mode %s
\n
"
,
}
__FILE__
,
__LINE__
,
fname
,
cfgptr
->
cfgmode
);
}
}
}
return
st
;
return
st
;
}
}
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* from here: interface implementtion of the configuration module */
/* from here: interface implementtion of the configuration module */
int
nooptfunc
(
void
)
{
int
nooptfunc
(
void
)
{
return
0
;
return
0
;
};
};
int
config_cmdlineonly_getlist
(
paramlist_def_t
*
ParamList
,
int
config_cmdlineonly_getlist
(
paramlist_def_t
*
ParamList
,
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
{
{
ParamList
->
numelt
=
0
;
ParamList
->
numelt
=
0
;
return
0
;
return
0
;
}
}
int
config_cmdlineonly_get
(
paramdef_t
*
cfgoptions
,
int
numoptions
,
char
*
prefix
)
int
config_cmdlineonly_get
(
paramdef_t
*
cfgoptions
,
int
numoptions
,
char
*
prefix
)
{
{
int
defval
;
int
defval
;
int
fatalerror
=
0
;
int
fatalerror
=
0
;
int
numdefvals
=
0
;
int
numdefvals
=
0
;
for
(
int
i
=
0
;
i
<
numoptions
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numoptions
;
i
++
)
{
defval
=
0
;
defval
=
0
;
switch
(
cfgoptions
[
i
].
type
)
{
switch
(
cfgoptions
[
i
].
type
)
{
case
TYPE_STRING
:
case
TYPE_STRING
:
defval
=
config_setdefault_string
(
&
(
cfgoptions
[
i
]),
prefix
);
defval
=
config_setdefault_string
(
&
(
cfgoptions
[
i
]),
prefix
);
break
;
break
;
case
TYPE_STRINGLIST
:
defval
=
config_setdefault_stringlist
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_STRINGLIST
:
break
;
defval
=
config_setdefault_stringlist
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_UINT8
:
break
;
case
TYPE_INT8
:
case
TYPE_UINT16
:
case
TYPE_UINT8
:
case
TYPE_INT16
:
case
TYPE_INT8
:
case
TYPE_UINT32
:
case
TYPE_UINT16
:
case
TYPE_INT32
:
case
TYPE_INT16
:
case
TYPE_MASK
:
case
TYPE_UINT32
:
defval
=
config_setdefault_int
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_INT32
:
case
TYPE_MASK
:
defval
=
config_setdefault_int
(
&
(
cfgoptions
[
i
]),
prefix
);
break
;
break
;
case
TYPE_UINT64
:
case
TYPE_INT64
:
case
TYPE_UINT64
:
defval
=
config_setdefault_int64
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_INT64
:
break
;
defval
=
config_setdefault_int64
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_UINTARRAY
:
case
TYPE_INTARRAY
:
defval
=
config_setdefault_intlist
(
&
(
cfgoptions
[
i
]),
prefix
);
break
;
break
;
case
TYPE_DOUBLE
:
defval
=
config_setdefault_double
(
&
(
cfgoptions
[
i
]),
prefix
);
case
TYPE_UINTARRAY
:
break
;
case
TYPE_INTARRAY
:
case
TYPE_IPV4ADDR
:
defval
=
config_setdefault_intlist
(
&
(
cfgoptions
[
i
]),
prefix
);
defval
=
config_setdefault_ipv4addr
(
&
(
cfgoptions
[
i
]),
prefix
);
break
;
break
;
default:
fprintf
(
stderr
,
"[CONFIG] %s.%s type %i not supported
\n
"
,
prefix
,
cfgoptions
[
i
].
optname
,
cfgoptions
[
i
].
type
);
case
TYPE_DOUBLE
:
fatalerror
=
1
;
defval
=
config_setdefault_double
(
&
(
cfgoptions
[
i
]),
prefix
)
;
break
;
break
;
}
/* switch on param type */
case
TYPE_IPV4ADDR
:
defval
=
config_setdefault_ipv4addr
(
&
(
cfgoptions
[
i
]),
prefix
);
break
;
default:
fprintf
(
stderr
,
"[CONFIG] %s.%s type %i not supported
\n
"
,
prefix
,
cfgoptions
[
i
].
optname
,
cfgoptions
[
i
].
type
);
fatalerror
=
1
;
break
;
}
/* switch on param type */
if
(
defval
==
1
)
{
if
(
defval
==
1
)
{
numdefvals
++
;
numdefvals
++
;
cfgoptions
[
i
].
paramflags
=
cfgoptions
[
i
].
paramflags
|
PARAMFLAG_PARAMSETDEF
;
cfgoptions
[
i
].
paramflags
=
cfgoptions
[
i
].
paramflags
|
PARAMFLAG_PARAMSETDEF
;
}
}
}
/* for loop on options */
}
/* for loop on options */
printf
(
"[CONFIG] %s: %i/%i parameters successfully set
\n
"
,
printf
(
"[CONFIG] %s: %i/%i parameters successfully set
\n
"
,
((
prefix
==
NULL
)
?
"(root)"
:
prefix
),
((
prefix
==
NULL
)
?
"(root)"
:
prefix
),
numdefvals
,
numoptions
);
numdefvals
,
numoptions
);
if
(
fatalerror
==
1
)
{
if
(
fatalerror
==
1
)
{
fprintf
(
stderr
,
"[CONFIG] fatal errors found when assigning %s parameters
\n
"
,
fprintf
(
stderr
,
"[CONFIG] fatal errors found when assigning %s parameters
\n
"
,
prefix
);
prefix
);
}
}
return
numdefvals
;
return
numdefvals
;
}
}
configmodule_interface_t
*
load_configmodule
(
int
argc
,
char
**
argv
,
uint32_t
initflags
)
configmodule_interface_t
*
load_configmodule
(
int
argc
,
char
**
argv
,
uint32_t
initflags
)
{
{
char
*
cfgparam
=
NULL
;
char
*
cfgparam
=
NULL
;
char
*
modeparams
=
NULL
;
char
*
modeparams
=
NULL
;
char
*
cfgmode
=
NULL
;
char
*
cfgmode
=
NULL
;
char
*
strtokctx
=
NULL
;
char
*
strtokctx
=
NULL
;
char
*
atoken
;
char
*
atoken
;
uint32_t
tmpflags
=
0
;
uint32_t
tmpflags
=
0
;
int
i
;
int
i
;
int
OoptIdx
=-
1
;
int
OoptIdx
=-
1
;
/* first parse the command line to look for the -O option */
/* first parse the command line to look for the -O option */
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
if
(
strlen
(
argv
[
i
])
<
2
)
continue
;
if
(
strlen
(
argv
[
i
])
<
2
)
continue
;
if
(
argv
[
i
][
1
]
==
'O'
&&
i
<
(
argc
-
1
))
{
if
(
argv
[
i
][
1
]
==
'O'
&&
i
<
(
argc
-
1
))
{
cfgparam
=
argv
[
i
+
1
];
cfgparam
=
argv
[
i
+
1
];
OoptIdx
=
i
;
OoptIdx
=
i
;
}
}
if
(
strstr
(
argv
[
i
],
"help_config"
)
!=
NULL
)
{
config_printhelp
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
));
if
(
strstr
(
argv
[
i
],
"help_config"
)
!=
NULL
)
{
exit
(
0
);
config_printhelp
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
));
}
exit
(
0
);
if
(
(
strcmp
(
argv
[
i
]
+
1
,
"h"
)
==
0
)
||
(
strstr
(
argv
[
i
]
+
1
,
"help_"
)
!=
NULL
)
)
{
}
tmpflags
=
CONFIG_HELP
;
}
if
(
(
strcmp
(
argv
[
i
]
+
1
,
"h"
)
==
0
)
||
(
strstr
(
argv
[
i
]
+
1
,
"help_"
)
!=
NULL
)
)
{
}
tmpflags
=
CONFIG_HELP
;
}
/* 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"
);
}
}
/* default different for UE and softmodem because UE doesn't use config file*/
/* default different for UE and softmodem because UE doesn't use config file*/
/* and -O option is not mandatory for UE */
/* and -O option is not mandatory for UE */
/* phy simulators behave as UE */
/* phy simulators behave as UE */
/* test of exec name would better be replaced by a parameter to the l */
/* test of exec name would better be replaced by a parameter to the l */
/* oad_configmodule function */
/* oad_configmodule function */
if
(
cfgparam
==
NULL
)
{
if
(
cfgparam
==
NULL
)
{
tmpflags
=
tmpflags
|
CONFIG_NOOOPT
;
tmpflags
=
tmpflags
|
CONFIG_NOOOPT
;
if
(
initflags
&
CONFIG_ENABLECMDLINEONLY
)
{
if
(
initflags
&
CONFIG_ENABLECMDLINEONLY
)
{
cfgparam
=
CONFIG_CMDLINEONLY
":dbgl0"
;
cfgparam
=
CONFIG_CMDLINEONLY
":dbgl0"
;
}
else
{
cfgparam
=
CONFIG_CMDLINEONLY
":dbgl0"
;
cfgparam
=
CONFIG_LIBCONFIGFILE
":"
DEFAULT_CFGFILENAME
;
}
}
/* parse the config parameters to set the config source */
i
=
sscanf
(
cfgparam
,
"%m[^':']:%ms"
,
&
cfgmode
,
&
modeparams
);
if
(
i
<
0
)
{
fprintf
(
stderr
,
"[CONFIG] %s, %d, sscanf error parsing config source %s: %s
\n
"
,
__FILE__
,
__LINE__
,
cfgparam
,
strerror
(
errno
));
exit
(
-
1
)
;
}
else
if
(
i
==
1
)
{
/* -O argument doesn't contain ":" separator, assume -O <conf file> option, default cfgmode to libconfig
with one parameter, the path to the configuration file cfgmode must not be NULL */
modeparams
=
cfgmode
;
cfgmode
=
strdup
(
CONFIG_LIBCONFIGFILE
);
}
cfgptr
=
calloc
(
sizeof
(
configmodule_interface_t
),
1
);
cfgptr
->
argv_info
=
calloc
(
sizeof
(
int32_t
),
argc
);
cfgptr
->
argv_info
[
0
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
OoptIdx
>=
0
)
{
cfgptr
->
argv_info
[
OoptIdx
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
cfgptr
->
argv_info
[
OoptIdx
+
1
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
}
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
tmpflags
;
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
;
aptr
=
strcasestr
(
atoken
,
"dbgl"
);
if
(
aptr
!=
NULL
)
{
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
strtol
(
aptr
+
4
,
NULL
,
0
);
}
else
{
cfgptr
->
cfgP
[
cfgptr
->
num_cfgP
]
=
strdup
(
atoken
);
cfgptr
->
num_cfgP
++
;
}
atoken
=
strtok_r
(
NULL
,
":"
,
&
strtokctx
);
}
printf
(
"[CONFIG] get parameters from %s "
,
cfgmode
);
for
(
i
=
0
;
i
<
cfgptr
->
num_cfgP
;
i
++
)
{
printf
(
"%s "
,
cfgptr
->
cfgP
[
i
]);
}
printf
(
", debug flags: 0x%08x
\n
"
,
cfgptr
->
rtflags
);
if
(
strstr
(
cfgparam
,
CONFIG_CMDLINEONLY
)
==
NULL
)
{
i
=
load_config_sharedlib
(
cfgptr
);
if
(
i
==
0
)
{
printf
(
"[CONFIG] config module %s loaded
\n
"
,
cfgmode
);
Config_Params
[
CONFIGPARAM_DEBUGFLAGS_IDX
].
uptr
=&
(
cfgptr
->
rtflags
);
config_get
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
),
CONFIG_SECTIONNAME
);
}
else
{
}
else
{
cfgparam
=
CONFIG_CMDLINEONLY
":dbgl0"
;
cfgparam
=
CONFIG_LIBCONFIGFILE
":"
DEFAULT_CFGFILENAME
;
fprintf
(
stderr
,
"[CONFIG] %s %d config module
\"
%s
\"
couldn't be loaded
\n
"
,
__FILE__
,
__LINE__
,
cfgmode
);
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
CONFIG_HELP
|
CONFIG_ABORT
;
}
}
}
else
{
cfgptr
->
init
=
(
configmodule_initfunc_t
)
nooptfunc
;
cfgptr
->
get
=
config_cmdlineonly_get
;
cfgptr
->
getlist
=
config_cmdlineonly_getlist
;
cfgptr
->
end
=
(
configmodule_endfunc_t
)
nooptfunc
;
}
if
(
modeparams
!=
NULL
)
free
(
modeparams
);
if
(
cfgmode
!=
NULL
)
free
(
cfgmode
);
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
config_printhelp
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
));
// exit(-1);
}
}
/* parse the config parameters to set the config source */
return
cfgptr
;
i
=
sscanf
(
cfgparam
,
"%m[^':']:%ms"
,
&
cfgmode
,
&
modeparams
);
if
(
i
<
0
)
{
fprintf
(
stderr
,
"[CONFIG] %s, %d, sscanf error parsing config source %s: %s
\n
"
,
__FILE__
,
__LINE__
,
cfgparam
,
strerror
(
errno
));
exit
(
-
1
)
;
}
else
if
(
i
==
1
)
{
/* -O argument doesn't contain ":" separator, assume -O <conf file> option, default cfgmode to libconfig
with one parameter, the path to the configuration file cfgmode must not be NULL */
modeparams
=
cfgmode
;
cfgmode
=
strdup
(
CONFIG_LIBCONFIGFILE
);
}
cfgptr
=
calloc
(
sizeof
(
configmodule_interface_t
),
1
);
cfgptr
->
argv_info
=
calloc
(
sizeof
(
int32_t
),
argc
);
cfgptr
->
argv_info
[
0
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
if
(
OoptIdx
>=
0
)
{
cfgptr
->
argv_info
[
OoptIdx
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
cfgptr
->
argv_info
[
OoptIdx
+
1
]
|=
CONFIG_CMDLINEOPT_PROCESSED
;
}
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
tmpflags
;
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
;
aptr
=
strcasestr
(
atoken
,
"dbgl"
);
if
(
aptr
!=
NULL
)
{
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
strtol
(
aptr
+
4
,
NULL
,
0
);
}
else
{
cfgptr
->
cfgP
[
cfgptr
->
num_cfgP
]
=
strdup
(
atoken
);
cfgptr
->
num_cfgP
++
;
}
atoken
=
strtok_r
(
NULL
,
":"
,
&
strtokctx
);
}
printf
(
"[CONFIG] get parameters from %s "
,
cfgmode
);
for
(
i
=
0
;
i
<
cfgptr
->
num_cfgP
;
i
++
)
{
printf
(
"%s "
,
cfgptr
->
cfgP
[
i
]);
}
printf
(
", debug flags: 0x%08x
\n
"
,
cfgptr
->
rtflags
);
if
(
strstr
(
cfgparam
,
CONFIG_CMDLINEONLY
)
==
NULL
)
{
i
=
load_config_sharedlib
(
cfgptr
);
if
(
i
==
0
)
{
printf
(
"[CONFIG] config module %s loaded
\n
"
,
cfgmode
);
Config_Params
[
CONFIGPARAM_DEBUGFLAGS_IDX
].
uptr
=&
(
cfgptr
->
rtflags
);
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
);
cfgptr
->
rtflags
=
cfgptr
->
rtflags
|
CONFIG_HELP
|
CONFIG_ABORT
;
}
}
else
{
cfgptr
->
init
=
(
configmodule_initfunc_t
)
nooptfunc
;
cfgptr
->
get
=
config_cmdlineonly_get
;
cfgptr
->
getlist
=
config_cmdlineonly_getlist
;
cfgptr
->
end
=
(
configmodule_endfunc_t
)
nooptfunc
;
}
if
(
modeparams
!=
NULL
)
free
(
modeparams
);
if
(
cfgmode
!=
NULL
)
free
(
cfgmode
);
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
config_printhelp
(
Config_Params
,
CONFIG_PARAMLENGTH
(
Config_Params
));
// exit(-1);
}
return
cfgptr
;
}
}
/* free memory allocated when reading parameters */
/* free memory allocated when reading parameters */
/* config module could be initialized again after this call */
/* config module could be initialized again after this call */
void
end_configmodule
(
void
)
void
end_configmodule
(
void
)
{
{
if
(
cfgptr
!=
NULL
)
{
if
(
cfgptr
!=
NULL
)
{
if
(
cfgptr
->
end
!=
NULL
)
{
if
(
cfgptr
->
end
!=
NULL
)
{
printf
(
"[CONFIG] calling config module end function...
\n
"
);
printf
(
"[CONFIG] calling config module end function...
\n
"
);
cfgptr
->
end
();
cfgptr
->
end
();
}
}
printf
(
"[CONFIG] free %u config value pointers
\n
"
,
cfgptr
->
numptrs
);
printf
(
"[CONFIG] free %u config value pointers
\n
"
,
cfgptr
->
numptrs
);
for
(
int
i
=
0
;
i
<
cfgptr
->
numptrs
;
i
++
)
{
if
(
cfgptr
->
ptrs
[
i
]
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
cfgptr
->
numptrs
;
i
++
)
{
free
(
cfgptr
->
ptrs
[
i
]);
if
(
cfgptr
->
ptrs
[
i
]
!=
NULL
)
{
cfgptr
->
ptrs
[
i
]
=
NULL
;
free
(
cfgptr
->
ptrs
[
i
])
;
}
cfgptr
->
ptrs
[
i
]
=
NULL
;
}
}
cfgptr
->
numptrs
=
0
;
}
cfgptr
->
numptrs
=
0
;
}
}
}
}
/* free all memory used by config module */
/* free all memory used by config module */
/* should be called only at program exit */
/* should be called only at program exit */
void
free_configmodule
(
void
)
void
free_configmodule
(
void
)
{
{
if
(
cfgptr
!=
NULL
)
{
if
(
cfgptr
!=
NULL
)
{
end_configmodule
();
end_configmodule
();
if
(
cfgptr
->
cfgmode
!=
NULL
)
free
(
cfgptr
->
cfgmode
);
printf
(
"[CONFIG] free %u config parameter pointers
\n
"
,
cfgptr
->
num_cfgP
);
if
(
cfgptr
->
cfgmode
!=
NULL
)
free
(
cfgptr
->
cfgmode
);
for
(
int
i
=
0
;
i
<
cfgptr
->
num_cfgP
;
i
++
)
{
if
(
cfgptr
->
cfgP
[
i
]
!=
NULL
)
free
(
cfgptr
->
cfgP
[
i
]);
}
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
]);
}
free
(
cfgptr
);
free
(
cfgptr
);
cfgptr
=
NULL
;
cfgptr
=
NULL
;
}
}
}
}
...
...
common/config/config_load_configmodule.h
View file @
55732deb
...
@@ -20,8 +20,8 @@
...
@@ -20,8 +20,8 @@
*/
*/
/*! \file common/config/config_load_configmodule.h
/*! \file common/config/config_load_configmodule.h
* \brief: configuration module, include file to be used by the source code calling the
* \brief: configuration module, include file to be used by the source code calling the
* configuration module initialization
* configuration module initialization
* \author Francois TABURET
* \author Francois TABURET
* \date 2017
* \date 2017
* \version 0.1
* \version 0.1
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
* \warning
* \warning
*/
*/
#ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H
#ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H
#define INCLUDE_CONFIG_LOADCONFIGMODULE_H
#define INCLUDE_CONFIG_LOADCONFIGMODULE_H
#include <string.h>
#include <string.h>
...
@@ -61,8 +61,7 @@ typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
...
@@ -61,8 +61,7 @@ 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
;
uint32_t
*
argv_info
;
uint32_t
*
argv_info
;
...
@@ -75,7 +74,7 @@ typedef struct configmodule_interface
...
@@ -75,7 +74,7 @@ typedef struct configmodule_interface
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
...
@@ -85,17 +84,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl
...
@@ -85,17 +84,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl
debugflags can also be defined in the config_libconfig section of the config file
\n
\
debugflags can also be defined in the config_libconfig section of the config file
\n
\
debugflags: mask, 1->print parameters, 2->print memory allocations debug messages
\n
\
debugflags: mask, 1->print parameters, 2->print memory allocations debug messages
\n
\
4->print command line processing debug messages
\n
"
;
4->print command line processing debug messages
\n
"
;
#define CONFIG_SECTIONNAME "config"
#define CONFIG_SECTIONNAME "config"
#define CONFIGPARAM_DEBUGFLAGS_IDX 0
#define CONFIGPARAM_DEBUGFLAGS_IDX 0
static
paramdef_t
Config_Params
[]
=
{
static
paramdef_t
Config_Params
[]
=
{
/*-----------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------*/
/* config parameters for config module */
/* config parameters for config module */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/*-----------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------*/
{
"debugflags"
,
config_helpstr
,
0
,
uptr
:
NULL
,
defintval
:
0
,
TYPE_MASK
,
0
},
{
"debugflags"
,
config_helpstr
,
0
,
uptr
:
NULL
,
defintval
:
0
,
TYPE_MASK
,
0
},
};
};
#else
#else
...
@@ -104,7 +103,7 @@ extern configmodule_interface_t *cfgptr;
...
@@ -104,7 +103,7 @@ extern configmodule_interface_t *cfgptr;
#define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); }
#define CONFIG_ENABLECMDLINEONLY (1<<1)
#define CONFIG_ENABLECMDLINEONLY (1<<1)
...
...
common/config/config_paramdesc.h
View file @
55732deb
...
@@ -59,78 +59,77 @@
...
@@ -59,78 +59,77 @@
#define CONFIG_MAX_NUMCHECKVAL 20
#define CONFIG_MAX_NUMCHECKVAL 20
typedef
struct
paramdef
paramdef_t
;
typedef
struct
paramdef
paramdef_t
;
typedef
union
checkedparam
{
typedef
union
checkedparam
{
struct
{
struct
{
int
(
*
f1
)(
paramdef_t
*
param
);
/* check an integer against a list of authorized values */
int
(
*
f1
)(
paramdef_t
*
param
);
/* check an integer against a list of authorized values */
int
okintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store possible values */
int
okintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store possible values */
int
num_okintval
;
/* number of valid values in the checkingval array */
int
num_okintval
;
/* number of valid values in the checkingval array */
}
s1
;
}
s1
;
struct
{
struct
{
int
(
*
f1a
)(
paramdef_t
*
param
);
/* check an integer against a list of authorized values and set param value */
int
(
*
f1a
)(
paramdef_t
*
param
);
/* check an integer against a list of authorized values and set param value */
/* to the corresponding item in setintval array (mainly for RRC params) */
/* to the corresponding item in setintval array (mainly for RRC params) */
int
okintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store possible values in config file */
int
okintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store possible values in config file */
int
setintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, values set in the paramdef structure */
int
setintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, values set in the paramdef structure */
int
num_okintval
;
/* number of valid values in the checkingval array */
int
num_okintval
;
/* number of valid values in the checkingval array */
}
s1a
;
}
s1a
;
struct
{
struct
{
int
(
*
f2
)(
paramdef_t
*
param
);
/* check an integer against an authorized range, defined by its min and max value */
int
(
*
f2
)(
paramdef_t
*
param
);
/* check an integer against an authorized range, defined by its min and max value */
int
okintrange
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store min and max values */
int
okintrange
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, store min and max values */
}
s2
;
}
s2
;
struct
{
struct
{
int
(
*
f3
)(
paramdef_t
*
param
);
/* check a string against a list of authorized values */
int
(
*
f3
)(
paramdef_t
*
param
);
/* check a string against a list of authorized values */
char
*
okstrval
[
CONFIG_MAX_NUMCHECKVAL
];
/* string array, store possible values */
char
*
okstrval
[
CONFIG_MAX_NUMCHECKVAL
];
/* string array, store possible values */
int
num_okstrval
;
/* number of valid values in the checkingval array */
int
num_okstrval
;
/* number of valid values in the checkingval array */
}
s3
;
}
s3
;
struct
{
struct
{
int
(
*
f3a
)(
paramdef_t
*
param
);
/* check a string against a list of authorized values and set param value */
int
(
*
f3a
)(
paramdef_t
*
param
);
/* check a string against a list of authorized values and set param value */
/* to the corresponding item in setintval array (mainly for RRC params) */
/* to the corresponding item in setintval array (mainly for RRC params) */
char
*
okstrval
[
CONFIG_MAX_NUMCHECKVAL
];
/* string array, store possible values */
char
*
okstrval
[
CONFIG_MAX_NUMCHECKVAL
];
/* string array, store possible values */
int
setintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, values set in the paramdef structure */
int
setintval
[
CONFIG_MAX_NUMCHECKVAL
];
/* integer array, values set in the paramdef structure */
int
num_okstrval
;
/* number of valid values in the checkingval array */
int
num_okstrval
;
/* number of valid values in the checkingval array */
}
s3a
;
}
s3a
;
struct
{
struct
{
int
(
*
f4
)(
paramdef_t
*
param
);
/* generic check function, no arguments but the param description */
int
(
*
f4
)(
paramdef_t
*
param
);
/* generic check function, no arguments but the param description */
}
s4
;
}
s4
;
struct
{
struct
{
void
(
*
checkfunc
)(
void
)
;
void
(
*
checkfunc
)(
void
)
;
}
s5
;
}
s5
;
}
checkedparam_t
;
}
checkedparam_t
;
/* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */
/* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */
/* config apis used to retrieve parameters values */
/* config apis used to retrieve parameters values */
typedef
struct
paramdef
typedef
struct
paramdef
{
{
char
optname
[
MAX_OPTNAME_SIZE
];
/* parameter name, can be used as long command line option */
char
optname
[
MAX_OPTNAME_SIZE
];
/* parameter name, can be used as long command line option */
char
*
helpstr
;
/* help string */
char
*
helpstr
;
/* help string */
unsigned
int
paramflags
;
/* value is a "ored" combination of above PARAMFLAG_XXXX values */
unsigned
int
paramflags
;
/* value is a "ored" combination of above PARAMFLAG_XXXX values */
union
{
/* pointer to the parameter value, completed by the config module */
union
{
/* pointer to the parameter value, completed by the config module */
char
**
strptr
;
char
**
strptr
;
char
**
strlistptr
;
char
**
strlistptr
;
uint8_t
*
u8ptr
;
uint8_t
*
u8ptr
;
int8_t
*
i8ptr
;
int8_t
*
i8ptr
;
uint16_t
*
u16ptr
;
uint16_t
*
u16ptr
;
int16_t
*
i16ptr
;
int16_t
*
i16ptr
;
uint32_t
*
uptr
;
uint32_t
*
uptr
;
int32_t
*
iptr
;
int32_t
*
iptr
;
uint64_t
*
u64ptr
;
uint64_t
*
u64ptr
;
int64_t
*
i64ptr
;
int64_t
*
i64ptr
;
double
*
dblptr
;
double
*
dblptr
;
void
*
voidptr
;
void
*
voidptr
;
}
;
}
;
union
{
/* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
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
;
double
defdblval
;
}
;
}
;
char
type
;
/* parameter value type, as listed below as TYPE_XXXX macro */
char
type
;
/* parameter value type, as listed below as TYPE_XXXX macro */
int
numelt
;
/* number of elements in a list or array parameters or max size of string value */
int
numelt
;
/* number of elements in a list or array parameters or max size of string value */
checkedparam_t
*
chkPptr
;
/* possible pointer to the structure containing the info used to check parameter values */
checkedparam_t
*
chkPptr
;
/* possible pointer to the structure containing the info used to check parameter values */
int
*
processedvalue
;
/* used to store integer values computed from string original value */
int
*
processedvalue
;
/* used to store integer values computed from string original value */
}
paramdef_t
;
}
paramdef_t
;
#define TYPE_INT TYPE_INT32
#define TYPE_INT TYPE_INT32
...
@@ -160,9 +159,9 @@ typedef struct paramdef
...
@@ -160,9 +159,9 @@ typedef struct paramdef
#define ANY_IPV4ADDR_STRING "0.0.0.0"
#define ANY_IPV4ADDR_STRING "0.0.0.0"
typedef
struct
paramlist_def
{
typedef
struct
paramlist_def
{
char
listname
[
MAX_OPTNAME_SIZE
];
char
listname
[
MAX_OPTNAME_SIZE
];
paramdef_t
**
paramarray
;
paramdef_t
**
paramarray
;
int
numelt
;
int
numelt
;
}
paramlist_def_t
;
}
paramlist_def_t
;
/* macro helpers for module users */
/* macro helpers for module users */
...
...
common/config/config_userapi.c
View file @
55732deb
...
@@ -44,409 +44,449 @@
...
@@ -44,409 +44,449 @@
#include "config_userapi.h"
#include "config_userapi.h"
configmodule_interface_t
*
config_get_if
(
void
)
configmodule_interface_t
*
config_get_if
(
void
)
{
{
if
(
cfgptr
==
NULL
)
{
if
(
cfgptr
==
NULL
)
{
fprintf
(
stderr
,
"[CONFIG] %s %d config module not initialized
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"[CONFIG] %s %d config module not initialized
\n
"
,
__FILE__
,
__LINE__
);
exit
(
-
1
);
exit
(
-
1
);
}
}
return
cfgptr
;
return
cfgptr
;
}
}
char
*
config_check_valptr
(
paramdef_t
*
cfgoptions
,
char
**
ptr
,
int
length
)
char
*
config_check_valptr
(
paramdef_t
*
cfgoptions
,
char
**
ptr
,
int
length
)
{
{
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
ptr
=
malloc
(
sizeof
(
char
*
));
ptr
=
malloc
(
sizeof
(
char
*
));
if
(
ptr
!=
NULL
)
{
if
(
ptr
!=
NULL
)
{
*
ptr
=
NULL
;
*
ptr
=
NULL
;
cfgoptions
->
strptr
=
ptr
;
cfgoptions
->
strptr
=
ptr
;
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_NOFREE
)
==
0
)
{
config_get_if
()
->
ptrs
[
config_get_if
()
->
numptrs
]
=
(
char
*
)
ptr
;
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_NOFREE
)
==
0
)
{
config_get_if
()
->
numptrs
++
;
config_get_if
()
->
ptrs
[
config_get_if
()
->
numptrs
]
=
(
char
*
)
ptr
;
}
config_get_if
()
->
numptrs
++
;
}
else
{
}
fprintf
(
stderr
,
"[CONFIG] %s %d option %s, cannot allocate pointer: %s
\n
"
,
}
else
{
__FILE__
,
__LINE__
,
cfgoptions
->
optname
,
strerror
(
errno
));
fprintf
(
stderr
,
"[CONFIG] %s %d option %s, cannot allocate pointer: %s
\n
"
,
exit
(
-
1
);
__FILE__
,
__LINE__
,
cfgoptions
->
optname
,
strerror
(
errno
));
}
exit
(
-
1
);
}
}
printf_ptrs
(
"[CONFIG] %s ptr: 0x%08lx requested size: %i
\n
"
,
cfgoptions
->
optname
,(
uintptr_t
)(
ptr
),
length
);
}
if
(
cfgoptions
->
numelt
>
0
&&
PARAM_ISSCALAR
(
cfgoptions
)
)
{
/* already allocated */
if
(
*
ptr
!=
NULL
)
{
printf_ptrs
(
"[CONFIG] %s ptr: 0x%08lx requested size: %i
\n
"
,
cfgoptions
->
optname
,(
uintptr_t
)(
ptr
),
length
);
return
*
ptr
;
}
else
{
if
(
cfgoptions
->
numelt
>
0
&&
PARAM_ISSCALAR
(
cfgoptions
)
)
{
/* already allocated */
fprintf
(
stderr
,
"[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated
\n
"
,
if
(
*
ptr
!=
NULL
)
{
__FILE__
,
__LINE__
,
cfgoptions
->
optname
,
cfgoptions
->
numelt
);
return
*
ptr
;
exit
(
-
1
);
}
else
{
}
fprintf
(
stderr
,
"[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated
\n
"
,
}
__FILE__
,
__LINE__
,
cfgoptions
->
optname
,
cfgoptions
->
numelt
);
exit
(
-
1
);
if
(
*
ptr
==
NULL
)
{
}
*
ptr
=
malloc
(
length
);
}
if
(
*
ptr
!=
NULL
)
{
memset
(
*
ptr
,
0
,
length
);
if
(
*
ptr
==
NULL
)
{
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_NOFREE
)
==
0
)
{
*
ptr
=
malloc
(
length
);
config_get_if
()
->
ptrs
[
config_get_if
()
->
numptrs
]
=
*
ptr
;
config_get_if
()
->
numptrs
++
;
if
(
*
ptr
!=
NULL
)
{
}
memset
(
*
ptr
,
0
,
length
);
}
else
{
fprintf
(
stderr
,
"[CONFIG] %s %d malloc error
\n
"
,
__FILE__
,
__LINE__
);
if
(
(
cfgoptions
->
paramflags
&
PARAMFLAG_NOFREE
)
==
0
)
{
exit
(
-
1
);
config_get_if
()
->
ptrs
[
config_get_if
()
->
numptrs
]
=
*
ptr
;
}
config_get_if
()
->
numptrs
++
;
}
}
return
*
ptr
;
}
else
{
fprintf
(
stderr
,
"[CONFIG] %s %d malloc error
\n
"
,
__FILE__
,
__LINE__
);
exit
(
-
1
);
}
}
return
*
ptr
;
}
}
void
config_assign_int
(
paramdef_t
*
cfgoptions
,
char
*
fullname
,
int
val
)
void
config_assign_int
(
paramdef_t
*
cfgoptions
,
char
*
fullname
,
int
val
)
{
{
int
tmpval
=
val
;
int
tmpval
=
val
;
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_BOOL
)
!=
0
)
&&
tmpval
>
0
)
{
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_BOOL
)
!=
0
)
&&
tmpval
>
0
)
{
tmpval
=
1
;
tmpval
=
1
;
}
}
switch
(
cfgoptions
->
type
)
{
switch
(
cfgoptions
->
type
)
{
case
TYPE_UINT8
:
case
TYPE_UINT8
:
*
(
cfgoptions
->
u8ptr
)
=
(
uint8_t
)
tmpval
;
*
(
cfgoptions
->
u8ptr
)
=
(
uint8_t
)
tmpval
;
printf_params
(
"[CONFIG] %s: %u
\n
"
,
fullname
,
(
uint8_t
)
tmpval
);
printf_params
(
"[CONFIG] %s: %u
\n
"
,
fullname
,
(
uint8_t
)
tmpval
);
break
;
break
;
case
TYPE_INT8
:
*
(
cfgoptions
->
i8ptr
)
=
(
int8_t
)
tmpval
;
case
TYPE_INT8
:
printf_params
(
"[CONFIG] %s: %i
\n
"
,
fullname
,
(
int8_t
)
tmpval
);
*
(
cfgoptions
->
i8ptr
)
=
(
int8_t
)
tmpval
;
break
;
printf_params
(
"[CONFIG] %s: %i
\n
"
,
fullname
,
(
int8_t
)
tmpval
);
case
TYPE_UINT16
:
break
;
*
(
cfgoptions
->
u16ptr
)
=
(
uint16_t
)
tmpval
;
printf_params
(
"[CONFIG] %s: %hu
\n
"
,
fullname
,
(
uint16_t
)
tmpval
);
case
TYPE_UINT16
:
break
;
*
(
cfgoptions
->
u16ptr
)
=
(
uint16_t
)
tmpval
;
case
TYPE_INT16
:
printf_params
(
"[CONFIG] %s: %hu
\n
"
,
fullname
,
(
uint16_t
)
tmpval
);
*
(
cfgoptions
->
i16ptr
)
=
(
int16_t
)
tmpval
;
break
;
printf_params
(
"[CONFIG] %s: %hi
\n
"
,
fullname
,
(
int16_t
)
tmpval
);
break
;
case
TYPE_INT16
:
case
TYPE_UINT32
:
*
(
cfgoptions
->
i16ptr
)
=
(
int16_t
)
tmpval
;
*
(
cfgoptions
->
uptr
)
=
(
uint32_t
)
tmpval
;
printf_params
(
"[CONFIG] %s: %hi
\n
"
,
fullname
,
(
int16_t
)
tmpval
);
printf_params
(
"[CONFIG] %s: %u
\n
"
,
fullname
,
(
uint32_t
)
tmpval
);
break
;
break
;
case
TYPE_MASK
:
case
TYPE_UINT32
:
*
(
cfgoptions
->
uptr
)
=
*
(
cfgoptions
->
uptr
)
|
(
uint32_t
)
tmpval
;
*
(
cfgoptions
->
uptr
)
=
(
uint32_t
)
tmpval
;
printf_params
(
"[CONFIG] %s: 0x%08x
\n
"
,
fullname
,
(
uint32_t
)
tmpval
);
printf_params
(
"[CONFIG] %s: %u
\n
"
,
fullname
,
(
uint32_t
)
tmpval
);
break
;
break
;
case
TYPE_INT32
:
*
(
cfgoptions
->
iptr
)
=
(
int32_t
)
tmpval
;
case
TYPE_MASK
:
printf_params
(
"[CONFIG] %s: %i
\n
"
,
fullname
,
(
int32_t
)
tmpval
);
*
(
cfgoptions
->
uptr
)
=
*
(
cfgoptions
->
uptr
)
|
(
uint32_t
)
tmpval
;
break
;
printf_params
(
"[CONFIG] %s: 0x%08x
\n
"
,
fullname
,
(
uint32_t
)
tmpval
);
default:
break
;
fprintf
(
stderr
,
"[CONFIG] %s %i type %i non integer parameter %s not assigned
\n
"
,
__FILE__
,
__LINE__
,
cfgoptions
->
type
,
fullname
);
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_assign_processedint
(
paramdef_t
*
cfgoption
,
int
val
)
{
void
config_assign_processedint
(
paramdef_t
*
cfgoption
,
int
val
)
{
cfgoption
->
processedvalue
=
malloc
(
sizeof
(
int
));
cfgoption
->
processedvalue
=
malloc
(
sizeof
(
int
));
if
(
cfgoption
->
processedvalue
!=
NULL
)
{
*
(
cfgoption
->
processedvalue
)
=
val
;
if
(
cfgoption
->
processedvalue
!=
NULL
)
{
}
else
{
*
(
cfgoption
->
processedvalue
)
=
val
;
fprintf
(
stderr
,
"[CONFIG] %s %d malloc error
\n
"
,
__FILE__
,
__LINE__
);
}
else
{
exit
(
-
1
);
fprintf
(
stderr
,
"[CONFIG] %s %d malloc error
\n
"
,
__FILE__
,
__LINE__
);
}
exit
(
-
1
);
}
}
}
int
config_get_processedint
(
paramdef_t
*
cfgoption
)
{
int
config_get_processedint
(
paramdef_t
*
cfgoption
)
{
int
ret
;
int
ret
;
if
(
cfgoption
->
processedvalue
!=
NULL
)
{
ret
=*
(
cfgoption
->
processedvalue
);
if
(
cfgoption
->
processedvalue
!=
NULL
)
{
free
(
cfgoption
->
processedvalue
);
ret
=*
(
cfgoption
->
processedvalue
);
cfgoption
->
processedvalue
=
NULL
;
free
(
cfgoption
->
processedvalue
);
printf_params
(
"[CONFIG] %s: set from %s to %i
\n
"
,
cfgoption
->
optname
,
*
(
cfgoption
->
strptr
),
ret
);
cfgoption
->
processedvalue
=
NULL
;
}
else
{
printf_params
(
"[CONFIG] %s: set from %s to %i
\n
"
,
cfgoption
->
optname
,
*
(
cfgoption
->
strptr
),
ret
);
fprintf
(
stderr
,
"[CONFIG] %s %d %s has no processed integer availablle
\n
"
,
__FILE__
,
__LINE__
,
cfgoption
->
optname
);
}
else
{
ret
=
0
;
fprintf
(
stderr
,
"[CONFIG] %s %d %s has no processed integer availablle
\n
"
,
__FILE__
,
__LINE__
,
cfgoption
->
optname
);
}
ret
=
0
;
return
ret
;
}
return
ret
;
}
}
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
++
)
{
if
(
params
[
i
].
helpstr
!=
NULL
)
{
if
(
params
[
i
].
helpstr
!=
NULL
)
{
printf
(
"%s%s: %s"
,
printf
(
"%s%s: %s"
,
(
strlen
(
params
[
i
].
optname
)
<=
1
)
?
"-"
:
"--"
,
(
strlen
(
params
[
i
].
optname
)
<=
1
)
?
"-"
:
"--"
,
params
[
i
].
optname
,
params
[
i
].
optname
,
params
[
i
].
helpstr
);
params
[
i
].
helpstr
);
}
}
}
}
}
}
int
config_execcheck
(
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
int
config_execcheck
(
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
{
{
int
st
=
0
;
int
st
=
0
;
for
(
int
i
=
0
;
i
<
numparams
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numparams
;
i
++
)
{
if
(
params
[
i
].
chkPptr
==
NULL
)
{
if
(
params
[
i
].
chkPptr
==
NULL
)
{
continue
;
continue
;
}
}
if
(
params
[
i
].
chkPptr
->
s4
.
f4
!=
NULL
)
{
if
(
params
[
i
].
chkPptr
->
s4
.
f4
!=
NULL
)
{
st
+=
params
[
i
].
chkPptr
->
s4
.
f4
(
&
(
params
[
i
]));
st
+=
params
[
i
].
chkPptr
->
s4
.
f4
(
&
(
params
[
i
]));
}
}
}
}
if
(
st
!=
0
)
{
fprintf
(
stderr
,
"[CONFIG] config_execcheck: section %s %i parameters with wrong value
\n
"
,
prefix
,
-
st
);
if
(
st
!=
0
)
{
if
(
CONFIG_ISFLAGSET
(
CONFIG_NOABORTONCHKF
)
==
0
)
{
fprintf
(
stderr
,
"[CONFIG] config_execcheck: section %s %i parameters with wrong value
\n
"
,
prefix
,
-
st
);
exit_fun
(
"exit because configuration failed
\n
"
);
}
if
(
CONFIG_ISFLAGSET
(
CONFIG_NOABORTONCHKF
)
==
0
)
{
}
exit_fun
(
"exit because configuration failed
\n
"
);
return
st
;
}
}
return
st
;
}
}
int
config_get
(
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
int
config_get
(
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
{
{
int
ret
=
-
1
;
int
ret
=
-
1
;
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
fprintf
(
stderr
,
"[CONFIG] config_get, section %s skipped, config module not properly initialized
\n
"
,
prefix
);
fprintf
(
stderr
,
"[CONFIG] config_get, section %s skipped, config module not properly initialized
\n
"
,
prefix
);
return
ret
;
return
ret
;
}
}
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
);
config_execcheck
(
params
,
numparams
,
prefix
);
config_execcheck
(
params
,
numparams
,
prefix
);
}
}
return
ret
;
return
ret
;
}
}
return
ret
;
return
ret
;
}
}
int
config_getlist
(
paramlist_def_t
*
ParamList
,
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
int
config_getlist
(
paramlist_def_t
*
ParamList
,
paramdef_t
*
params
,
int
numparams
,
char
*
prefix
)
{
{
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
if
(
CONFIG_ISFLAGSET
(
CONFIG_ABORT
))
{
fprintf
(
stderr
,
"[CONFIG] config_get skipped, config module not properly initialized
\n
"
);
fprintf
(
stderr
,
"[CONFIG] config_get skipped, config module not properly initialized
\n
"
);
return
-
1
;
return
-
1
;
}
}
if
(
!
config_get_if
())
if
(
!
config_get_if
())
return
-
1
;
return
-
1
;
const
int
ret
=
config_get_if
()
->
getlist
(
ParamList
,
params
,
numparams
,
prefix
);
const
int
ret
=
config_get_if
()
->
getlist
(
ParamList
,
params
,
numparams
,
prefix
);
if
(
ret
>=
0
&&
params
)
{
if
(
ret
>=
0
&&
params
)
{
char
*
newprefix
;
char
*
newprefix
;
if
(
prefix
)
{
if
(
prefix
)
{
int
rc
=
asprintf
(
&
newprefix
,
"%s.%s"
,
prefix
,
ParamList
->
listname
);
int
rc
=
asprintf
(
&
newprefix
,
"%s.%s"
,
prefix
,
ParamList
->
listname
);
if
(
rc
<
0
)
newprefix
=
NULL
;
if
(
rc
<
0
)
newprefix
=
NULL
;
}
else
{
}
else
{
newprefix
=
ParamList
->
listname
;
newprefix
=
ParamList
->
listname
;
}
}
char
cfgpath
[
MAX_OPTNAME_SIZE
*
2
+
6
];
/* prefix.listname.[listindex] */
char
cfgpath
[
MAX_OPTNAME_SIZE
*
2
+
6
];
/* prefix.listname.[listindex] */
for
(
int
i
=
0
;
i
<
ParamList
->
numelt
;
++
i
)
{
for
(
int
i
=
0
;
i
<
ParamList
->
numelt
;
++
i
)
{
// TODO config_process_cmdline?
// TODO config_process_cmdline?
sprintf
(
cfgpath
,
"%s.[%i]"
,
newprefix
,
i
);
sprintf
(
cfgpath
,
"%s.[%i]"
,
newprefix
,
i
);
config_execcheck
(
ParamList
->
paramarray
[
i
],
numparams
,
cfgpath
);
config_execcheck
(
ParamList
->
paramarray
[
i
],
numparams
,
cfgpath
);
}
}
if
(
prefix
)
if
(
prefix
)
free
(
newprefix
);
free
(
newprefix
);
}
}
return
ret
;
return
ret
;
}
}
int
config_isparamset
(
paramdef_t
*
params
,
int
paramidx
)
int
config_isparamset
(
paramdef_t
*
params
,
int
paramidx
)
{
{
if
((
params
[
paramidx
].
paramflags
&
PARAMFLAG_PARAMSET
)
!=
0
)
{
if
((
params
[
paramidx
].
paramflags
&
PARAMFLAG_PARAMSET
)
!=
0
)
{
return
1
;
return
1
;
}
else
{
}
else
{
return
0
;
return
0
;
}
}
}
}
void
print_intvalueerror
(
paramdef_t
*
param
,
char
*
fname
,
int
*
okval
,
int
numokval
)
{
void
print_intvalueerror
(
paramdef_t
*
param
,
char
*
fname
,
int
*
okval
,
int
numokval
)
{
fprintf
(
stderr
,
"[CONFIG] %s: %s: %i invalid value, authorized values:
\n
"
,
fprintf
(
stderr
,
"[CONFIG] %s: %s: %i invalid value, authorized values:
\n
"
,
fname
,
param
->
optname
,
(
int
)
*
(
param
->
uptr
));
fname
,
param
->
optname
,
(
int
)
*
(
param
->
uptr
));
for
(
int
i
=
0
;
i
<
numokval
;
i
++
)
{
fprintf
(
stderr
,
" %i"
,
okval
[
i
]);
for
(
int
i
=
0
;
i
<
numokval
;
i
++
)
{
}
fprintf
(
stderr
,
" %i"
,
okval
[
i
]);
fprintf
(
stderr
,
"
\n
"
);
}
fprintf
(
stderr
,
"
\n
"
);
}
}
int
config_check_intval
(
paramdef_t
*
param
)
int
config_check_intval
(
paramdef_t
*
param
)
{
{
if
(
param
==
NULL
)
{
if
(
param
==
NULL
){
fprintf
(
stderr
,
"[CONFIG] config_check_intval: NULL param argument
\n
"
);
fprintf
(
stderr
,
"[CONFIG] config_check_intval: NULL param argument
\n
"
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s1
.
num_okintval
;
i
++
)
{
if
(
*
(
param
->
uptr
)
==
param
->
chkPptr
->
s1
.
okintval
[
i
]
)
{
return
0
;
}
}
print_intvalueerror
(
param
,
"config_check_intval"
,
param
->
chkPptr
->
s1
.
okintval
,
param
->
chkPptr
->
s1
.
num_okintval
);
return
-
1
;
return
-
1
;
}
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s1
.
num_okintval
;
i
++
)
{
if
(
*
(
param
->
uptr
)
==
param
->
chkPptr
->
s1
.
okintval
[
i
]
)
{
return
0
;
}
}
print_intvalueerror
(
param
,
"config_check_intval"
,
param
->
chkPptr
->
s1
.
okintval
,
param
->
chkPptr
->
s1
.
num_okintval
);
return
-
1
;
}
}
int
config_check_modify_integer
(
paramdef_t
*
param
)
int
config_check_modify_integer
(
paramdef_t
*
param
)
{
{
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s1a
.
num_okintval
;
i
++
)
{
if
(
*
(
param
->
uptr
)
==
param
->
chkPptr
->
s1a
.
okintval
[
i
]
)
{
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s1a
.
num_okintval
;
i
++
)
{
printf_params
(
"[CONFIG] %s: read value %i, set to %i
\n
"
,
param
->
optname
,
*
(
param
->
uptr
),
param
->
chkPptr
->
s1a
.
setintval
[
i
]);
if
(
*
(
param
->
uptr
)
==
param
->
chkPptr
->
s1a
.
okintval
[
i
]
)
{
*
(
param
->
uptr
)
=
param
->
chkPptr
->
s1a
.
setintval
[
i
];
printf_params
(
"[CONFIG] %s: read value %i, set to %i
\n
"
,
param
->
optname
,
*
(
param
->
uptr
),
param
->
chkPptr
->
s1a
.
setintval
[
i
]);
return
0
;
*
(
param
->
uptr
)
=
param
->
chkPptr
->
s1a
.
setintval
[
i
];
}
return
0
;
}
}
}
print_intvalueerror
(
param
,
"config_check_modify_integer"
,
param
->
chkPptr
->
s1a
.
okintval
,
param
->
chkPptr
->
s1a
.
num_okintval
);
print_intvalueerror
(
param
,
"config_check_modify_integer"
,
param
->
chkPptr
->
s1a
.
okintval
,
param
->
chkPptr
->
s1a
.
num_okintval
);
return
-
1
;
return
-
1
;
}
}
int
config_check_intrange
(
paramdef_t
*
param
)
int
config_check_intrange
(
paramdef_t
*
param
)
{
{
if
(
*
(
param
->
iptr
)
>=
param
->
chkPptr
->
s2
.
okintrange
[
0
]
&&
*
(
param
->
iptr
)
<=
param
->
chkPptr
->
s2
.
okintrange
[
1
]
)
{
if
(
*
(
param
->
iptr
)
>=
param
->
chkPptr
->
s2
.
okintrange
[
0
]
&&
*
(
param
->
iptr
)
<=
param
->
chkPptr
->
s2
.
okintrange
[
1
]
)
{
return
0
;
return
0
;
}
}
fprintf
(
stderr
,
"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i
\n
"
,
fprintf
(
stderr
,
"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i
\n
"
,
param
->
optname
,
(
int
)
*
(
param
->
uptr
),
param
->
chkPptr
->
s2
.
okintrange
[
0
],
param
->
chkPptr
->
s2
.
okintrange
[
1
]);
param
->
optname
,
(
int
)
*
(
param
->
uptr
),
param
->
chkPptr
->
s2
.
okintrange
[
0
],
param
->
chkPptr
->
s2
.
okintrange
[
1
]);
return
-
1
;
return
-
1
;
}
}
void
print_strvalueerror
(
paramdef_t
*
param
,
char
*
fname
,
char
**
okval
,
int
numokval
)
{
void
print_strvalueerror
(
paramdef_t
*
param
,
char
*
fname
,
char
**
okval
,
int
numokval
)
{
fprintf
(
stderr
,
"[CONFIG] %s: %s: %s invalid value, authorized values:
\n
"
,
fprintf
(
stderr
,
"[CONFIG] %s: %s: %s invalid value, authorized values:
\n
"
,
fname
,
param
->
optname
,
*
(
param
->
strptr
));
fname
,
param
->
optname
,
*
(
param
->
strptr
));
for
(
int
i
=
0
;
i
<
numokval
;
i
++
)
{
fprintf
(
stderr
,
" %s"
,
okval
[
i
]);
for
(
int
i
=
0
;
i
<
numokval
;
i
++
)
{
}
fprintf
(
stderr
,
" %s"
,
okval
[
i
]);
fprintf
(
stderr
,
"
\n
"
);
}
fprintf
(
stderr
,
"
\n
"
);
}
}
int
config_check_strval
(
paramdef_t
*
param
)
int
config_check_strval
(
paramdef_t
*
param
)
{
{
if
(
param
==
NULL
)
{
if
(
param
==
NULL
){
fprintf
(
stderr
,
"[CONFIG] config_check_strval: NULL param argument
\n
"
);
fprintf
(
stderr
,
"[CONFIG] config_check_strval: NULL param argument
\n
"
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s3
.
num_okstrval
;
i
++
)
{
if
(
strcasecmp
(
*
(
param
->
strptr
),
param
->
chkPptr
->
s3
.
okstrval
[
i
]
)
==
0
)
{
return
0
;
}
}
print_strvalueerror
(
param
,
"config_check_strval"
,
param
->
chkPptr
->
s3
.
okstrval
,
param
->
chkPptr
->
s3
.
num_okstrval
);
return
-
1
;
return
-
1
;
}
}
int
config_checkstr_assign_integer
(
paramdef_t
*
param
)
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s3
.
num_okstrval
;
i
++
)
{
{
if
(
strcasecmp
(
*
(
param
->
strptr
),
param
->
chkPptr
->
s3
.
okstrval
[
i
]
)
==
0
)
{
return
0
;
}
}
print_strvalueerror
(
param
,
"config_check_strval"
,
param
->
chkPptr
->
s3
.
okstrval
,
param
->
chkPptr
->
s3
.
num_okstrval
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s3a
.
num_okstrval
;
i
++
)
{
int
config_checkstr_assign_integer
(
paramdef_t
*
param
)
{
if
(
strcasecmp
(
*
(
param
->
strptr
),
param
->
chkPptr
->
s3a
.
okstrval
[
i
]
)
==
0
)
{
for
(
int
i
=
0
;
i
<
param
->
chkPptr
->
s3a
.
num_okstrval
;
i
++
)
{
config_assign_processedint
(
param
,
param
->
chkPptr
->
s3a
.
setintval
[
i
]);
if
(
strcasecmp
(
*
(
param
->
strptr
),
param
->
chkPptr
->
s3a
.
okstrval
[
i
]
)
==
0
)
{
return
0
;
config_assign_processedint
(
param
,
param
->
chkPptr
->
s3a
.
setintval
[
i
]);
}
return
0
;
}
}
print_strvalueerror
(
param
,
"config_check_strval"
,
param
->
chkPptr
->
s3a
.
okstrval
,
param
->
chkPptr
->
s3a
.
num_okstrval
);
}
return
-
1
;
print_strvalueerror
(
param
,
"config_check_strval"
,
param
->
chkPptr
->
s3a
.
okstrval
,
param
->
chkPptr
->
s3a
.
num_okstrval
);
return
-
1
;
}
}
int
config_setdefault_string
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_string
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
if
(
cfgoptions
->
defstrval
!=
NULL
)
{
if
(
cfgoptions
->
defstrval
!=
NULL
)
{
status
=
1
;
status
=
1
;
if
(
cfgoptions
->
numelt
==
0
)
{
if
(
cfgoptions
->
numelt
==
0
)
{
config_check_valptr
(
cfgoptions
,
(
char
**
)(
cfgoptions
->
strptr
),
sizeof
(
char
*
));
config_check_valptr
(
cfgoptions
,
(
char
**
)(
cfgoptions
->
strptr
),
sizeof
(
char
*
));
config_check_valptr
(
cfgoptions
,
cfgoptions
->
strptr
,
strlen
(
cfgoptions
->
defstrval
)
+
1
);
config_check_valptr
(
cfgoptions
,
cfgoptions
->
strptr
,
strlen
(
cfgoptions
->
defstrval
)
+
1
);
sprintf
(
*
(
cfgoptions
->
strptr
),
"%s"
,
cfgoptions
->
defstrval
);
sprintf
(
*
(
cfgoptions
->
strptr
),
"%s"
,
cfgoptions
->
defstrval
);
printf_params
(
"[CONFIG] %s.%s set to default value
\"
%s
\"\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
*
(
cfgoptions
->
strptr
));
printf_params
(
"[CONFIG] %s.%s set to default value
\"
%s
\"\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
*
(
cfgoptions
->
strptr
));
}
else
{
}
else
{
sprintf
((
char
*
)
*
(
cfgoptions
->
strptr
),
"%s"
,
cfgoptions
->
defstrval
);
sprintf
((
char
*
)
*
(
cfgoptions
->
strptr
),
"%s"
,
cfgoptions
->
defstrval
);
printf_params
(
"[CONFIG] %s.%s set to default value
\"
%s
\"\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
(
char
*
)
*
(
cfgoptions
->
strptr
));
printf_params
(
"[CONFIG] %s.%s set to default value
\"
%s
\"\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
(
char
*
)
*
(
cfgoptions
->
strptr
));
}
}
}
}
return
status
;
return
status
;
}
}
int
config_setdefault_stringlist
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_stringlist
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
if
(
cfgoptions
->
defstrlistval
!=
NULL
)
{
if
(
cfgoptions
->
defstrlistval
!=
NULL
)
{
cfgoptions
->
strlistptr
=
cfgoptions
->
defstrlistval
;
cfgoptions
->
strlistptr
=
cfgoptions
->
defstrlistval
;
status
=
1
;
status
=
1
;
for
(
int
j
=
0
;
j
<
cfgoptions
->
numelt
;
j
++
)
printf_params
(
"[CONFIG] %s.%s[%i] set to default value %s
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
j
,
cfgoptions
->
strlistptr
[
j
]);
for
(
int
j
=
0
;
j
<
cfgoptions
->
numelt
;
j
++
)
printf_params
(
"[CONFIG] %s.%s[%i] set to default value %s
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
j
,
cfgoptions
->
strlistptr
[
j
]);
}
}
return
status
;
return
status
;
}
}
int
config_setdefault_int
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_int
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
config_check_valptr
(
cfgoptions
,
(
char
**
)(
&
(
cfgoptions
->
iptr
)),
sizeof
(
int32_t
));
config_check_valptr
(
cfgoptions
,
(
char
**
)(
&
(
cfgoptions
->
iptr
)),
sizeof
(
int32_t
));
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
config_assign_int
(
cfgoptions
,
cfgoptions
->
optname
,
cfgoptions
->
defintval
);
config_assign_int
(
cfgoptions
,
cfgoptions
->
optname
,
cfgoptions
->
defintval
);
status
=
1
;
status
=
1
;
printf_params
(
"[CONFIG] %s.%s set to default value
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
);
printf_params
(
"[CONFIG] %s.%s set to default value
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
);
}
}
return
status
;
return
status
;
}
}
int
config_setdefault_int64
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_int64
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
i64ptr
),
sizeof
(
long
long
));
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
i64ptr
),
sizeof
(
long
long
));
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
*
(
cfgoptions
->
u64ptr
)
=
cfgoptions
->
defuintval
;
*
(
cfgoptions
->
u64ptr
)
=
cfgoptions
->
defuintval
;
status
=
1
;
status
=
1
;
printf_params
(
"[CONFIG] %s.%s set to default value %llu
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
(
long
long
unsigned
)(
*
(
cfgoptions
->
u64ptr
)));
printf_params
(
"[CONFIG] %s.%s set to default value %llu
\n
"
,
((
prefix
==
NULL
)
?
""
:
prefix
),
cfgoptions
->
optname
,
(
long
long
unsigned
)(
*
(
cfgoptions
->
u64ptr
)));
}
}
return
status
;
return
status
;
}
}
int
config_setdefault_intlist
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_intlist
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
if
(
cfgoptions
->
defintarrayval
!=
NULL
)
{
if
(
cfgoptions
->
defintarrayval
!=
NULL
)
{
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
iptr
),
sizeof
(
int32_t
*
));
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
iptr
),
sizeof
(
int32_t
*
));
cfgoptions
->
iptr
=
cfgoptions
->
defintarrayval
;
cfgoptions
->
iptr
=
cfgoptions
->
defintarrayval
;
status
=
1
;
status
=
1
;
for
(
int
j
=
0
;
j
<
cfgoptions
->
numelt
;
j
++
)
{
for
(
int
j
=
0
;
j
<
cfgoptions
->
numelt
;
j
++
)
{
printf_params
(
"[CONFIG] %s[%i] set to default value %i
\n
"
,
cfgoptions
->
optname
,
j
,(
int
)
cfgoptions
->
iptr
[
j
]);
printf_params
(
"[CONFIG] %s[%i] set to default value %i
\n
"
,
cfgoptions
->
optname
,
j
,(
int
)
cfgoptions
->
iptr
[
j
]);
}
}
}
}
return
status
;
return
status
;
}
}
int
config_setdefault_double
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_double
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
dblptr
),
sizeof
(
double
));
config_check_valptr
(
cfgoptions
,
(
char
**
)
&
(
cfgoptions
->
dblptr
),
sizeof
(
double
));
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
if
(
((
cfgoptions
->
paramflags
&
PARAMFLAG_MANDATORY
)
==
0
))
{
*
(
cfgoptions
->
u64ptr
)
=
cfgoptions
->
defdblval
;
*
(
cfgoptions
->
u64ptr
)
=
cfgoptions
->
defdblval
;
status
=
1
;
status
=
1
;
printf_params
(
"[CONFIG] %s set to default value %lf
\n
"
,
cfgoptions
->
optname
,
*
(
cfgoptions
->
dblptr
));
printf_params
(
"[CONFIG] %s set to default value %lf
\n
"
,
cfgoptions
->
optname
,
*
(
cfgoptions
->
dblptr
));
}
}
return
status
;
return
status
;
}
}
int
config_assign_ipv4addr
(
paramdef_t
*
cfgoptions
,
char
*
ipv4addr
)
int
config_assign_ipv4addr
(
paramdef_t
*
cfgoptions
,
char
*
ipv4addr
)
{
{
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
uptr
),
sizeof
(
int
));
config_check_valptr
(
cfgoptions
,(
char
**
)
&
(
cfgoptions
->
uptr
),
sizeof
(
int
));
int
rst
=
inet_pton
(
AF_INET
,
ipv4addr
,
cfgoptions
->
uptr
);
int
rst
=
inet_pton
(
AF_INET
,
ipv4addr
,
cfgoptions
->
uptr
);
if
(
rst
==
1
&&
*
(
cfgoptions
->
uptr
)
>
0
)
{
if
(
rst
==
1
&&
*
(
cfgoptions
->
uptr
)
>
0
)
{
printf_params
(
"[CONFIG] %s: %s
\n
"
,
cfgoptions
->
optname
,
ipv4addr
);
printf_params
(
"[CONFIG] %s: %s
\n
"
,
cfgoptions
->
optname
,
ipv4addr
);
return
1
;
return
1
;
}
else
{
}
else
{
if
(
strncmp
(
ipv4addr
,
ANY_IPV4ADDR_STRING
,
sizeof
(
ANY_IPV4ADDR_STRING
))
==
0
)
{
if
(
strncmp
(
ipv4addr
,
ANY_IPV4ADDR_STRING
,
sizeof
(
ANY_IPV4ADDR_STRING
))
==
0
)
{
printf_params
(
"[CONFIG] %s:%s (INADDR_ANY)
\n
"
,
cfgoptions
->
optname
,
ipv4addr
);
printf_params
(
"[CONFIG] %s:%s (INADDR_ANY)
\n
"
,
cfgoptions
->
optname
,
ipv4addr
);
*
cfgoptions
->
uptr
=
INADDR_ANY
;
*
cfgoptions
->
uptr
=
INADDR_ANY
;
return
1
;
return
1
;
}
else
{
}
else
{
fprintf
(
stderr
,
"[CONFIG] %s not valid for %s
\n
"
,
ipv4addr
,
cfgoptions
->
optname
);
fprintf
(
stderr
,
"[CONFIG] %s not valid for %s
\n
"
,
ipv4addr
,
cfgoptions
->
optname
);
return
-
1
;
return
-
1
;
}
}
}
}
return
0
;
return
0
;
}
}
int
config_setdefault_ipv4addr
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
int
config_setdefault_ipv4addr
(
paramdef_t
*
cfgoptions
,
char
*
prefix
)
{
{
int
status
=
0
;
int
status
=
0
;
if
(
cfgoptions
->
defstrval
!=
NULL
)
{
if
(
cfgoptions
->
defstrval
!=
NULL
)
{
status
=
config_assign_ipv4addr
(
cfgoptions
,
cfgoptions
->
defstrval
);
status
=
config_assign_ipv4addr
(
cfgoptions
,
cfgoptions
->
defstrval
);
}
}
return
status
;
return
status
;
}
}
common/config/config_userapi.h
View file @
55732deb
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
*/
*/
/*! \file common/config/config_userapi.h
/*! \file common/config/config_userapi.h
* \brief: configuration module, include file to be used by the source code calling the
* \brief: configuration module, include file to be used by the source code calling the
* configuration module to access configuration parameters
* configuration module to access configuration parameters
* \author Francois TABURET
* \author Francois TABURET
* \date 2017
* \date 2017
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
* \warning
* \warning
*/
*/
#ifndef INCLUDE_CONFIG_USERAPI_H
#ifndef INCLUDE_CONFIG_USERAPI_H
#define INCLUDE_CONFIG_USERAPI_H
#define INCLUDE_CONFIG_USERAPI_H
#include "config_load_configmodule.h"
#include "config_load_configmodule.h"
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -48,7 +48,7 @@ extern "C"
...
@@ -48,7 +48,7 @@ extern "C"
#define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F))
#define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F))
/* utility functions, to be used by configuration module and/or configuration libraries */
/* utility functions, to be used by configuration module and/or configuration libraries */
extern
configmodule_interface_t
*
config_get_if
(
void
);
extern
configmodule_interface_t
*
config_get_if
(
void
);
extern
char
*
config_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
void
config_assign_processedint
(
paramdef_t
*
cfgoption
,
int
val
);
extern
void
config_assign_processedint
(
paramdef_t
*
cfgoption
,
int
val
);
...
...
common/utils/LOG/log.c
View file @
55732deb
...
@@ -72,16 +72,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL
...
@@ -72,16 +72,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL
char
*
log_level_highlight_end
[]
=
{
LOG_RESET
,
LOG_RESET
,
LOG_RESET
,
LOG_RESET
,
LOG_RESET
};
/*!< \brief Optional end-format strings for highlighting */
char
*
log_level_highlight_end
[]
=
{
LOG_RESET
,
LOG_RESET
,
LOG_RESET
,
LOG_RESET
,
LOG_RESET
};
/*!< \brief Optional end-format strings for highlighting */
int
write_file_matlab
(
const
char
*
fname
,
const
char
*
vname
,
void
*
data
,
int
length
,
int
dec
,
char
format
)
int
write_file_matlab
(
const
char
*
fname
,
const
char
*
vname
,
void
*
data
,
int
length
,
int
dec
,
char
format
)
{
{
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
int
i
;
int
i
;
if
(
data
==
NULL
)
if
(
data
==
NULL
)
return
-
1
;
return
-
1
;
//printf("Writing %d elements of type %d to %s\n",length,format,fname);
//printf("Writing %d elements of type %d to %s\n",length,format,fname);
if
(
format
==
10
||
format
==
11
||
format
==
12
||
format
==
13
||
format
==
14
)
{
if
(
format
==
10
||
format
==
11
||
format
==
12
||
format
==
13
||
format
==
14
)
{
fp
=
fopen
(
fname
,
"a+"
);
fp
=
fopen
(
fname
,
"a+"
);
...
@@ -89,8 +87,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
...
@@ -89,8 +87,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
fp
=
fopen
(
fname
,
"w+"
);
fp
=
fopen
(
fname
,
"w+"
);
}
}
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
printf
(
"[OPENAIR][FILE OUTPUT] Cannot open file %s
\n
"
,
fname
);
printf
(
"[OPENAIR][FILE OUTPUT] Cannot open file %s
\n
"
,
fname
);
return
(
-
1
);
return
(
-
1
);
...
@@ -99,121 +95,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
...
@@ -99,121 +95,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
if
(
format
!=
10
&&
format
!=
11
&&
format
!=
12
&&
format
!=
13
&&
format
!=
14
)
if
(
format
!=
10
&&
format
!=
11
&&
format
!=
12
&&
format
!=
13
&&
format
!=
14
)
fprintf
(
fp
,
"%s = ["
,
vname
);
fprintf
(
fp
,
"%s = ["
,
vname
);
switch
(
format
)
{
switch
(
format
)
{
case
0
:
// real 16-bit
case
0
:
// real 16-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%d
\n
"
,((
short
*
)
data
)[
i
]);
fprintf
(
fp
,
"%d
\n
"
,((
short
*
)
data
)[
i
]);
}
}
break
;
case
1
:
// complex 16-bit
case
13
:
case
14
:
case
15
:
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
}
break
;
case
2
:
// real 32-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%d
\n
"
,((
int
*
)
data
)[
i
]);
}
break
;
case
3
:
// complex 32-bit
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
int
*
)
data
)[
i
],((
int
*
)
data
)[
i
+
1
]);
}
break
;
case
4
:
// real 8-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%d
\n
"
,((
char
*
)
data
)[
i
]);
}
break
;
break
;
case
5
:
// complex 8-bit
case
1
:
// complex 16-bit
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
case
13
:
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
char
*
)
data
)[
i
],((
char
*
)
data
)[
i
+
1
]);
case
14
:
}
case
15
:
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
}
break
;
break
;
case
6
:
// real 64
-bit
case
2
:
// real 32
-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%lld
\n
"
,((
long
long
*
)
data
)[
i
]);
fprintf
(
fp
,
"%d
\n
"
,((
int
*
)
data
)[
i
]);
}
}
break
;
break
;
case
7
:
// real double
case
3
:
// complex 32-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
)
)
{
fprintf
(
fp
,
"%g
\n
"
,((
double
*
)
data
)[
i
]);
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
int
*
)
data
)[
i
],((
int
*
)
data
)[
i
+
1
]);
}
}
break
;
break
;
case
8
:
// complex double
case
4
:
// real 8-bit
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
2
*
dec
)
{
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%g + j*(%g)
\n
"
,((
double
*
)
data
)[
i
],
((
double
*
)
data
)[
i
+
1
]);
fprintf
(
fp
,
"%d
\n
"
,((
char
*
)
data
)[
i
]);
}
}
break
;
break
;
case
9
:
// real unsigned
8-bit
case
5
:
// complex
8-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
)
)
{
fprintf
(
fp
,
"%d
\n
"
,((
unsigned
char
*
)
data
)[
i
]);
fprintf
(
fp
,
"%d + j*(%d)
\n
"
,((
char
*
)
data
)[
i
],((
char
*
)
data
)[
i
+
1
]);
}
}
break
;
break
;
case
6
:
// real 64-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%lld
\n
"
,((
long
long
*
)
data
)[
i
]);
}
case
10
:
// case eren 16 bit complex :
break
;
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
case
7
:
// real double
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%g
\n
"
,((
double
*
)
data
)[
i
]);
}
if
((
i
<
2
*
(
length
-
1
))
&&
(
i
>
0
))
break
;
fprintf
(
fp
,
"%d + j*(%d),"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
else
if
(
i
==
2
*
(
length
-
1
))
fprintf
(
fp
,
"%d + j*(%d);"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
else
if
(
i
==
0
)
fprintf
(
fp
,
"
\n
%d + j*(%d),"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
case
8
:
// complex double
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
2
*
dec
)
{
fprintf
(
fp
,
"%g + j*(%g)
\n
"
,((
double
*
)
data
)[
i
],
((
double
*
)
data
)[
i
+
1
]);
}
break
;
}
case
9
:
// real unsigned 8-bit
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
fprintf
(
fp
,
"%d
\n
"
,((
unsigned
char
*
)
data
)[
i
]);
}
break
;
break
;
case
11
:
//case eren 16 bit real for channel magnitudes:
case
10
:
// case eren 16 bit complex :
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
for
(
i
=
0
;
i
<
length
<<
1
;
i
+=
(
2
*
dec
))
{
if
((
i
<
2
*
(
length
-
1
))
&&
(
i
>
0
))
fprintf
(
fp
,
"%d + j*(%d),"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
else
if
(
i
==
2
*
(
length
-
1
))
fprintf
(
fp
,
"%d + j*(%d);"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
else
if
(
i
==
0
)
fprintf
(
fp
,
"
\n
%d + j*(%d),"
,((
short
*
)
data
)[
i
],((
short
*
)
data
)[
i
+
1
]);
}
if
((
i
<
(
length
-
1
))
&&
(
i
>
0
))
break
;
fprintf
(
fp
,
"%d,"
,((
short
*
)
data
)[
i
]);
else
if
(
i
==
(
length
-
1
))
fprintf
(
fp
,
"%d;"
,((
short
*
)
data
)[
i
]);
else
if
(
i
==
0
)
fprintf
(
fp
,
"
\n
%d,"
,((
short
*
)
data
)[
i
]);
}
printf
(
"
\n
eren: length :%d"
,
length
);
case
11
:
//case eren 16 bit real for channel magnitudes:
break
;
for
(
i
=
0
;
i
<
length
;
i
+=
dec
)
{
if
((
i
<
(
length
-
1
))
&&
(
i
>
0
))
fprintf
(
fp
,
"%d,"
,((
short
*
)
data
)[
i
]);
else
if
(
i
==
(
length
-
1
))
fprintf
(
fp
,
"%d;"
,((
short
*
)
data
)[
i
]);
else
if
(
i
==
0
)
fprintf
(
fp
,
"
\n
%d,"
,((
short
*
)
data
)[
i
]);
}
case
12
:
// case eren for log2_maxh real unsigned 8 bit
printf
(
"
\n
eren: length :%d"
,
length
);
fprintf
(
fp
,
"%d
\n
"
,((
unsigned
char
*
)
&
data
)[
0
]);
break
;
break
;
case
12
:
// case eren for log2_maxh real unsigned 8 bit
fprintf
(
fp
,
"%d
\n
"
,((
unsigned
char
*
)
&
data
)[
0
]);
break
;
}
}
if
(
format
!=
10
&&
format
!=
11
&&
format
!=
12
&&
format
!=
13
&&
format
!=
15
)
{
if
(
format
!=
10
&&
format
!=
11
&&
format
!=
12
&&
format
!=
13
&&
format
!=
15
)
{
...
@@ -232,8 +215,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
...
@@ -232,8 +215,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
void
log_getconfig
(
log_t
*
g_log
)
{
void
log_getconfig
(
log_t
*
g_log
)
{
char
*
gloglevel
=
NULL
;
char
*
gloglevel
=
NULL
;
int
consolelog
;
int
consolelog
;
paramdef_t
logparams_defaults
[]
=
LOG_GLOBALPARAMS_DESC
;
paramdef_t
logparams_defaults
[]
=
LOG_GLOBALPARAMS_DESC
;
paramdef_t
logparams_level
[
MAX_LOG_PREDEF_COMPONENTS
];
paramdef_t
logparams_level
[
MAX_LOG_PREDEF_COMPONENTS
];
paramdef_t
logparams_logfile
[
MAX_LOG_PREDEF_COMPONENTS
];
paramdef_t
logparams_logfile
[
MAX_LOG_PREDEF_COMPONENTS
];
...
@@ -241,131 +222,146 @@ void log_getconfig(log_t *g_log) {
...
@@ -241,131 +222,146 @@ void log_getconfig(log_t *g_log) {
paramdef_t
logparams_dump
[
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
)];
paramdef_t
logparams_dump
[
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
)];
CONFIG_SETRTFLAG
(
CONFIG_NOCHECKUNKOPT
);
CONFIG_SETRTFLAG
(
CONFIG_NOCHECKUNKOPT
);
int
ret
=
config_get
(
logparams_defaults
,
sizeof
(
logparams_defaults
)
/
sizeof
(
paramdef_t
),
CONFIG_STRING_LOG_PREFIX
);
int
ret
=
config_get
(
logparams_defaults
,
sizeof
(
logparams_defaults
)
/
sizeof
(
paramdef_t
),
CONFIG_STRING_LOG_PREFIX
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"[LOG] init aborted, configuration couldn't be performed"
);
fprintf
(
stderr
,
"[LOG] init aborted, configuration couldn't be performed"
);
return
;
return
;
}
}
/* set LOG display options (enable/disable color, thread name, level ) */
/* set LOG display options (enable/disable color, thread name, level ) */
for
(
int
i
=
0
;
i
<
logparams_defaults
[
LOG_OPTIONS_IDX
].
numelt
;
i
++
)
{
for
(
int
i
=
0
;
i
<
logparams_defaults
[
LOG_OPTIONS_IDX
].
numelt
;
i
++
)
{
for
(
int
j
=
0
;
log_options
[
j
].
name
!=
NULL
;
j
++
)
{
for
(
int
j
=
0
;
log_options
[
j
].
name
!=
NULL
;
j
++
)
{
if
(
strcmp
(
logparams_defaults
[
LOG_OPTIONS_IDX
].
strlistptr
[
i
],
log_options
[
j
].
name
)
==
0
)
{
if
(
strcmp
(
logparams_defaults
[
LOG_OPTIONS_IDX
].
strlistptr
[
i
],
log_options
[
j
].
name
)
==
0
)
{
g_log
->
flag
=
g_log
->
flag
|
log_options
[
j
].
value
;
g_log
->
flag
=
g_log
->
flag
|
log_options
[
j
].
value
;
break
;
break
;
}
else
if
(
log_options
[
j
+
1
].
name
==
NULL
)
{
}
else
if
(
log_options
[
j
+
1
].
name
==
NULL
)
{
fprintf
(
stderr
,
"Unknown log option: %s
\n
"
,
logparams_defaults
[
LOG_OPTIONS_IDX
].
strlistptr
[
i
]);
fprintf
(
stderr
,
"Unknown log option: %s
\n
"
,
logparams_defaults
[
LOG_OPTIONS_IDX
].
strlistptr
[
i
]);
exit
(
-
1
);
exit
(
-
1
);
}
}
}
}
}
}
/* build the parameter array for setting per component log level and infile options */
/* build the parameter array for setting per component log level and infile options */
memset
(
logparams_level
,
0
,
sizeof
(
paramdef_t
)
*
MAX_LOG_PREDEF_COMPONENTS
);
memset
(
logparams_level
,
0
,
sizeof
(
paramdef_t
)
*
MAX_LOG_PREDEF_COMPONENTS
);
memset
(
logparams_logfile
,
0
,
sizeof
(
paramdef_t
)
*
MAX_LOG_PREDEF_COMPONENTS
);
memset
(
logparams_logfile
,
0
,
sizeof
(
paramdef_t
)
*
MAX_LOG_PREDEF_COMPONENTS
);
for
(
int
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_PREDEF_COMPONENTS
;
i
++
)
{
for
(
int
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_PREDEF_COMPONENTS
;
i
++
)
{
if
(
g_log
->
log_component
[
i
].
name
==
NULL
)
{
if
(
g_log
->
log_component
[
i
].
name
==
NULL
)
{
g_log
->
log_component
[
i
].
name
=
malloc
(
16
);
g_log
->
log_component
[
i
].
name
=
malloc
(
16
);
sprintf
((
char
*
)
g_log
->
log_component
[
i
].
name
,
"comp%i?"
,
i
);
sprintf
((
char
*
)
g_log
->
log_component
[
i
].
name
,
"comp%i?"
,
i
);
logparams_logfile
[
i
].
paramflags
=
PARAMFLAG_DONOTREAD
;
logparams_logfile
[
i
].
paramflags
=
PARAMFLAG_DONOTREAD
;
logparams_level
[
i
].
paramflags
=
PARAMFLAG_DONOTREAD
;
logparams_level
[
i
].
paramflags
=
PARAMFLAG_DONOTREAD
;
}
}
sprintf
(
logparams_level
[
i
].
optname
,
LOG_CONFIG_LEVEL_FORMAT
,
g_log
->
log_component
[
i
].
name
);
sprintf
(
logparams_level
[
i
].
optname
,
LOG_CONFIG_LEVEL_FORMAT
,
g_log
->
log_component
[
i
].
name
);
sprintf
(
logparams_logfile
[
i
].
optname
,
LOG_CONFIG_LOGFILE_FORMAT
,
g_log
->
log_component
[
i
].
name
);
sprintf
(
logparams_logfile
[
i
].
optname
,
LOG_CONFIG_LOGFILE_FORMAT
,
g_log
->
log_component
[
i
].
name
);
/* workaround: all log options in existing configuration files use lower case component names
where component names include uppercase char in log.h.... */
/* workaround: all log options in existing configuration files use lower case component names
for
(
int
j
=
0
;
j
<
strlen
(
logparams_level
[
i
].
optname
);
j
++
)
where component names include uppercase char in log.h.... */
logparams_level
[
i
].
optname
[
j
]
=
tolower
(
logparams_level
[
i
].
optname
[
j
]);
for
(
int
j
=
0
;
j
<
strlen
(
logparams_level
[
i
].
optname
);
j
++
)
for
(
int
j
=
0
;
j
<
strlen
(
logparams_level
[
i
].
optname
);
j
++
)
logparams_level
[
i
].
optname
[
j
]
=
tolower
(
logparams_level
[
i
].
optname
[
j
]);
logparams_logfile
[
i
].
optname
[
j
]
=
tolower
(
logparams_logfile
[
i
].
optname
[
j
]);
/* */
for
(
int
j
=
0
;
j
<
strlen
(
logparams_level
[
i
].
optname
);
j
++
)
logparams_logfile
[
i
].
optname
[
j
]
=
tolower
(
logparams_logfile
[
i
].
optname
[
j
]);
/* */
logparams_level
[
i
].
defstrval
=
gloglevel
;
logparams_level
[
i
].
defstrval
=
gloglevel
;
logparams_logfile
[
i
].
defuintval
=
0
;
logparams_logfile
[
i
].
defuintval
=
0
;
logparams_logfile
[
i
].
numelt
=
0
;
logparams_logfile
[
i
].
numelt
=
0
;
logparams_level
[
i
].
numelt
=
0
;
logparams_level
[
i
].
numelt
=
0
;
logparams_level
[
i
].
type
=
TYPE_STRING
;
logparams_level
[
i
].
type
=
TYPE_STRING
;
logparams_logfile
[
i
].
type
=
TYPE_UINT
;
logparams_logfile
[
i
].
type
=
TYPE_UINT
;
logparams_logfile
[
i
].
paramflags
=
logparams_logfile
[
i
].
paramflags
|
PARAMFLAG_BOOL
;
logparams_logfile
[
i
].
paramflags
=
logparams_logfile
[
i
].
paramflags
|
PARAMFLAG_BOOL
;
}
}
/* read the per component parameters */
config_get
(
logparams_level
,
MAX_LOG_PREDEF_COMPONENTS
,
CONFIG_STRING_LOG_PREFIX
);
/* read the per component parameters */
config_get
(
logparams_logfile
,
MAX_LOG_PREDEF_COMPONENTS
,
CONFIG_STRING_LOG_PREFIX
);
config_get
(
logparams_level
,
MAX_LOG_PREDEF_COMPONENTS
,
CONFIG_STRING_LOG_PREFIX
);
/* now set the log levels and infile option, according to what we read */
config_get
(
logparams_logfile
,
MAX_LOG_PREDEF_COMPONENTS
,
CONFIG_STRING_LOG_PREFIX
);
/* now set the log levels and infile option, according to what we read */
for
(
int
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_PREDEF_COMPONENTS
;
i
++
)
{
for
(
int
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_PREDEF_COMPONENTS
;
i
++
)
{
g_log
->
log_component
[
i
].
level
=
map_str_to_int
(
log_level_names
,
*
(
logparams_level
[
i
].
strptr
));
g_log
->
log_component
[
i
].
level
=
map_str_to_int
(
log_level_names
,
*
(
logparams_level
[
i
].
strptr
));
set_log
(
i
,
g_log
->
log_component
[
i
].
level
);
set_log
(
i
,
g_log
->
log_component
[
i
].
level
);
if
(
*
(
logparams_logfile
[
i
].
uptr
)
==
1
)
if
(
*
(
logparams_logfile
[
i
].
uptr
)
==
1
)
set_component_filelog
(
i
);
set_component_filelog
(
i
);
}
}
/* build then read the debug and dump parameter array */
/* build then read the debug and dump parameter array */
for
(
int
i
=
0
;
log_maskmap
[
i
].
name
!=
NULL
;
i
++
)
{
for
(
int
i
=
0
;
log_maskmap
[
i
].
name
!=
NULL
;
i
++
)
{
sprintf
(
logparams_debug
[
i
].
optname
,
LOG_CONFIG_DEBUG_FORMAT
,
log_maskmap
[
i
].
name
);
sprintf
(
logparams_debug
[
i
].
optname
,
LOG_CONFIG_DEBUG_FORMAT
,
log_maskmap
[
i
].
name
);
sprintf
(
logparams_dump
[
i
].
optname
,
LOG_CONFIG_DUMP_FORMAT
,
log_maskmap
[
i
].
name
);
sprintf
(
logparams_dump
[
i
].
optname
,
LOG_CONFIG_DUMP_FORMAT
,
log_maskmap
[
i
].
name
);
logparams_debug
[
i
].
defuintval
=
0
;
logparams_debug
[
i
].
defuintval
=
0
;
logparams_debug
[
i
].
type
=
TYPE_UINT
;
logparams_debug
[
i
].
type
=
TYPE_UINT
;
logparams_debug
[
i
].
paramflags
=
PARAMFLAG_BOOL
;
logparams_debug
[
i
].
paramflags
=
PARAMFLAG_BOOL
;
logparams_debug
[
i
].
uptr
=
NULL
;
logparams_debug
[
i
].
uptr
=
NULL
;
logparams_debug
[
i
].
chkPptr
=
NULL
;
logparams_debug
[
i
].
chkPptr
=
NULL
;
logparams_debug
[
i
].
numelt
=
0
;
logparams_debug
[
i
].
numelt
=
0
;
logparams_dump
[
i
].
defuintval
=
0
;
logparams_dump
[
i
].
defuintval
=
0
;
logparams_dump
[
i
].
type
=
TYPE_UINT
;
logparams_dump
[
i
].
type
=
TYPE_UINT
;
logparams_dump
[
i
].
paramflags
=
PARAMFLAG_BOOL
;
logparams_dump
[
i
].
paramflags
=
PARAMFLAG_BOOL
;
logparams_dump
[
i
].
uptr
=
NULL
;
logparams_dump
[
i
].
uptr
=
NULL
;
logparams_dump
[
i
].
chkPptr
=
NULL
;
logparams_dump
[
i
].
chkPptr
=
NULL
;
logparams_dump
[
i
].
numelt
=
0
;
logparams_dump
[
i
].
numelt
=
0
;
}
}
config_get
(
logparams_debug
,(
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
))
-
1
,
CONFIG_STRING_LOG_PREFIX
);
config_get
(
logparams_debug
,(
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
))
-
1
,
CONFIG_STRING_LOG_PREFIX
);
CONFIG_CLEARRTFLAG
(
CONFIG_NOCHECKUNKOPT
);
CONFIG_CLEARRTFLAG
(
CONFIG_NOCHECKUNKOPT
);
config_get
(
logparams_dump
,(
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
))
-
1
,
CONFIG_STRING_LOG_PREFIX
);
config_get
(
logparams_dump
,(
sizeof
(
log_maskmap
)
/
sizeof
(
mapping
))
-
1
,
CONFIG_STRING_LOG_PREFIX
);
/* set the debug mask according to the debug parameters values */
/* set the debug mask according to the debug parameters values */
for
(
int
i
=
0
;
log_maskmap
[
i
].
name
!=
NULL
;
i
++
)
{
for
(
int
i
=
0
;
log_maskmap
[
i
].
name
!=
NULL
;
i
++
)
{
if
(
*
(
logparams_debug
[
i
].
uptr
)
)
if
(
*
(
logparams_debug
[
i
].
uptr
)
)
g_log
->
debug_mask
=
g_log
->
debug_mask
|
log_maskmap
[
i
].
value
;
g_log
->
debug_mask
=
g_log
->
debug_mask
|
log_maskmap
[
i
].
value
;
if
(
*
(
logparams_dump
[
i
].
uptr
)
)
if
(
*
(
logparams_dump
[
i
].
uptr
)
)
g_log
->
dump_mask
=
g_log
->
dump_mask
|
log_maskmap
[
i
].
value
;
g_log
->
dump_mask
=
g_log
->
dump_mask
|
log_maskmap
[
i
].
value
;
}
}
/* log globally enabled/disabled */
/* log globally enabled/disabled */
set_glog_onlinelog
(
consolelog
);
set_glog_onlinelog
(
consolelog
);
}
}
int
register_log_component
(
char
*
name
,
char
*
fext
,
int
compidx
)
int
register_log_component
(
char
*
name
,
char
*
fext
,
int
compidx
)
{
{
int
computed_compidx
=
compidx
;
int
computed_compidx
=
compidx
;
if
(
strlen
(
fext
)
>
3
)
{
if
(
strlen
(
fext
)
>
3
)
{
fext
[
3
]
=
0
;
/* limit log file extension to 3 chars */
fext
[
3
]
=
0
;
/* limit log file extension to 3 chars */
}
}
if
(
compidx
<
0
)
{
/* this is not a pre-defined component */
if
(
compidx
<
0
)
{
/* this is not a pre-defined component */
for
(
int
i
=
MAX_LOG_PREDEF_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
for
(
int
i
=
MAX_LOG_PREDEF_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
if
(
g_log
->
log_component
[
i
].
name
==
NULL
)
{
if
(
g_log
->
log_component
[
i
].
name
==
NULL
)
{
computed_compidx
=
i
;
computed_compidx
=
i
;
break
;
break
;
}
}
}
}
}
}
if
(
computed_compidx
>=
0
&&
computed_compidx
<
MAX_LOG_COMPONENTS
)
{
if
(
computed_compidx
>=
0
&&
computed_compidx
<
MAX_LOG_COMPONENTS
)
{
g_log
->
log_component
[
computed_compidx
].
name
=
strdup
(
name
);
g_log
->
log_component
[
computed_compidx
].
name
=
strdup
(
name
);
g_log
->
log_component
[
computed_compidx
].
stream
=
stdout
;
g_log
->
log_component
[
computed_compidx
].
stream
=
stdout
;
g_log
->
log_component
[
computed_compidx
].
filelog
=
0
;
g_log
->
log_component
[
computed_compidx
].
filelog
=
0
;
g_log
->
log_component
[
computed_compidx
].
filelog_name
=
malloc
(
strlen
(
name
)
+
16
);
/* /tmp/<name>.%s */
g_log
->
log_component
[
computed_compidx
].
filelog_name
=
malloc
(
strlen
(
name
)
+
16
);
/* /tmp/<name>.%s */
sprintf
(
g_log
->
log_component
[
computed_compidx
].
filelog_name
,
"/tmp/%s.%s"
,
name
,
fext
);
sprintf
(
g_log
->
log_component
[
computed_compidx
].
filelog_name
,
"/tmp/%s.%s"
,
name
,
fext
);
}
else
{
}
else
{
fprintf
(
stderr
,
"{LOG} %s %d Couldn't register componemt %s
\n
"
,
__FILE__
,
__LINE__
,
name
);
fprintf
(
stderr
,
"{LOG} %s %d Couldn't register componemt %s
\n
"
,
__FILE__
,
__LINE__
,
name
);
}
}
return
computed_compidx
;
return
computed_compidx
;
}
}
int
isLogInitDone
(
void
){
int
isLogInitDone
(
void
)
{
if
(
g_log
==
NULL
)
if
(
g_log
==
NULL
)
return
0
;
return
0
;
if
(
!
(
g_log
->
flag
&
FLAG_INITIALIZED
))
return
0
;
if
(
!
(
g_log
->
flag
&
FLAG_INITIALIZED
))
return
1
;
return
0
;
return
1
;
}
}
int
logInit
(
void
)
int
logInit
(
void
)
{
{
int
i
;
int
i
;
g_log
=
calloc
(
1
,
sizeof
(
log_t
));
g_log
=
calloc
(
1
,
sizeof
(
log_t
));
...
@@ -373,10 +369,8 @@ int logInit (void)
...
@@ -373,10 +369,8 @@ int logInit (void)
perror
(
"cannot allocated memory for log generation module
\n
"
);
perror
(
"cannot allocated memory for log generation module
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
memset
(
g_log
,
0
,
sizeof
(
log_t
));
memset
(
g_log
,
0
,
sizeof
(
log_t
));
register_log_component
(
"PHY"
,
"log"
,
PHY
);
register_log_component
(
"PHY"
,
"log"
,
PHY
);
register_log_component
(
"MAC"
,
"log"
,
MAC
);
register_log_component
(
"MAC"
,
"log"
,
MAC
);
register_log_component
(
"OPT"
,
"log"
,
OPT
);
register_log_component
(
"OPT"
,
"log"
,
OPT
);
...
@@ -392,144 +386,121 @@ int logInit (void)
...
@@ -392,144 +386,121 @@ int logInit (void)
register_log_component
(
"OTG_JITTER"
,
"dat"
,
OTG_JITTER
);
register_log_component
(
"OTG_JITTER"
,
"dat"
,
OTG_JITTER
);
register_log_component
(
"OCG"
,
""
,
OCG
);
register_log_component
(
"OCG"
,
""
,
OCG
);
register_log_component
(
"PERF"
,
""
,
PERF
);
register_log_component
(
"PERF"
,
""
,
PERF
);
register_log_component
(
"OIP"
,
""
,
OIP
);
register_log_component
(
"OIP"
,
""
,
OIP
);
register_log_component
(
"CLI"
,
""
,
CLI
);
register_log_component
(
"CLI"
,
""
,
CLI
);
register_log_component
(
"MSC"
,
"log"
,
MSC
);
register_log_component
(
"MSC"
,
"log"
,
MSC
);
register_log_component
(
"OCM"
,
"log"
,
OCM
);
register_log_component
(
"OCM"
,
"log"
,
OCM
);
register_log_component
(
"HW"
,
""
,
HW
);
register_log_component
(
"HW"
,
""
,
HW
);
register_log_component
(
"OSA"
,
""
,
OSA
);
register_log_component
(
"OSA"
,
""
,
OSA
);
register_log_component
(
"eRAL"
,
""
,
RAL_ENB
);
register_log_component
(
"eRAL"
,
""
,
RAL_ENB
);
register_log_component
(
"mRAL"
,
""
,
RAL_UE
);
register_log_component
(
"mRAL"
,
""
,
RAL_UE
);
register_log_component
(
"ENB_APP"
,
"log"
,
ENB_APP
);
register_log_component
(
"ENB_APP"
,
"log"
,
ENB_APP
);
register_log_component
(
"FLEXRAN_AGENT"
,
"log"
,
FLEXRAN_AGENT
);
register_log_component
(
"FLEXRAN_AGENT"
,
"log"
,
FLEXRAN_AGENT
);
register_log_component
(
"TMR"
,
""
,
TMR
);
register_log_component
(
"TMR"
,
""
,
TMR
);
register_log_component
(
"USIM"
,
"txt"
,
USIM
);
register_log_component
(
"USIM"
,
"txt"
,
USIM
);
register_log_component
(
"SIM"
,
"txt"
,
SIM
);
register_log_component
(
"SIM"
,
"txt"
,
SIM
);
/* following log component are used for the localization*/
/* following log component are used for the localization*/
register_log_component
(
"LOCALIZE"
,
"log"
,
LOCALIZE
);
register_log_component
(
"LOCALIZE"
,
"log"
,
LOCALIZE
);
register_log_component
(
"NAS"
,
"log"
,
NAS
);
register_log_component
(
"NAS"
,
"log"
,
NAS
);
register_log_component
(
"UDP"
,
""
,
UDP_
);
register_log_component
(
"UDP"
,
""
,
UDP_
);
register_log_component
(
"GTPV1U"
,
""
,
GTPU
);
register_log_component
(
"GTPV1U"
,
""
,
GTPU
);
register_log_component
(
"S1AP"
,
""
,
S1AP
);
register_log_component
(
"S1AP"
,
""
,
S1AP
);
register_log_component
(
"X2AP"
,
""
,
X2AP
);
register_log_component
(
"X2AP"
,
""
,
X2AP
);
register_log_component
(
"SCTP"
,
""
,
SCTP
);
register_log_component
(
"SCTP"
,
""
,
SCTP
);
register_log_component
(
"X2AP"
,
""
,
X2AP
);
register_log_component
(
"X2AP"
,
""
,
X2AP
);
register_log_component
(
"LOADER"
,
"log"
,
LOADER
);
register_log_component
(
"LOADER"
,
"log"
,
LOADER
);
register_log_component
(
"ASN"
,
"log"
,
ASN
);
register_log_component
(
"ASN"
,
"log"
,
ASN
);
for
(
int
i
=
0
;
log_level_names
[
i
].
name
!=
NULL
;
i
++
)
for
(
int
i
=
0
;
log_level_names
[
i
].
name
!=
NULL
;
i
++
)
g_log
->
level2string
[
i
]
=
toupper
(
log_level_names
[
i
].
name
[
0
]);
// uppercased first letter of level name
g_log
->
level2string
[
i
]
=
toupper
(
log_level_names
[
i
].
name
[
0
]);
// uppercased first letter of level name
g_log
->
filelog_name
=
"/tmp/openair.log"
;
g_log
->
filelog_name
=
"/tmp/openair.log"
;
log_getconfig
(
g_log
);
log_getconfig
(
g_log
);
// set all unused component items to 0, they are for non predefined components
// set all unused component items to 0, they are for non predefined components
for
(
i
=
MAX_LOG_PREDEF_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
for
(
i
=
MAX_LOG_PREDEF_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
memset
(
&
(
g_log
->
log_component
[
i
]),
0
,
sizeof
(
log_component_t
));
memset
(
&
(
g_log
->
log_component
[
i
]),
0
,
sizeof
(
log_component_t
));
}
}
g_log
->
flag
=
g_log
->
flag
|
FLAG_INITIALIZED
;
g_log
->
flag
=
g_log
->
flag
|
FLAG_INITIALIZED
;
printf
(
"log init done
\n
"
);
printf
(
"log init done
\n
"
);
return
0
;
return
0
;
}
}
char
*
log_getthreadname
(
char
*
threadname
,
int
bufsize
)
{
char
*
log_getthreadname
(
char
*
threadname
,
int
bufsize
)
{
int
rt
=
pthread_getname_np
(
pthread_self
(),
threadname
,
bufsize
)
;
int
rt
=
pthread_getname_np
(
pthread_self
(),
threadname
,
bufsize
)
;
if
(
rt
==
0
)
{
if
(
rt
==
0
)
return
threadname
;
{
}
else
{
return
threadname
;
return
"thread?"
;
}
else
{
}
return
"thread?"
;
}
}
}
static
int
log_header
(
char
*
log_buffer
,
int
buffsize
,
int
comp
,
int
level
,
const
char
*
format
)
{
static
int
log_header
(
char
*
log_buffer
,
int
buffsize
,
int
comp
,
int
level
,
const
char
*
format
)
{
char
threadname
[
PR_SET_NAME
];
char
threadname
[
PR_SET_NAME
];
return
snprintf
(
log_buffer
,
buffsize
,
"%s%s[%s]%c %s %s%s"
,
return
snprintf
(
log_buffer
,
buffsize
,
"%s%s[%s]%c %s %s%s"
,
log_level_highlight_end
[
level
],
log_level_highlight_end
[
level
],
(
(
g_log
->
flag
&
FLAG_NOCOLOR
)
?
""
:
log_level_highlight_start
[
level
]),
(
(
g_log
->
flag
&
FLAG_NOCOLOR
)
?
""
:
log_level_highlight_start
[
level
]),
g_log
->
log_component
[
comp
].
name
,
g_log
->
log_component
[
comp
].
name
,
(
(
g_log
->
flag
&
FLAG_LEVEL
)
?
g_log
->
level2string
[
level
]
:
' '
),
(
(
g_log
->
flag
&
FLAG_LEVEL
)
?
g_log
->
level2string
[
level
]
:
' '
),
(
(
g_log
->
flag
&
FLAG_THREAD
)
?
log_getthreadname
(
threadname
,
PR_SET_NAME
+
1
)
:
""
),
(
(
g_log
->
flag
&
FLAG_THREAD
)
?
log_getthreadname
(
threadname
,
PR_SET_NAME
+
1
)
:
""
),
format
,
format
,
log_level_highlight_end
[
level
]);
log_level_highlight_end
[
level
]);
}
}
void
logRecord_mt
(
const
char
*
file
,
const
char
*
func
,
int
line
,
int
comp
,
int
level
,
const
char
*
format
,
...
)
void
logRecord_mt
(
const
char
*
file
,
const
char
*
func
,
int
line
,
int
comp
,
int
level
,
const
char
*
format
,
...
)
{
{
char
log_buffer
[
MAX_LOG_TOTAL
];
char
log_buffer
[
MAX_LOG_TOTAL
];
va_list
args
;
va_list
args
;
va_start
(
args
,
format
);
va_start
(
args
,
format
);
log_header
(
log_buffer
,
MAX_LOG_TOTAL
,
comp
,
level
,
format
);
log_header
(
log_buffer
,
MAX_LOG_TOTAL
,
comp
,
level
,
format
);
g_log
->
log_component
[
comp
].
vprint
(
g_log
->
log_component
[
comp
].
stream
,
log_buffer
,
args
);
g_log
->
log_component
[
comp
].
vprint
(
g_log
->
log_component
[
comp
].
stream
,
log_buffer
,
args
);
va_end
(
args
);
va_end
(
args
);
}
}
void
log_dump
(
int
component
,
void
*
buffer
,
int
buffsize
,
int
datatype
,
const
char
*
format
,
...
)
{
void
log_dump
(
int
component
,
void
*
buffer
,
int
buffsize
,
int
datatype
,
const
char
*
format
,
...
)
{
va_list
args
;
va_list
args
;
char
*
wbuf
;
char
*
wbuf
;
switch
(
datatype
)
{
case
LOG_DUMP_DOUBLE
:
wbuf
=
malloc
((
buffsize
*
10
)
+
64
+
MAX_LOG_TOTAL
);
break
;
case
LOG_DUMP_CHAR
:
default:
wbuf
=
malloc
((
buffsize
*
3
)
+
64
+
MAX_LOG_TOTAL
);
break
;
}
switch
(
datatype
)
{
if
(
wbuf
!=
NULL
)
{
case
LOG_DUMP_DOUBLE
:
va_start
(
args
,
format
);
wbuf
=
malloc
((
buffsize
*
10
)
+
64
+
MAX_LOG_TOTAL
);
int
pos
=
log_header
(
wbuf
,
MAX_LOG_TOTAL
,
component
,
OAILOG_INFO
,
""
);
break
;
int
pos2
=
vsprintf
(
wbuf
+
pos
,
format
,
args
);
case
LOG_DUMP_CHAR
:
pos
=
pos
+
pos2
;
default:
va_end
(
args
);
wbuf
=
malloc
((
buffsize
*
3
)
+
64
+
MAX_LOG_TOTAL
);
break
;
for
(
int
i
=
0
;
i
<
buffsize
;
i
++
)
{
switch
(
datatype
)
{
case
LOG_DUMP_DOUBLE
:
pos
=
pos
+
sprintf
(
wbuf
+
pos
,
"%04.4lf "
,
(
double
)((
double
*
)
buffer
)[
i
]);
break
;
case
LOG_DUMP_CHAR
:
default:
pos
=
pos
+
sprintf
(
wbuf
+
pos
,
"%02x "
,
(
unsigned
char
)((
unsigned
char
*
)
buffer
)[
i
]);
break
;
}
}
}
if
(
wbuf
!=
NULL
)
{
va_start
(
args
,
format
);
int
pos
=
log_header
(
wbuf
,
MAX_LOG_TOTAL
,
component
,
OAILOG_INFO
,
""
);
int
pos2
=
vsprintf
(
wbuf
+
pos
,
format
,
args
);
pos
=
pos
+
pos2
;
va_end
(
args
);
for
(
int
i
=
0
;
i
<
buffsize
;
i
++
)
{
switch
(
datatype
)
{
case
LOG_DUMP_DOUBLE
:
pos
=
pos
+
sprintf
(
wbuf
+
pos
,
"%04.4lf "
,
(
double
)((
double
*
)
buffer
)[
i
]);
break
;
case
LOG_DUMP_CHAR
:
default:
pos
=
pos
+
sprintf
(
wbuf
+
pos
,
"%02x "
,
(
unsigned
char
)((
unsigned
char
*
)
buffer
)[
i
]);
break
;
}
}
sprintf
(
wbuf
+
pos
,
"
\n
"
);
sprintf
(
wbuf
+
pos
,
"
\n
"
);
g_log
->
log_component
[
component
].
print
(
g_log
->
log_component
[
component
].
stream
,
wbuf
);
g_log
->
log_component
[
component
].
print
(
g_log
->
log_component
[
component
].
stream
,
wbuf
);
free
(
wbuf
);
free
(
wbuf
);
}
}
}
}
int
set_log
(
int
component
,
int
level
)
int
set_log
(
int
component
,
int
level
)
{
{
/* Checking parameters */
/* Checking parameters */
DevCheck
((
component
>=
MIN_LOG_COMPONENTS
)
&&
(
component
<
MAX_LOG_COMPONENTS
),
DevCheck
((
component
>=
MIN_LOG_COMPONENTS
)
&&
(
component
<
MAX_LOG_COMPONENTS
),
component
,
MIN_LOG_COMPONENTS
,
MAX_LOG_COMPONENTS
);
component
,
MIN_LOG_COMPONENTS
,
MAX_LOG_COMPONENTS
);
...
@@ -537,38 +508,34 @@ int set_log(int component, int level)
...
@@ -537,38 +508,34 @@ int set_log(int component, int level)
OAILOG_ERR
);
OAILOG_ERR
);
if
(
g_log
->
log_component
[
component
].
level
!=
OAILOG_DISABLE
)
if
(
g_log
->
log_component
[
component
].
level
!=
OAILOG_DISABLE
)
g_log
->
log_component
[
component
].
savedlevel
=
g_log
->
log_component
[
component
].
level
;
g_log
->
log_component
[
component
].
savedlevel
=
g_log
->
log_component
[
component
].
level
;
g_log
->
log_component
[
component
].
level
=
level
;
g_log
->
log_component
[
component
].
level
=
level
;
return
0
;
return
0
;
}
}
void
set_glog
(
int
level
)
void
set_glog
(
int
level
)
{
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
set_log
(
c
,
level
);
set_log
(
c
,
level
);
}
}
}
}
void
set_glog_onlinelog
(
int
enable
)
void
set_glog_onlinelog
(
int
enable
)
{
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
if
(
enable
)
{
if
(
enable
)
{
g_log
->
log_component
[
c
].
level
=
g_log
->
log_component
[
c
].
savedlevel
;
g_log
->
log_component
[
c
].
level
=
g_log
->
log_component
[
c
].
savedlevel
;
g_log
->
log_component
[
c
].
vprint
=
vfprintf
;
g_log
->
log_component
[
c
].
vprint
=
vfprintf
;
g_log
->
log_component
[
c
].
print
=
fprintf
;
g_log
->
log_component
[
c
].
print
=
fprintf
;
g_log
->
log_component
[
c
].
stream
=
stdout
;
g_log
->
log_component
[
c
].
stream
=
stdout
;
}
else
{
}
else
{
g_log
->
log_component
[
c
].
level
=
OAILOG_DISABLE
;
g_log
->
log_component
[
c
].
level
=
OAILOG_DISABLE
;
}
}
}
}
}
}
void
set_glog_filelog
(
int
enable
)
void
set_glog_filelog
(
int
enable
)
{
{
static
FILE
*
fptr
;
static
FILE
*
fptr
;
if
(
enable
)
{
if
(
enable
)
{
fptr
=
fopen
(
g_log
->
filelog_name
,
"w"
);
fptr
=
fopen
(
g_log
->
filelog_name
,
"w"
);
...
@@ -581,33 +548,35 @@ static FILE *fptr;
...
@@ -581,33 +548,35 @@ static FILE *fptr;
}
else
{
}
else
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
for
(
int
c
=
0
;
c
<
MAX_LOG_COMPONENTS
;
c
++
)
{
g_log
->
log_component
[
c
].
filelog
=
0
;
g_log
->
log_component
[
c
].
filelog
=
0
;
if
(
fptr
!=
NULL
)
{
if
(
fptr
!=
NULL
)
{
fclose
(
fptr
);
fclose
(
fptr
);
}
}
g_log
->
log_component
[
c
].
stream
=
stdout
;
g_log
->
log_component
[
c
].
stream
=
stdout
;
}
}
}
}
}
}
void
set_component_filelog
(
int
comp
)
void
set_component_filelog
(
int
comp
)
{
{
if
(
g_log
->
log_component
[
comp
].
stream
==
NULL
||
g_log
->
log_component
[
comp
].
stream
==
stdout
)
{
if
(
g_log
->
log_component
[
comp
].
stream
==
NULL
||
g_log
->
log_component
[
comp
].
stream
==
stdout
)
{
g_log
->
log_component
[
comp
].
stream
=
fopen
(
g_log
->
log_component
[
comp
].
filelog_name
,
"w"
);
g_log
->
log_component
[
comp
].
stream
=
fopen
(
g_log
->
log_component
[
comp
].
filelog_name
,
"w"
);
}
}
g_log
->
log_component
[
comp
].
vprint
=
vfprintf
;
g_log
->
log_component
[
comp
].
vprint
=
vfprintf
;
g_log
->
log_component
[
comp
].
print
=
fprintf
;
g_log
->
log_component
[
comp
].
print
=
fprintf
;
g_log
->
log_component
[
comp
].
filelog
=
1
;
g_log
->
log_component
[
comp
].
filelog
=
1
;
}
}
void
close_component_filelog
(
int
comp
)
void
close_component_filelog
(
int
comp
)
{
{
g_log
->
log_component
[
comp
].
filelog
=
0
;
g_log
->
log_component
[
comp
].
filelog
=
0
;
if
(
g_log
->
log_component
[
comp
].
stream
!=
NULL
&&
g_log
->
log_component
[
comp
].
stream
!=
stdout
)
{
if
(
g_log
->
log_component
[
comp
].
stream
!=
NULL
&&
g_log
->
log_component
[
comp
].
stream
!=
stdout
)
{
fclose
(
g_log
->
log_component
[
comp
].
stream
);
fclose
(
g_log
->
log_component
[
comp
].
stream
);
g_log
->
log_component
[
comp
].
stream
=
stdout
;
g_log
->
log_component
[
comp
].
stream
=
stdout
;
}
}
g_log
->
log_component
[
comp
].
vprint
=
vfprintf
;
g_log
->
log_component
[
comp
].
print
=
fprintf
;
g_log
->
log_component
[
comp
].
vprint
=
v
fprintf
;
g_log
->
log_component
[
comp
].
print
=
fprintf
;
}
}
/*
/*
...
@@ -615,8 +584,7 @@ void close_component_filelog(int comp)
...
@@ -615,8 +584,7 @@ void close_component_filelog(int comp)
* with string value NULL
* with string value NULL
*/
*/
/* map a string to an int. Takes a mapping array and a string as arg */
/* map a string to an int. Takes a mapping array and a string as arg */
int
map_str_to_int
(
mapping
*
map
,
const
char
*
str
)
int
map_str_to_int
(
mapping
*
map
,
const
char
*
str
)
{
{
while
(
1
)
{
while
(
1
)
{
if
(
map
->
name
==
NULL
)
{
if
(
map
->
name
==
NULL
)
{
return
(
-
1
);
return
(
-
1
);
...
@@ -631,8 +599,7 @@ int map_str_to_int(mapping *map, const char *str)
...
@@ -631,8 +599,7 @@ int map_str_to_int(mapping *map, const char *str)
}
}
/* map an int to a string. Takes a mapping array and a value */
/* map an int to a string. Takes a mapping array and a value */
char
*
map_int_to_str
(
mapping
*
map
,
int
val
)
char
*
map_int_to_str
(
mapping
*
map
,
int
val
)
{
{
while
(
1
)
{
while
(
1
)
{
if
(
map
->
name
==
NULL
)
{
if
(
map
->
name
==
NULL
)
{
return
NULL
;
return
NULL
;
...
@@ -646,8 +613,7 @@ char *map_int_to_str(mapping *map, int val)
...
@@ -646,8 +613,7 @@ char *map_int_to_str(mapping *map, int val)
}
}
}
}
int
is_newline
(
char
*
str
,
int
size
)
int
is_newline
(
char
*
str
,
int
size
)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
for
(
i
=
0
;
i
<
size
;
i
++
)
{
...
@@ -660,84 +626,65 @@ int is_newline( char *str, int size)
...
@@ -660,84 +626,65 @@ int is_newline( char *str, int size)
return
0
;
return
0
;
}
}
void
logClean
(
void
)
void
logClean
(
void
)
{
{
int
i
;
int
i
;
if
(
isLogInitDone
())
{
if
(
isLogInitDone
())
{
LOG_UI
(
PHY
,
"
\n
"
);
LOG_UI
(
PHY
,
"
\n
"
);
for
(
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
for
(
i
=
MIN_LOG_COMPONENTS
;
i
<
MAX_LOG_COMPONENTS
;
i
++
)
{
close_component_filelog
(
i
);
close_component_filelog
(
i
);
}
}
}
}
}
}
#ifdef LOG_TEST
int
main
(
int
argc
,
char
*
argv
[])
#ifdef LOG_TEST
{
int
main
(
int
argc
,
char
*
argv
[])
{
logInit
();
logInit
();
test_log
();
test_log
();
return
1
;
return
1
;
}
}
int
test_log
(
void
)
int
test_log
(
void
)
{
{
LOG_ENTER
(
MAC
);
// because the default level is DEBUG
LOG_ENTER
(
MAC
);
// because the default level is DEBUG
LOG_I
(
EMU
,
"1 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
EMU
,
"1 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
LOG_D
(
MAC
,
"1 debug MAC
\n
"
);
LOG_D
(
MAC
,
"1 debug MAC
\n
"
);
LOG_W
(
MAC
,
"1 warning MAC
\n
"
);
LOG_W
(
MAC
,
"1 warning MAC
\n
"
);
set_log
(
EMU
,
OAILOG_INFO
);
set_log
(
EMU
,
OAILOG_INFO
);
set_log
(
MAC
,
OAILOG_WARNING
);
set_log
(
MAC
,
OAILOG_WARNING
);
LOG_I
(
EMU
,
"2 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
EMU
,
"2 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
LOG_E
(
MAC
,
"2 error MAC
\n
"
);
LOG_E
(
MAC
,
"2 error MAC
\n
"
);
LOG_D
(
MAC
,
"2 debug MAC
\n
"
);
LOG_D
(
MAC
,
"2 debug MAC
\n
"
);
LOG_W
(
MAC
,
"2 warning MAC
\n
"
);
LOG_W
(
MAC
,
"2 warning MAC
\n
"
);
LOG_I
(
MAC
,
"2 info MAC
\n
"
);
LOG_I
(
MAC
,
"2 info MAC
\n
"
);
set_log
(
MAC
,
OAILOG_NOTICE
);
set_log
(
MAC
,
OAILOG_NOTICE
);
LOG_ENTER
(
MAC
);
LOG_ENTER
(
MAC
);
LOG_I
(
EMU
,
"3 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
EMU
,
"3 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
LOG_D
(
MAC
,
"3 debug MAC
\n
"
);
LOG_D
(
MAC
,
"3 debug MAC
\n
"
);
LOG_W
(
MAC
,
"3 warning MAC
\n
"
);
LOG_W
(
MAC
,
"3 warning MAC
\n
"
);
LOG_I
(
MAC
,
"3 info MAC
\n
"
);
LOG_I
(
MAC
,
"3 info MAC
\n
"
);
set_log
(
MAC
,
LOG_DEBUG
);
set_log
(
MAC
,
LOG_DEBUG
);
set_log
(
EMU
,
LOG_DEBUG
);
set_log
(
EMU
,
LOG_DEBUG
);
LOG_ENTER
(
MAC
);
LOG_ENTER
(
MAC
);
LOG_I
(
EMU
,
"4 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
EMU
,
"4 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
LOG_D
(
MAC
,
"4 debug MAC
\n
"
);
LOG_D
(
MAC
,
"4 debug MAC
\n
"
);
LOG_W
(
MAC
,
"4 warning MAC
\n
"
);
LOG_W
(
MAC
,
"4 warning MAC
\n
"
);
LOG_I
(
MAC
,
"4 info MAC
\n
"
);
LOG_I
(
MAC
,
"4 info MAC
\n
"
);
set_log
(
MAC
,
LOG_DEBUG
);
set_log
(
MAC
,
LOG_DEBUG
);
set_log
(
EMU
,
LOG_DEBUG
);
set_log
(
EMU
,
LOG_DEBUG
);
LOG_I
(
LOG
,
"5 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
LOG
,
"5 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
LOG_D
(
MAC
,
"5 debug MAC
\n
"
);
LOG_D
(
MAC
,
"5 debug MAC
\n
"
);
LOG_W
(
MAC
,
"5 warning MAC
\n
"
);
LOG_W
(
MAC
,
"5 warning MAC
\n
"
);
LOG_I
(
MAC
,
"5 info MAC
\n
"
);
LOG_I
(
MAC
,
"5 info MAC
\n
"
);
set_log
(
MAC
,
LOG_TRACE
);
set_log
(
MAC
,
LOG_TRACE
);
set_log
(
EMU
,
LOG_TRACE
);
set_log
(
EMU
,
LOG_TRACE
);
LOG_ENTER
(
MAC
);
LOG_ENTER
(
MAC
);
LOG_I
(
LOG
,
"6 Starting OAI logs version %s Build date: %s on %s
\n
"
,
LOG_I
(
LOG
,
"6 Starting OAI logs version %s Build date: %s on %s
\n
"
,
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
BUILD_VERSION
,
BUILD_DATE
,
BUILD_HOST
);
...
@@ -745,7 +692,6 @@ int test_log(void)
...
@@ -745,7 +692,6 @@ int test_log(void)
LOG_W
(
MAC
,
"6 warning MAC
\n
"
);
LOG_W
(
MAC
,
"6 warning MAC
\n
"
);
LOG_I
(
MAC
,
"6 info MAC
\n
"
);
LOG_I
(
MAC
,
"6 info MAC
\n
"
);
LOG_EXIT
(
MAC
);
LOG_EXIT
(
MAC
);
return
0
;
return
0
;
}
}
#endif
#endif
common/utils/LOG/log.h
View file @
55732deb
...
@@ -45,11 +45,11 @@
...
@@ -45,11 +45,11 @@
#include <time.h>
#include <time.h>
#include <stdint.h>
#include <stdint.h>
#ifndef __STDC_FORMAT_MACROS
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#endif
#include <inttypes.h>
#include <inttypes.h>
#ifndef _GNU_SOURCE
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#define _GNU_SOURCE
#endif
#endif
#include <pthread.h>
#include <pthread.h>
#include "T.h"
#include "T.h"
...
@@ -126,11 +126,11 @@ extern "C" {
...
@@ -126,11 +126,11 @@ extern "C" {
/** @defgroup macros to identify a debug entity
/** @defgroup macros to identify a debug entity
* @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged
* @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged
* it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro
* it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro
* is used to map a character string name to each debug bit, it allows to set or clear
* is used to map a character string name to each debug bit, it allows to set or clear
* the corresponding bit via the defined name, from the configuration or from the telnet
* the corresponding bit via the defined name, from the configuration or from the telnet
* server.
* server.
* @brief
* @brief
* @{*/
* @{*/
#define DEBUG_PRACH (1<<0)
#define DEBUG_PRACH (1<<0)
#define DEBUG_RU (1<<1)
#define DEBUG_RU (1<<1)
...
@@ -149,22 +149,22 @@ extern "C" {
...
@@ -149,22 +149,22 @@ extern "C" {
#define LOG_MASKMAP_INIT {\
#define LOG_MASKMAP_INIT {\
{"PRACH", DEBUG_PRACH},\
{"PRACH", DEBUG_PRACH},\
{"RU", DEBUG_RU},\
{"RU", DEBUG_RU},\
{"UE_PHYPROC", DEBUG_UE_PHYPROC},\
{"UE_PHYPROC", DEBUG_UE_PHYPROC},\
{"LTEESTIM", DEBUG_LTEESTIM},\
{"LTEESTIM", DEBUG_LTEESTIM},\
{"DLCELLSPEC", DEBUG_DLCELLSPEC},\
{"DLCELLSPEC", DEBUG_DLCELLSPEC},\
{"ULSCH", DEBUG_ULSCH},\
{"ULSCH", DEBUG_ULSCH},\
{"RRC", DEBUG_RRC},\
{"RRC", DEBUG_RRC},\
{"PDCP", DEBUG_PDCP},\
{"PDCP", DEBUG_PDCP},\
{"DFT", DEBUG_DFT},\
{"DFT", DEBUG_DFT},\
{"ASN1", DEBUG_ASN1},\
{"ASN1", DEBUG_ASN1},\
{"CTRLSOCKET", DEBUG_CTRLSOCKET},\
{"CTRLSOCKET", DEBUG_CTRLSOCKET},\
{"SECURITY", DEBUG_SECURITY},\
{"SECURITY", DEBUG_SECURITY},\
{"NAS", DEBUG_NAS},\
{"NAS", DEBUG_NAS},\
{"UE_TIMING", UE_TIMING},\
{"UE_TIMING", UE_TIMING},\
{NULL,-1}\
{NULL,-1}\
}
}
...
@@ -177,46 +177,46 @@ extern "C" {
...
@@ -177,46 +177,46 @@ extern "C" {
typedef
enum
{
typedef
enum
{
MIN_LOG_COMPONENTS
=
0
,
MIN_LOG_COMPONENTS
=
0
,
PHY
=
MIN_LOG_COMPONENTS
,
PHY
=
MIN_LOG_COMPONENTS
,
MAC
,
MAC
,
SIM
,
SIM
,
OCG
,
OCG
,
OMG
,
OMG
,
OPT
,
OPT
,
OTG
,
OTG
,
OTG_LATENCY
,
OTG_LATENCY
,
OTG_LATENCY_BG
,
OTG_LATENCY_BG
,
OTG_GP
,
OTG_GP
,
OTG_GP_BG
,
OTG_GP_BG
,
OTG_JITTER
,
OTG_JITTER
,
RLC
,
RLC
,
PDCP
,
PDCP
,
RRC
,
RRC
,
NAS
,
NAS
,
PERF
,
PERF
,
OIP
,
OIP
,
CLI
,
CLI
,
MSC
,
MSC
,
OCM
,
OCM
,
UDP_
,
UDP_
,
GTPU
,
GTPU
,
SPGW
,
SPGW
,
S1AP
,
S1AP
,
SCTP
,
SCTP
,
HW
,
HW
,
OSA
,
OSA
,
RAL_ENB
,
RAL_ENB
,
RAL_UE
,
RAL_UE
,
ENB_APP
,
ENB_APP
,
FLEXRAN_AGENT
,
FLEXRAN_AGENT
,
TMR
,
TMR
,
USIM
,
USIM
,
LOCALIZE
,
LOCALIZE
,
X2AP
,
X2AP
,
LOADER
,
LOADER
,
ASN
,
ASN
,
MAX_LOG_PREDEF_COMPONENTS
,
MAX_LOG_PREDEF_COMPONENTS
,
}
}
comp_name_t
;
comp_name_t
;
...
@@ -225,42 +225,42 @@ comp_name_t;
...
@@ -225,42 +225,42 @@ comp_name_t;
typedef
struct
{
typedef
struct
{
char
*
name
;
/*!< \brief string name of item */
char
*
name
;
/*!< \brief string name of item */
int
value
;
/*!< \brief integer value of mapping */
int
value
;
/*!< \brief integer value of mapping */
}
mapping
;
}
mapping
;
typedef
int
(
*
log_vprint_func_t
)(
FILE
*
stream
,
const
char
*
format
,
va_list
ap
);
typedef
int
(
*
log_vprint_func_t
)(
FILE
*
stream
,
const
char
*
format
,
va_list
ap
);
typedef
int
(
*
log_print_func_t
)(
FILE
*
stream
,
const
char
*
format
,
...
);
typedef
int
(
*
log_print_func_t
)(
FILE
*
stream
,
const
char
*
format
,
...
);
typedef
struct
{
typedef
struct
{
const
char
*
name
;
const
char
*
name
;
int
level
;
int
level
;
int
savedlevel
;
int
savedlevel
;
int
flag
;
int
flag
;
int
filelog
;
int
filelog
;
char
*
filelog_name
;
char
*
filelog_name
;
FILE
*
stream
;
FILE
*
stream
;
log_vprint_func_t
vprint
;
log_vprint_func_t
vprint
;
log_print_func_t
print
;
log_print_func_t
print
;
/* SR: make the log buffer component relative */
/* SR: make the log buffer component relative */
char
log_buffer
[
MAX_LOG_TOTAL
];
char
log_buffer
[
MAX_LOG_TOTAL
];
}
log_component_t
;
}
log_component_t
;
typedef
struct
{
typedef
struct
{
log_component_t
log_component
[
MAX_LOG_COMPONENTS
];
log_component_t
log_component
[
MAX_LOG_COMPONENTS
];
char
level2string
[
NUM_LOG_LEVEL
];
char
level2string
[
NUM_LOG_LEVEL
];
int
flag
;
int
flag
;
char
*
filelog_name
;
char
*
filelog_name
;
uint64_t
debug_mask
;
uint64_t
debug_mask
;
uint64_t
dump_mask
;
uint64_t
dump_mask
;
}
log_t
;
}
log_t
;
#if defined(ENABLE_ITTI)
#if defined(ENABLE_ITTI)
typedef
enum
log_instance_type_e
{
typedef
enum
log_instance_type_e
{
LOG_INSTANCE_UNKNOWN
,
LOG_INSTANCE_UNKNOWN
,
LOG_INSTANCE_ENB
,
LOG_INSTANCE_ENB
,
LOG_INSTANCE_UE
,
LOG_INSTANCE_UE
,
}
log_instance_type_t
;
}
log_instance_type_t
;
void
log_set_instance_type
(
log_instance_type_t
instance
);
void
log_set_instance_type
(
log_instance_type_t
instance
);
...
@@ -271,9 +271,9 @@ void log_set_instance_type (log_instance_type_t instance);
...
@@ -271,9 +271,9 @@ void log_set_instance_type (log_instance_type_t instance);
log_t
*
g_log
;
log_t
*
g_log
;
#else
#else
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
extern
log_t
*
g_log
;
extern
log_t
*
g_log
;
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
@@ -284,7 +284,7 @@ extern log_t *g_log;
...
@@ -284,7 +284,7 @@ extern log_t *g_log;
int
logInit
(
void
);
int
logInit
(
void
);
int
isLogInitDone
(
void
);
int
isLogInitDone
(
void
);
void
logRecord_mt
(
const
char
*
file
,
const
char
*
func
,
int
line
,
int
comp
,
int
level
,
const
char
*
format
,
...)
__attribute__
((
format
(
printf
,
6
,
7
)));
void
logRecord_mt
(
const
char
*
file
,
const
char
*
func
,
int
line
,
int
comp
,
int
level
,
const
char
*
format
,
...)
__attribute__
((
format
(
printf
,
6
,
7
)));
void
log_dump
(
int
component
,
void
*
buffer
,
int
buffsize
,
int
datatype
,
const
char
*
format
,
...
);
void
log_dump
(
int
component
,
void
*
buffer
,
int
buffsize
,
int
datatype
,
const
char
*
format
,
...
);
int
set_log
(
int
component
,
int
level
);
int
set_log
(
int
component
,
int
level
);
void
set_glog
(
int
level
);
void
set_glog
(
int
level
);
...
@@ -327,22 +327,22 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
...
@@ -327,22 +327,22 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
#define LOG_CONFIG_DUMP_FORMAT "%s_dump"
#define LOG_CONFIG_DUMP_FORMAT "%s_dump"
#define LOG_CONFIG_HELP_OPTIONS " list of comma separated options to enable log module behavior. Available options: \n"\
#define LOG_CONFIG_HELP_OPTIONS " list of comma separated options to enable log module behavior. Available options: \n"\
" nocolor: disable color usage in log messages\n"\
" nocolor: disable color usage in log messages\n"\
" level: add log level indication in log messages\n"\
" level: add log level indication in log messages\n"\
" thread: add threads names in log messages\n"
" thread: add threads names in log messages\n"
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* LOG globalconfiguration parameters
*/
/* LOG globalconfiguration parameters
*/
/* optname help paramflags XXXptr
defXXXval type numelt
*/
/* optname help paramflags XXXptr
defXXXval type numelt
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
#define LOG_GLOBALPARAMS_DESC { \
#define LOG_GLOBALPARAMS_DESC { \
{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0,
strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \
{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0,
strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \
{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0,
iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \
{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0,
iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \
{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0,
strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \
{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0,
strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \
}
}
#define LOG_OPTIONS_IDX 2
#define LOG_OPTIONS_IDX 2
/*----------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------*/
...
@@ -354,23 +354,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
...
@@ -354,23 +354,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
#define LOG_DUMP_DOUBLE 1
#define LOG_DUMP_DOUBLE 1
// debugging macros
// debugging macros
#define LOG_F LOG_I
/* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */
#define LOG_F LOG_I
/* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */
# if T_TRACER
# if T_TRACER
/* per component, level dependant macros */
/* per component, level dependant macros */
# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0)
# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0)
# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0)
# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0)
# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0)
# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0)
# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0)
# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0)
# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0)
# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0)
/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
# define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0)
/* */
# define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0)
/* */
# define nfapi_log(FILE, FNC, LN, COMP, LVL, F...) do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F) ;}} while (0)
/* */
# define nfapi_log(FILE, FNC, LN, COMP, LVL, F...) do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F) ;}} while (0)
/* */
/* bitmask dependant macros, to isolate debugging code */
/* bitmask dependant macros, to isolate debugging code */
# define LOG_DEBUGFLAG(D) (g_log->debug_mask & D)
# define LOG_DEBUGFLAG(D) (g_log->debug_mask & D)
/* bitmask dependant macros, to generate debug file such as matlab file or message dump */
/* bitmask dependant macros, to generate debug file such as matlab file or message dump */
# define LOG_DUMPFLAG(D) (g_log->dump_mask & D)
# define LOG_DUMPFLAG(D) (g_log->dump_mask & D)
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
/* */
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
/* */
/* define variable only used in LOG macro's */
/* define variable only used in LOG macro's */
# define LOG_VAR(A,B) A B
# define LOG_VAR(A,B) A B
# else
/* T_TRACER: remove all debugging and tracing messages, except errors */
# else
/* T_TRACER: remove all debugging and tracing messages, except errors */
# define LOG_I(c, x...)
/* */
# define LOG_I(c, x...)
/* */
...
@@ -380,15 +380,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
...
@@ -380,15 +380,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
# define LOG_T(c, x...)
/* */
# define LOG_T(c, x...)
/* */
# define LOG_DUMPMSG(c, b, s, x...)
/* */
# define LOG_DUMPMSG(c, b, s, x...)
/* */
# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...)
# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...)
# define LOG_DEBUGFLAG(D) ( 0 )
# define LOG_DEBUGFLAG(D) ( 0 )
# define LOG_DUMPFLAG(D) ( 0 )
# define LOG_DUMPFLAG(D) ( 0 )
# define LOG_M(file, vector, data, len, dec, format)
# define LOG_M(file, vector, data, len, dec, format)
# define LOG_VAR(A,B)
# define LOG_VAR(A,B)
# endif
/* T_TRACER */
# endif
/* T_TRACER */
/* avoid warnings for variables only used in LOG macro's but set outside debug section */
/* avoid warnings for variables only used in LOG macro's but set outside debug section */
#define
GCC_NOTUSED
__attribute__((unused))
#define
GCC_NOTUSED
__attribute__((unused))
#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
/* unfiltered macros, usefull for simulators or messages at init time, before log is configured */
/* unfiltered macros, usefull for simulators or messages at init time, before log is configured */
#define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
#define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
...
@@ -420,78 +420,82 @@ static __inline__ uint64_t rdtsc(void) {
...
@@ -420,78 +420,82 @@ static __inline__ uint64_t rdtsc(void) {
extern
double
cpuf
;
extern
double
cpuf
;
static
inline
uint64_t
checkTCPU
(
int
timeout
,
char
*
file
,
int
line
)
{
static
inline
uint64_t
checkTCPU
(
int
timeout
,
char
*
file
,
int
line
)
{
static
uint64_t
__thread
lastCPUTime
=
0
;
static
uint64_t
__thread
lastCPUTime
=
0
;
static
uint64_t
__thread
last
=
0
;
static
uint64_t
__thread
last
=
0
;
uint64_t
cur
=
rdtsc
();
uint64_t
cur
=
rdtsc
();
struct
timespec
CPUt
;
struct
timespec
CPUt
;
clock_gettime
(
CLOCK_THREAD_CPUTIME_ID
,
&
CPUt
);
clock_gettime
(
CLOCK_THREAD_CPUTIME_ID
,
&
CPUt
);
uint64_t
CPUTime
=
CPUt
.
tv_sec
*
1000
*
1000
+
CPUt
.
tv_nsec
/
1000
;
uint64_t
CPUTime
=
CPUt
.
tv_sec
*
1000
*
1000
+
CPUt
.
tv_nsec
/
1000
;
double
microCycles
=
(
double
)(
cpuf
*
1000
);
double
microCycles
=
(
double
)(
cpuf
*
1000
);
int
duration
=
(
int
)((
cur
-
last
)
/
microCycles
);
int
duration
=
(
int
)((
cur
-
last
)
/
microCycles
);
if
(
last
!=
0
&&
duration
>
timeout
)
{
//struct timespec ts;
if
(
last
!=
0
&&
duration
>
timeout
)
{
//clock_gettime(CLOCK_MONOTONIC, &ts);
//struct timespec ts;
printf
(
"%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld
\n
"
,
file
,
line
,
//clock_gettime(CLOCK_MONOTONIC, &ts);
duration
,
timeout
,
(
long
long
)
CPUTime
-
lastCPUTime
);
printf
(
"%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld
\n
"
,
file
,
line
,
}
duration
,
timeout
,
(
long
long
)
CPUTime
-
lastCPUTime
);
last
=
cur
;
}
lastCPUTime
=
CPUTime
;
return
cur
;
last
=
cur
;
lastCPUTime
=
CPUTime
;
return
cur
;
}
}
static
inline
unsigned
long
long
checkT
(
int
timeout
,
char
*
file
,
int
line
)
{
static
inline
unsigned
long
long
checkT
(
int
timeout
,
char
*
file
,
int
line
)
{
static
unsigned
long
long
__thread
last
=
0
;
static
unsigned
long
long
__thread
last
=
0
;
unsigned
long
long
cur
=
rdtsc
();
unsigned
long
long
cur
=
rdtsc
();
int
microCycles
=
(
int
)(
cpuf
*
1000
);
int
microCycles
=
(
int
)(
cpuf
*
1000
);
int
duration
=
(
int
)((
cur
-
last
)
/
microCycles
);
int
duration
=
(
int
)((
cur
-
last
)
/
microCycles
);
if
(
last
!=
0
&&
duration
>
timeout
)
printf
(
"%s:%d lte-ue delay %d (exceed %d)
\n
"
,
file
,
line
,
if
(
last
!=
0
&&
duration
>
timeout
)
duration
,
timeout
);
printf
(
"%s:%d lte-ue delay %d (exceed %d)
\n
"
,
file
,
line
,
last
=
cur
;
duration
,
timeout
);
return
cur
;
last
=
cur
;
return
cur
;
}
}
typedef
struct
m
{
typedef
struct
m
{
uint64_t
iterations
;
uint64_t
iterations
;
uint64_t
sum
;
uint64_t
sum
;
uint64_t
maxArray
[
11
];
uint64_t
maxArray
[
11
];
}
Meas
;
}
Meas
;
static
inline
void
printMeas
(
char
*
txt
,
Meas
*
M
,
int
period
)
{
static
inline
void
printMeas
(
char
*
txt
,
Meas
*
M
,
int
period
)
{
if
(
M
->
iterations
%
period
==
0
)
{
if
(
M
->
iterations
%
period
==
0
)
{
char
txt2
[
512
];
char
txt2
[
512
];
sprintf
(
txt2
,
"%s avg=%"
PRIu64
" iterations=%"
PRIu64
" max=%"
sprintf
(
txt2
,
"%s avg=%"
PRIu64
" iterations=%"
PRIu64
" max=%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
"
\n
"
,
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
":%"
PRIu64
"
\n
"
,
txt
,
txt
,
M
->
sum
/
M
->
iterations
,
M
->
sum
/
M
->
iterations
,
M
->
iterations
,
M
->
iterations
,
M
->
maxArray
[
1
],
M
->
maxArray
[
2
],
M
->
maxArray
[
3
],
M
->
maxArray
[
4
],
M
->
maxArray
[
5
],
M
->
maxArray
[
1
],
M
->
maxArray
[
2
],
M
->
maxArray
[
3
],
M
->
maxArray
[
4
],
M
->
maxArray
[
5
],
M
->
maxArray
[
6
],
M
->
maxArray
[
7
],
M
->
maxArray
[
8
],
M
->
maxArray
[
9
],
M
->
maxArray
[
10
]);
M
->
maxArray
[
6
],
M
->
maxArray
[
7
],
M
->
maxArray
[
8
],
M
->
maxArray
[
9
],
M
->
maxArray
[
10
]);
#if DISABLE_LOG_X
#if DISABLE_LOG_X
printf
(
"%s"
,
txt2
);
printf
(
"%s"
,
txt2
);
#else
#else
LOG_W
(
PHY
,
"%s"
,
txt2
);
LOG_W
(
PHY
,
"%s"
,
txt2
);
#endif
#endif
}
}
}
}
static
inline
int
cmpint
(
const
void
*
a
,
const
void
*
b
)
{
static
inline
int
cmpint
(
const
void
*
a
,
const
void
*
b
)
{
uint64_t
*
aa
=
(
uint64_t
*
)
a
;
uint64_t
*
aa
=
(
uint64_t
*
)
a
;
uint64_t
*
bb
=
(
uint64_t
*
)
b
;
uint64_t
*
bb
=
(
uint64_t
*
)
b
;
return
(
int
)(
*
aa
-*
bb
);
return
(
int
)(
*
aa
-*
bb
);
}
}
static
inline
void
updateTimes
(
uint64_t
start
,
Meas
*
M
,
int
period
,
char
*
txt
)
{
static
inline
void
updateTimes
(
uint64_t
start
,
Meas
*
M
,
int
period
,
char
*
txt
)
{
if
(
start
!=
0
)
{
if
(
start
!=
0
)
{
uint64_t
end
=
rdtsc
();
uint64_t
end
=
rdtsc
();
long
long
diff
=
(
end
-
start
)
/
(
cpuf
*
1000
);
long
long
diff
=
(
end
-
start
)
/
(
cpuf
*
1000
);
M
->
maxArray
[
0
]
=
diff
;
M
->
maxArray
[
0
]
=
diff
;
M
->
sum
+=
diff
;
M
->
sum
+=
diff
;
M
->
iterations
++
;
M
->
iterations
++
;
qsort
(
M
->
maxArray
,
11
,
sizeof
(
uint64_t
),
cmpint
);
qsort
(
M
->
maxArray
,
11
,
sizeof
(
uint64_t
),
cmpint
);
printMeas
(
txt
,
M
,
period
);
printMeas
(
txt
,
M
,
period
);
}
}
}
}
#define check(a) do { checkT(a,__FILE__,__LINE__); } while (0)
#define check(a) do { checkT(a,__FILE__,__LINE__); } while (0)
...
...
common/utils/T/genids.c
View file @
55732deb
...
@@ -8,27 +8,35 @@ char **unique_ids;
...
@@ -8,27 +8,35 @@ char **unique_ids;
int
unique_ids_size
;
int
unique_ids_size
;
int
unique_ids_maxsize
;
int
unique_ids_maxsize
;
int
cmp
(
const
void
*
p1
,
const
void
*
p2
)
int
cmp
(
const
void
*
p1
,
const
void
*
p2
)
{
{
return
strcmp
(
*
(
char
*
const
*
)
p1
,
*
(
char
*
const
*
)
p2
);
return
strcmp
(
*
(
char
*
const
*
)
p1
,
*
(
char
*
const
*
)
p2
);
}
}
/* return 1 if s was not already known, 0 if it was */
/* return 1 if s was not already known, 0 if it was */
int
new_unique_id
(
char
*
s
,
char
*
input_file
)
int
new_unique_id
(
char
*
s
,
char
*
input_file
)
{
{
if
(
unique_ids_size
)
if
(
unique_ids_size
)
if
(
bsearch
(
&
s
,
unique_ids
,
unique_ids_size
,
sizeof
(
char
*
),
cmp
)
!=
NULL
)
{
if
(
bsearch
(
&
s
,
unique_ids
,
unique_ids_size
,
sizeof
(
char
*
),
cmp
)
!=
NULL
)
{
printf
(
"error: ID %s is not unique in %s
\n
"
,
s
,
input_file
);
printf
(
"error: ID %s is not unique in %s
\n
"
,
s
,
input_file
);
return
0
;
return
0
;
}
}
if
(
unique_ids_size
==
unique_ids_maxsize
)
{
if
(
unique_ids_size
==
unique_ids_maxsize
)
{
unique_ids_maxsize
+=
256
;
unique_ids_maxsize
+=
256
;
unique_ids
=
realloc
(
unique_ids
,
unique_ids_maxsize
*
sizeof
(
char
*
));
unique_ids
=
realloc
(
unique_ids
,
unique_ids_maxsize
*
sizeof
(
char
*
));
if
(
unique_ids
==
NULL
)
{
printf
(
"error: out of memory
\n
"
);
abort
();
}
if
(
unique_ids
==
NULL
)
{
printf
(
"error: out of memory
\n
"
);
abort
();
}
}
}
unique_ids
[
unique_ids_size
]
=
strdup
(
s
);
unique_ids
[
unique_ids_size
]
=
strdup
(
s
);
if
(
unique_ids
[
unique_ids_size
]
==
NULL
)
{
printf
(
"error: out of memory
\n
"
);
abort
();
}
if
(
unique_ids
[
unique_ids_size
]
==
NULL
)
{
printf
(
"error: out of memory
\n
"
);
abort
();
}
unique_ids_size
++
;
unique_ids_size
++
;
qsort
(
unique_ids
,
unique_ids_size
,
sizeof
(
char
*
),
cmp
);
qsort
(
unique_ids
,
unique_ids_size
,
sizeof
(
char
*
),
cmp
);
return
1
;
return
1
;
...
@@ -38,14 +46,17 @@ char *bufname;
...
@@ -38,14 +46,17 @@ char *bufname;
int
bufname_size
;
int
bufname_size
;
int
bufname_maxsize
;
int
bufname_maxsize
;
void
putname
(
int
c
)
void
putname
(
int
c
)
{
{
if
(
bufname_size
==
bufname_maxsize
)
{
if
(
bufname_size
==
bufname_maxsize
)
{
bufname_maxsize
+=
256
;
bufname_maxsize
+=
256
;
bufname
=
realloc
(
bufname
,
bufname_maxsize
);
bufname
=
realloc
(
bufname
,
bufname_maxsize
);
if
(
bufname
==
NULL
)
{
printf
(
"error: memory allocation error
\n
"
);
exit
(
1
);
}
if
(
bufname
==
NULL
)
{
printf
(
"error: memory allocation error
\n
"
);
exit
(
1
);
}
}
}
bufname
[
bufname_size
]
=
c
;
bufname
[
bufname_size
]
=
c
;
bufname_size
++
;
bufname_size
++
;
}
}
...
@@ -54,42 +65,54 @@ char *bufvalue;
...
@@ -54,42 +65,54 @@ char *bufvalue;
int
bufvalue_size
;
int
bufvalue_size
;
int
bufvalue_maxsize
;
int
bufvalue_maxsize
;
void
putvalue
(
int
c
)
void
putvalue
(
int
c
)
{
{
if
(
bufvalue_size
==
bufvalue_maxsize
)
{
if
(
bufvalue_size
==
bufvalue_maxsize
)
{
bufvalue_maxsize
+=
256
;
bufvalue_maxsize
+=
256
;
bufvalue
=
realloc
(
bufvalue
,
bufvalue_maxsize
);
bufvalue
=
realloc
(
bufvalue
,
bufvalue_maxsize
);
if
(
bufvalue
==
NULL
)
{
printf
(
"error: memory allocation error
\n
"
);
exit
(
1
);
}
if
(
bufvalue
==
NULL
)
{
printf
(
"error: memory allocation error
\n
"
);
exit
(
1
);
}
}
}
bufvalue
[
bufvalue_size
]
=
c
;
bufvalue
[
bufvalue_size
]
=
c
;
bufvalue_size
++
;
bufvalue_size
++
;
}
}
void
smash_spaces
(
FILE
*
f
)
void
smash_spaces
(
FILE
*
f
)
{
{
int
c
;
int
c
;
while
(
1
)
{
while
(
1
)
{
c
=
fgetc
(
f
);
c
=
fgetc
(
f
);
if
(
isspace
(
c
))
continue
;
if
(
isspace
(
c
))
continue
;
if
(
c
==
' '
)
continue
;
if
(
c
==
' '
)
continue
;
if
(
c
==
'\t'
)
continue
;
if
(
c
==
'\t'
)
continue
;
if
(
c
==
'\n'
)
continue
;
if
(
c
==
'\n'
)
continue
;
if
(
c
==
10
||
c
==
13
)
continue
;
if
(
c
==
10
||
c
==
13
)
continue
;
if
(
c
==
'#'
)
{
if
(
c
==
'#'
)
{
while
(
1
)
{
while
(
1
)
{
c
=
fgetc
(
f
);
c
=
fgetc
(
f
);
if
(
c
==
'\n'
||
c
==
EOF
)
break
;
if
(
c
==
'\n'
||
c
==
EOF
)
break
;
}
}
continue
;
continue
;
}
}
break
;
break
;
}
}
if
(
c
!=
EOF
)
ungetc
(
c
,
f
);
if
(
c
!=
EOF
)
ungetc
(
c
,
f
);
}
}
void
get_line
(
FILE
*
f
,
char
**
name
,
char
**
value
)
void
get_line
(
FILE
*
f
,
char
**
name
,
char
**
value
)
{
{
int
c
;
int
c
;
bufname_size
=
0
;
bufname_size
=
0
;
bufvalue_size
=
0
;
bufvalue_size
=
0
;
...
@@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value)
...
@@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value)
*
value
=
NULL
;
*
value
=
NULL
;
smash_spaces
(
f
);
smash_spaces
(
f
);
c
=
fgetc
(
f
);
c
=
fgetc
(
f
);
while
(
!
(
c
==
'='
||
isspace
(
c
)
||
c
==
EOF
))
{
putname
(
c
);
c
=
fgetc
(
f
);
}
while
(
!
(
c
==
'='
||
isspace
(
c
)
||
c
==
EOF
))
{
putname
(
c
);
c
=
fgetc
(
f
);
}
if
(
c
==
EOF
)
return
;
if
(
c
==
EOF
)
return
;
putname
(
0
);
putname
(
0
);
while
(
!
(
c
==
EOF
||
c
==
'='
))
c
=
fgetc
(
f
);
while
(
!
(
c
==
EOF
||
c
==
'='
))
c
=
fgetc
(
f
);
if
(
c
==
EOF
)
return
;
if
(
c
==
EOF
)
return
;
smash_spaces
(
f
);
smash_spaces
(
f
);
c
=
fgetc
(
f
);
c
=
fgetc
(
f
);
while
(
!
(
c
==
10
||
c
==
13
||
c
==
EOF
))
{
putvalue
(
c
);
c
=
fgetc
(
f
);
}
while
(
!
(
c
==
10
||
c
==
13
||
c
==
EOF
))
{
putvalue
(
c
);
c
=
fgetc
(
f
);
}
putvalue
(
0
);
putvalue
(
0
);
if
(
bufname_size
<=
1
)
return
;
if
(
bufname_size
<=
1
)
return
;
if
(
bufvalue_size
<=
1
)
return
;
if
(
bufvalue_size
<=
1
)
return
;
*
name
=
bufname
;
*
name
=
bufname
;
*
value
=
bufvalue
;
*
value
=
bufvalue
;
}
}
int
main
(
int
n
,
char
**
v
)
int
main
(
int
n
,
char
**
v
)
{
{
FILE
*
in
;
FILE
*
in
;
FILE
*
out
;
FILE
*
out
;
char
*
name
;
char
*
name
;
...
@@ -121,36 +160,54 @@ int main(int n, char **v)
...
@@ -121,36 +160,54 @@ int main(int n, char **v)
char
*
in_name
;
char
*
in_name
;
char
*
out_name
;
char
*
out_name
;
if
(
n
!=
3
)
{
printf
(
"error: gimme <source> <dest>
\n
"
);
exit
(
1
);
}
if
(
n
!=
3
)
{
printf
(
"error: gimme <source> <dest>
\n
"
);
exit
(
1
);
}
n
=
0
;
n
=
0
;
in_name
=
v
[
1
];
in_name
=
v
[
1
];
out_name
=
v
[
2
];
out_name
=
v
[
2
];
in
=
fopen
(
in_name
,
"r"
);
if
(
in
==
NULL
)
{
perror
(
in_name
);
exit
(
1
);
}
in
=
fopen
(
in_name
,
"r"
);
if
(
in
==
NULL
)
{
perror
(
in_name
);
exit
(
1
);
}
out
=
fopen
(
out_name
,
"w"
);
out
=
fopen
(
out_name
,
"w"
);
if
(
out
==
NULL
)
{
perror
(
out_name
);
exit
(
1
);
}
if
(
out
==
NULL
)
{
perror
(
out_name
);
exit
(
1
);
}
fprintf
(
out
,
"/* generated file, do not edit by hand */
\n\n
"
);
fprintf
(
out
,
"/* generated file, do not edit by hand */
\n\n
"
);
while
(
1
)
{
while
(
1
)
{
get_line
(
in
,
&
name
,
&
value
);
get_line
(
in
,
&
name
,
&
value
);
if
(
name
==
NULL
)
break
;
if
(
name
==
NULL
)
break
;
if
(
isspace
(
value
[
strlen
(
value
)
-
1
]))
{
if
(
isspace
(
value
[
strlen
(
value
)
-
1
]))
{
printf
(
"error: bad value '%s' (no space at the end please!)
\n
"
,
value
);
printf
(
"error: bad value '%s' (no space at the end please!)
\n
"
,
value
);
unlink
(
out_name
);
unlink
(
out_name
);
exit
(
1
);
exit
(
1
);
}
}
if
(
!
strcmp
(
name
,
"ID"
))
{
if
(
!
strcmp
(
name
,
"ID"
))
{
if
(
!
new_unique_id
(
value
,
in_name
))
{
unlink
(
out_name
);
exit
(
1
);
}
if
(
!
new_unique_id
(
value
,
in_name
))
{
unlink
(
out_name
);
exit
(
1
);
}
fprintf
(
out
,
"#define T_%s T_ID(%d)
\n
"
,
value
,
n
);
fprintf
(
out
,
"#define T_%s T_ID(%d)
\n
"
,
value
,
n
);
n
++
;
n
++
;
}
}
}
}
fprintf
(
out
,
"#define T_NUMBER_OF_IDS %d
\n
"
,
n
);
fprintf
(
out
,
"#define T_NUMBER_OF_IDS %d
\n
"
,
n
);
fclose
(
in
);
fclose
(
in
);
fclose
(
out
);
fclose
(
out
);
return
0
;
return
0
;
}
}
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