summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d64762e)
raw | patch | inline | side by side (parent: d64762e)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 22 Oct 2014 09:16:05 +0000 (11:16 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 22 Oct 2014 09:16:05 +0000 (11:16 +0200) |
src/core/store-private.h | patch | blob | history | |
src/core/store_lookup.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
index be262ec61ecfb901a2fb12ff96667d8083f5786c..6e232ddf145fcc6b76816c98e1bbadd9291288aa 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
sdb_data_t data;
};
-/*
- * conditionals
- */
-
-/* compares an object using the specified conditional and taking the specified
- * filter into account */
-typedef int (*cmp_cb)(sdb_store_obj_t *, sdb_store_cond_t *,
- sdb_store_matcher_t *);
-
-struct sdb_store_cond {
- sdb_object_t super;
- cmp_cb cmp;
-};
-
-typedef struct {
- sdb_store_cond_t super;
- char *name;
- sdb_store_expr_t *expr;
-} attr_cond_t;
-#define ATTR_C(obj) ((attr_cond_t *)(obj))
-
/*
* matchers
*/
MATCHER_SERVICE,
MATCHER_METRIC,
MATCHER_ATTRIBUTE,
- MATCHER_LT,
- MATCHER_LE,
- MATCHER_EQ,
- MATCHER_GE,
- MATCHER_GT,
MATCHER_CMP_LT,
MATCHER_CMP_LE,
MATCHER_CMP_EQ,
: ((t) == MATCHER_SERVICE) ? "SERVICE" \
: ((t) == MATCHER_METRIC) ? "METRIC" \
: ((t) == MATCHER_ATTRIBUTE) ? "ATTRIBUTE" \
- : ((t) == MATCHER_LT) ? "<" \
- : ((t) == MATCHER_LE) ? "<=" \
- : ((t) == MATCHER_EQ) ? "=" \
: ((t) == MATCHER_CMP_NE) ? "!=" \
- : ((t) == MATCHER_GE) ? ">=" \
- : ((t) == MATCHER_GT) ? ">" \
: ((t) == MATCHER_IN) ? "IN" \
: ((t) == MATCHER_REGEX) ? "=~" \
: ((t) == MATCHER_NREGEX) ? "!~" \
} isnull_matcher_t;
#define ISNULL_M(m) ((isnull_matcher_t *)(m))
-/* match using conditionals */
-typedef struct {
- sdb_store_matcher_t super;
- sdb_store_cond_t *cond;
-} cond_matcher_t;
-#define COND_M(m) ((cond_matcher_t *)(m))
-
#ifdef __cplusplus
} /* extern "C" */
#endif
index 6730e11f59eedc18b51837f35f8b0c19bc77b4ba..05e6b74d51b70117bc01a06b1b17ca9ef0f77f50 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
return status;
} /* match_child */
-static int
-match_lt(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_LT);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status < 0);
-} /* match_lt */
-
-static int
-match_le(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_LE);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status <= 0);
-} /* match_le */
-
-static int
-match_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_EQ);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (! status);
-} /* match_eq */
-
-static int
-match_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_GE);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status >= 0);
-} /* match_ge */
-
-static int
-match_gt(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_GT);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status > 0);
-} /* match_gt */
-
/*
* cmp_expr:
* Compare the values of two expressions when evaluating them using the
match_child,
match_child,
match_child,
- match_lt,
- match_le,
- match_eq,
- match_ge,
- match_gt,
match_cmp_lt,
match_cmp_le,
match_cmp_eq,
string_matcher_destroy(&attr->value);
} /* attr_matcher_destroy */
-static int
-cond_matcher_init(sdb_object_t *obj, va_list ap)
-{
- int type = va_arg(ap, int);
- sdb_store_cond_t *cond = va_arg(ap, sdb_store_cond_t *);
-
- if (! cond)
- return -1;
-
- sdb_object_ref(SDB_OBJ(cond));
-
- M(obj)->type = type;
- COND_M(obj)->cond = cond;
- return 0;
-} /* cond_matcher_init */
-
-static void
-cond_matcher_destroy(sdb_object_t *obj)
-{
- sdb_object_deref(SDB_OBJ(COND_M(obj)->cond));
-} /* cond_matcher_destroy */
-
static int
op_matcher_init(sdb_object_t *obj, va_list ap)
{
/* destroy = */ attr_matcher_destroy,
};
-static sdb_type_t cond_type = {
- /* size = */ sizeof(cond_matcher_t),
- /* init = */ cond_matcher_init,
- /* destroy = */ cond_matcher_destroy,
-};
-
static sdb_type_t op_type = {
/* size = */ sizeof(op_matcher_t),
/* init = */ op_matcher_init,
return M(sdb_object_create("any-matcher", child_type, type, m));
} /* sdb_store_child_matcher */
-sdb_store_matcher_t *
-sdb_store_lt_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("lt-matcher", cond_type,
- MATCHER_LT, cond));
-} /* sdb_store_lt_matcher */
-
-sdb_store_matcher_t *
-sdb_store_le_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("le-matcher", cond_type,
- MATCHER_LE, cond));
-} /* sdb_store_le_matcher */
-
-sdb_store_matcher_t *
-sdb_store_eq_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("eq-matcher", cond_type,
- MATCHER_EQ, cond));
-} /* sdb_store_eq_matcher */
-
-sdb_store_matcher_t *
-sdb_store_ge_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("ge-matcher", cond_type,
- MATCHER_GE, cond));
-} /* sdb_store_ge_matcher */
-
-sdb_store_matcher_t *
-sdb_store_gt_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("gt-matcher", cond_type,
- MATCHER_GT, cond));
-} /* sdb_store_gt_matcher */
-
/*
* TODO: Rename sdb_store_cmp_* to sdb_store_* once the old code is unused and
* has been removed.
index 684a3ccf020e5d996acf717e7c06bb3a0925ce3e..cef3d063cf0f41f18aad997eedf92971d7cf93ac 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
sdb_data_t *res, sdb_store_matcher_t *filter);
-/*
- * Conditionals may be used to lookup hosts from the store based on a
- * conditional expression.
- *
- * A conditional object inherits from sdb_object_t and, thus, may safely be
- * cast to a generic object.
- */
-struct sdb_store_cond;
-typedef struct sdb_store_cond sdb_store_cond_t;
-#define SDB_STORE_COND(obj) ((sdb_store_cond_t *)(obj))
-
/*
* sdb_store_name_matcher:
* Creates a matcher matching by the specified object type's name. If 're' is
* equal, equal, greater or equal, or greater than the conditional's value
* repsectively.
*/
-sdb_store_matcher_t *
-sdb_store_lt_matcher(sdb_store_cond_t *cond);
-sdb_store_matcher_t *
-sdb_store_le_matcher(sdb_store_cond_t *cond);
-sdb_store_matcher_t *
-sdb_store_eq_matcher(sdb_store_cond_t *cond);
-sdb_store_matcher_t *
-sdb_store_ge_matcher(sdb_store_cond_t *cond);
-sdb_store_matcher_t *
-sdb_store_gt_matcher(sdb_store_cond_t *cond);
-
sdb_store_matcher_t *
sdb_store_cmp_lt(sdb_store_expr_t *left, sdb_store_expr_t *right);
sdb_store_matcher_t *