Code

Cleaned up some internal type names.
[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"
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 };
94 /* match the name of something */
95 typedef struct {
96         char    *name;
97         regex_t *name_re;
98 } string_matcher_t;
100 /* matcher base type */
101 struct sdb_store_matcher {
102         sdb_object_t super;
103         /* type of the matcher */
104         int type;
105 };
106 #define M(m) ((sdb_store_matcher_t *)(m))
108 /* logical infix operator matcher */
109 typedef struct {
110         sdb_store_matcher_t super;
112         /* left and right hand operands */
113         sdb_store_matcher_t *left;
114         sdb_store_matcher_t *right;
115 } op_matcher_t;
116 #define OP_M(m) ((op_matcher_t *)(m))
118 /* logical unary operator matcher */
119 typedef struct {
120         sdb_store_matcher_t super;
122         /* operand */
123         sdb_store_matcher_t *op;
124 } uop_matcher_t;
125 #define UOP_M(m) ((uop_matcher_t *)(m))
127 /* match any type of object by it's name */
128 typedef struct {
129         sdb_store_matcher_t super;
131         int obj_type;
132         string_matcher_t name;
133 } name_matcher_t;
134 #define NAME_M(m) ((name_matcher_t *)(m))
136 /* match attributes */
137 typedef struct {
138         sdb_store_matcher_t super;
139         char *name;
140         /* XXX: this needs to be more flexible;
141          *      add support for type-specific operators */
142         string_matcher_t value;
143 } attr_matcher_t;
144 #define ATTR_M(m) ((attr_matcher_t *)(m))
146 #ifdef __cplusplus
147 } /* extern "C" */
148 #endif
150 #endif /* ! SDB_CORE_STORE_H */
152 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */