Tor 0.4.9.0-alpha-dev
Macros | Typedefs | Variables
confdecl.h File Reference

Macros for generating a configuration struct from a list of its individual fields. More...

#include "lib/cc/tokpaste.h"
#include "lib/cc/torint.h"

Go to the source code of this file.

Macros

#define BEGIN_CONF_STRUCT(name)    PASTE(BEGIN_CONF_STRUCT__, CONF_CONTEXT)(name)
 
#define END_CONF_STRUCT(name)    PASTE(END_CONF_STRUCT__, CONF_CONTEXT)(name)
 
#define CONF_VAR(varname, vartype, varflags, initval)    PASTE(CONF_VAR__, CONF_CONTEXT)(varname, vartype, varflags, initval)
 
#define BEGIN_CONF_STRUCT__STRUCT(name)
 
#define END_CONF_STRUCT__STRUCT(name)    };
 
#define CONF_VAR__STRUCT(varname, vartype, varflags, initval)    config_decl_ ## vartype varname;
 
#define BEGIN_CONF_STRUCT__TABLE(structname)
 
#define END_CONF_STRUCT__TABLE(structname)
 
#define CONF_VAR__TABLE(varname, vartype, varflags, initval)
 
#define BEGIN_CONF_STRUCT__LL_TABLE(structname)
 
#define END_CONF_STRUCT__LL_TABLE(structname)
 
#define CONF_VAR__LL_TABLE(varname, vartype, varflags, initval)
 
#define BEGIN_CONF_STRUCT__STUB_TABLE(structname)    static const config_var_t structname##_vars[] = {
 
#define END_CONF_STRUCT__STUB_TABLE(structname)
 
#define CONF_VAR__STUB_TABLE(varname, vartype, varflags, initval)
 

Typedefs

typedef char * config_decl_STRING
 
typedef char * config_decl_FILENAME
 
typedef int config_decl_POSINT
 
typedef uint64_t config_decl_UINT64
 
typedef int config_decl_INT
 
typedef int config_decl_INTERVAL
 
typedef int config_decl_MSEC_INTERVAL
 
typedef uint64_t config_decl_MEMUNIT
 
typedef double config_decl_DOUBLE
 
typedef int config_decl_BOOL
 
typedef int config_decl_AUTOBOOL
 
typedef time_t config_decl_ISOTIME
 
typedef int config_decl_CSV_INTERVAL
 
typedef struct nonexistent_struct * config_decl_LINELIST_S
 

Variables

const struct var_type_def_t STRING_type_defn
 
const struct var_type_def_t FILENAME_type_defn
 
const struct var_type_def_t POSINT_type_defn
 
const struct var_type_def_t UINT64_type_defn
 
const struct var_type_def_t INT_type_defn
 
const struct var_type_def_t INTERVAL_type_defn
 
const struct var_type_def_t MSEC_INTERVAL_type_defn
 
const struct var_type_def_t MEMUNIT_type_defn
 
const struct var_type_def_t DOUBLE_type_defn
 
const struct var_type_def_t BOOL_type_defn
 
const struct var_type_def_t AUTOBOOL_type_defn
 
const struct var_type_def_t ISOTIME_type_defn
 
const struct var_type_def_t CSV_type_defn
 
const struct var_type_def_t CSV_INTERVAL_type_defn
 
const struct var_type_def_t LINELIST_type_defn
 
const struct var_type_def_t LINELIST_V_type_defn
 
const struct var_type_def_t LINELIST_S_type_defn
 
const struct var_type_def_t IGNORE_type_defn
 
const struct var_type_def_t OBSOLETE_type_defn
 

Detailed Description

Macros for generating a configuration struct from a list of its individual fields.

This header defines three important macros: BEGIN_CONF_STRUCT(), END_CONF_STRUCT(), and CONF_VAR(). They're meant to be used together to define a configuration structure and the means for encoding and decoding it.

To use them, make a new header with a name like MOD_options.inc. Start it with a BEGIN_CONF_STRUCT(), then define your variables with CONF_VAR(), then end the header with END_CONF_STRUCT(), as in:

BEGIN_CONF_STRUCT(module_options_t)
CONF_VAR(ModuleIsActive, BOOLEAN, 0, "1")
END_CONF_STRUCT(module_options_t)

Once you've done that, you can use that header to define a configuration structure by saying:

typedef struct module_options_t module_options_t;
#define CONF_CONTEXT STRUCT
#include "MOD_options.inc"
#undef CONF_CONTEXT

And you can define your field definition table by saying:

#define CONF_CONTEXT TABLE
#include "MOD_options.inc"
#undef CONF_CONTEXT

The two above snippets will define a structure called module_options_t with appropriate members, and a table of config_var_t objects called module_options_t_vars[].

For lower-level modules, you can say #define CONF_TABLE LL_TABLE, and get a table definition suitable for use in modules that are at a lower level than lib/confmgt. Note that the types for these tables cannot include any extended types.

Definition in file confdecl.h.

Macro Definition Documentation

◆ BEGIN_CONF_STRUCT

#define BEGIN_CONF_STRUCT (   name)     PASTE(BEGIN_CONF_STRUCT__, CONF_CONTEXT)(name)

Begin the definition of a configuration object called name.

Definition at line 59 of file confdecl.h.

◆ CONF_VAR

#define CONF_VAR (   varname,
  vartype,
  varflags,
  initval 
)     PASTE(CONF_VAR__, CONF_CONTEXT)(varname, vartype, varflags, initval)

Declare a single configuration field with name varname, type vartype, flags varflags, and initial value initval.

Definition at line 70 of file confdecl.h.

◆ END_CONF_STRUCT

#define END_CONF_STRUCT (   name)     PASTE(END_CONF_STRUCT__, CONF_CONTEXT)(name)

End the definition of a configuration object called name.

Definition at line 64 of file confdecl.h.