Merge branch 'ff/netlib'
[collectd.git] / src / libcollectdclient / collectd / client.h
1 /**
2  * libcollectdclient - src/libcollectdclient/client.h
3  * Copyright (C) 2008  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  **/
21
22 #ifndef LIBCOLLECTD_COLLECTDCLIENT_H
23 #define LIBCOLLECTD_COLLECTDCLIENT_H 1
24
25 #include "lcc_features.h"
26
27 /*
28  * Includes (for data types)
29  */
30 #if HAVE_STDINT_H
31 # include <stdint.h>
32 #endif
33 #include <inttypes.h>
34 #include <time.h>
35
36 /*
37  * Defines
38  */
39 #define LCC_NAME_LEN 64
40 #define LCC_DEFAULT_PORT "25826"
41
42 /*
43  * Types
44  */
45 #define LCC_TYPE_COUNTER 0
46 #define LCC_TYPE_GAUGE   1
47 #define LCC_TYPE_DERIVE   2
48 #define LCC_TYPE_ABSOLUTE   3
49
50 LCC_BEGIN_DECLS
51
52 typedef uint64_t counter_t;
53 typedef double gauge_t;
54 typedef uint64_t derive_t;
55 typedef uint64_t absolute_t;
56
57 union value_u
58 {
59   counter_t counter;
60   gauge_t   gauge;
61   derive_t  derive;
62   absolute_t absolute;
63 };
64 typedef union value_u value_t;
65
66 struct lcc_identifier_s
67 {
68   char host[LCC_NAME_LEN];
69   char plugin[LCC_NAME_LEN];
70   char plugin_instance[LCC_NAME_LEN];
71   char type[LCC_NAME_LEN];
72   char type_instance[LCC_NAME_LEN];
73 };
74 typedef struct lcc_identifier_s lcc_identifier_t;
75 #define LCC_IDENTIFIER_INIT { "localhost", "", "", "", "" }
76
77 struct lcc_value_list_s
78 {
79   value_t *values;
80   int     *values_types;
81   size_t   values_len;
82   time_t   time;
83   int      interval;
84   lcc_identifier_t identifier;
85 };
86 typedef struct lcc_value_list_s lcc_value_list_t;
87 #define LCC_VALUE_LIST_INIT { NULL, NULL, 0, 0, 0, LCC_IDENTIFIER_INIT }
88
89 struct lcc_connection_s;
90 typedef struct lcc_connection_s lcc_connection_t;
91
92 /*
93  * Functions
94  */
95 int lcc_connect (const char *address, lcc_connection_t **ret_con);
96 int lcc_disconnect (lcc_connection_t *c);
97 #define LCC_DESTROY(c) do { lcc_disconnect (c); (c) = NULL; } while (0)
98
99 int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident,
100     size_t *ret_values_num, gauge_t **ret_values, char ***ret_values_names);
101
102 int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl);
103
104 int lcc_flush (lcc_connection_t *c, const char *plugin,
105     lcc_identifier_t *ident, int timeout);
106
107 int lcc_listval (lcc_connection_t *c,
108     lcc_identifier_t **ret_ident, size_t *ret_ident_num);
109
110 /* TODO: putnotif */
111
112 const char *lcc_strerror (lcc_connection_t *c);
113
114 int lcc_identifier_to_string (lcc_connection_t *c,
115     char *string, size_t string_size, const lcc_identifier_t *ident);
116 int lcc_string_to_identifier (lcc_connection_t *c,
117     lcc_identifier_t *ident, const char *string);
118
119 /* Compares the identifiers "i0" and "i1" and returns less than zero or greater
120  * than zero if "i0" is smaller than or greater than "i1", respectively. If
121  * "i0" and "i1" are identical, zero is returned. */
122 int lcc_identifier_compare (const lcc_identifier_t *i0,
123     const lcc_identifier_t *i1);
124 int lcc_sort_identifiers (lcc_connection_t *c,
125     lcc_identifier_t *idents, size_t idents_num);
126
127 LCC_END_DECLS
128
129 /* vim: set sw=2 sts=2 et : */
130 #endif /* LIBCOLLECTD_COLLECTDCLIENT_H */