From: Florian Forster Date: Wed, 8 Sep 2010 11:33:37 +0000 (+0200) Subject: src/data_provider.[ch]: Move privider handling functions to a central place. X-Git-Tag: v4.0.0~41 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9e7f6711d2cebfec79c8038c51037ba79810323c;p=collection4.git src/data_provider.[ch]: Move privider handling functions to a central place. --- diff --git a/src/data_provider.c b/src/data_provider.c index bf4cf88..e0028f8 100644 --- a/src/data_provider.c +++ b/src/data_provider.c @@ -21,13 +21,52 @@ * Florian octo Forster **/ +#include +#include + #include "data_provider.h" #include "dp_rrdtool.h" +#include +#include + +/* TODO: Turn this into an array for multiple data providers. */ +static data_provider_t *data_provider = NULL; + int data_provider_config (const oconfig_item_t *ci) /* {{{ */ { /* FIXME: Actually determine which data provider to call. */ return (dp_rrdtool_config (ci)); } /* }}} int data_provider_config */ +int data_provider_register (const char *name, data_provider_t *p) /* {{{ */ +{ + fprintf (stderr, "data_provider_register (name = %s, ptr = %p)\n", + name, (void *) p); + + if (data_provider == NULL) + data_provider = malloc (sizeof (*data_provider)); + if (data_provider == NULL) + return (ENOMEM); + + *data_provider = *p; + + return (0); +} /* }}} int data_provider_register */ + +int data_provider_get_idents (dp_get_idents_callback callback, /* {{{ */ + void *user_data) +{ + int status; + + if (data_provider == NULL) + return (EINVAL); + + /* TODO: Iterate over all data providers */ + status = data_provider->get_idents (data_provider->private_data, + callback, user_data); + + return (status); +} /* }}} int data_provider_get_idents */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/data_provider.h b/src/data_provider.h index 6dbcd1e..054c0a9 100644 --- a/src/data_provider.h +++ b/src/data_provider.h @@ -66,5 +66,8 @@ typedef struct data_provider_s data_provider_t; int data_provider_config (const oconfig_item_t *ci); +int data_provider_register (const char *name, data_provider_t *p); +int data_provider_get_idents (dp_get_idents_callback callback, void *user_data); + #endif /* DATA_PROVIDER_H */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/dp_rrdtool.c b/src/dp_rrdtool.c index b72e512..6db0205 100644 --- a/src/dp_rrdtool.c +++ b/src/dp_rrdtool.c @@ -23,7 +23,6 @@ #include "graph_types.h" #include "graph_ident.h" -#include "graph_list.h" #include "data_provider.h" #include "filesystem.h" #include "oconfig.h" @@ -371,7 +370,7 @@ int dp_rrdtool_config (const oconfig_item_t *ci) dp.private_data = conf; - gl_register_data_provider ("rrdtool", &dp); + data_provider_register ("rrdtool", &dp); return (0); } /* }}} int dp_rrdtool_config */ diff --git a/src/graph_list.c b/src/graph_list.c index ecd873b..d767ef9 100644 --- a/src/graph_list.c +++ b/src/graph_list.c @@ -38,6 +38,7 @@ #include "graph_list.h" #include "common.h" +#include "data_provider.h" #include "filesystem.h" #include "graph.h" #include "graph_config.h" @@ -75,9 +76,6 @@ static size_t host_list_len = 0; static time_t gl_last_update = 0; -/* TODO: Turn this into an array for multiple data providers. */ -static data_provider_t *data_provider = NULL; - /* * Private functions */ @@ -783,21 +781,6 @@ int gl_config_submit (void) /* {{{ */ return (0); } /* }}} int graph_config_submit */ -int gl_register_data_provider (const char *name, data_provider_t *p) /* {{{ */ -{ - fprintf (stderr, "gl_register_data_provider (name = %s, ptr = %p)\n", - name, (void *) p); - - if (data_provider == NULL) - data_provider = malloc (sizeof (*data_provider)); - if (data_provider == NULL) - return (ENOMEM); - - *data_provider = *p; - - return (0); -} /* }}} int gl_register_data_provider */ - int gl_graph_get_all (_Bool include_dynamic, /* {{{ */ graph_callback_t callback, void *user_data) { @@ -1105,20 +1088,12 @@ int gl_update (_Bool request_served) /* {{{ */ if ((status != 0) || ((gl_last_update + UPDATE_INTERVAL) < now)) { - if (data_provider == NULL) - { - fprintf (stderr, "No data provider has been registered\n"); - return (ENOENT); - } - /* Clear state */ gl_clear_instances (); gl_clear_hosts (); gl_destroy (&gl_dynamic, &gl_dynamic_num); - /* TODO: Iterate over all data providers */ - data_provider->get_idents (data_provider->private_data, - gl_register_ident, /* user data = */ NULL); + data_provider_get_idents (gl_register_ident, /* user data = */ NULL); gl_last_update = now; }