summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9f1edc0)
raw | patch | inline | side by side (parent: 9f1edc0)
author | Florian Forster <ff@octo.it> | |
Mon, 14 Jun 2010 21:19:56 +0000 (23:19 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 14 Jun 2010 21:19:56 +0000 (23:19 +0200) |
graph_def.c | patch | blob | history | |
graph_def.h | patch | blob | history | |
graph_list.c | patch | blob | history | |
graph_list.h | patch | blob | history |
diff --git a/graph_def.c b/graph_def.c
index 926fde2946f1573fd06a3d1d78e947a78402d399..529b3b19d4a18d680a72dcf4a349ca915ff31e4f 100644 (file)
--- a/graph_def.c
+++ b/graph_def.c
#include <errno.h>
#include "graph_def.h"
+#include "graph_config.h"
#include "common.h"
+#include "oconfig.h"
+
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
/*
* Data structures
graph_ident_t *select;
char *ds_name;
+ char *legend;
uint32_t color;
graph_def_t *next;
/*
* Private functions
*/
+#define DEF_CONFIG_FIELD(field) \
+static int def_config_##field (const oconfig_item_t *ci, graph_ident_t *ident) \
+{ \
+ char *tmp = NULL; \
+ int status = graph_config_get_string (ci, &tmp); \
+ if (status != 0) \
+ return (status); \
+ ident_set_##field (ident, tmp); \
+ free (tmp); \
+ return (0); \
+} /* }}} int def_config_field */
+
+DEF_CONFIG_FIELD (host);
+DEF_CONFIG_FIELD (plugin);
+DEF_CONFIG_FIELD (plugin_instance);
+DEF_CONFIG_FIELD (type);
+DEF_CONFIG_FIELD (type_instance);
+
+#undef DEF_CONFIG_FIELD
/*
* Public functions
return (NULL);
}
memset (ret, 0, sizeof (*ret));
+ ret->legend = NULL;
ret->ds_name = strdup (ds_name);
if (ret->ds_name == NULL)
ident_destroy (selector);
return (ret);
-}; /* }}} graph_def_t *def_create */
+} /* }}} graph_def_t *def_create */
void def_destroy (graph_def_t *def) /* {{{ */
{
def_destroy (next);
} /* }}} void def_destroy */
+int def_config (graph_config_t *cfg, const oconfig_item_t *ci) /* {{{ */
+{
+ graph_ident_t *ident;
+ char *ds_name = NULL;
+ char *legend = NULL;
+ graph_def_t *def;
+ int i;
+
+ ident = gl_graph_get_selector (cfg);
+ if (ident == NULL)
+ return (ENOMEM);
+
+ 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);
+ 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->legend = legend;
+
+ ident_destroy (ident);
+ free (ds_name);
+
+ return (gl_graph_add_def (cfg, def));
+} /* }}} int def_config */
+
int def_append (graph_def_t *head, graph_def_t *def) /* {{{ */
{
graph_def_t *ptr;
/* Graph part */
array_append_format (args, "LINE1:def_%04i_avg#%06"PRIx32":%s",
- index, def->color, def->ds_name);
+ index, def->color,
+ (def->legend != NULL) ? def->legend : def->ds_name);
array_append_format (args, "GPRINT:vdef_%04i_min:%%lg min,", index);
array_append_format (args, "GPRINT:vdef_%04i_avg:%%lg avg,", index);
array_append_format (args, "GPRINT:vdef_%04i_max:%%lg max,", index);
diff --git a/graph_def.h b/graph_def.h
index 3c27ac83b2a05531ed4192ee8d252b836dccb774..3d852c082c71752f0f809da6681fcaa1d526f6ed 100644 (file)
--- a/graph_def.h
+++ b/graph_def.h
#ifndef GRAPH_DEF_H
#define GRAPH_DEF_H 1
-#include "graph_ident.h"
-#include "utils_array.h"
-#include "graph_list.h"
-
struct graph_def_s;
typedef struct graph_def_s graph_def_t;
typedef int (*def_callback_t) (graph_def_t *def,
void *user_data);
+#include "graph_ident.h"
+#include "graph_list.h"
+#include "utils_array.h"
+#include "oconfig.h"
+
graph_def_t *def_create (graph_config_t *cfg, graph_ident_t *ident,
const char *ds_name);
void def_destroy (graph_def_t *def);
+int def_config (graph_config_t *cfg, const oconfig_item_t *ci);
+
int def_append (graph_def_t *head, graph_def_t *def);
graph_def_t *def_search (graph_def_t *head, graph_ident_t *ident,
diff --git a/graph_list.c b/graph_list.c
index c9fbbaba72d72c011bd398520ce5bb0b7a7b8d7b..eff134f350edac10e6f7bc5ba1f532bf713e0334 100644 (file)
--- a/graph_list.c
+++ b/graph_list.c
/*
* Config functions
*/
-static int config_get_string (const oconfig_item_t *ci, /* {{{ */
- char **ret_str)
+static graph_ident_t *graph_config_get_selector (const oconfig_item_t *ci) /* {{{ */
{
- char *tmp;
+ char *host = NULL;
+ char *plugin = NULL;
+ char *plugin_instance = NULL;
+ char *type = NULL;
+ char *type_instance = NULL;
+ graph_ident_t *ret;
+ int i;
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
- return (EINVAL);
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child;
- tmp = strdup (ci->values[0].value.string);
- if (tmp == NULL)
- return (ENOMEM);
+ child = ci->children + i;
- free (*ret_str);
- *ret_str = tmp;
+ if (strcasecmp ("Host", child->key) == 0)
+ graph_config_get_string (child, &host);
+ else if (strcasecmp ("Plugin", child->key) == 0)
+ graph_config_get_string (child, &plugin);
+ else if (strcasecmp ("PluginInstance", child->key) == 0)
+ graph_config_get_string (child, &plugin_instance);
+ else if (strcasecmp ("Type", child->key) == 0)
+ graph_config_get_string (child, &type);
+ else if (strcasecmp ("TypeInstance", child->key) == 0)
+ graph_config_get_string (child, &type_instance);
+ /* else: ignore all other directives here. */
+ } /* for */
- return (0);
-} /* }}} int config_get_string */
+ ret = ident_create (host, plugin, plugin_instance, type, type_instance);
+
+ free (host);
+ free (plugin);
+ free (plugin_instance);
+ free (type);
+ free (type_instance);
+
+ return (ret);
+} /* }}} int graph_config_get_selector */
/*
* Global functions
*/
+
int graph_config_add (const oconfig_item_t *ci) /* {{{ */
{
- char *host = NULL;
- char *plugin = NULL;
- char *plugin_instance = NULL;
- char *type = NULL;
- char *type_instance = NULL;
+ graph_ident_t *select;
graph_config_t *cfg = NULL;
int i;
+ select = graph_config_get_selector (ci);
+ if (select == NULL)
+ return (EINVAL);
+
cfg = graph_create (/* selector = */ NULL);
if (cfg == NULL)
return (ENOMEM);
+ cfg->select = select;
+
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child;
child = ci->children + i;
- if (strcasecmp ("Host", child->key) == 0)
- config_get_string (child, &host);
- else if (strcasecmp ("Plugin", child->key) == 0)
- config_get_string (child, &plugin);
- else if (strcasecmp ("PluginInstance", child->key) == 0)
- config_get_string (child, &plugin_instance);
- else if (strcasecmp ("Type", child->key) == 0)
- config_get_string (child, &type);
- else if (strcasecmp ("TypeInstance", child->key) == 0)
- config_get_string (child, &type_instance);
- else if (strcasecmp ("Title", child->key) == 0)
- config_get_string (child, &cfg->title);
+ if (strcasecmp ("Title", child->key) == 0)
+ graph_config_get_string (child, &cfg->title);
else if (strcasecmp ("VerticalLabel", child->key) == 0)
- config_get_string (child, &cfg->vertical_label);
- /* TODO: DEFs! */
+ graph_config_get_string (child, &cfg->vertical_label);
+ else if (strcasecmp ("DEF", child->key) == 0)
+ def_config (cfg, child);
} /* for */
- cfg->select = ident_create (host, plugin, plugin_instance,
- type, type_instance);
- if (cfg->select == NULL)
- {
- graph_destroy (cfg);
- return (EINVAL);
- }
-
graph_append (&graph_config_staging, cfg);
return (0);
return (ident_clone (cfg->select));
} /* }}} graph_ident_t *gl_graph_get_selector */
+int gl_graph_add_def (graph_config_t *cfg, graph_def_t *def) /* {{{ */
+{
+ if ((cfg == NULL) || (def == NULL))
+ return (EINVAL);
+
+ if (cfg->defs == NULL)
+ {
+ cfg->defs = def;
+ return (0);
+ }
+
+ return (def_append (cfg->defs, def));
+} /* }}} int gl_graph_add_def */
+
+
int gl_instance_get_all (gl_inst_callback callback, /* {{{ */
void *user_data)
{
diff --git a/graph_list.h b/graph_list.h
index 40d35ea08d21780d588793ca3fa16b9a1d0f2c75..89351a981723cb6c266248ea59c49f3a500e2af2 100644 (file)
--- a/graph_list.h
+++ b/graph_list.h
#ifndef GRAPH_LIST_H
#define GRAPH_LIST_H 1
-#include "utils_array.h"
-#include "graph_ident.h"
-#include "oconfig.h"
-
+/*
+ * Data types
+ */
struct graph_instance_s;
typedef struct graph_instance_s graph_instance_t;
typedef int (*gl_inst_callback) (graph_config_t *cfg,
graph_instance_t *inst, void *user_data);
+#include "graph_def.h"
+#include "graph_ident.h"
+#include "utils_array.h"
+#include "oconfig.h"
+
/*
* Functions
*/
graph_ident_t *gl_graph_get_selector (graph_config_t *cfg);
+int gl_graph_add_def (graph_config_t *cfg, graph_def_t *def);
+
int gl_graph_instance_get_all (graph_config_t *cfg,
gl_inst_callback callback, void *user_data);
graph_ident_t *gl_instance_get_selector (graph_instance_t *inst);
-struct graph_list_s
-{
- char *host;
- char *plugin;
- char *plugin_instance;
- char *type;
- char *type_instance;
-};
-typedef struct graph_list_s graph_list_t;
-
-typedef int (*gl_callback) (
- const graph_list_t *, void *user_data);
-
int gl_update (void);
#endif /* GRAPH_LIST_H */