The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ConfigContext class

A base class for remembering configuration values of various types in a hash table with capabilities to go to and from JSON. More...

Collaboration diagram for ConfigContext class:

Macros

#define JSONREPLACES   "\\\"\b\f\n\r\t"
 
#define JSONREPLACEMENTS   "\\\"bfnrt"
 
#define TOKEN_COLON   ':'
 
#define GULP   (void)g_scanner_get_next_token(scan)
 
#define SYNERROR(scan, token, symbol, msg)   {g_warning("In Function %s line %d", __FUNCTION__, __LINE__);g_scanner_unexp_token(scan, token, "keyword", "keyword", symbol, msg, TRUE);}
 

Functions

void assim_slist_free_full (GSList *list, void(*)(gpointer))
 
FSTATIC void _key_free (gpointer vself)
 
ConfigContextconfigcontext_new (gsize objsize)
 Construct a new ConfigContext object - with no values defaulted. More...
 
FSTATIC void _configcontext_finalize (AssimObj *aself)
 Finalize (free) a ConfigContext object. More...
 
FSTATIC gint _configcontext_key_compare (gconstpointer a, gconstpointer b)
 Compare two string keys (for GSList sorting) More...
 
FSTATIC guint _configcontext_keycount (const ConfigContext *cfg)
 Return the number of keys in a ConfigContext object. More...
 
FSTATIC GSList * _configcontext_keys (const ConfigContext *cfg)
 Return a GSList of all the keys in a ConfigContext object. More...
 
FSTATIC enum ConfigValType _configcontext_gettype (const ConfigContext *self, const char *name)
 Return a the type of value associated with a given name. More...
 
FSTATIC ConfigValue_configcontext_getvalue (const ConfigContext *self, const char *name)
 Return a the value structure associated with a given name. More...
 
FSTATIC gint64 _configcontext_getint (const ConfigContext *self, const char *name)
 Get an integer value. More...
 
FSTATIC void _configcontext_setint (ConfigContext *self, const char *name, gint value)
 Set a name to an integer value. More...
 
FSTATIC gboolean _configcontext_getbool (const ConfigContext *self, const char *name)
 Get an boolean value. More...
 
FSTATIC void _configcontext_setbool (ConfigContext *self, const char *name, gint value)
 Set a name to an integer value. More...
 
FSTATIC const char * _configcontext_getstring (const ConfigContext *self, const char *name)
 Return the value of a string name. More...
 
FSTATIC void _configcontext_setstring (ConfigContext *self,const char *name,const char *value)
 Set a name to a string value. More...
 
FSTATIC GSList * _configcontext_getarray (const ConfigContext *, const char *name)
 
FSTATIC void _configcontext_setarray (ConfigContext *, const char *name, GSList *value)
 
FSTATIC NetAddr_configcontext_getaddr (const ConfigContext *self, const char *name)
 Return the NetAddr value of a name. More...
 
FSTATIC void _configcontext_setaddr (ConfigContext *self, const char *name, NetAddr *addr)
 Set the NetAddr value of a name. More...
 
FSTATIC Frame_configcontext_getframe (const ConfigContext *self, const char *name)
 Return the Frame class value of a name. More...
 
FSTATIC void _configcontext_setframe (ConfigContext *self, const char *name, Frame *frame)
 Set the signature frame to the given SignFrame. More...
 
FSTATIC ConfigContext_configcontext_getconfig (const ConfigContext *self, const char *name)
 Return a the a ConfigContext value associated with a given name. More...
 
FSTATIC void _configcontext_setconfig (ConfigContext *self, const char *name, ConfigContext *value)
 Save/Set a ConfigContext value associated with a given name. More...
 
FSTATIC char * _configcontext_getstr (const ConfigContext *self, const char *name)
 Return a string value (toString) associated with a given name. More...
 
FSTATIC ConfigValue_configcontext_value_new (enum ConfigValType t)
 Create a ConfigValue object (containing an object and its type) More...
 
FSTATIC void _configcontext_value_vfinalize (void *vself)
 Finalize (free) a ConfigValue object. More...
 
FSTATIC void _configcontext_value_finalize (AssimObj *aself)
 
FSTATIC char * JSONquotestring (char *s)
 Escape characters in a string according to JSON conventions... More...
 
