1 /**
2 * collection4 - data_provider.c
3 * Copyright (C) 2010 Florian octo Forster
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
19 *
20 * Authors:
21 * Florian octo Forster <ff at octo.it>
22 **/
24 #include <stdlib.h>
25 #include <errno.h>
27 #include "data_provider.h"
28 #include "dp_rrdtool.h"
30 #include <fcgiapp.h>
31 #include <fcgi_stdio.h>
33 /* TODO: Turn this into an array for multiple data providers. */
34 static data_provider_t *data_provider = NULL;
36 int data_provider_config (const oconfig_item_t *ci) /* {{{ */
37 {
38 /* FIXME: Actually determine which data provider to call. */
39 return (dp_rrdtool_config (ci));
40 } /* }}} int data_provider_config */
42 int data_provider_register (const char *name, data_provider_t *p) /* {{{ */
43 {
44 fprintf (stderr, "data_provider_register (name = %s, ptr = %p)\n",
45 name, (void *) p);
47 if (data_provider == NULL)
48 data_provider = malloc (sizeof (*data_provider));
49 if (data_provider == NULL)
50 return (ENOMEM);
52 *data_provider = *p;
54 return (0);
55 } /* }}} int data_provider_register */
57 int data_provider_get_idents (dp_get_idents_callback callback, /* {{{ */
58 void *user_data)
59 {
60 int status;
62 if (data_provider == NULL)
63 return (EINVAL);
65 /* TODO: Iterate over all data providers */
66 status = data_provider->get_idents (data_provider->private_data,
67 callback, user_data);
69 return (status);
70 } /* }}} int data_provider_get_idents */
72 int data_provider_get_ident_ds_names (graph_ident_t *ident, /* {{{ */
73 dp_list_get_ident_ds_names_callback callback, void *user_data)
74 {
75 if (data_provider == NULL)
76 return (EINVAL);
78 return (data_provider->get_ident_ds_names (data_provider->private_data,
79 ident, callback, user_data));
80 } /* }}} int data_provider_get_ident_ds_names */
82 int data_provider_get_ident_data (graph_ident_t *ident, /* {{{ */
83 const char *ds_name,
84 dp_time_t begin, dp_time_t end,
85 dp_get_ident_data_callback callback, void *user_data)
86 {
87 if (data_provider == NULL)
88 return (EINVAL);
90 return (data_provider->get_ident_data (data_provider->private_data,
91 ident, ds_name, begin, end, callback, user_data));
92 } /* }}} int data_provider_get_ident_data */
94 /* vim: set sw=2 sts=2 et fdm=marker : */