From 154743df86134ba53bc870ba7e25993da304a431 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sat, 18 Oct 2008 21:15:45 +0200 Subject: [PATCH] ucw docs: Section about advanced uses of config Describes custom parsers, reloading and hooks. Still some API documentation needs to be done. --- ucw/doc/conf.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/ucw/doc/conf.txt b/ucw/doc/conf.txt index 6c46a7a4..3044f5c4 100644 --- a/ucw/doc/conf.txt +++ b/ucw/doc/conf.txt @@ -20,6 +20,10 @@ from command line. - <> * <> * <> +- <> + * <> + * <> + * <> - <> * <> * <> @@ -36,6 +40,10 @@ from command line. [[example]] Example ------- +If you want to just load simple configuration, this is the part you +want to read. This simple example should give you the overview. Look +into the <> section to see list of +supported data types, sections, etc. [[ex_cfile]] Let's say you have configuration file with this content and want to @@ -117,6 +125,84 @@ giving you your program's options. See documentation of unix getopt_long() function. +[[deep]] +Getting deeper +-------------- + +Since the configuration system is somehow complicated, this part gives +you a little overview of what you can find and where. + +[[reload]] +Reloading configuration +~~~~~~~~~~~~~~~~~~~~~~~ + +The configuration system allows you to reload configuration at +runtime. The new config changes the values against the default values. +It means, if the default value for variable `A` is `10`, the currently +loaded config sets it to `42` and the new config does not talk about +this variable, `A` will have a value of `10` after a successful load. + +Furthermore, if the loading of a new configuration fails, the current +configuration is preserved. + +All this is done with <>. The load of the +first config creates a journal entry. If you try to load some new +configuration, it is partially rolled back to defaults (the rollback +happens, but instead of removing the journal entry, another journal +entry is added for the rollback). If the loading succeeds, the two +journal entries are removed and a new one, for the new configuration, +is added. If it fails, the first one is replayed and the rollback +entry is removed. + +See <>. + +[[custom_parser]] +Creating custom parsers +~~~~~~~~~~~~~~~~~~~~~~~ + +If you need to parse some data type the configuration system can't +handle, you can write your own parser. But before you start, you +should know few thinks. + +The parser needs to support <>. To accomplish that, +you have to use the <> for memory allocation. +Furthermore, you need to call @cf_journal_block() before you change +the configuration (eg. before you save the parsed value to the destination +variable). You can use <> macro +instead if it is simple variable. + +Now, you need a function with the same signature as +<>. Parse the first parameter (the +string), call @cf_journal_block() on the second parameter and store +the data there. You may want to write a dumper function, with +signature of <> (needed for debug +dumps). + +// TODO Does the config system support storing of configuration? + +Fill in a <> and use the +new data type in your configuration description with +<>. + +[[hooks]] +Hooks +~~~~~ + +The configuration system supports hooks. They are used to initiate the +configuration (if simple default value of variable is not enough) and +to check the sanity of loaded data. + +Each hook is of type <> and you can include +them in configuration description using <> and +<> macros. + +The hooks should follow similar guidelines as custom parsers (well, +init hooks do not need to call @cf_journal_block()) to support +journaling. If you change nothing in the commit hook, you do not need +to care about the journaling either. + +// TODO maybe copier here too? What good is it? + [[conf_h]] ucw/conf.h ---------- -- 2.39.2