summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5218bf1)
raw | patch | inline | side by side (parent: 5218bf1)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 27 Jun 2014 17:04:34 +0000 (19:04 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 27 Jun 2014 17:04:34 +0000 (19:04 +0200) |
index 603648ca057b51ced94b5a7ecd05bdadd615acbc..6af3c8e5fb8c08e59002308e45fe4e4d9ea665be 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
extern "C" {
#endif
-struct sdb_store_base {
+struct sdb_store_obj {
sdb_object_t super;
/* object type */
/* 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;
#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;
#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;
*/
/* 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 ccb5f0a954d97e0f867bc2bb2067573245e30133..9fb05dfdf72c8ff20a8a783ad9069746b7651878 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
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);
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)
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;
sdb_host_t *sobj = HOST(obj);
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
if (sobj->services)
sdb_llist_destroy(sobj->services);
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;
sdb_service_t *sobj = SVC(obj);
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
if (sobj->attributes)
sdb_llist_destroy(sobj->attributes);
/* 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 *);
{
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
sdb_data_free_datum(&ATTR(obj)->value);
} /* sdb_attr_destroy */
/* 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)
}
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) {
*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) {
/* 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))
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);
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;
return NULL;
sdb_object_ref(SDB_OBJ(host));
- return STORE_BASE(host);
+ return STORE_OBJ(host);
} /* sdb_store_get_host */
int
{
int status;
- sdb_store_base_t *updated_attr = NULL;
+ sdb_store_obj_t *updated_attr = NULL;
if ((! hostname) || (! key))
return -1;
} /* 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];
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))
/* 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)) {
index 66f3f22dcfb9b5ec7a9fd447135ab493c7360f92..90ca2fed6060b36e15b8d4e04ea6fbdc341c0b07 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
*/
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;
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)) {
if (strcasecmp(name, SDB_OBJ(a)->name))
continue;
- attr = STORE_BASE(a);
+ attr = STORE_OBJ(a);
break;
}
sdb_llist_iter_destroy(iter);
*/
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;
} /* 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;
} /* 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);
} /* 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;
}
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;
} /* 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;
} /* 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);
} /* 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);
} /* 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);
} /* 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);
} /* 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);
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 */
} /* 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 0b582f54dce54e8481b8b6e0292b52856c48c9ec..d7476d345d48791f7cac512daca7ebfcfae49782 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
*/
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)
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) {
index 59200815482e9d5540837dfd1fce07e19fdfd743..20656b37bdb8dbb0272db666d56dacf20fbf7583 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
/*
- * 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:
_Bool
sdb_store_has_host(const char *name);
-sdb_store_base_t *
+sdb_store_obj_t *
sdb_store_get_host(const char *name);
/*
* - 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:
* 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:
* - 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:
index 6dd7bb3fa1916a2119cc1985f9c2dc7393a3db47..0754a3b528fadb760e4a73dae8c4e062c60e7ce7 100644 (file)
START_TEST(test_store_match_name)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
int type;
START_TEST(test_store_match_attr)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
const char *attr_name;
START_TEST(test_store_cond)
{
- sdb_store_base_t *obj;
+ sdb_store_obj_t *obj;
struct {
const char *attr;
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);
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;
index 07651ee602f2444cbd9f8f6dc546b9c4c41286ee..cca3968c4674df076a948d641a71d211c1257e3d 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
}
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]),
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",
START_TEST(test_interval)
{
- sdb_store_base_t *host;
+ sdb_store_obj_t *host;
/* 10 us interval */
sdb_store_host("host", 10);
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;
} /* 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;