1 /**
2 * collectd - src/utils_db_query.h
3 * Copyright (C) 2008,2009 Florian octo Forster
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * Authors:
19 * Florian octo Forster <octo at verplant.org>
20 **/
22 #ifndef UTILS_DB_QUERY_H
23 #define UTILS_DB_QUERY_H 1
25 #include "configfile.h"
27 /*
28 * Data types
29 */
30 struct udb_query_s;
31 typedef struct udb_query_s udb_query_t;
33 struct udb_query_preparation_area_s;
34 typedef struct udb_query_preparation_area_s udb_query_preparation_area_t;
36 typedef int (*udb_query_create_callback_t) (udb_query_t *q,
37 oconfig_item_t *ci);
39 /*
40 * Public functions
41 */
42 int udb_query_create (udb_query_t ***ret_query_list,
43 size_t *ret_query_list_len, oconfig_item_t *ci,
44 udb_query_create_callback_t cb);
45 void udb_query_free (udb_query_t **query_list, size_t query_list_len);
47 int udb_query_pick_from_list_by_name (const char *name,
48 udb_query_t **src_list, size_t src_list_len,
49 udb_query_t ***dst_list, size_t *dst_list_len);
50 int udb_query_pick_from_list (oconfig_item_t *ci,
51 udb_query_t **src_list, size_t src_list_len,
52 udb_query_t ***dst_list, size_t *dst_list_len);
54 const char *udb_query_get_name (udb_query_t *q);
55 const char *udb_query_get_statement (udb_query_t *q);
57 void udb_query_set_user_data (udb_query_t *q, void *user_data);
58 void *udb_query_get_user_data (udb_query_t *q);
60 /*
61 * udb_query_check_version
62 *
63 * Returns 0 if the query is NOT suitable for `version' and >0 if the
64 * query IS suitable.
65 */
66 int udb_query_check_version (udb_query_t *q, unsigned int version);
68 int udb_query_prepare_result (udb_query_t const *q,
69 udb_query_preparation_area_t *prep_area,
70 const char *host, const char *plugin, const char *db_name,
71 char **column_names, size_t column_num, cdtime_t interval);
72 int udb_query_handle_result (udb_query_t const *q,
73 udb_query_preparation_area_t *prep_area, char **column_values);
74 void udb_query_finish_result (udb_query_t const *q,
75 udb_query_preparation_area_t *prep_area);
77 udb_query_preparation_area_t *
78 udb_query_allocate_preparation_area (udb_query_t *q);
79 void
80 udb_query_delete_preparation_area (udb_query_preparation_area_t *q_area);
82 #endif /* UTILS_DB_QUERY_H */
83 /* vim: set sw=2 sts=2 et : */