summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d14486b)
raw | patch | inline | side by side (parent: d14486b)
author | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 16:53:10 +0000 (17:53 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 16:53:10 +0000 (17:53 +0100) |
index 1ba067892459b7d231a0c7cd872bfa64e44676d0..2003d2f4c062c5d6b643baeeb9353d97770897a7 100644 (file)
#include "action_graph_def_json.h"
#include "common.h"
#include "graph.h"
+#include "graph_instance.h"
#include "graph_list.h"
#include "utils_cgi.h"
int action_graph_def_json (void) /* {{{ */
{
graph_config_t *cfg;
+ graph_instance_t *inst;
yajl_gen_config handler_config;
yajl_gen handler;
if (cfg == NULL)
return (ENOMEM);
+ inst = inst_get_selected (cfg);
+ if (inst == NULL)
+ return (EINVAL);
+
memset (&handler_config, 0, sizeof (handler_config));
handler_config.beautify = 1;
handler_config.indentString = " ";
time_buffer);
printf ("\n");
- status = graph_def_to_json (cfg, handler);
+ status = graph_def_to_json (cfg, inst, handler);
yajl_gen_free (handler);
diff --git a/src/graph.c b/src/graph.c
index deeb05a649aa50a11bec580acde42b63c11e8e1e..713d45f92c2b8c984da9ec309bbdd832e0904697 100644 (file)
--- a/src/graph.c
+++ b/src/graph.c
return (0);
} /* }}} int graph_to_json */
-int graph_def_to_json (const graph_config_t *cfg, /* {{{ */
+int graph_def_to_json (graph_config_t *cfg, /* {{{ */
+ graph_instance_t *inst,
yajl_gen handler)
{
#define yajl_gen_string_cast(h,p,l) \
yajl_gen_bool (handler, cfg->show_zero);
yajl_gen_string_cast (handler, "defs", strlen ("defs"));
- def_to_json (cfg->defs, handler);
+ if (cfg->defs == NULL)
+ {
+ graph_def_t *defs;
+
+ defs = inst_get_default_defs (cfg, inst);
+ def_to_json (defs, handler);
+ def_destroy (defs);
+ }
+ else
+ {
+ def_to_json (cfg->defs, handler);
+ }
yajl_gen_map_close (handler);
diff --git a/src/graph.h b/src/graph.h
index 2873103ba1153f5c105ce0903f8e72080b7b5cec..46964e5e6f0b296f0f5bc03d8a0529cab8a76c11 100644 (file)
--- a/src/graph.h
+++ b/src/graph.h
int graph_compare (graph_config_t *cfg, const graph_ident_t *ident);
int graph_to_json (const graph_config_t *cfg, yajl_gen handler);
-int graph_def_to_json (const graph_config_t *cfg, yajl_gen handler);
+int graph_def_to_json (graph_config_t *cfg,
+ graph_instance_t *inst,
+ yajl_gen handler);
size_t graph_num_instances (graph_config_t *cfg);
diff --git a/src/graph_instance.c b/src/graph_instance.c
index a834950c7517f2c63ca72356ac49fd2a9ac5bd9b..2249cc031b50e5b983ebfd9102150b058010671c 100644 (file)
--- a/src/graph_instance.c
+++ b/src/graph_instance.c
/*
* Private functions
*/
+struct ident_get_default_defs__data_s
+{
+ char **dses;
+ size_t dses_num;
+};
+typedef struct ident_get_default_defs__data_s ident_get_default_defs__data_t;
+
+static int ident_get_default_defs__callback (__attribute__((unused))
+ graph_ident_t *ident,
+ const char *ds_name, void *user_data)
+{
+ ident_get_default_defs__data_t *data = user_data;
+ char **tmp;
+
+ tmp = realloc (data->dses, (data->dses_num + 1) * sizeof (data->dses));
+ if (tmp == NULL)
+ return (ENOMEM);
+ data->dses = tmp;
+
+ data->dses[data->dses_num] = strdup (ds_name);
+ if (data->dses[data->dses_num] == NULL)
+ return (ENOMEM);
+
+ data->dses_num++;
+ return (0);
+} /* }}} int ident_get_default_defs__callback */
+
/* Create one DEF for each data source in the file. Called by
* "inst_get_default_defs" for each file. */
static graph_def_t *ident_get_default_defs (graph_config_t *cfg, /* {{{ */
{
graph_def_t *defs = NULL;
char *file;
- char **dses = NULL;
- size_t dses_num = 0;
+ ident_get_default_defs__data_t ds_data;
int status;
size_t i;
+ ds_data.dses = NULL;
+ ds_data.dses_num = 0;
+
if ((cfg == NULL) || (ident == NULL))
return (def_head);
return (def_head);
}
- status = ds_list_from_rrd_file (file, &dses_num, &dses);
+ status = data_provider_get_ident_ds_names (ident,
+ ident_get_default_defs__callback, &ds_data);
if (status != 0)
{
free (file);
return (def_head);
}
- for (i = 0; i < dses_num; i++)
+ for (i = 0; i < ds_data.dses_num; i++)
{
graph_def_t *def;
- def = def_search (def_head, ident, dses[i]);
+ def = def_search (def_head, ident, ds_data.dses[i]);
if (def != NULL)
continue;
- def = def_create (cfg, ident, dses[i]);
+ def = def_create (cfg, ident, ds_data.dses[i]);
if (def == NULL)
continue;
else
def_append (defs, def);
- free (dses[i]);
+ free (ds_data.dses[i]);
}
- free (dses);
+ free (ds_data.dses);
free (file);
return (defs);
} /* }}} int ident_get_default_defs */
-/* Create one or more DEFs for each file in the graph instance. The number
- * depends on the number of data sources in each of the files. Called from
- * "inst_get_rrdargs" if no DEFs are available from the configuration.
- * */
-static graph_def_t *inst_get_default_defs (graph_config_t *cfg, /* {{{ */
- graph_instance_t *inst)
-{
- graph_def_t *defs = NULL;
- size_t i;
-
- if ((cfg == NULL) || (inst == NULL))
- return (NULL);
-
- for (i = 0; i < inst->files_num; i++)
- {
- graph_def_t *def;
-
- def = ident_get_default_defs (cfg, inst->files[i], defs);
- if (def == NULL)
- continue;
-
- if (defs == NULL)
- defs = def;
- else
- def_append (defs, def);
- }
-
- return (defs);
-} /* }}} graph_def_t *inst_get_default_defs */
-
/* Called with each DEF in turn. Calls "def_get_rrdargs" with every appropriate
* file / DEF pair. */
static int gl_instance_get_rrdargs_cb (graph_def_t *def, void *user_data) /* {{{ */
return (status);
} /* }}} int inst_get_rrdargs */
+/* Create one or more DEFs for each file in the graph instance. The number
+ * depends on the number of data sources in each of the files. Called from
+ * "inst_get_rrdargs" if no DEFs are available from the configuration.
+ * */
+graph_def_t *inst_get_default_defs (graph_config_t *cfg, /* {{{ */
+ graph_instance_t *inst)
+{
+ graph_def_t *defs = NULL;
+ size_t i;
+
+ if ((cfg == NULL) || (inst == NULL))
+ return (NULL);
+
+ for (i = 0; i < inst->files_num; i++)
+ {
+ graph_def_t *def;
+
+ def = ident_get_default_defs (cfg, inst->files[i], defs);
+ if (def == NULL)
+ continue;
+
+ if (defs == NULL)
+ defs = def;
+ else
+ def_append (defs, def);
+ }
+
+ return (defs);
+} /* }}} graph_def_t *inst_get_default_defs */
+
graph_ident_t *inst_get_selector (graph_instance_t *inst) /* {{{ */
{
if (inst == NULL)
diff --git a/src/graph_instance.h b/src/graph_instance.h
index ebf6bc63c75f88611fb54b6ab08fc5c687313771..56858533adb62ce7a297bb4325230354ca735b19 100644 (file)
--- a/src/graph_instance.h
+++ b/src/graph_instance.h
int inst_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst,
rrd_args_t *args);
+graph_def_t *inst_get_default_defs (graph_config_t *cfg,
+ graph_instance_t *inst);
+
/* Returns a copy of the selector which must be freed by the caller. */
graph_ident_t *inst_get_selector (graph_instance_t *inst);