Преглед изворни кода

cfg framework: documentation for cfg_read_var*

- How to read the variables of another module, core, or
the script is documented.
- cfg_read_var() fixed -- it did not allow reading the variables
that had a fixup function.
Miklos Tirpak пре 16 година
родитељ
комит
249df0253d
2 измењених фајлова са 39 додато и 7 уклоњено
  1. 0 7
      cfg/cfg_select.c
  2. 39 0
      doc/cfg.txt

+ 0 - 7
cfg/cfg_select.c

@@ -274,13 +274,6 @@ int read_cfg_var_fixup(char *gname, char *vname, struct cfg_read_handle *read_ha
 		return 0;
 		return 0;
 	}
 	}
 
 
-	if (var->def->on_change_cb) {
-		/* fixup function is defined -- safer to return an error
-		than an incorrect value */
-		LOG(L_ERR, "ERROR: read_cfg_var_fixup(): variable cannot be retrieved\n");
-		return -1;
-	}
-
 	read_handle->group = (void *)group;
 	read_handle->group = (void *)group;
 	read_handle->var = (void *)var;
 	read_handle->var = (void *)var;
 	return 1;
 	return 1;

+ 39 - 0
doc/cfg.txt

@@ -166,6 +166,45 @@ cfg_get(foo, cfg_handle, s)
 cfg_get(foo, cfg_handle, p)
 cfg_get(foo, cfg_handle, p)
 
 
 
 
+It is also possible to access the variables of other modules or the core in two
+different ways:
+
+1) Include the header file of the other module/core that declares the cfg_group_*
+structure and the handle for it. Than use the handle of that module/core to access
+the variable:
+
+cfg_get(bar, cfg_handle_of_bar, j);
+
+2) Access the variables by their group and variable name:
+
+#include "../../cfg/cfg_select.h"
+
+struct cfg_read_handle var_bar_j;
+
+in the module init function:
+static int mod_init(void)
+{
+	if ((read_cfg_var_fixup("bar", "j", &var_bar_j)) < 0)
+		return -1;
+	/* Note that the variable may or may not exist at this point
+	 * depending on the module loading order. The fixup will still
+	 * be successful but the variable cannot be read if it has not been
+	 * declared yet. If the variable will not be declared at all
+	 * SER will fail to start
+	 */
+}
+
+int	j;
+if ((cfg_read_var_int(&var_bar_j, &j)) < 0) { error... }
+
+or similarly,
+str	s;
+if ((cfg_read_var_str(&var_bar_j, &s)) < 0) { error... }
+
+2) is a bit slower than 1) because the first solution returns the pointer directly
+to the variable, but 2) supports also the variables declared in the script that are
+not known at compile time.
+
 3. Using the framework in the core
 3. Using the framework in the core
 ===============================================================================
 ===============================================================================