From 033aa984a8b4be78ced113a3715422841a48d9a8 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 27 Jun 2014 19:04:34 +0200 Subject: [PATCH] store: Renamed store_base to store_obj. --- src/core/store-private.h | 16 +++++----- src/core/store.c | 55 +++++++++++++++++---------------- src/core/store_lookup.c | 34 ++++++++++---------- src/frontend/query.c | 4 +-- src/include/core/store.h | 16 +++++----- t/unit/core/store_lookup_test.c | 10 +++--- t/unit/core/store_test.c | 10 +++--- 7 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/core/store-private.h b/src/core/store-private.h index 603648c..6af3c8e 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -41,7 +41,7 @@ extern "C" { #endif -struct sdb_store_base { +struct sdb_store_obj { sdb_object_t super; /* object type */ @@ -50,13 +50,13 @@ struct sdb_store_base { /* common meta information */ sdb_time_t last_update; sdb_time_t interval; /* moving average */ - sdb_store_base_t *parent; + sdb_store_obj_t *parent; }; -#define STORE_BASE(obj) ((sdb_store_base_t *)(obj)) -#define STORE_CONST_BASE(obj) ((const sdb_store_base_t *)(obj)) +#define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj)) +#define STORE_CONST_OBJ(obj) ((const sdb_store_obj_t *)(obj)) typedef struct { - sdb_store_base_t super; + sdb_store_obj_t super; sdb_data_t value; } sdb_attribute_t; @@ -64,7 +64,7 @@ typedef struct { #define CONST_ATTR(obj) ((const sdb_attribute_t *)(obj)) typedef struct { - sdb_store_base_t super; + sdb_store_obj_t super; sdb_llist_t *attributes; } sdb_service_t; @@ -72,7 +72,7 @@ typedef struct { #define CONST_SVC(obj) ((const sdb_service_t *)(obj)) typedef struct { - sdb_store_base_t super; + sdb_store_obj_t super; sdb_llist_t *services; sdb_llist_t *attributes; @@ -89,7 +89,7 @@ typedef struct { */ /* compares a store object using the specified conditional */ -typedef int (*cmp_cb)(sdb_store_base_t *, sdb_store_cond_t *); +typedef int (*cmp_cb)(sdb_store_obj_t *, sdb_store_cond_t *); struct sdb_store_cond { sdb_object_t super; diff --git a/src/core/store.c b/src/core/store.c index ccb5f0a..9fb05df 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -61,9 +61,9 @@ static sdb_type_t sdb_service_type; static sdb_type_t sdb_attribute_type; static int -store_base_init(sdb_object_t *obj, va_list ap) +store_obj_init(sdb_object_t *obj, va_list ap) { - sdb_store_base_t *sobj = STORE_BASE(obj); + sdb_store_obj_t *sobj = STORE_OBJ(obj); sobj->type = va_arg(ap, int); @@ -71,16 +71,16 @@ store_base_init(sdb_object_t *obj, va_list ap) sobj->interval = 0; sobj->parent = NULL; return 0; -} /* store_base_init */ +} /* store_obj_init */ static void -store_base_destroy(sdb_object_t *obj) +store_obj_destroy(sdb_object_t *obj) { - const sdb_store_base_t *sobj = STORE_CONST_BASE(obj); + const sdb_store_obj_t *sobj = STORE_CONST_OBJ(obj); if (sobj->parent) sdb_object_deref(SDB_OBJ(sobj->parent)); -} /* store_base_destroy */ +} /* store_obj_destroy */ static int sdb_host_init(sdb_object_t *obj, va_list ap) @@ -89,7 +89,7 @@ sdb_host_init(sdb_object_t *obj, va_list ap) int ret; /* this will consume the first argument (type) of ap */ - ret = store_base_init(obj, ap); + ret = store_obj_init(obj, ap); if (ret) return ret; @@ -108,7 +108,7 @@ sdb_host_destroy(sdb_object_t *obj) sdb_host_t *sobj = HOST(obj); assert(obj); - store_base_destroy(obj); + store_obj_destroy(obj); if (sobj->services) sdb_llist_destroy(sobj->services); @@ -123,7 +123,7 @@ sdb_service_init(sdb_object_t *obj, va_list ap) int ret; /* this will consume the first argument (type) of ap */ - ret = store_base_init(obj, ap); + ret = store_obj_init(obj, ap); if (ret) return ret; @@ -139,7 +139,7 @@ sdb_service_destroy(sdb_object_t *obj) sdb_service_t *sobj = SVC(obj); assert(obj); - store_base_destroy(obj); + store_obj_destroy(obj); if (sobj->attributes) sdb_llist_destroy(sobj->attributes); @@ -153,7 +153,7 @@ sdb_attr_init(sdb_object_t *obj, va_list ap) /* this will consume the first two arguments * (type and last_update) of ap */ - ret = store_base_init(obj, ap); + ret = store_obj_init(obj, ap); if (ret) return ret; value = va_arg(ap, const sdb_data_t *); @@ -169,7 +169,7 @@ sdb_attr_destroy(sdb_object_t *obj) { assert(obj); - store_base_destroy(obj); + store_obj_destroy(obj); sdb_data_free_datum(&ATTR(obj)->value); } /* sdb_attr_destroy */ @@ -204,12 +204,12 @@ lookup_host(const char *name) /* The obj_lock has to be acquired before calling this function. */ static int store_obj(const char *hostname, int type, const char *name, - sdb_time_t last_update, sdb_store_base_t **updated_obj) + sdb_time_t last_update, sdb_store_obj_t **updated_obj) { char *host_cname = NULL, *cname = NULL; sdb_llist_t *parent_list; - sdb_store_base_t *old; + sdb_store_obj_t *old; int status = 0; if (last_update <= 0) @@ -267,9 +267,9 @@ store_obj(const char *hostname, int type, const char *name, } if (type == SDB_HOST) - old = STORE_BASE(sdb_llist_search_by_name(host_list, name)); + old = STORE_OBJ(sdb_llist_search_by_name(host_list, name)); else - old = STORE_BASE(sdb_llist_search_by_name(parent_list, name)); + old = STORE_OBJ(sdb_llist_search_by_name(parent_list, name)); if (old) { if (old->last_update > last_update) { @@ -297,17 +297,17 @@ store_obj(const char *hostname, int type, const char *name, *updated_obj = old; } else { - sdb_store_base_t *new; + sdb_store_obj_t *new; if (type == SDB_ATTRIBUTE) { /* the value will be updated by the caller */ - new = STORE_BASE(sdb_object_create(name, sdb_attribute_type, + new = STORE_OBJ(sdb_object_create(name, sdb_attribute_type, type, last_update, NULL)); } else { sdb_type_t t; t = type == SDB_HOST ? sdb_host_type : sdb_service_type; - new = STORE_BASE(sdb_object_create(name, t, type, last_update)); + new = STORE_OBJ(sdb_object_create(name, t, type, last_update)); } if (! new) { @@ -363,8 +363,9 @@ store_obj_tojson(sdb_llist_t *list, int type, sdb_strbuf_t *buf) /* has_next returns false if the iterator is NULL */ while (sdb_llist_iter_has_next(iter)) { - sdb_store_base_t *sobj = STORE_BASE(sdb_llist_iter_get_next(iter)); + sdb_store_obj_t *sobj = STORE_OBJ(sdb_llist_iter_get_next(iter)); assert(sobj); + assert(sobj->type == type); if (! sdb_strftime(time_str, sizeof(time_str), "%F %T %z", sobj->last_update)) @@ -377,7 +378,7 @@ store_obj_tojson(sdb_llist_t *list, int type, sdb_strbuf_t *buf) interval_str[sizeof(interval_str) - 1] = '\0'; sdb_strbuf_append(buf, "{\"name\": \"%s\", ", SDB_OBJ(sobj)->name); - if (type == SDB_ATTRIBUTE) { + if (sobj->type == SDB_ATTRIBUTE) { char tmp[sdb_data_strlen(&ATTR(sobj)->value) + 1]; sdb_data_format(&ATTR(sobj)->value, tmp, sizeof(tmp), SDB_DOUBLE_QUOTED); @@ -436,7 +437,7 @@ sdb_store_has_host(const char *name) return host != NULL; } /* sdb_store_has_host */ -sdb_store_base_t * +sdb_store_obj_t * sdb_store_get_host(const char *name) { sdb_host_t *host; @@ -449,7 +450,7 @@ sdb_store_get_host(const char *name) return NULL; sdb_object_ref(SDB_OBJ(host)); - return STORE_BASE(host); + return STORE_OBJ(host); } /* sdb_store_get_host */ int @@ -459,7 +460,7 @@ sdb_store_attribute(const char *hostname, { int status; - sdb_store_base_t *updated_attr = NULL; + sdb_store_obj_t *updated_attr = NULL; if ((! hostname) || (! key)) return -1; @@ -500,7 +501,7 @@ sdb_store_service(const char *hostname, const char *name, } /* sdb_store_service */ int -sdb_store_host_tojson(sdb_store_base_t *h, sdb_strbuf_t *buf, int flags) +sdb_store_host_tojson(sdb_store_obj_t *h, sdb_strbuf_t *buf, int flags) { sdb_host_t *host; char time_str[64]; @@ -558,7 +559,7 @@ sdb_store_tojson(sdb_strbuf_t *buf, int flags) sdb_strbuf_append(buf, "{\"hosts\":["); while (sdb_llist_iter_has_next(host_iter)) { - sdb_store_base_t *host = STORE_BASE(sdb_llist_iter_get_next(host_iter)); + sdb_store_obj_t *host = STORE_OBJ(sdb_llist_iter_get_next(host_iter)); assert(host); if (sdb_store_host_tojson(host, buf, flags)) @@ -590,7 +591,7 @@ sdb_store_iterate(sdb_store_iter_cb cb, void *user_data) /* has_next returns false if the iterator is NULL */ while (sdb_llist_iter_has_next(host_iter)) { - sdb_store_base_t *host = STORE_BASE(sdb_llist_iter_get_next(host_iter)); + sdb_store_obj_t *host = STORE_OBJ(sdb_llist_iter_get_next(host_iter)); assert(host); if (cb(host, user_data)) { diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 66f3f22..90ca2fe 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -64,7 +64,7 @@ typedef struct { */ static int -lookup_iter(sdb_store_base_t *obj, void *user_data) +lookup_iter(sdb_store_obj_t *obj, void *user_data) { lookup_iter_data_t *d = user_data; @@ -73,11 +73,11 @@ lookup_iter(sdb_store_base_t *obj, void *user_data) return 0; } /* lookup_iter */ -static sdb_store_base_t * +static sdb_store_obj_t * attr_get(sdb_host_t *host, const char *name) { sdb_llist_iter_t *iter = NULL; - sdb_store_base_t *attr = NULL; + sdb_store_obj_t *attr = NULL; iter = sdb_llist_get_iter(host->attributes); while (sdb_llist_iter_has_next(iter)) { @@ -85,7 +85,7 @@ attr_get(sdb_host_t *host, const char *name) if (strcasecmp(name, SDB_OBJ(a)->name)) continue; - attr = STORE_BASE(a); + attr = STORE_OBJ(a); break; } sdb_llist_iter_destroy(iter); @@ -97,7 +97,7 @@ attr_get(sdb_host_t *host, const char *name) */ static int -attr_cmp(sdb_store_base_t *obj, sdb_store_cond_t *cond) +attr_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond) { sdb_attribute_t *attr; @@ -131,7 +131,7 @@ match_string(string_matcher_t *m, const char *name) } /* match_string */ static int -match_logical(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_logical(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; @@ -149,7 +149,7 @@ match_logical(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_logical */ static int -match_unary(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { assert(m->type == MATCHER_NOT); assert(UOP_M(m)->op); @@ -158,7 +158,7 @@ match_unary(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_unary */ static int -match_name(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_name(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { sdb_llist_iter_t *iter = NULL; int status = 0; @@ -178,7 +178,7 @@ match_name(sdb_store_matcher_t *m, sdb_store_base_t *obj) } while (sdb_llist_iter_has_next(iter)) { - sdb_store_base_t *child = STORE_BASE(sdb_llist_iter_get_next(iter)); + sdb_store_obj_t *child = STORE_OBJ(sdb_llist_iter_get_next(iter)); if (match_string(&NAME_M(m)->name, child->super.name)) { status = 1; break; @@ -189,7 +189,7 @@ match_name(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_name */ static int -match_attr(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_attr(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { sdb_attribute_t *attr; @@ -208,7 +208,7 @@ match_attr(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_attr */ static int -match_lt(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_lt(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; assert(m->type == MATCHER_LT); @@ -217,7 +217,7 @@ match_lt(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_lt */ static int -match_le(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_le(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; assert(m->type == MATCHER_LE); @@ -226,7 +226,7 @@ match_le(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_le */ static int -match_eq(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; assert(m->type == MATCHER_EQ); @@ -235,7 +235,7 @@ match_eq(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_eq */ static int -match_ge(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; assert(m->type == MATCHER_GE); @@ -244,7 +244,7 @@ match_ge(sdb_store_matcher_t *m, sdb_store_base_t *obj) } /* match_ge */ static int -match_gt(sdb_store_matcher_t *m, sdb_store_base_t *obj) +match_gt(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { int status; assert(m->type == MATCHER_GT); @@ -252,7 +252,7 @@ match_gt(sdb_store_matcher_t *m, sdb_store_base_t *obj) return (status != INT_MAX) && (status > 0); } /* match_gt */ -typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_base_t *); +typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_obj_t *); /* this array needs to be indexable by the matcher types; * -> update the enum in store-private.h when updating this */ @@ -798,7 +798,7 @@ sdb_store_inv_matcher(sdb_store_matcher_t *m) } /* sdb_store_inv_matcher */ int -sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_base_t *obj) +sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj) { if (obj->type != SDB_HOST) return 0; diff --git a/src/frontend/query.c b/src/frontend/query.c index 0b582f5..d7476d3 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -39,7 +39,7 @@ */ static int -lookup_tojson(sdb_store_base_t *obj, void *user_data) +lookup_tojson(sdb_store_obj_t *obj, void *user_data) { sdb_strbuf_t *buf = user_data; if (sdb_strbuf_len(buf) > 1) @@ -76,7 +76,7 @@ int sdb_fe_fetch(sdb_conn_t *conn, const char *name) { sdb_strbuf_t *buf; - sdb_store_base_t *host; + sdb_store_obj_t *host; host = sdb_store_get_host(name); if (! host) { diff --git a/src/include/core/store.h b/src/include/core/store.h index 5920081..20656b3 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -56,12 +56,12 @@ enum { /* - * sdb_store_base_t represents the super-class of any object stored in the + * sdb_store_obj_t represents the super-class of any object stored in the * database. It inherits from sdb_object_t and may safely be cast to a generic * object to access its name. */ -struct sdb_store_base; -typedef struct sdb_store_base sdb_store_base_t; +struct sdb_store_obj; +typedef struct sdb_store_obj sdb_store_obj_t; /* * sdb_store_clear: @@ -98,7 +98,7 @@ sdb_store_host(const char *name, sdb_time_t last_update); _Bool sdb_store_has_host(const char *name); -sdb_store_base_t * +sdb_store_obj_t * sdb_store_get_host(const char *name); /* @@ -253,7 +253,7 @@ sdb_store_inv_matcher(sdb_store_matcher_t *m); * - 0 else */ int -sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_base_t *obj); +sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj); /* * sdb_store_matcher_tostring: @@ -268,7 +268,7 @@ sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen); * Lookup callback. It is called for each matching object when looking up data * in the store. The lookup aborts if the callback returns non-zero. */ -typedef int (*sdb_store_lookup_cb)(sdb_store_base_t *obj, void *user_data); +typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj, void *user_data); /* * sdb_store_lookup: @@ -319,13 +319,13 @@ sdb_store_tojson(sdb_strbuf_t *buf, int flags); * - a negative value on error */ int -sdb_store_host_tojson(sdb_store_base_t *host, sdb_strbuf_t *buf, int flags); +sdb_store_host_tojson(sdb_store_obj_t *host, sdb_strbuf_t *buf, int flags); /* * sdb_store_iter_cb: * Store iterator callback. Iteration stops if the callback returns non-zero. */ -typedef int (*sdb_store_iter_cb)(sdb_store_base_t *obj, void *user_data); +typedef int (*sdb_store_iter_cb)(sdb_store_obj_t *obj, void *user_data); /* * sdb_store_iterate: diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 6dd7bb3..0754a3b 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -85,7 +85,7 @@ populate(void) START_TEST(test_store_match_name) { - sdb_store_base_t *obj; + sdb_store_obj_t *obj; struct { int type; @@ -170,7 +170,7 @@ END_TEST START_TEST(test_store_match_attr) { - sdb_store_base_t *obj; + sdb_store_obj_t *obj; struct { const char *attr_name; @@ -247,7 +247,7 @@ END_TEST START_TEST(test_store_cond) { - sdb_store_base_t *obj; + sdb_store_obj_t *obj; struct { const char *attr; @@ -327,7 +327,7 @@ END_TEST START_TEST(test_store_match_op) { - sdb_store_base_t *obj; + sdb_store_obj_t *obj; sdb_store_matcher_t *always = sdb_store_name_matcher(SDB_HOST, "a", 0); sdb_store_matcher_t *never = sdb_store_name_matcher(SDB_HOST, "z", 0); @@ -491,7 +491,7 @@ START_TEST(test_parse_cmp) END_TEST static int -lookup_cb(sdb_store_base_t *obj, void *user_data) +lookup_cb(sdb_store_obj_t *obj, void *user_data) { int *i = user_data; diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 07651ee..cca3968 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -116,7 +116,7 @@ START_TEST(test_store_get_host) } for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) { - sdb_store_base_t *sobj1, *sobj2; + sdb_store_obj_t *sobj1, *sobj2; int ref_cnt; fail_unless(sdb_store_has_host(golden_hosts[i]), @@ -150,7 +150,7 @@ START_TEST(test_store_get_host) sdb_object_deref(SDB_OBJ(sobj2)); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(unknown_hosts); ++i) { - sdb_store_base_t *sobj; + sdb_store_obj_t *sobj; fail_unless(!sdb_store_has_host(unknown_hosts[i]), "sdb_store_has_host(%s) = TRUE; expected: FALSE", @@ -369,7 +369,7 @@ END_TEST START_TEST(test_interval) { - sdb_store_base_t *host; + sdb_store_obj_t *host; /* 10 us interval */ sdb_store_host("host", 10); @@ -424,7 +424,7 @@ START_TEST(test_interval) END_TEST static int -iter_incr(sdb_store_base_t *obj, void *user_data) +iter_incr(sdb_store_obj_t *obj, void *user_data) { intptr_t *i = user_data; @@ -440,7 +440,7 @@ iter_incr(sdb_store_base_t *obj, void *user_data) } /* iter_incr */ static int -iter_error(sdb_store_base_t *obj, void *user_data) +iter_error(sdb_store_obj_t *obj, void *user_data) { intptr_t *i = user_data; -- 2.30.2