FSTATIC char * _configcontext_toString (gconstpointer aself)
 Convert a ConfigContext to a printable string (in JSON notation) More...
 
FSTATIC char * _configcontext_elem_toString (ConfigValue *val)
 Convert a ConfigContext element (ConfigValue) to a String. More...
 
FSTATIC GScanner * _configcontext_JSON_GScanner_new (void)
 Create a GScanner object that is set up to scan JSON text. More...
 
ConfigContextconfigcontext_new_JSON_string (const char *jsontext)
 Construct a ConfigContext object from the given JSON string. More...
 
FSTATIC ConfigContext_configcontext_JSON_parse_objandEOF (GScanner *scan)
 Parse complete JSON object followed by EOF. More...
 
FSTATIC ConfigContext_configcontext_JSON_parse_object (GScanner *scan)
 Parse a JSON object. More...
 
FSTATIC ConfigContext_configcontext_JSON_parse_members (GScanner *scan, ConfigContext *cfg)
 Parse a JSON (object) members (a list of "name" : "value" pairs) More...
 
FSTATIC ConfigContext_configcontext_JSON_parse_pair (GScanner *scan, ConfigContext *cfg)
 
FSTATIC ConfigValue_configcontext_JSON_parse_value (GScanner *scan)
 
FSTATIC gboolean _configcontext_JSON_parse_array (GScanner *scan, GSList **retval)
 
typedef struct _ConfigContext ConfigContext
 This is the base ConfigContext class object providing configuration context for our clients, and is managed by our C-Class Management system. More...
 

Detailed Description

A base class for remembering configuration values of various types in a hash table with capabilities to go to and from JSON.

Macro Definition Documentation

#define JSONREPLACEMENTS   "\\\"bfnrt"

Definition at line 535 of file configcontext.c.

Referenced by JSONquotestring().

#define JSONREPLACES   "\\\"\b\f\n\r\t"

Definition at line 534 of file configcontext.c.

Referenced by JSONquotestring().

#define SYNERROR (   scan,
  token,
  symbol,
  msg 
)    {g_warning("In Function %s line %d", __FUNCTION__, __LINE__);g_scanner_unexp_token(scan, token, "keyword", "keyword", symbol, msg, TRUE);}
#define TOKEN_COLON   ':'

Definition at line 710 of file configcontext.c.

Referenced by _configcontext_JSON_parse_pair().

Typedef Documentation

typedef struct _ConfigContext ConfigContext

This is the base ConfigContext class object providing configuration context for our clients, and is managed by our C-Class Management system.

It provides the analog of global variables for remembering configuration defaults, etc, but in a hash table, with capabilities to go to and from JSON.

Definition at line 42 of file configcontext.h.

Function Documentation

FSTATIC char * _configcontext_elem_toString ( ConfigValue val)

Convert a ConfigContext element (ConfigValue) to a String.

Todo:
  • make NetAddrs into things that we can recognize and make back into a NetAddr when we parse the JSON.

Definition at line 591 of file configcontext.c.

References _ConfigValue::addrvalue, _ConfigValue::arrayvalue, _ConfigContext::baseclass, CASTTOCLASS, CFG_ARRAY, CFG_BOOL, CFG_CFGCTX, CFG_EEXIST, CFG_FLOAT, CFG_FRAME, CFG_INT64, CFG_NETADDR, CFG_NULL, CFG_STRING, _ConfigValue::cfgctxvalue, _ConfigValue::floatvalue, FMT_64BIT, _ConfigValue::framevalue, FREE, _ConfigValue::intvalue, JSONquotestring(), _ConfigValue::strvalue, _AssimObj::toString, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by _configcontext_getstr(), and _configcontext_toString().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_finalize ( AssimObj self)

Finalize (free) a ConfigContext object.

Definition at line 160 of file configcontext.c.

References CASTTOCLASS, and FREECLASSOBJ.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC NetAddr * _configcontext_getaddr ( const ConfigContext self,
const char *  name 
)

Return the NetAddr value of a name.

Parameters
[in]selfConfigContext object
[in]nameName to get the NetAddr value of

Definition at line 362 of file configcontext.c.

References _ConfigValue::addrvalue, CASTTOCLASS, CFG_NETADDR, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC GSList * _configcontext_getarray ( const ConfigContext self,
const char *  name 
)

Definition at line 333 of file configcontext.c.

References _ConfigValue::arrayvalue, CASTTOCLASS, CFG_ARRAY, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC gboolean _configcontext_getbool ( const ConfigContext self,
const char *  name 
)

Get an boolean value.

Parameters
[in]selfConfigContext object
[in]nameName to get the associated int value of

Definition at line 273 of file configcontext.c.

References CASTTOCLASS, CFG_BOOL, _ConfigValue::intvalue, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC ConfigContext * _configcontext_getconfig ( const ConfigContext self,
const char *  name 
)

Return a the a ConfigContext value associated with a given name.

Definition at line 427 of file configcontext.c.

References CASTTOCLASS, CFG_CFGCTX, _ConfigValue::cfgctxvalue, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC Frame * _configcontext_getframe ( const ConfigContext self,
const char *  name 
)

Return the Frame class value of a name.

Parameters
[in]selfConfigContext object
[in]nameName to retrieve the Frame class value of

Definition at line 394 of file configcontext.c.

References CASTTOCLASS, CFG_FRAME, _ConfigValue::framevalue, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC gint64 _configcontext_getint ( const ConfigContext self,
const char *  name 
)

Get an integer value.

Parameters
[in]selfConfigContext object
[in]nameName to get the associated int value of

Definition at line 241 of file configcontext.c.

References CASTTOCLASS, CFG_INT64, _ConfigValue::intvalue, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC char * _configcontext_getstr ( const ConfigContext self,
const char *  name 
)

Return a string value (toString) associated with a given name.

Definition at line 455 of file configcontext.c.

References _configcontext_elem_toString().

Here is the call graph for this function:

FSTATIC const char * _configcontext_getstring ( const ConfigContext self,
const char *  name 
)

Return the value of a string name.

Parameters
[in]selfConfigContext object
[in]nameName to get the associated string value of

Definition at line 305 of file configcontext.c.

References CASTTOCLASS, CFG_STRING, _ConfigValue::strvalue, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC enum ConfigValType _configcontext_gettype ( const ConfigContext self,
const char *  name 
)

Return a the type of value associated with a given name.

Definition at line 217 of file configcontext.c.

References CASTTOCLASS, CFG_EEXIST, and _ConfigValue::valtype.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC ConfigValue * _configcontext_getvalue ( const ConfigContext self,
const char *  name 
)

Return a the value structure associated with a given name.

Definition at line 230 of file configcontext.c.

References CASTTOCLASS.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC GScanner * _configcontext_JSON_GScanner_new ( void  )

Create a GScanner object that is set up to scan JSON text.

See JSON web site for details on JSON syntax.

Definition at line 658 of file configcontext.c.

References obsolete_cma::config.

Referenced by configcontext_new_JSON_string().

Here is the caller graph for this function:

FSTATIC gboolean _configcontext_JSON_parse_array ( GScanner *  scan,
GSList **  retval 
)

Definition at line 932 of file configcontext.c.

References _configcontext_JSON_parse_value(), _configcontext_value_vfinalize(), g_slist_free_full, GULP, and SYNERROR.

Referenced by _configcontext_JSON_parse_value().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigContext * _configcontext_JSON_parse_members ( GScanner *  scan,
ConfigContext cfg 
)

Parse a JSON (object) members (a list of "name" : "value" pairs)

Definition at line 777 of file configcontext.c.

References _configcontext_JSON_parse_pair(), and GULP.

Referenced by _configcontext_JSON_parse_object().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigContext * _configcontext_JSON_parse_objandEOF ( GScanner *  scan)

Parse complete JSON object followed by EOF.

Definition at line 731 of file configcontext.c.

References _configcontext_JSON_parse_object(), SYNERROR, and UNREF.

Referenced by configcontext_new_JSON_string().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigContext * _configcontext_JSON_parse_object ( GScanner *  scan)

Parse a JSON object.

Definition at line 744 of file configcontext.c.

References _configcontext_JSON_parse_members(), configcontext_new(), GULP, SYNERROR, and UNREF.

Referenced by _configcontext_JSON_parse_objandEOF(), and _configcontext_JSON_parse_value().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigContext * _configcontext_JSON_parse_pair ( GScanner *  scan,
ConfigContext cfg 
)

