2 * collectd - src/utils_vl_lookup.h
3 * Copyright (C) 2012 Florian Forster
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 * Florian Forster <octo at collectd.org>
27 #ifndef UTILS_VL_LOOKUP_H
28 #define UTILS_VL_LOOKUP_H 1
36 typedef struct lookup_s lookup_t;
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);
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);
48 /* Used to free user_class pointers. May be NULL in which case nothing is
50 typedef void (*lookup_free_class_callback_t) (void *user_class);
52 /* Used to free user_obj pointers. May be NULL in which case nothing is
54 typedef void (*lookup_free_obj_callback_t) (void *user_obj);
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];
64 typedef struct identifier_s identifier_t;
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
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);
82 int lookup_add (lookup_t *obj,
83 identifier_t const *ident, unsigned int group_by, void *user_class);
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);
89 #endif /* UTILS_VL_LOOKUP_H */