summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2cd28ec)
raw | patch | inline | side by side (parent: 2cd28ec)
author | Florian Forster <ff@octo.it> | |
Mon, 14 Jun 2010 21:43:42 +0000 (23:43 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 14 Jun 2010 21:43:42 +0000 (23:43 +0200) |
graph_def.c | patch | blob | history |
diff --git a/graph_def.c b/graph_def.c
index 24e66d4ef71621ed130f9060d3c0b83f5f931b7c..36b6747a4d46a9e9b7d6754734ba2e691eb27952 100644 (file)
--- a/graph_def.c
+++ b/graph_def.c
return (0);
} /* }}} int def_config_color */
+static graph_def_t *def_config_get_obj (graph_config_t *cfg, /* {{{ */
+ const oconfig_item_t *ci)
+{
+ graph_ident_t *ident;
+ char *ds_name = NULL;
+ graph_def_t *def;
+ int i;
+
+ ident = gl_graph_get_selector (cfg);
+ if (ident == NULL)
+ {
+ fprintf (stderr, "def_config_get_obj: gl_graph_get_selector failed");
+ return (NULL);
+ }
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child;
+
+#define HANDLE_FIELD(name,field) \
+ else if (strcasecmp (name, child->key) == 0) \
+ def_config_##field (child, ident)
+
+ child = ci->children + i;
+ if (strcasecmp ("DSName", child->key) == 0)
+ graph_config_get_string (child, &ds_name);
+
+ HANDLE_FIELD ("Host", host);
+ HANDLE_FIELD ("Plugin", plugin);
+ HANDLE_FIELD ("PluginInstance", plugin_instance);
+ HANDLE_FIELD ("Type", type);
+ HANDLE_FIELD ("TypeInstance", type_instance);
+
+#undef HANDLE_FIELD
+ }
+
+ def = def_create (cfg, ident, ds_name);
+ if (def == NULL)
+ {
+ fprintf (stderr, "def_config_get_obj: def_create failed\n");
+ ident_destroy (ident);
+ free (ds_name);
+ return (NULL);
+ }
+
+ ident_destroy (ident);
+ free (ds_name);
+
+ return (def);
+} /* }}} graph_def_t *def_config_get_obj */
+
/*
* Public functions
*/
int def_config (graph_config_t *cfg, const oconfig_item_t *ci) /* {{{ */
{
- graph_ident_t *ident;
- char *ds_name = NULL;
- char *legend = NULL;
- uint32_t color = 0x01000000;
graph_def_t *def;
int i;
- ident = gl_graph_get_selector (cfg);
- if (ident == NULL)
- return (ENOMEM);
+ def = def_config_get_obj (cfg, ci);
+ if (def == NULL)
+ return (EINVAL);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child;
-#define HANDLE_FIELD(name,field) \
- else if (strcasecmp (name, child->key) == 0) \
- def_config_##field (child, ident)
-
child = ci->children + i;
- if (strcasecmp ("DSName", child->key) == 0)
- graph_config_get_string (child, &ds_name);
- else if (strcasecmp ("Legend", child->key) == 0)
- graph_config_get_string (child, &legend);
+ if (strcasecmp ("Legend", child->key) == 0)
+ graph_config_get_string (child, &def->legend);
else if (strcasecmp ("Color", child->key) == 0)
- def_config_color (child, &color);
-
- HANDLE_FIELD ("Host", host);
- HANDLE_FIELD ("Plugin", plugin);
- HANDLE_FIELD ("PluginInstance", plugin_instance);
- HANDLE_FIELD ("Type", type);
- HANDLE_FIELD ("TypeInstance", type_instance);
-
-#undef HANDLE_FIELD
- }
-
- def = def_create (cfg, ident, ds_name);
- if (def == NULL)
- {
- fprintf (stderr, "def_config: def_create failed (ds_name = %s)\n",
- (ds_name != NULL) ? ds_name : "(null)");
- ident_destroy (ident);
- return (EINVAL);
+ def_config_color (child, &def->color);
}
- def->legend = legend;
- if (color < 0x01000000)
- def->color = color;
-
- ident_destroy (ident);
- free (ds_name);
-
return (gl_graph_add_def (cfg, def));
} /* }}} int def_config */