7 #include "graph_list.h"
10 static graph_list_t *graph_list = NULL;
11 static size_t graph_list_length = 0;
12 static time_t gl_last_update = 0;
14 static int gl_add_copy (graph_list_t *gl) /* {{{ */
22 ptr = realloc (graph_list, sizeof (*graph_list) * (graph_list_length + 1));
27 ptr = graph_list + graph_list_length;
28 memset (ptr, 0, sizeof (*ptr));
31 ptr->plugin_instance = NULL;
33 ptr->type_instance = NULL;
35 #define DUP_OR_BREAK(member) do { \
37 if (gl->member != NULL) \
39 ptr->member = strdup (gl->member); \
40 if (ptr->member == NULL) \
50 DUP_OR_BREAK(plugin_instance);
52 DUP_OR_BREAK(type_instance);
63 free (ptr->plugin_instance);
65 free (ptr->type_instance);
71 } /* }}} int gl_add_copy */
73 static int callback_type (const char *type, void *user_data) /* {{{ */
78 if ((type == NULL) || (user_data == NULL))
82 if ((gl->type != NULL) || (gl->type_instance != NULL))
85 gl->type = strdup (type);
89 gl->type_instance = strchr (gl->type, '-');
90 if (gl->type_instance != NULL)
92 *gl->type_instance = 0;
96 status = gl_add_copy (gl);
100 gl->type_instance = NULL;
103 } /* }}} int callback_type */
105 static int callback_plugin (const char *plugin, void *user_data) /* {{{ */
110 if ((plugin == NULL) || (user_data == NULL))
114 if ((gl->plugin != NULL) || (gl->plugin_instance != NULL))
117 gl->plugin = strdup (plugin);
118 if (gl->plugin == NULL)
121 gl->plugin_instance = strchr (gl->plugin, '-');
122 if (gl->plugin_instance != NULL)
124 *gl->plugin_instance = 0;
125 gl->plugin_instance++;
128 status = foreach_type (gl->host, plugin, callback_type, gl);
132 gl->plugin_instance = NULL;
135 } /* }}} int callback_plugin */
137 static int callback_host (const char *host, void *user_data) /* {{{ */
142 if ((host == NULL) || (user_data == NULL))
146 if (gl->host != NULL)
149 gl->host = strdup (host);
150 if (gl->host == NULL)
153 status = foreach_plugin (host, callback_plugin, gl);
159 } /* }}} int callback_host */
161 int gl_update (void) /* {{{ */
169 if ((gl_last_update + 2) >= now)
172 memset (&gl, 0, sizeof (gl));
175 gl.plugin_instance = NULL;
177 gl.type_instance = NULL;
179 /* TODO: Free old list */
181 status = foreach_host (callback_host, &gl);
183 } /* }}} int gl_update */
185 int gl_foreach (gl_callback callback, void *user_data) /* {{{ */
189 for (i = 0; i < graph_list_length; i++)
193 status = (*callback) (graph_list + i, user_data);
199 } /* }}} int gl_foreach */
201 /* vim: set sw=2 sts=2 et fdm=marker : */