Code

775057f09e235f9033edc10526a08e65d7f43d47
[sysdb.git] / src / core / store-private.h
1 /*
2  * SysDB - src/core/store-private.h
3  * Copyright (C) 2012-2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 /*
29  * private data structures used by the store module
30  */
32 #ifndef SDB_CORE_STORE_PRIVATE_H
33 #define SDB_CORE_STORE_PRIVATE_H 1
35 #include "core/store.h"
36 #include "utils/avltree.h"
38 #include <sys/types.h>
39 #include <regex.h>
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
45 /*
46  * core types
47  */
49 struct sdb_store_obj {
50         sdb_object_t super;
52         /* object type */
53         int type;
55         /* common meta information */
56         sdb_time_t last_update;
57         sdb_time_t interval; /* moving average */
58         char **backends;
59         size_t backends_num;
60         sdb_store_obj_t *parent;
61 };
62 #define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
63 #define STORE_CONST_OBJ(obj) ((const sdb_store_obj_t *)(obj))
65 typedef struct {
66         sdb_store_obj_t super;
68         sdb_data_t value;
69 } sdb_attribute_t;
70 #define ATTR(obj) ((sdb_attribute_t *)(obj))
71 #define CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
73 typedef struct {
74         sdb_store_obj_t super;
76         sdb_avltree_t *attributes;
77 } sdb_service_t;
78 #define SVC(obj) ((sdb_service_t *)(obj))
79 #define CONST_SVC(obj) ((const sdb_service_t *)(obj))
81 typedef struct {
82         sdb_store_obj_t super;
84         sdb_avltree_t *attributes;
85         struct {
86                 char *type;
87                 char *id;
88         } store;
89 } sdb_metric_t;
90 #define METRIC(obj) ((sdb_metric_t *)(obj))
92 typedef struct {
93         sdb_store_obj_t super;
95         sdb_avltree_t *services;
96         sdb_avltree_t *metrics;
97         sdb_avltree_t *attributes;
98 } sdb_host_t;
99 #define HOST(obj) ((sdb_host_t *)(obj))
100 #define CONST_HOST(obj) ((const sdb_host_t *)(obj))
102 /* shortcuts for accessing service/host attributes */
103 #define _last_update super.last_update
104 #define _interval super.interval
106 /*
107  * expressions
108  */
109 enum {
110         ATTR_VALUE  = -2, /* attr name stored in data.data.string */
111         FIELD_VALUE = -1, /* field type stored in data.data.integer */
112         /*  0: const value (stored in data) */
113         /* >0: operator id */
114 };
116 struct sdb_store_expr {
117         sdb_object_t super;
119         int type; /* see above */
120         int data_type;
122         sdb_store_expr_t *left;
123         sdb_store_expr_t *right;
125         sdb_data_t data;
126 };
128 /*
129  * matchers
130  */
132 /* when adding to this, also update 'MATCHER_SYM' below and 'matchers' in
133  * store_lookup.c */
134 enum {
135         MATCHER_OR,
136         MATCHER_AND,
137         MATCHER_NOT,
138         MATCHER_ANY,
139         MATCHER_ALL,
140         MATCHER_LT,
141         MATCHER_LE,
142         MATCHER_EQ,
143         MATCHER_NE,
144         MATCHER_GE,
145         MATCHER_GT,
146         MATCHER_IN,
147         MATCHER_REGEX,
148         MATCHER_NREGEX,
149         MATCHER_ISNULL,
150         MATCHER_ISNNULL,
151 };
153 #define MATCHER_SYM(t) \
154         (((t) == MATCHER_OR) ? "OR" \
155                 : ((t) == MATCHER_AND) ? "AND" \
156                 : ((t) == MATCHER_NOT) ? "NOT" \
157                 : ((t) == MATCHER_ANY) ? "ANY" \
158                 : ((t) == MATCHER_ALL) ? "ALL" \
159                 : ((t) == MATCHER_LT) ? "<" \
160                 : ((t) == MATCHER_LE) ? "<=" \
161                 : ((t) == MATCHER_EQ) ? "=" \
162                 : ((t) == MATCHER_NE) ? "!=" \
163                 : ((t) == MATCHER_GE) ? ">=" \
164                 : ((t) == MATCHER_GT) ? ">" \
165                 : ((t) == MATCHER_IN) ? "IN" \
166                 : ((t) == MATCHER_REGEX) ? "=~" \
167                 : ((t) == MATCHER_NREGEX) ? "!~" \
168                 : ((t) == MATCHER_ISNULL) ? "IS NULL" \
169                 : ((t) == MATCHER_ISNNULL) ? "IS NOT NULL" \
170                 : "UNKNOWN")
172 /* matcher base type */
173 struct sdb_store_matcher {
174         sdb_object_t super;
175         /* type of the matcher */
176         int type;
177 };
178 #define M(m) ((sdb_store_matcher_t *)(m))
180 /* infix operator matcher */
181 typedef struct {
182         sdb_store_matcher_t super;
184         /* left and right hand operands */
185         sdb_store_matcher_t *left;
186         sdb_store_matcher_t *right;
187 } op_matcher_t;
188 #define OP_M(m) ((op_matcher_t *)(m))
190 /* unary operator matcher */
191 typedef struct {
192         sdb_store_matcher_t super;
194         /* operand */
195         sdb_store_matcher_t *op;
196 } uop_matcher_t;
197 #define UOP_M(m) ((uop_matcher_t *)(m))
199 /* iter matcher */
200 typedef struct {
201         sdb_store_matcher_t super;
202         int type;
203         sdb_store_matcher_t *m;
204 } iter_matcher_t;
205 #define ITER_M(m) ((iter_matcher_t *)(m))
207 /* compare operator matcher */
208 typedef struct {
209         sdb_store_matcher_t super;
211         /* left and right hand expressions */
212         sdb_store_expr_t *left;
213         sdb_store_expr_t *right;
214 } cmp_matcher_t;
215 #define CMP_M(m) ((cmp_matcher_t *)(m))
217 typedef struct {
218         sdb_store_matcher_t super;
219         sdb_store_expr_t *expr;
220 } isnull_matcher_t;
221 #define ISNULL_M(m) ((isnull_matcher_t *)(m))
223 #ifdef __cplusplus
224 } /* extern "C" */
225 #endif
227 #endif /* ! SDB_CORE_STORE_H */
229 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */