first skeleton for the config loader
This commit is contained in:
parent
0bd886249b
commit
85e789742f
3 changed files with 282 additions and 2 deletions
|
|
@ -27,7 +27,8 @@ liblumibackend_a_SOURCES = \
|
|||
$(liblumibackend_a_srcdir)/file.c \
|
||||
$(liblumibackend_a_srcdir)/filehandle.c \
|
||||
$(liblumibackend_a_srcdir)/filedescriptor.c \
|
||||
$(liblumibackend_a_srcdir)/filehandlecache.c
|
||||
$(liblumibackend_a_srcdir)/filehandlecache.c \
|
||||
$(liblumibackend_a_srcdir)/config.c
|
||||
|
||||
|
||||
noinst_HEADERS += \
|
||||
|
|
@ -36,5 +37,6 @@ noinst_HEADERS += \
|
|||
$(liblumibackend_a_srcdir)/file.h \
|
||||
$(liblumibackend_a_srcdir)/filehandle.h \
|
||||
$(liblumibackend_a_srcdir)/filedescriptor.h \
|
||||
$(liblumibackend_a_srcdir)/filehandlecache.h
|
||||
$(liblumibackend_a_srcdir)/filehandlecache.h \
|
||||
$(liblumibackend_a_srcdir)/config.h
|
||||
|
||||
|
|
|
|||
123
src/backend/config.c
Normal file
123
src/backend/config.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
config.c - Lumiera configuration system
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
//TODO: Support library includes//
|
||||
|
||||
|
||||
//TODO: Lumiera header includes//
|
||||
#include "backend/config.h"
|
||||
|
||||
//TODO: internal/static forward declarations//
|
||||
|
||||
|
||||
//TODO: System includes//
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
*/
|
||||
|
||||
NOBUG_DEFINE_FLAG_PARENT (config_all, backend);
|
||||
NOBUG_DEFINE_FLAG_PARENT (config, config_all);
|
||||
|
||||
LUMIERA_ERROR_DEFINE (CONFIG_SYNTAX, "Syntax error in configfile");
|
||||
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_init (const char* path)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_destroy()
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_load (const char* file)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_save ()
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_purge (const char* filename)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_get (const char* key, const char** value)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_set (const char* key, const char* value)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_reset(const char* key)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
lumiera_err
|
||||
lumiera_config_info (const char* key, const char** filename, unsigned* line)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
// Local Variables:
|
||||
// mode: C
|
||||
// c-file-style: "gnu"
|
||||
// indent-tabs-mode: nil
|
||||
// End:
|
||||
*/
|
||||
155
src/backend/config.h
Normal file
155
src/backend/config.h
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
config.h - Lumiera configuration system
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef LUMIERA_CONFIG_H
|
||||
#define LUMIERA_CONFIG_H
|
||||
|
||||
//TODO: Support library includes//
|
||||
#include "lib/error.h"
|
||||
|
||||
//TODO: Forward declarations//
|
||||
struct lumiera_config_struct;
|
||||
|
||||
NOBUG_DECLARE_FLAG (config_all);
|
||||
NOBUG_DECLARE_FLAG (config);
|
||||
|
||||
LUMIERA_ERROR_DECLARE (CONFIG_SYNTAX);
|
||||
|
||||
//TODO: Lumiera header includes//
|
||||
|
||||
|
||||
//TODO: System includes//
|
||||
#include <nobug.h>
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TODO documentation, http://www.pipapo.org/pipawiki/Lumiera/ConfigLoader
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Supported high level types: TODO documenting
|
||||
*/
|
||||
/* TODO: add here as 'LUMIERA_CONFIG_TYPE(name, ctype)' the _get/_set prototypes are declared automatically below, you still have to implement them in config.c */
|
||||
#define LUMIERA_CONFIG_TYPES \
|
||||
LUMIERA_CONFIG_TYPE(number, signed long long) \
|
||||
LUMIERA_CONFIG_TYPE(real, long double) \
|
||||
LUMIERA_CONFIG_TYPE(string, const char*) \
|
||||
LUMIERA_CONFIG_TYPE(word, const char*) \
|
||||
LUMIERA_CONFIG_TYPE(bool, int)
|
||||
|
||||
|
||||
// * does only initialize the variables, so that they get valid values, but does not allocate them as they will be allocated before as they are singleton.
|
||||
// * lumiera_config_init (const char* searchpath) searchpath is a buildin-default, can be changed via configure and can be appended and overridden by using a flag, e.g. {{{ --config-path-append="" }}} or {{{ --config-path="" }}}
|
||||
lumiera_err
|
||||
lumiera_config_init (const char* path);
|
||||
|
||||
|
||||
// * frees all space allocated by the ConfigLoader.
|
||||
lumiera_err
|
||||
lumiera_config_destroy();
|
||||
|
||||
|
||||
// * reads '''one''' single configuration file that will include all settings from other files.
|
||||
// * does not read itself but give delegates reading. The actual reading and parsing will be done in configfile object. s.later.
|
||||
lumiera_err
|
||||
lumiera_config_load (const char* file);
|
||||
|
||||
|
||||
//{{{ lumiera_config_save () { LLIST_FOREACH(config_singleton.files, f) { LumieraFile file = (LumieraFile) f; if(lumiera_configfile_isdirty (file)) lumiera_configfile_save(file); } } }}}
|
||||
// * saves all the changed settings to user's configuration files, but recognizes where settings came from and will write them to an appropriate named file. Example: '''changed''' values from ''/usr/local/share/lumiera/plugins/blur.conf'' will be saved into ''~/.lumiera/plugins/blur.conf''
|
||||
// * finds out which files are dirty and which settings have to be written to user's config files.
|
||||
// * does initiate the actual saving procedure by delegating the save to the actual configfile objects, see below.
|
||||
// * empty user configuration files in RAM will be deleted from disk on write.
|
||||
// * checks whether the file has changed since last read, and will print out an error if necessary instead of overriding it without notification.
|
||||
lumiera_err
|
||||
lumiera_config_save ();
|
||||
|
||||
|
||||
// * `lumiera_config_purge(const char* filename)` removes all configs loaded from filename
|
||||
lumiera_err
|
||||
lumiera_config_purge (const char* filename);
|
||||
|
||||
|
||||
// * {{{ lumiera_config_get(...) }}}
|
||||
// * get a value by key
|
||||
// * handles internally everything as string:string key:value pair.
|
||||
// * lowlevel function
|
||||
// * lumiera_config_integer_get (const char* key, int *value) will return integers instead of strings and return 0 if succeeded and -1 if it failed.
|
||||
lumiera_err
|
||||
lumiera_config_get (const char* key, const char** value);
|
||||
|
||||
|
||||
// * {{{ lumiera_config_set(...) }}}
|
||||
// * set a value by key
|
||||
// * handles internally everything as string:string key:value pair.
|
||||
// * lowlevel function
|
||||
// * tag file as dirty
|
||||
// * set will create a new user configuration file if it does not exist yet or will append a line to the existing one in RAM. These files, tagged as 'dirty', will be only written if save() is called.
|
||||
lumiera_err
|
||||
lumiera_config_set (const char* key, const char* value);
|
||||
|
||||
|
||||
|
||||
// * {{{int lumiera_config_TYPE_get(const char* key, TYPE* value, const char* default) }}}
|
||||
// High level config interface for different types.
|
||||
// if default is given (!NULL) then value is set to default in case key was not found or any other error occured.
|
||||
// error code is still set and -1 (fail) is returned in case of an error, but it might be cleared with no ill effects.
|
||||
// NOTE: errors are persistent in our error handler, they must still be cleared, even when ignored.
|
||||
// if default is given then 'KEY_NOT_FOUND' is not a error here, if default is NULL then it is
|
||||
// NOTE2: default values are given as strings, the config loader remembers a given default value and checks if it got changed
|
||||
// when it is _set(). Thus a default value can be supressed when set/written
|
||||
#define LUMIERA_CONFIG_TYPE(name, type) \
|
||||
lumiera_err \
|
||||
lumiera_config_##name##_get (const char* key, type* value, const char* def);
|
||||
LUMIERA_CONFIG_TYPES
|
||||
#undef LUMIERA_CONFIG_TYPE
|
||||
|
||||
|
||||
|
||||
// * {{{ lumiera_config_TYPE_set (const char* key, TYPE*value, const char* fmt) }}}
|
||||
// Highlevel interface for different types, fmt is a printf format specifier for the desired format, when NULL, defaults apply.
|
||||
#define LUMIERA_CONFIG_TYPE(name, type) \
|
||||
lumiera_err \
|
||||
lumiera_config_##name##_set (const char* key, type* value, const char* fmt);
|
||||
LUMIERA_CONFIG_TYPES
|
||||
#undef LUMIERA_CONFIG_TYPE
|
||||
|
||||
|
||||
// * {{{ lumiera_config_reset(...) }}}
|
||||
// * reset a value by key to the system default values, thus removes a user's configuration line.
|
||||
lumiera_err
|
||||
lumiera_config_reset(const char* key);
|
||||
|
||||
|
||||
// * Find exact place of a setting.
|
||||
lumiera_err
|
||||
lumiera_config_info (const char* key, const char** filename, unsigned* line);
|
||||
|
||||
#endif
|
||||
/*
|
||||
// Local Variables:
|
||||
// mode: C
|
||||
// c-file-style: "gnu"
|
||||
// indent-tabs-mode: nil
|
||||
// End:
|
||||
*/
|
||||
Loading…
Reference in a new issue