QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Enumerations | Functions
config.h File Reference

Handles configuration for the entire server and exposes a remote-management/monitoring interface. More...

#include "qev.h"

Go to the source code of this file.

Classes

union  qev_cfg_valptr
 Where the values of the options live. More...
 
union  qev_cfg_val
 The default values for the values. More...
 
struct  qev_cfg
 A configuration option that can be parsed in a config file. More...
 

Macros

#define QEV_CFG_GROUP   "quick-event"
 The name of the group quick-event uses in configuration files.
 
#define QEV_CFG_INCLUDE   "include"
 The magic name that causes other config files to be loaded.
 
#define QEV_CFG_LIST_SEPARATOR   ','
 The value used to separate lists in the config file.
 
#define QEV_CFG_WRAP_AT   75
 When generating a config file, wrap long lines at this length.
 

Typedefs

typedef void(* qev_cfg_validator )(const gchar *name, union qev_cfg_val *val, GError **error)
 Validation callback for options. More...
 
typedef void(* qev_cfg_cb )(const gchar *name, union qev_cfg_valptr curr_val, union qev_cfg_val new_val)
 Callback type for after an option has been set / updated, included when it's initialized to its default value. More...
 
typedef void(* qev_cfg_listener_cb )(const gchar *name, const gchar *val)
 Callback for listeners. More...
 

Enumerations

enum  qev_cfg_type {
  QEV_CFG_BOOL, QEV_CFG_INT64, QEV_CFG_UINT64, QEV_CFG_DBL,
  QEV_CFG_STR, QEV_CFG_STRV
}
 Supported option types. More...
 

Functions

void qev_cfg_set_default_file (const gchar *file_pattern)
 Set the default path to look for the config file(s). More...
 
void qev_cfg_add (const gchar *group_name, const struct qev_cfg *opts, const guint opts_len)
 Add config options under the given group. More...
 
void qev_cfg_listen (const gchar *group_name, const qev_cfg_listener_cb cb)
 Receive a callback for every key and value found in group_name. More...
 
void qev_cfg_set (const gchar *group_name, const gchar *name, union qev_cfg_val val, GError **error)
 Dynamically change an option at run time, executing all callbacks, validators, and etc. More...
 
void qev_cfg_validate_port (const gchar *name, union qev_cfg_val *val, GError **error)
 Validating ports is a fairly common task.
 
guint64 qev_cfg_get_max_clients ()
 Gets that maximum number of clients that may be connected.
 
guint64 qev_cfg_get_timeout ()
 Gets the timeout.
 

Detailed Description

Handles configuration for the entire server and exposes a remote-management/monitoring interface.

Command line arguments only allow setting configuration file locations.

Note
All config options are expected to be registered at start up, from the same thread, before qev_run() is called, so none of these functions are thread safe, and once the server is up, you probably shouldn't alter anything.
Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Typedef Documentation

typedef void(* qev_cfg_cb)(const gchar *name, union qev_cfg_valptr curr_val, union qev_cfg_val new_val)

Callback type for after an option has been set / updated, included when it's initialized to its default value.

Note
Only 1 callback will ever be executing at a time, so you don't need to worry about configuration updates stepping on other updates.
Parameters
nameThe name of the config value
curr_valThe current value. If you need to synchronize threads on this value (which is particularly important for strings), feel free to do any necessary locking and and set curr_val to new_val while holing the lock. To set the new value, do something like the following, based on the data type. 1) *curr_val.bool = new_val.bool; 2) *curr_val.dbl = new_val.dbl; 3) *curr_val.i64 = new_val.i64; 4) *curr_val.str = new_val.str; 5) *curr_val.strv = new_val.strv; 6) *curr_val.ui64 = new_val.ui64;
new_valThe value that will be set
typedef void(* qev_cfg_listener_cb)(const gchar *name, const gchar *val)

Callback for listeners.

Note
Only 1 callback will ever be executing at a time, so you don't need to worry threading issues here.
Parameters
nameThe key that was found
valsThe value
typedef void(* qev_cfg_validator)(const gchar *name, union qev_cfg_val *val, GError **error)

Validation callback for options.

Parameters
nameThe name of the config option
typeType of the value
valThe value; the callback may modify this value if it sees fit. Just be sure to free any strings/string vectors that are replaced.
[out]errorWhere the error should be placed; QEV will only see the value as invalid if an error is set, so the callback MUST return a new GError describing the error if the value is invalid. [transfer-full]

Enumeration Type Documentation

Supported option types.

Enumerator
QEV_CFG_BOOL 

A boolean.

QEV_CFG_INT64 

Signed, 64bit integer.

QEV_CFG_UINT64 

Unsigned, 64bit integer.

QEV_CFG_DBL 

A double.

QEV_CFG_STR 

A string.

QEV_CFG_STRV 

A string array.

Function Documentation

void qev_cfg_add ( const gchar *  group_name,
const struct qev_cfg opts,
const guint  opts_len 
)

Add config options under the given group.

If any duplicate configuration options are encountered, a warning is emitted, and life moves on. All options are immediately initialized to their default values when they're encountered, even if a duplicate exists.

Parameters
group_nameThe name of the group where the set of options can be located
optsAn array of options
opts_lenThe number of items in opts
void qev_cfg_listen ( const gchar *  group_name,
const qev_cfg_listener_cb  cb 
)

Receive a callback for every key and value found in group_name.

Callbacks are sent for all values that do not have a more specific configuration set; that is, if an option is qev_cfg_add()ed, then that value will not be given the listener; it will just be set like any other value.

Note
All values given to the callback will be strings.
Only a single listener per group may exist
Parameters
group_nameThe name of the group to get all keys and values for
cbFunction to call when values discovered
void qev_cfg_set ( const gchar *  group_name,
const gchar *  name,
union qev_cfg_val  val,
GError **  error 
)

Dynamically change an option at run time, executing all callbacks, validators, and etc.

Parameters
group_nameThe name of the group the option is part of
nameThe name of the option to update
valThe value that should be set
[out]errorIf you wish, you may ask for the error to be returned here; NULL will cause any errors to be written to the server log. On return, if this value is still NULL, it means no errors were encountered. [transfer-full]
void qev_cfg_set_default_file ( const gchar *  file_pattern)

Set the default path to look for the config file(s).

Parameters
file_patternA globbing pattern to search for config files.