Definition at line 792 of file configcontext.c.

References _configcontext_JSON_parse_value(), _ConfigContext::_values, GULP, cma.store::name, SYNERROR, and TOKEN_COLON.

Referenced by _configcontext_JSON_parse_members().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigValue * _configcontext_JSON_parse_value ( GScanner *  scan)
Todo:
recognize NetAddr objects encoded as strings and reconstitute them

FIXME: Need to make the conversion to a NetAddr optional...

Definition at line 835 of file configcontext.c.

References _configcontext_JSON_parse_array(), _configcontext_JSON_parse_object(), _configcontext_value_new(), _ConfigValue::addrvalue, _ConfigValue::arrayvalue, CFG_ARRAY, CFG_BOOL, CFG_CFGCTX, CFG_FLOAT, CFG_INT64, CFG_NETADDR, CFG_NULL, CFG_STRING, _ConfigValue::cfgctxvalue, _ConfigValue::floatvalue, GULP, _ConfigValue::intvalue, netaddr_string_new(), _ConfigValue::strvalue, SYNERROR, and _ConfigValue::u.

Referenced by _configcontext_JSON_parse_array(), and _configcontext_JSON_parse_pair().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC gint _configcontext_key_compare ( gconstpointer  a,
gconstpointer  b 
)

Compare two string keys (for GSList sorting)

Definition at line 173 of file configcontext.c.

Referenced by _configcontext_keys().

Here is the caller graph for this function:

FSTATIC guint _configcontext_keycount ( const ConfigContext cfg)

Return the number of keys in a ConfigContext object.

Definition at line 180 of file configcontext.c.

References _ConfigContext::_values.

Referenced by configcontext_new().

Here is the caller graph for this function:

FSTATIC GSList * _configcontext_keys ( const ConfigContext cfg)

Return a GSList of all the keys in a ConfigContext object.

Definition at line 196 of file configcontext.c.

References _configcontext_key_compare(), and _ConfigContext::_values.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setaddr ( ConfigContext self,
const char *  name,
NetAddr addr 
)

Set the NetAddr value of a name.

Parameters
[in,out]selfConfigContext object
[in]nameName to set to 'addr' (we copy it)
[in,out]addrAddress to set it to (we hold a ref to it)

Definition at line 380 of file configcontext.c.

References _configcontext_value_new(), _ConfigValue::addrvalue, CFG_NETADDR, REF, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setarray ( ConfigContext self,
const char *  name,
GSList *  value 
)
Todo:
WHAT ABOUT OBJECT LIFE??

Definition at line 350 of file configcontext.c.

References _configcontext_value_new(), _ConfigValue::arrayvalue, CFG_ARRAY, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setbool ( ConfigContext self,
const char *  name,
gint  value 
)

Set a name to an integer value.

Parameters
[in,out]selfConfigContext Object
[in]nameName to set the associated int value of
[in]valueInt value to set the 'name' to

Definition at line 292 of file configcontext.c.

References _configcontext_value_new(), CFG_BOOL, _ConfigValue::intvalue, and _ConfigValue::u.

Here is the call graph for this function:

FSTATIC void _configcontext_setconfig ( ConfigContext self,
const char *  name,
ConfigContext value 
)

Save/Set a ConfigContext value associated with a given name.

Definition at line 443 of file configcontext.c.

References _configcontext_value_new(), CFG_CFGCTX, _ConfigValue::cfgctxvalue, REF, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setframe ( ConfigContext self,
const char *  name,
Frame frame 
)

Set the signature frame to the given SignFrame.

Parameters
[in,out]selfConfigContext object
[in]namename to set value of (we copy it)
[in,out]frameFrame class value to set 'name' to (we hold a ref to it)

Definition at line 412 of file configcontext.c.

References _configcontext_value_new(), CFG_FRAME, _ConfigValue::framevalue, REF, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setint ( ConfigContext self,
const char *  name,
gint  value 
)

Set a name to an integer value.

Parameters
[in,out]selfConfigContext Object
[in]nameName to set the associated int value of
[in]valueInt value to set the 'name' to

Definition at line 260 of file configcontext.c.

References _configcontext_value_new(), CFG_INT64, _ConfigValue::intvalue, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_setstring ( ConfigContext self,
const char *  name,
const char *  value 
)

