index abd94c22f1d40dba2e097870abfb5d47b343e9f8..6dc68c0c1fe6f837a55c61b1c92b5208d342cf58 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
#define SDB_CORE_STORE_PRIVATE_H 1
#include "core/store.h"
+#include "utils/avltree.h"
+
+#include <sys/types.h>
+#include <regex.h>
#ifdef __cplusplus
extern "C" {
#endif
-struct sdb_store_base {
+/*
+ * core types
+ */
+
+struct sdb_store_obj {
sdb_object_t super;
/* object type */
/* common meta information */
sdb_time_t last_update;
- sdb_store_base_t *parent;
+ sdb_time_t interval; /* moving average */
+ char **backends;
+ size_t backends_num;
+ 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 SDB_ATTR(obj) ((sdb_attribute_t *)(obj))
-#define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
+#define ATTR(obj) ((sdb_attribute_t *)(obj))
+#define CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
+
+typedef struct {
+ sdb_store_obj_t super;
+
+ sdb_avltree_t *attributes;
+} sdb_service_t;
+#define SVC(obj) ((sdb_service_t *)(obj))
+#define CONST_SVC(obj) ((const sdb_service_t *)(obj))
+
+typedef struct {
+ sdb_store_obj_t super;
+
+ sdb_avltree_t *attributes;
+ struct {
+ char *type;
+ char *id;
+ } store;
+} sdb_metric_t;
+#define METRIC(obj) ((sdb_metric_t *)(obj))
+
+typedef struct {
+ sdb_store_obj_t super;
+
+ sdb_avltree_t *services;
+ sdb_avltree_t *metrics;
+ sdb_avltree_t *attributes;
+} sdb_host_t;
+#define HOST(obj) ((sdb_host_t *)(obj))
+#define CONST_HOST(obj) ((const sdb_host_t *)(obj))
+
+/* shortcuts for accessing service/host attributes */
+#define _last_update super.last_update
+#define _interval super.interval
+
+/*
+ * 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_base_t super;
+ sdb_store_cond_t super;
+ char *name;
+ sdb_store_expr_t *expr;
+} attr_cond_t;
+#define ATTR_C(obj) ((attr_cond_t *)(obj))
- sdb_llist_t *children;
- sdb_llist_t *attributes;
-} sdb_store_obj_t;
-#define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
-#define SDB_CONST_STORE_OBJ(obj) ((const sdb_store_obj_t *)(obj))
+typedef struct {
+ sdb_store_cond_t super;
+ int field;
+ sdb_store_expr_t *expr;
+} obj_cond_t;
+#define OBJ_C(obj) ((obj_cond_t *)(obj))
+/*
+ * matchers
+ */
+
+/* when adding to this, also update 'matchers' and 'matchers_tostring'
+ * in store_lookup.c */
enum {
- SDB_HOST = 1,
- SDB_SERVICE,
- SDB_ATTRIBUTE,
+ MATCHER_OR,
+ MATCHER_AND,
+ MATCHER_NOT,
+ MATCHER_NAME,
+ MATCHER_ATTR,
+ MATCHER_LT,
+ MATCHER_LE,
+ MATCHER_EQ,
+ MATCHER_GE,
+ MATCHER_GT,
+ MATCHER_ISNULL,
};
-#define TYPE_TO_NAME(t) \
- (((t) == SDB_HOST) ? "host" \
- : ((t) == SDB_SERVICE) ? "service" \
- : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown")
-/* shortcuts for accessing the sdb_store_obj_t attributes
- * of inheriting objects */
-#define _last_update super.last_update
+#define MATCHER_SYM(t) \
+ (((t) == MATCHER_OR) ? "OR" \
+ : ((t) == MATCHER_AND) ? "AND" \
+ : ((t) == MATCHER_NOT) ? "NOT" \
+ : ((t) == MATCHER_NAME) ? "NAME" \
+ : ((t) == MATCHER_ATTR) ? "ATTR" \
+ : ((t) == MATCHER_LT) ? "<" \
+ : ((t) == MATCHER_LE) ? "<=" \
+ : ((t) == MATCHER_EQ) ? "=" \
+ : ((t) == MATCHER_GE) ? ">=" \
+ : ((t) == MATCHER_GT) ? ">" \
+ : ((t) == MATCHER_ISNULL) ? "IS NULL" \
+ : "UNKNOWN")
+
+/* match the name of something */
+typedef struct {
+ char *name;
+ regex_t *name_re;
+} string_matcher_t;
+
+/* matcher base type */
+struct sdb_store_matcher {
+ sdb_object_t super;
+ /* type of the matcher */
+ int type;
+};
+#define M(m) ((sdb_store_matcher_t *)(m))
+
+/* infix operator matcher */
+typedef struct {
+ sdb_store_matcher_t super;
+
+ /* left and right hand operands */
+ sdb_store_matcher_t *left;
+ sdb_store_matcher_t *right;
+} op_matcher_t;
+#define OP_M(m) ((op_matcher_t *)(m))
+
+/* unary operator matcher */
+typedef struct {
+ sdb_store_matcher_t super;
+
+ /* operand */
+ sdb_store_matcher_t *op;
+} uop_matcher_t;
+#define UOP_M(m) ((uop_matcher_t *)(m))
+
+/* match any type of object by it's name */
+typedef struct {
+ sdb_store_matcher_t super;
+
+ int obj_type;
+ string_matcher_t name;
+} name_matcher_t;
+#define NAME_M(m) ((name_matcher_t *)(m))
+
+/* match attributes */
+typedef struct {
+ sdb_store_matcher_t super;
+ char *name;
+ string_matcher_t value;
+} attr_matcher_t;
+#define ATTR_M(m) ((attr_matcher_t *)(m))
+
+typedef struct {
+ sdb_store_matcher_t super;
+ char *attr_name; /* we only support matching attributes */
+} 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" */