13 graph_ident_t *select;
28 graph_def_t *def_create (graph_config_t *cfg, graph_ident_t *ident, /* {{{ */
31 graph_ident_t *selector;
34 if ((cfg == NULL) || (ident == NULL) || (ds_name == NULL))
37 selector = gl_graph_get_selector (cfg);
41 ret = malloc (sizeof (*ret));
44 ident_destroy (selector);
47 memset (ret, 0, sizeof (*ret));
49 ret->ds_name = strdup (ds_name);
50 if (ret->ds_name == NULL)
52 ident_destroy (selector);
57 ret->color = get_random_color ();
60 ret->select = ident_copy_with_selector (selector, ident,
61 IDENT_FLAG_REPLACE_ALL);
62 if (ret->select == NULL)
64 ident_destroy (selector);
70 ident_destroy (selector);
72 }; /* }}} graph_def_t *def_create */
74 void def_destroy (graph_def_t *def) /* {{{ */
83 ident_destroy (def->select);
90 } /* }}} void def_destroy */
92 int def_append (graph_def_t *head, graph_def_t *def) /* {{{ */
96 if ((head == NULL) || (def == NULL))
100 while (ptr->next != NULL)
106 } /* }}} int def_append */
108 graph_def_t *def_search (graph_def_t *head, graph_ident_t *ident, /* {{{ */
113 if ((head == NULL) || (ident == NULL) || (ds_name == NULL))
116 for (ptr = head; ptr != NULL; ptr = ptr->next)
118 if (!ident_matches (ptr->select, ident))
121 if (strcmp (ptr->ds_name, ds_name) == 0)
126 } /* }}} graph_def_t *def_search */
128 _Bool def_matches (graph_def_t *def, graph_ident_t *ident) /* {{{ */
130 return (ident_matches (def->select, ident));
131 } /* }}} _Bool def_matches */
133 int def_foreach (graph_def_t *def, def_callback_t callback, /* {{{ */
138 if ((def == NULL) || (callback == NULL))
141 for (ptr = def; ptr != NULL; ptr = ptr->next)
145 status = (*callback) (ptr, user_data);
151 } /* }}} int def_foreach */
153 int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
159 if ((def == NULL) || (ident == NULL) || (args == NULL))
162 file = ident_to_file (ident);
165 DEBUG ("gl_ident_get_rrdargs: ident_to_file returned NULL.\n");
169 DEBUG ("gl_ident_get_rrdargs: file = %s;\n", file);
171 index = array_argc (args);
174 array_append_format (args, "DEF:def_%04i_min=%s:%s:MIN",
175 index, file, def->ds_name);
176 array_append_format (args, "DEF:def_%04i_avg=%s:%s:AVERAGE",
177 index, file, def->ds_name);
178 array_append_format (args, "DEF:def_%04i_max=%s:%s:MAX",
179 index, file, def->ds_name);
181 array_append_format (args, "VDEF:vdef_%04i_min=def_%04i_min,MINIMUM",
183 array_append_format (args, "VDEF:vdef_%04i_avg=def_%04i_avg,AVERAGE",
185 array_append_format (args, "VDEF:vdef_%04i_max=def_%04i_max,MAXIMUM",
187 array_append_format (args, "VDEF:vdef_%04i_lst=def_%04i_avg,LAST",
191 array_append_format (args, "LINE1:def_%04i_avg#%06"PRIx32":%s",
192 index, def->color, def->ds_name);
193 array_append_format (args, "GPRINT:vdef_%04i_min:%%lg min,", index);
194 array_append_format (args, "GPRINT:vdef_%04i_avg:%%lg avg,", index);
195 array_append_format (args, "GPRINT:vdef_%04i_max:%%lg max,", index);
196 array_append_format (args, "GPRINT:vdef_%04i_lst:%%lg last\\l", index);
201 } /* }}} int def_get_rrdargs */
203 /* vim: set sw=2 sts=2 et fdm=marker : */