00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _CONFIG_GENERIC_H
00034 #define _CONFIG_GENERIC_H
00035
00036 #include <stdio.h>
00037 #include <libconfig.h>
00038
00039 #define CONFIG_NO_CHECK 0
00040 #define CONFIG_RANGE_CHECK 1
00041 #define CONFIG_LIST_CHECK 2
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #define CONFIG_SETTING_LOOKUP(config, values, group, member, type_name, type, \
00053 default_val, validitycheck, args...) \
00054 (values)->member = default_val; \
00055 m_config_setting_lookup_##type_name(config, #group, #member, \
00056 &((values)->member), \
00057 validitycheck, args);
00058
00059 #define CONFIG_SETTING_ENTRY(config, values, group, member, type_name, type, \
00060 default_val, validitycheck, args...) \
00061 type member;
00062
00063 #define CONFIG_GROUP_STRUCT(group) \
00064 struct { \
00065 FOREACH_RUNTIME_CONFIG_SETTING(CONFIG_SETTING_ENTRY, group, NULL, NULL) \
00066 }
00067
00068 static inline void
00069 config_setting_print_bool(FILE * stream, char *group, char *member, int val) {
00070 fprintf(stream, "%s.%s = %s\n", group, member, val==1 ? "true": "false");
00071 }
00072
00073 static inline void
00074 config_setting_print_int(FILE * stream, char *group, char *member, int val) {
00075 fprintf(stream, "%s.%s = %d\n", group, member, val);
00076 }
00077
00078 static inline void
00079 config_setting_print_string(FILE * stream, char *group, char *member, char *val) {
00080 fprintf(stream, "%s.%s = %s\n", group, member, val);
00081 }
00082
00083
00084 #define CONFIG_SETTING_PRINT(config, values, group, member, type_name, type, \
00085 default_val, validitycheck, args...) \
00086 config_setting_print_##type_name(__stream, #group, #member, (values)->member);
00087
00088
00089 #define CONFIG_GROUP_PRINT(stream, group, values) \
00090 do { \
00091 FILE *__stream = stream; \
00092 FOREACH_RUNTIME_CONFIG_SETTING(CONFIG_SETTING_PRINT, group, NULL, values) \
00093 } while(0);
00094
00095 int m_config_setting_lookup_string(config_t *cfg, char *group_name, char *member_name, char **value, int validity_check, ...);
00096 int m_config_setting_lookup_int(config_t *cfg, char *group_name, char *member_name, int *value, int validity_check, ...);
00097 int m_config_setting_lookup_bool(config_t *cfg, char *group_name, char *member_name, int *value, int validity_check, ...);
00098
00099 #endif