From 7747e2ad9a86c2307094cd4ca3f753e46329c7a5 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 5 Jun 2016 16:44:39 +0200 Subject: [PATCH] plugin.h: Introduce the identifier_t type with pointer fields. This serves two purposes: - Allow field values of arbitrary length. - Reuse the identifier in other places. Renamed identifier_t from utils_vl_lookup to lookup_identifier_t. --- src/aggregation.c | 4 ++-- src/daemon/plugin.h | 10 ++++++++++ src/utils_vl_lookup.c | 6 +++--- src/utils_vl_lookup.h | 6 +++--- src/utils_vl_lookup_test.c | 14 +++++++------- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/aggregation.c b/src/aggregation.c index 2744c89e..bb37b858 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -38,7 +38,7 @@ struct aggregation_s /* {{{ */ { - identifier_t ident; + lookup_identifier_t ident; unsigned int group_by; unsigned int regex_fields; @@ -62,7 +62,7 @@ typedef struct agg_instance_s agg_instance_t; struct agg_instance_s /* {{{ */ { pthread_mutex_t lock; - identifier_t ident; + lookup_identifier_t ident; int ds_type; diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h index de42c068..c4cf566d 100644 --- a/src/daemon/plugin.h +++ b/src/daemon/plugin.h @@ -81,6 +81,16 @@ /* * Public data types */ +struct identifier_s +{ + char *host; + char *plugin; + char *plugin_instance; + char *type; + char *type_instance; +}; +typedef struct identifier_s identifier_t; + typedef unsigned long long counter_t; typedef double gauge_t; typedef int64_t derive_t; diff --git a/src/utils_vl_lookup.c b/src/utils_vl_lookup.c index 2ca9ddf8..226ba0ba 100644 --- a/src/utils_vl_lookup.c +++ b/src/utils_vl_lookup.c @@ -85,7 +85,7 @@ typedef struct user_obj_s user_obj_t; struct user_obj_s { void *user_obj; - identifier_t ident; + lookup_identifier_t ident; user_obj_t *next; }; @@ -175,7 +175,7 @@ static int lu_copy_ident_to_match_part (part_match_t *match_part, /* {{{ */ } /* }}} int lu_copy_ident_to_match_part */ static int lu_copy_ident_to_match (identifier_match_t *match, /* {{{ */ - identifier_t const *ident, unsigned int group_by) + lookup_identifier_t const *ident, unsigned int group_by) { memset (match, 0, sizeof (*match)); @@ -609,7 +609,7 @@ void lookup_destroy (lookup_t *obj) /* {{{ */ } /* }}} void lookup_destroy */ int lookup_add (lookup_t *obj, /* {{{ */ - identifier_t const *ident, unsigned int group_by, void *user_class) + lookup_identifier_t const *ident, unsigned int group_by, void *user_class) { by_type_entry_t *by_type = NULL; user_class_list_t *user_class_obj; diff --git a/src/utils_vl_lookup.h b/src/utils_vl_lookup.h index 1d01ebdf..e46e7637 100644 --- a/src/utils_vl_lookup.h +++ b/src/utils_vl_lookup.h @@ -53,7 +53,7 @@ typedef void (*lookup_free_class_callback_t) (void *user_class); * freed. */ typedef void (*lookup_free_obj_callback_t) (void *user_obj); -struct identifier_s +struct lookup_identifier_s { char host[DATA_MAX_NAME_LEN]; char plugin[DATA_MAX_NAME_LEN]; @@ -61,7 +61,7 @@ struct identifier_s char type[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; }; -typedef struct identifier_s identifier_t; +typedef struct lookup_identifier_s lookup_identifier_t; #define LU_GROUP_BY_HOST 0x01 #define LU_GROUP_BY_PLUGIN 0x02 @@ -80,7 +80,7 @@ lookup_t *lookup_create (lookup_class_callback_t, void lookup_destroy (lookup_t *obj); int lookup_add (lookup_t *obj, - identifier_t const *ident, unsigned int group_by, void *user_class); + lookup_identifier_t const *ident, unsigned int group_by, void *user_class); /* TODO(octo): Pass lookup_obj_callback_t to lookup_search()? */ int lookup_search (lookup_t *obj, diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c index 44660638..b3765e9f 100644 --- a/src/utils_vl_lookup_test.c +++ b/src/utils_vl_lookup_test.c @@ -32,8 +32,8 @@ static _Bool expect_new_obj = 0; static _Bool have_new_obj = 0; -static identifier_t last_class_ident; -static identifier_t last_obj_ident; +static lookup_identifier_t last_class_ident; +static lookup_identifier_t last_obj_ident; static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN }; static data_set_t const ds_test = { "test", 1, &dsrc_test }; @@ -45,8 +45,8 @@ static int lookup_obj_callback (data_set_t const *ds, value_list_t const *vl, void *user_class, void *user_obj) { - identifier_t *class = user_class; - identifier_t *obj = user_obj; + lookup_identifier_t *class = user_class; + lookup_identifier_t *obj = user_obj; OK1(expect_new_obj == have_new_obj, (expect_new_obj ? "New obj is created." : "Updating existing obj.")); @@ -63,8 +63,8 @@ static int lookup_obj_callback (data_set_t const *ds, static void *lookup_class_callback (data_set_t const *ds, value_list_t const *vl, void *user_class) { - identifier_t *class = user_class; - identifier_t *obj; + lookup_identifier_t *class = user_class; + lookup_identifier_t *obj; assert (expect_new_obj); @@ -88,7 +88,7 @@ static int checked_lookup_add (lookup_t *obj, /* {{{ */ char const *type, char const *type_instance, unsigned int group_by) { - identifier_t ident; + lookup_identifier_t ident; void *user_class; strncpy (ident.host, host, sizeof (ident.host)); -- 2.11.0