summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d2a2cba)
raw | patch | inline | side by side (parent: d2a2cba)
author | Florian Forster <ff@octo.it> | |
Mon, 14 Jun 2010 15:25:22 +0000 (17:25 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 14 Jun 2010 15:25:22 +0000 (17:25 +0200) |
graph_list.c | patch | blob | history |
diff --git a/graph_list.c b/graph_list.c
index 8c5e7158208f57077e81886f2044d367e68dc090..fc63620f7b5e9f5b36b78a3eb015f67e6736ff7f 100644 (file)
--- a/graph_list.c
+++ b/graph_list.c
#include "graph_list.h"
#include "graph_ident.h"
+#include "graph_def.h"
#include "common.h"
#include "utils_params.h"
#define ANY_TOKEN "/any/"
#define ALL_TOKEN "/all/"
-#define IS_ANY(str) (((str) != NULL) && (strcmp (ANY_TOKEN, (str)) == 0))
-#define IS_ALL(str) (((str) != NULL) && (strcmp (ALL_TOKEN, (str)) == 0))
-
/*
* Data types
*/
graph_instance_t *next;
}; /* }}} struct graph_instance_s */
-struct graph_def_s;
-typedef struct graph_def_s graph_def_t;
-struct graph_def_s /* {{{ */
-{
- graph_ident_t *select;
-
- char *name;
- char *legend;
- double scale;
- _Bool nan_to_zero;
- _Bool draw_area;
- uint32_t color;
-
- graph_def_t *next;
-}; /* }}} struct graph_def_s */
-
struct graph_config_s /* {{{ */
{
graph_ident_t *select;
char *title;
char *vertical_label;
+ graph_def_t *defs;
+
graph_instance_t *instances;
graph_config_t *next;
instance_destroy (next);
} /* }}} void instance_destroy */
-static void graph_destroy (graph_config_t *cfg) /* {{{ */
-{
- graph_config_t *next;
-
- if (cfg == NULL)
- return;
-
- next = cfg->next;
-
- ident_destroy (cfg->select);
-
- free (cfg->title);
- free (cfg->vertical_label);
-
- instance_destroy (cfg->instances);
-
- graph_destroy (next);
-} /* }}} void graph_destroy */
-
/*
* Copy part of an identifier. If the "template" value is ANY_TOKEN, "value" is
* copied and returned. This function is used when creating graph_instance_t
return (0);
} /* }}} int graph_append */
-static int graph_create_from_file (const graph_ident_t *file) /* {{{ */
+static graph_config_t *graph_create (const graph_ident_t *selector) /* {{{ */
{
graph_config_t *cfg;
cfg = malloc (sizeof (*cfg));
if (cfg == NULL)
- return (ENOMEM);
+ return (NULL);
memset (cfg, 0, sizeof (*cfg));
- cfg->select = ident_clone (file);
+ cfg->select = ident_clone (selector);
cfg->title = NULL;
cfg->vertical_label = NULL;
+ cfg->defs = NULL;
cfg->instances = NULL;
cfg->next = NULL;
- graph_append (cfg);
+ return (cfg);
+} /* }}} int graph_create */
+
+static void graph_destroy (graph_config_t *cfg) /* {{{ */
+{
+ graph_config_t *next;
+
+ if (cfg == NULL)
+ return;
+
+ next = cfg->next;
+
+ ident_destroy (cfg->select);
- return (graph_add_file (cfg, file));
-} /* }}} int graph_create_from_file */
+ free (cfg->title);
+ free (cfg->vertical_label);
+
+ def_destroy (cfg->defs);
+ instance_destroy (cfg->instances);
+
+ graph_destroy (next);
+} /* }}} void graph_destroy */
static int register_file (const graph_ident_t *file) /* {{{ */
{
}
if (num_graphs == 0)
- graph_create_from_file (file);
+ {
+ cfg = graph_create (file);
+ graph_append (cfg);
+ graph_add_file (cfg, file);
+ }
return (0);
} /* }}} int register_file */
for (i = 0; i < inst->files_num; i++)
{
+ graph_def_t *def;
int status;
- status = gl_ident_get_rrdargs (cfg, inst, inst->files[i], args);
+ def = def_search (cfg->defs, inst->files[i]);
+ if (def == NULL)
+ {
+ def = def_create (cfg, inst->files[i]);
+ if (def == NULL)
+ return (-1);
+
+ if (cfg->defs == NULL)
+ cfg->defs = def;
+ else
+ def_append (cfg->defs, def);
+ }
+
+ status = def_get_rrdargs (def, inst->files[i], args);
if (status != 0)
return (status);
}