d5371fb2a20f8f6a1c80b3401fefb0b69f02aeab
[collectd.git] / src / libcollectdclient / 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 #include <stdint.h>
31 #include <inttypes.h>
32 #include <time.h>
33
34 /*
35  * Defines
36  */
37 #define LCC_NAME_LEN 64
38 #define LCC_DEFAULT_PORT "25826"
39
40 /*
41  * Types
42  */
43 #define LCC_TYPE_COUNTER 0
44 #define LCC_TYPE_GAUGE   1
45
46 LCC_BEGIN_DECLS
47
48 typedef uint64_t counter_t;
49 typedef double gauge_t;
50
51 union value_u
52 {
53   counter_t counter;
54   gauge_t   gauge;
55 };
56 typedef union value_u value_t;
57
58 struct lcc_identifier_s
59 {
60   char host[LCC_NAME_LEN];
61   char plugin[LCC_NAME_LEN];
62   char plugin_instance[LCC_NAME_LEN];
63   char type[LCC_NAME_LEN];
64   char type_instance[LCC_NAME_LEN];
65 };
66 typedef struct lcc_identifier_s lcc_identifier_t;
67 #define LCC_IDENTIFIER_INIT { "localhost", "", "", "", "" }
68
69 struct lcc_value_list_s
70 {
71   value_t *values;
72   int     *values_types;
73   size_t   values_len;
74   time_t   time;
75   int      interval;
76   lcc_identifier_t identifier;
77 };
78 typedef struct lcc_value_list_s lcc_value_list_t;
79 #define LCC_VALUE_LIST_INIT { NULL, 0, 0, 0, LCC_IDENTIFIER_INIT }
80
81 struct lcc_connection_s;
82 typedef struct lcc_connection_s lcc_connection_t;
83
84 /*
85  * Functions
86  */
87 int lcc_connect (const char *address, lcc_connection_t **ret_con);
88 int lcc_disconnect (lcc_connection_t *c);
89 #define LCC_DESTROY(c) do { lcc_disconnect (c); (c) = NULL; } while (0)
90
91 int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident,
92     size_t *ret_values_num, gauge_t **ret_values, char ***ret_values_names);
93
94 int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl);
95
96 int lcc_flush (lcc_connection_t *c, const char *plugin,
97     lcc_identifier_t *ident, int timeout);
98
99 int lcc_listval (lcc_connection_t *c,
100     lcc_identifier_t **ret_ident, size_t *ret_ident_num);
101
102 /* TODO: putnotif */
103
104 const char *lcc_strerror (lcc_connection_t *c);
105
106 int lcc_identifier_to_string (lcc_connection_t *c,
107     char *string, size_t string_size, const lcc_identifier_t *ident);
108 int lcc_string_to_identifier (lcc_connection_t *c,
109     lcc_identifier_t *ident, const char *string);
110
111 LCC_END_DECLS
112
113 /* vim: set sw=2 sts=2 et : */
114 #endif /* LIBCOLLECTD_COLLECTDCLIENT_H */