1 /** @file config_file.h
2  * Razorback Configuration API
3  */
4 #ifndef RAZORBACK_CONFIG_FILE_H
5 #define RAZORBACK_CONFIG_FILE_H
6 
7 #include <razorback/visibility.h>
8 #include <razorback/types.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #ifdef _MSC_VER
15 typedef DWORD conf_int_t;
16 
17 #else //_MSC_VER
18 #include <libconfig.h>
19 
20 
21 
22 
23 #if (((LIBCONFIG_VER_MAJOR == 1) && (LIBCONFIG_VER_MINOR >= 4)) \
24        || (LIBCONFIG_VER_MAJOR > 1))
25     /* use features present in libconfig 1.4 and later */
26 typedef int conf_int_t;
27 #else
28 typedef long conf_int_t;
29 #endif
30 
31 #endif //_MSC_VER
32 
33 /** Avaliable types to read from the config file.
34  */
35 typedef enum
36 {
37     RZB_CONF_KEY_TYPE_STRING = 5,   ///< A String.
38     RZB_CONF_KEY_TYPE_INT,      ///< A signed int.
39     RZB_CONF_KEY_TYPE_PARSED_STRING,    ///< A string with a callback to turn it into an int.
40     RZB_CONF_KEY_TYPE_UUID,     ///< A UUID in string format.
41     RZB_CONF_KEY_TYPE_BOOL,     ///< A Bool in string format.
42     RZB_CONF_KEY_TYPE_ARRAY,    ///< An array of simple items
43     RZB_CONF_KEY_TYPE_LIST,     ///< An list of complex items
44     RZB_CONF_KEY_TYPE_END       ///< End of block marker.
45 } RZB_CONF_KEY_TYPE_t;
46 
47 /**
48  * Configuration callbacks
49  */
50 typedef struct
51 {
52     bool (*parseString) (const char *, conf_int_t *);   ///< Call back to convert the passed string into an int.
53 } RZBConfCallBack;
54 
55 struct ConfArray
56 {
57     RZB_CONF_KEY_TYPE_t type;
58     void **data;
59     conf_int_t *count;
60     bool (*parseString) (const char *, conf_int_t *);   ///< Call back to convert the passed string into an int.
61 };
62 /**
63  * Configuration file entry definition.
64  */
65 typedef struct
66 {
67     const char *key;            ///< The path to the entry in the config file.
68     RZB_CONF_KEY_TYPE_t type;   ///< The ::RZB_CONF_KEY_TYPE_t value for the type of value to read for the entry.
69     void *dest;                 ///< A pointer to the pointer to the memory to be used to store the value.
70     void *callback;  ///< Callback structure.
71 } RZBConfKey_t;
72 
73 struct ConfList
74 {
75     void **data;
76     conf_int_t *count;
77     RZBConfKey_t *items;
78 };
79 
80 /** Read a component configuration file.
81  * @param *configDir the dir to look in
82  * @param *configFile the file read
83  * @param *config the structure of the file.
84  * @return true on success false on error
85  */
86 SO_PUBLIC extern bool readMyConfig (const char *configDir, const char *configFile,
87                           RZBConfKey_t * config);
88 
89 /** Clean the memory allocated by ::readApiConfig and ::readMyConfig
90  *
91  */
92 SO_PUBLIC extern void rzbConfCleanUp (void);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 #endif // RAZORBACK_CONFIG_FILE_H
98 
99  /** @example read_config.c
100   * The following example shows how to use ::readMyConfig
101   */
102