e501b2cd830169b2b7de01660207c976ca66f089
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"
37 #include <sys/types.h>
38 #include <regex.h>
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 struct sdb_store_base {
45 sdb_object_t super;
47 /* object type */
48 int type;
50 /* common meta information */
51 sdb_time_t last_update;
52 sdb_time_t interval; /* moving average */
53 sdb_store_base_t *parent;
54 };
55 #define STORE_BASE(obj) ((sdb_store_base_t *)(obj))
56 #define STORE_CONST_BASE(obj) ((const sdb_store_base_t *)(obj))
58 typedef struct {
59 sdb_store_base_t super;
61 sdb_data_t value;
62 } sdb_attribute_t;
63 #define SDB_ATTR(obj) ((sdb_attribute_t *)(obj))
64 #define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
66 typedef struct {
67 sdb_store_base_t super;
69 sdb_llist_t *services;
70 sdb_llist_t *attributes;
71 } sdb_store_obj_t;
72 #define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
73 #define SDB_CONST_STORE_OBJ(obj) ((const sdb_store_obj_t *)(obj))
75 /* shortcuts for accessing the sdb_store_obj_t attributes
76 * of inheriting objects */
77 #define _last_update super.last_update
78 #define _interval super.interval
80 /*
81 * conditionals
82 */
84 /* compares a store object using the specified conditional */
85 typedef int (*cmp_cb)(sdb_store_base_t *, sdb_store_cond_t *);
87 struct sdb_store_cond {
88 sdb_object_t super;
89 cmp_cb cmp;
90 };
92 typedef struct {
93 sdb_store_cond_t super;
94 char *name;
95 sdb_data_t value;
96 } attr_cond_t;
97 #define ATTR_C(obj) ((attr_cond_t *)(obj))
99 /*
100 * matchers
101 */
103 /* when adding to this, also update 'matchers' and 'matchers_tostring'
104 * in store_lookup.c */
105 enum {
106 MATCHER_OR,
107 MATCHER_AND,
108 MATCHER_NOT,
109 MATCHER_NAME,
110 MATCHER_ATTR,
111 MATCHER_LT,
112 MATCHER_LE,
113 MATCHER_EQ,
114 MATCHER_GE,
115 MATCHER_GT,
116 };
118 #define MATCHER_SYM(t) \
119 (((t) == MATCHER_OR) ? "OR" \
120 : ((t) == MATCHER_AND) ? "AND" \
121 : ((t) == MATCHER_NOT) ? "NOT" \
122 : ((t) == MATCHER_NAME) ? "NAME" \
123 : ((t) == MATCHER_ATTR) ? "ATTR" \
124 : ((t) == MATCHER_LT) ? "<" \
125 : ((t) == MATCHER_LE) ? "<=" \
126 : ((t) == MATCHER_EQ) ? "=" \
127 : ((t) == MATCHER_GE) ? ">=" \
128 : ((t) == MATCHER_GT) ? ">" \
129 : "UNKNOWN")
131 /* match the name of something */
132 typedef struct {
133 char *name;
134 regex_t *name_re;
135 } string_matcher_t;
137 /* matcher base type */
138 struct sdb_store_matcher {
139 sdb_object_t super;
140 /* type of the matcher */
141 int type;
142 };
143 #define M(m) ((sdb_store_matcher_t *)(m))
145 /* infix operator matcher */
146 typedef struct {
147 sdb_store_matcher_t super;
149 /* left and right hand operands */
150 sdb_store_matcher_t *left;
151 sdb_store_matcher_t *right;
152 } op_matcher_t;
153 #define OP_M(m) ((op_matcher_t *)(m))
155 /* unary operator matcher */
156 typedef struct {
157 sdb_store_matcher_t super;
159 /* operand */
160 sdb_store_matcher_t *op;
161 } uop_matcher_t;
162 #define UOP_M(m) ((uop_matcher_t *)(m))
164 /* match any type of object by it's name */
165 typedef struct {
166 sdb_store_matcher_t super;
168 int obj_type;
169 string_matcher_t name;
170 } name_matcher_t;
171 #define NAME_M(m) ((name_matcher_t *)(m))
173 /* match attributes */
174 typedef struct {
175 sdb_store_matcher_t super;
176 char *name;
177 string_matcher_t value;
178 } attr_matcher_t;
179 #define ATTR_M(m) ((attr_matcher_t *)(m))
181 /* match using conditionals */
182 typedef struct {
183 sdb_store_matcher_t super;
184 sdb_store_cond_t *cond;
185 } cond_matcher_t;
186 #define COND_M(m) ((cond_matcher_t *)(m))
188 #ifdef __cplusplus
189 } /* extern "C" */
190 #endif
192 #endif /* ! SDB_CORE_STORE_H */
194 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */