11 #include "graph_list.h"
12 #include "graph_ident.h"
13 #include "graph_def.h"
14 #include "graph_config.h"
16 #include "filesystem.h"
17 #include "utils_params.h"
20 #include <fcgi_stdio.h>
25 struct graph_config_s /* {{{ */
27 graph_ident_t *select;
34 graph_instance_t *instances;
35 }; /* }}} struct graph_config_s */
40 static graph_instance_t *graph_find_instance (graph_config_t *cfg, /* {{{ */
41 const graph_ident_t *ident)
43 if ((cfg == NULL) || (ident == NULL))
46 return (inst_find_matching (cfg->instances, ident));
47 } /* }}} graph_instance_t *graph_find_instance */
52 static graph_ident_t *graph_config_get_selector (const oconfig_item_t *ci) /* {{{ */
56 char *plugin_instance = NULL;
58 char *type_instance = NULL;
62 for (i = 0; i < ci->children_num; i++)
64 oconfig_item_t *child;
66 child = ci->children + i;
68 if (strcasecmp ("Host", child->key) == 0)
69 graph_config_get_string (child, &host);
70 else if (strcasecmp ("Plugin", child->key) == 0)
71 graph_config_get_string (child, &plugin);
72 else if (strcasecmp ("PluginInstance", child->key) == 0)
73 graph_config_get_string (child, &plugin_instance);
74 else if (strcasecmp ("Type", child->key) == 0)
75 graph_config_get_string (child, &type);
76 else if (strcasecmp ("TypeInstance", child->key) == 0)
77 graph_config_get_string (child, &type_instance);
78 /* else: ignore all other directives here. */
81 ret = ident_create (host, plugin, plugin_instance, type, type_instance);
85 free (plugin_instance);
90 } /* }}} int graph_config_get_selector */
95 graph_config_t *graph_create (const graph_ident_t *selector) /* {{{ */
99 cfg = malloc (sizeof (*cfg));
102 memset (cfg, 0, sizeof (*cfg));
104 if (selector != NULL)
105 cfg->select = ident_clone (selector);
110 cfg->vertical_label = NULL;
112 cfg->instances = NULL;
115 } /* }}} int graph_create */
117 void graph_destroy (graph_config_t *cfg) /* {{{ */
122 ident_destroy (cfg->select);
125 free (cfg->vertical_label);
127 def_destroy (cfg->defs);
128 inst_destroy (cfg->instances);
129 } /* }}} void graph_destroy */
131 int graph_config_add (const oconfig_item_t *ci) /* {{{ */
133 graph_ident_t *select;
134 graph_config_t *cfg = NULL;
137 select = graph_config_get_selector (ci);
141 cfg = graph_create (/* selector = */ NULL);
145 cfg->select = select;
147 for (i = 0; i < ci->children_num; i++)
149 oconfig_item_t *child;
151 child = ci->children + i;
153 if (strcasecmp ("Title", child->key) == 0)
154 graph_config_get_string (child, &cfg->title);
155 else if (strcasecmp ("VerticalLabel", child->key) == 0)
156 graph_config_get_string (child, &cfg->vertical_label);
157 else if (strcasecmp ("DEF", child->key) == 0)
158 def_config (cfg, child);
164 } /* }}} graph_config_add */
166 int graph_add_file (graph_config_t *cfg, const graph_ident_t *file) /* {{{ */
168 graph_instance_t *inst;
170 inst = graph_find_instance (cfg, file);
173 inst = inst_create (cfg, file);
177 if (cfg->instances == NULL)
178 cfg->instances = inst;
180 inst_append (cfg->instances, inst);
183 return (inst_add_file (inst, file));
184 } /* }}} int graph_add_file */
186 int graph_get_title (graph_config_t *cfg, /* {{{ */
187 char *buffer, size_t buffer_size)
189 if ((cfg == NULL) || (buffer == NULL) || (buffer_size < 1))
192 if (cfg->title == NULL)
193 cfg->title = ident_to_string (cfg->select);
195 if (cfg->title == NULL)
198 strncpy (buffer, cfg->title, buffer_size);
199 buffer[buffer_size - 1] = 0;
202 } /* }}} int graph_get_title */
204 graph_ident_t *graph_get_selector (graph_config_t *cfg) /* {{{ */
209 return (ident_clone (cfg->select));
210 } /* }}} graph_ident_t *graph_get_selector */
212 graph_instance_t *graph_get_instances (graph_config_t *cfg) /* {{{ */
217 return (cfg->instances);
218 } /* }}} graph_instance_t *graph_get_instances */
220 graph_def_t *graph_get_defs (graph_config_t *cfg) /* {{{ */
226 } /* }}} graph_def_t *graph_get_defs */
228 int graph_add_def (graph_config_t *cfg, graph_def_t *def) /* {{{ */
230 if ((cfg == NULL) || (def == NULL))
233 if (cfg->defs == NULL)
239 return (def_append (cfg->defs, def));
240 } /* }}} int graph_add_def */
242 _Bool graph_matches (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */
244 if ((cfg == NULL) || (ident == NULL))
247 return (ident_matches (cfg->select, ident));
248 } /* }}} _Bool graph_matches */
250 int graph_compare (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */
252 if ((cfg == NULL) || (ident == NULL))
255 return (ident_compare (cfg->select, ident));
256 } /* }}} int graph_compare */
258 int graph_clear_instances (graph_config_t *cfg) /* {{{ */
263 inst_destroy (cfg->instances);
264 cfg->instances = NULL;
267 } /* }}} int graph_clear_instances */
269 /* vim: set sw=2 sts=2 et fdm=marker : */