Merge branch 'collectd-5.5'
[collectd.git] / src / utils_db_query.h
1 /**
2  * collectd - src/utils_db_query.h
3  * Copyright (C) 2008,2009  Florian octo Forster
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *   Florian octo Forster <octo at collectd.org>
25  **/
26
27 #ifndef UTILS_DB_QUERY_H
28 #define UTILS_DB_QUERY_H 1
29
30 #include "configfile.h"
31
32 /*
33  * Data types
34  */
35 struct udb_query_s;
36 typedef struct udb_query_s udb_query_t;
37
38 struct udb_query_preparation_area_s;
39 typedef struct udb_query_preparation_area_s udb_query_preparation_area_t;
40
41 typedef int (*udb_query_create_callback_t) (udb_query_t *q,
42     oconfig_item_t *ci);
43
44 /*
45  * Public functions
46  */
47 int udb_query_create (udb_query_t ***ret_query_list,
48     size_t *ret_query_list_len, oconfig_item_t *ci,
49     udb_query_create_callback_t cb);
50 void udb_query_free (udb_query_t **query_list, size_t query_list_len);
51
52 int udb_query_pick_from_list_by_name (const char *name,
53     udb_query_t **src_list, size_t src_list_len,
54     udb_query_t ***dst_list, size_t *dst_list_len);
55 int udb_query_pick_from_list (oconfig_item_t *ci,
56     udb_query_t **src_list, size_t src_list_len,
57     udb_query_t ***dst_list, size_t *dst_list_len);
58
59 const char *udb_query_get_name (udb_query_t *q);
60 const char *udb_query_get_statement (udb_query_t *q);
61
62 void  udb_query_set_user_data (udb_query_t *q, void *user_data);
63 void *udb_query_get_user_data (udb_query_t *q);
64
65 /*
66  * udb_query_check_version
67  *
68  * Returns 0 if the query is NOT suitable for `version' and >0 if the
69  * query IS suitable.
70  */
71 int udb_query_check_version (udb_query_t *q, unsigned int version);
72
73 int udb_query_prepare_result (udb_query_t const *q,
74     udb_query_preparation_area_t *prep_area,
75     const char *host, const char *plugin, const char *db_name,
76     char **column_names, size_t column_num, cdtime_t interval);
77 int udb_query_handle_result (udb_query_t const *q,
78     udb_query_preparation_area_t *prep_area, char **column_values);
79 void udb_query_finish_result (udb_query_t const *q,
80     udb_query_preparation_area_t *prep_area);
81
82 udb_query_preparation_area_t *
83 udb_query_allocate_preparation_area (udb_query_t *q);
84 void
85 udb_query_delete_preparation_area (udb_query_preparation_area_t *q_area);
86
87 #endif /* UTILS_DB_QUERY_H */
88 /* vim: set sw=2 sts=2 et : */