From: Sven Trenkel Date: Wed, 9 Dec 2009 12:18:49 +0000 (+0100) Subject: Added function to get the data type of a meta data entry. X-Git-Tag: collectd-4.10.0~93 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9c52b4ff1590251ea5fcefab15c0af655d49624c;p=collectd.git Added function to get the data type of a meta data entry. --- diff --git a/src/meta_data.c b/src/meta_data.c index 3a3f5e79..a7c11c10 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -26,15 +26,6 @@ #include /* - * Defines - */ -#define MD_TYPE_STRING 1 -#define MD_TYPE_SIGNED_INT 2 -#define MD_TYPE_UNSIGNED_INT 3 -#define MD_TYPE_DOUBLE 4 -#define MD_TYPE_BOOLEAN 5 - -/* * Data types */ union meta_value_u @@ -249,6 +240,28 @@ int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */ return (0); } /* }}} int meta_data_exists */ +int meta_data_type (meta_data_t *md, const char *key) /* {{{ */ +{ + meta_entry_t *e; + + if ((md == NULL) || (key == NULL)) + return 0; + + pthread_mutex_lock (&md->lock); + + for (e = md->head; e != NULL; e = e->next) + { + if (strcasecmp (key, e->key) == 0) + { + pthread_mutex_unlock (&md->lock); + return e->type; + } + } + + pthread_mutex_unlock (&md->lock); + return 0; +} /* }}} int meta_data_type */ + int meta_data_delete (meta_data_t *md, const char *key) /* {{{ */ { meta_entry_t *this; diff --git a/src/meta_data.h b/src/meta_data.h index 8e5a7852..7a9afee5 100644 --- a/src/meta_data.h +++ b/src/meta_data.h @@ -24,6 +24,15 @@ #include "collectd.h" +/* + * Defines + */ +#define MD_TYPE_STRING 1 +#define MD_TYPE_SIGNED_INT 2 +#define MD_TYPE_UNSIGNED_INT 3 +#define MD_TYPE_DOUBLE 4 +#define MD_TYPE_BOOLEAN 5 + struct meta_data_s; typedef struct meta_data_s meta_data_t; @@ -31,6 +40,7 @@ meta_data_t *meta_data_create (void); void meta_data_destroy (meta_data_t *md); int meta_data_exists (meta_data_t *md, const char *key); +int meta_data_type (meta_data_t *md, const char *key); int meta_data_delete (meta_data_t *md, const char *key); int meta_data_add_string (meta_data_t *md,