{GPL, other}: Relicense to MIT license.
[collectd.git] / src / utils_vl_lookup.h
1 /**
2  * collectd - src/utils_vl_lookup.h
3  * Copyright (C) 2012       Florian 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 Forster <octo at collectd.org>
25  **/
26
27 #ifndef UTILS_VL_LOOKUP_H
28 #define UTILS_VL_LOOKUP_H 1
29
30 #include "plugin.h"
31
32 /*
33  * Types
34  */
35 struct lookup_s;
36 typedef struct lookup_s lookup_t;
37
38 /* Given a user_class, constructs a new user_obj. */
39 typedef void *(*lookup_class_callback_t) (data_set_t const *ds,
40     value_list_t const *vl, void *user_class);
41
42 /* Given a user_class and a ds/vl combination, does stuff with the data.
43  * This is the main working horse of the module. */
44 typedef int (*lookup_obj_callback_t) (data_set_t const *ds,
45     value_list_t const *vl,
46     void *user_class, void *user_obj);
47
48 /* Used to free user_class pointers. May be NULL in which case nothing is
49  * freed. */
50 typedef void (*lookup_free_class_callback_t) (void *user_class);
51
52 /* Used to free user_obj pointers. May be NULL in which case nothing is
53  * freed. */
54 typedef void (*lookup_free_obj_callback_t) (void *user_obj);
55
56 struct identifier_s
57 {
58   char host[DATA_MAX_NAME_LEN];
59   char plugin[DATA_MAX_NAME_LEN];
60   char plugin_instance[DATA_MAX_NAME_LEN];
61   char type[DATA_MAX_NAME_LEN];
62   char type_instance[DATA_MAX_NAME_LEN];
63 };
64 typedef struct identifier_s identifier_t;
65
66 #define LU_GROUP_BY_HOST            0x01
67 #define LU_GROUP_BY_PLUGIN          0x02
68 #define LU_GROUP_BY_PLUGIN_INSTANCE 0x04
69 /* #define LU_GROUP_BY_TYPE            0x00 */
70 #define LU_GROUP_BY_TYPE_INSTANCE   0x10
71
72 /*
73  * Functions
74  */
75 __attribute__((nonnull(1,2)))
76 lookup_t *lookup_create (lookup_class_callback_t,
77     lookup_obj_callback_t,
78     lookup_free_class_callback_t,
79     lookup_free_obj_callback_t);
80 void lookup_destroy (lookup_t *obj);
81
82 int lookup_add (lookup_t *obj,
83     identifier_t const *ident, unsigned int group_by, void *user_class);
84
85 /* TODO(octo): Pass lookup_obj_callback_t to lookup_search()? */
86 int lookup_search (lookup_t *obj,
87     data_set_t const *ds, value_list_t const *vl);
88
89 #endif /* UTILS_VL_LOOKUP_H */