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