Set a name to a string value.

Parameters
[in,out]selfConfigContext object
[in]nameName to set the string value of (we copy it)
[in]valueValue to set 'name' to (we copy it)

Definition at line 323 of file configcontext.c.

References _configcontext_value_new(), CFG_STRING, _ConfigValue::strvalue, and _ConfigValue::u.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC char * _configcontext_toString ( gconstpointer  aself)

Convert a ConfigContext to a printable string (in JSON notation)

Definition at line 563 of file configcontext.c.

References _configcontext_elem_toString(), and CASTTOCONSTCLASS.

Referenced by configcontext_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_value_finalize ( AssimObj aself)

Definition at line 490 of file configcontext.c.

References _configcontext_value_vfinalize(), CASTTOCLASS, CFG_ARRAY, CFG_CFGCTX, CFG_EEXIST, CFG_FRAME, CFG_NETADDR, CFG_STRING, FREECLASSOBJ, g_slist_free_full, and UNREF.

Referenced by _configcontext_value_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC ConfigValue * _configcontext_value_new ( enum ConfigValType  t)

Create a ConfigValue object (containing an object and its type)

Definition at line 466 of file configcontext.c.

References _configcontext_value_finalize(), _AssimObj::_finalize, assimobj_new(), NEWSUBCLASS, _ConfigValue::u, and _ConfigValue::valtype.

Referenced by _configcontext_JSON_parse_value(), _configcontext_setaddr(), _configcontext_setarray(), _configcontext_setbool(), _configcontext_setconfig(), _configcontext_setframe(), _configcontext_setint(), and _configcontext_setstring().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _configcontext_value_vfinalize ( void *  vself)

Finalize (free) a ConfigValue object.

Definition at line 481 of file configcontext.c.

References CASTTOCLASS, and UNREF.

FSTATIC void _key_free ( gpointer  vself)

Definition at line 114 of file configcontext.c.

Referenced by configcontext_new().

Here is the caller graph for this function:

void assim_slist_free_full ( GSList *  list,
void(*)(gpointer)  datafree 
)

Definition at line 91 of file configcontext.c.

ConfigContext* configcontext_new ( gsize  objsize)

Construct a new ConfigContext object - with no values defaulted.

Parameters
objsizesize of ConfigContext structure (or zero for min size)

Definition at line 123 of file configcontext.c.

References _configcontext_finalize(), _configcontext_getaddr(), _configcontext_getarray(), _configcontext_getbool(), _configcontext_getconfig(), _configcontext_getframe(), _configcontext_getint(), _configcontext_getstring(), _configcontext_gettype(), _configcontext_getvalue(), _configcontext_keycount(), _configcontext_keys(), _configcontext_setaddr(), _configcontext_setarray(), _configcontext_setbool(), _configcontext_setconfig(), _configcontext_setframe(), _configcontext_setint(), _configcontext_setstring(), _configcontext_toString(), _configcontext_value_vfinalize(), _AssimObj::_finalize, _key_free(), _ConfigContext::_values, assimobj_new(), _ConfigContext::getaddr, _ConfigContext::getarray, _ConfigContext::getbool, _ConfigContext::getconfig, _ConfigContext::getframe, _ConfigContext::getint, _ConfigContext::getstring, _ConfigContext::gettype, _ConfigContext::getvalue, _ConfigContext::keycount, _ConfigContext::keys, NEWSUBCLASS, _ConfigContext::setaddr, _ConfigContext::setarray, _ConfigContext::setbool, _ConfigContext::setconfig, _ConfigContext::setframe, _ConfigContext::setint, _ConfigContext::setstring, and _AssimObj::toString.

Referenced by cma.AssimCclasses.pyConfigContext::__init__(), _childprocess_toString(), _configcontext_JSON_parse_object(), _nano_send_rscexitstatus(), main(), and resourceocf_new().

Here is the call graph for this function:

Here is the caller graph for this function:

ConfigContext* configcontext_new_JSON_string ( const char *  jsontext)
FSTATIC char * JSONquotestring ( char *  s)

Escape characters in a string according to JSON conventions...

Definition at line 538 of file configcontext.c.

References JSONREPLACEMENTS, and JSONREPLACES.

Referenced by _configcontext_elem_toString().

Here is the caller graph for this function: