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 *children;
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 * matchers
82 */
84 /* when adding to this, also update 'matchers' and 'matchers_tostring'
85 * in store_lookup.c */
86 enum {
87 MATCHER_OR,
88 MATCHER_AND,
89 MATCHER_NOT,
90 MATCHER_NAME,
91 MATCHER_ATTR,
92 MATCHER_HOST,
93 };
95 /* match the name of something */
96 typedef struct {
97 char *name;
98 regex_t *name_re;
99 } name_matcher_t;
101 /* matcher base type */
102 struct sdb_store_matcher {
103 sdb_object_t super;
104 /* type of the matcher */
105 int type;
106 };
107 #define M(m) ((sdb_store_matcher_t *)(m))
109 /* logical infix operator matcher */
110 typedef struct {
111 sdb_store_matcher_t super;
113 /* left and right hand operands */
114 sdb_store_matcher_t *left;
115 sdb_store_matcher_t *right;
116 } op_matcher_t;
117 #define OP_M(m) ((op_matcher_t *)(m))
119 /* logical unary operator matcher */
120 typedef struct {
121 sdb_store_matcher_t super;
123 /* operand */
124 sdb_store_matcher_t *op;
125 } uop_matcher_t;
126 #define UOP_M(m) ((uop_matcher_t *)(m))
128 /* match any type of object by it's name */
129 typedef struct {
130 sdb_store_matcher_t super;
132 int obj_type;
134 /* match by the name of the object */
135 name_matcher_t name;
136 } obj_matcher_t;
137 #define OBJ_M(m) ((obj_matcher_t *)(m))
139 /* match attributes */
140 typedef struct {
141 obj_matcher_t super;
142 /* XXX: this needs to be more flexible;
143 * add support for type-specific operators */
144 name_matcher_t value;
145 } attr_matcher_t;
146 #define ATTR_M(m) ((attr_matcher_t *)(m))
148 /* match hosts */
149 typedef struct {
150 obj_matcher_t super;
151 /* match by attributes assigned to the host */
152 attr_matcher_t *attr;
153 } host_matcher_t;
154 #define HOST_M(m) ((host_matcher_t *)(m))
156 #ifdef __cplusplus
157 } /* extern "C" */
158 #endif
160 #endif /* ! SDB_CORE_STORE_H */
162 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */