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, 41 void *user_class); 42 43 /* Given a user_class and a ds/vl combination, does stuff with the data. 44 * This is the main working horse of the module. */ 45 typedef int (*lookup_obj_callback_t)(data_set_t const *ds, 46 value_list_t const *vl, void *user_class, 47 void *user_obj); 48 49 /* Used to free user_class pointers. May be NULL in which case nothing is 50 * freed. */ 51 typedef void (*lookup_free_class_callback_t)(void *user_class); 52 53 /* Used to free user_obj pointers. May be NULL in which case nothing is 54 * freed. */ 55 typedef void (*lookup_free_obj_callback_t)(void *user_obj); 56 57 struct lookup_identifier_s { 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 lookup_identifier_s lookup_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, lookup_obj_callback_t, 77 lookup_free_class_callback_t, 78 lookup_free_obj_callback_t); 79 void lookup_destroy(lookup_t *obj); 80 81 int lookup_add(lookup_t *obj, lookup_identifier_t const *ident, 82 unsigned int group_by, void *user_class); 83 84 /* TODO(octo): Pass lookup_obj_callback_t to lookup_search()? */ 85 int lookup_search(lookup_t *obj, data_set_t const *ds, value_list_t const *vl); 86 87 #endif /* UTILS_VL_LOOKUP_H */ 88