| Mercury Monitor Reference Manual |
|---|
ConfigurationConfiguration — Parsing configuration files and querying configuration data |
#include <monitor/monitor.h> #define MON_CFG_SECTION mon_cfg_section; mon_cfg_node; enum mon_cfg_flags; mon_cfg_iterator; int mon_cfg_parse_file (const char *filename, mon_cfg_node **cfg); void mon_cfg_free (mon_cfg_node *cfg); int mon_cfg_get (const mon_cfg_node *root, const char *key, mon_cfg_node **node); int mon_cfg_get_int (const mon_cfg_node *root, const char *key, int *value); int mon_cfg_get_bool (const mon_cfg_node *root, const char *key, int *value); int mon_cfg_get_double (const mon_cfg_node *root, const char *key, double *value); int mon_cfg_get_string (const mon_cfg_node *root, const char *key, char **value); int mon_cfg_query (const mon_cfg_node *root, const char *key, int *type, mon_simple_val *val); mon_cfg_node* mon_cfg_first (const mon_cfg_node *root, const char *name, mon_cfg_iterator *iter); mon_cfg_node* mon_cfg_next (mon_cfg_iterator *iter); void mon_cfg_end (mon_cfg_iterator *iter); mon_cfg_node* mon_cfg_get_section (const mon_cfg_node *root, const char *name, const char *title); mon_cfg_desc; int mon_cfg_check (const mon_cfg_node *root, const mon_cfg_desc desc[], const char *msg);
#define MON_CFG_SECTION (MON_T_MAX_TYPE + 1) /* Cfg section */
Data type for configuration sections.
typedef struct {
char *title;
GList *nodes;
} mon_cfg_section;
The mon_cfg_section struct contains the contents of a section in the configuration file.
| char *title; | the title of the section. |
| GList *nodes; | list of nodes in the section. |
typedef struct {
int type : 16;
mon_cfg_flags flags : 16;
char *name;
mon_cfg_node *parent;
union
{
mon_cfg_section section;
mon_simple_val value;
};
} mon_cfg_node;
The mon_cfg_node struct contains a node from the configuration.
| int type : 16; | the data type of this node. |
| mon_cfg_flags flags : 16; | one or more of mon_cfg_flags. |
| char *name; | name of the node. |
| mon_cfg_node *parent; | the address of the parent node. |
| mon_cfg_section section; | a mon_cfg_section if this node is a section. |
| mon_simple_val value; | the node's value if this is not a section. |
typedef enum {
MON_CFG_F_CHECKED = (1 << 0),
MON_CFG_F_REQUIRED = (1 << 1),
MON_CFG_F_MULTIPLE = (1 << 2),
MON_CFG_F_REQ_TITLE = (1 << 3)
} mon_cfg_flags;
Flags for checking configuration nodes.
| MON_CFG_F_CHECKED | the node was checked by mon_cfg_check(). |
| MON_CFG_F_REQUIRED | the node is required. |
| MON_CFG_F_MULTIPLE | multiple nodes with the same name might exist. |
| MON_CFG_F_REQ_TITLE | a section title is required. |
typedef struct {
const mon_cfg_node *root;
GList *listptr;
char *name;
} mon_cfg_iterator;
Structure used when iterating through the configuration space.
| const mon_cfg_node *root; | the root node where the iteration has started. |
| GList *listptr; | the current position. |
| char *name; | the name of the configuration node to locate. |
int mon_cfg_parse_file (const char *filename,
mon_cfg_node **cfg);Parse a configuration file.
| filename : | a configuration file name. |
| cfg : | pointer to store the root node of the configuration tree if successful. |
| Returns : | 0 or an error code. |
void mon_cfg_free (mon_cfg_node *cfg);
Free the configuration tree rooted at cfg.
| cfg : | a configuration tree. |
int mon_cfg_get (const mon_cfg_node *root, const char *key, mon_cfg_node **node);
Find a node in a configuration tree.
The key parameter has the syntax
[section [ '[' sectionname ']' ] "::" ]* nodename
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| node : | pointer to store the matching mon_cfg_node if successful. |
| Returns : | 0 if successful or a non-0 error code. |
int mon_cfg_get_int (const mon_cfg_node *root, const char *key, int *value);
Get the value of an integer configuration parameter.
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| value : | the value of the configuration parameter. |
| Returns : | 0 if successful or a non-0 error code. |
int mon_cfg_get_bool (const mon_cfg_node *root, const char *key, int *value);
Get the value of a boolean configuration parameter.
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| value : | the value of the configuration parameter. |
| Returns : | 0 if successful or a non-0 error code. |
int mon_cfg_get_double (const mon_cfg_node *root, const char *key, double *value);
Get the value of a double configuration parameter.
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| value : | the value of the configuration parameter. |
| Returns : | 0 if successful or a non-0 error code. |
int mon_cfg_get_string (const mon_cfg_node *root, const char *key, char **value);
Get the value of a string configuration parameter.
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| value : | the value of the configuration parameter. |
| Returns : | 0 if successful or a non-0 error code. |
int mon_cfg_query (const mon_cfg_node *root, const char *key, int *type, mon_simple_val *val);
Get the value of a configuration parameter.
| root : | the root of a configuration tree. |
| key : | the name of the node to find. |
| type : | pointer to store the type of the matching configuration node if successful. |
| val : | pointer to store the value of the matching configuration node if successful. |
| Returns : | 0 if successful or a non-0 error code. |
mon_cfg_node* mon_cfg_first (const mon_cfg_node *root, const char *name, mon_cfg_iterator *iter);
Get the first occurance of a key in a configuration section.
| root : | a configuration section. |
| name : | the name of the node to find. It must be a single component, section selectors are not allowed. |
| iter : | the internal enumeration state. |
| Returns : | the first node found or NULL if name does not exist. |
mon_cfg_node* mon_cfg_next (mon_cfg_iterator *iter);
Get the next occurance of a key in a configuration section.
| iter : | the internal enumeration state returned by mon_cfg_first(). |
| Returns : | the next node found or NULL if there were no more entries. |
void mon_cfg_end (mon_cfg_iterator *iter);
Free memory allocated to a configuration node enumeration.
| iter : | the internal enumeration state returned by mon_cfg_first(). |
mon_cfg_node* mon_cfg_get_section (const mon_cfg_node *root, const char *name, const char *title);
Get a configuration section.
| root : | the root of a configuration tree. |
| name : | the name of the section. |
| title : | the title of the section. |
| Returns : | a mon_cfg_node. |
typedef struct {
char *name;
char *description;
mon_basic_type type;
mon_cfg_flags flags;
const mon_cfg_desc *link;
} mon_cfg_desc;
Structure to describe the configuration's syntax.
| char *name; | the name of a configuration key. |
| char *description; | the description of the configuration key. |
| mon_basic_type type; | the type of the key. MON_T_UNKNOWN means perform no checking. |
| mon_cfg_flags flags; | one or more mon_cfg_flags. |
| const mon_cfg_desc *link; | if this is a section descriptor (type is MON_CFG_SECTION), link points to the descriptor of the section. |
int mon_cfg_check (const mon_cfg_node *root, const mon_cfg_desc desc[], const char *msg);
Validate a configuration tree against a descriptor.
| root : | the configuration tree to validate. |
| desc : | a mon_cfg_desc descriptor that defines the allowed syntax. |
| msg : | string to use in error messages. |
| Returns : | 0 if the configuration matches the description or an error
code. NoteKeys present in the configuration but not mentioned in desc are not checked. |
| << Buffer Handling | Lightweight Context Switching >> |