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