Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-partition-table.h
1 /*
2  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
3  *
4  * Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
22 #error "Only <camel/camel.h> can be included directly."
23 #endif
24
25 #ifndef CAMEL_PARTITION_TABLE_H
26 #define CAMEL_PARTITION_TABLE_H
27
28 #include <camel/camel-object.h>
29
30 #include "camel-block-file.h"
31
32 /* Standard GObject macros */
33 #define CAMEL_TYPE_PARTITION_TABLE \
34         (camel_partition_table_get_type ())
35 #define CAMEL_PARTITION_TABLE(obj) \
36         (G_TYPE_CHECK_INSTANCE_CAST \
37         ((obj), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTable))
38 #define CAMEL_PARTITION_TABLE_CLASS(cls) \
39         (G_TYPE_CHECK_CLASS_CAST \
40         ((cls), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTableClass))
41 #define CAMEL_IS_PARTITION_TABLE(obj) \
42         (G_TYPE_CHECK_INSTANCE_TYPE \
43         ((obj), CAMEL_TYPE_PARTITION_TABLE))
44 #define CAMEL_IS_PARTITION_TABLE_CLASS(cls) \
45         (G_TYPE_CHECK_CLASS_TYPE \
46         ((cls), CAMEL_TYPE_PARTITION_TABLE))
47 #define CAMEL_PARTITION_TABLE_GET_CLASS(obj) \
48         (G_TYPE_INSTANCE_GET_CLASS \
49         ((obj), CAMEL_TYPE_PARTITION_TABLE, CamelPartitionTableClass))
50
51 #define CAMEL_TYPE_KEY_TABLE \
52         (camel_key_table_get_type ())
53 #define CAMEL_KEY_TABLE(obj) \
54         (G_TYPE_CHECK_INSTANCE_CAST \
55         ((obj), CAMEL_TYPE_KEY_TABLE, CamelKeyTable))
56 #define CAMEL_KEY_TABLE_CLASS(cls) \
57         (G_TYPE_CHECK_CLASS_CAST \
58         ((cls), CAMEL_TYPE_KEY_TABLE, CamelKeyTableClass))
59 #define CAMEL_IS_KEY_TABLE(obj) \
60         (G_TYPE_CHECK_INSTANCE_TYPE \
61         ((obj), CAMEL_TYPE_KEY_TABLE))
62 #define CAMEL_IS_KEY_TABLE_CLASS(cls) \
63         (G_TYPE_CHECK_CLASS_TYPE \
64         ((cls), CAMEL_TYPE_KEY_TABLE))
65 #define CAMEL_KEY_TABLE_GET_CLASS(obj) \
66         (G_TYPE_INSTANCE_GET_CLASS \
67         ((obj), CAMEL_TYPE_KEY_TABLE, CamelKeyTableClass))
68
69 G_BEGIN_DECLS
70
71 /* ********************************************************************** */
72
73 /* CamelPartitionTable - index of key to keyid */
74
75 typedef guint32 camel_hash_t;   /* a hashed key */
76
77 typedef struct _CamelPartitionKey CamelPartitionKey;
78 typedef struct _CamelPartitionKeyBlock CamelPartitionKeyBlock;
79 typedef struct _CamelPartitionMap CamelPartitionMap;
80 typedef struct _CamelPartitionMapBlock CamelPartitionMapBlock;
81
82 typedef struct _CamelPartitionTable CamelPartitionTable;
83 typedef struct _CamelPartitionTableClass CamelPartitionTableClass;
84 typedef struct _CamelPartitionTablePrivate CamelPartitionTablePrivate;
85
86 struct _CamelPartitionKey {
87         camel_hash_t hashid;
88         camel_key_t keyid;
89 };
90
91 struct _CamelPartitionKeyBlock {
92         guint32 used;
93         struct _CamelPartitionKey keys[(CAMEL_BLOCK_SIZE - 4) / sizeof (struct _CamelPartitionKey)];
94 };
95
96 struct _CamelPartitionMap {
97         camel_hash_t hashid;
98         camel_block_t blockid;
99 };
100
101 struct _CamelPartitionMapBlock {
102         camel_block_t next;
103         guint32 used;
104         struct _CamelPartitionMap partition[(CAMEL_BLOCK_SIZE - 8) / sizeof (struct _CamelPartitionMap)];
105 };
106
107 struct _CamelPartitionTable {
108         CamelObject parent;
109         CamelPartitionTablePrivate *priv;
110
111         CamelBlockFile *blocks;
112         camel_block_t rootid;
113
114         gint (*is_key)(CamelPartitionTable *cpi, const gchar *key, camel_key_t keyid, gpointer data);
115         gpointer is_key_data;
116
117         /* we keep a list of partition blocks active at all times */
118         GQueue partition;
119 };
120
121 struct _CamelPartitionTableClass {
122         CamelObjectClass parent;
123 };
124
125 GType           camel_partition_table_get_type  (void);
126 CamelPartitionTable *
127                 camel_partition_table_new       (struct _CamelBlockFile *bs,
128                                                  camel_block_t root);
129 gint            camel_partition_table_sync      (CamelPartitionTable *cpi);
130 gint            camel_partition_table_add       (CamelPartitionTable *cpi,
131                                                  const gchar *key,
132                                                  camel_key_t keyid);
133 camel_key_t     camel_partition_table_lookup    (CamelPartitionTable *cpi,
134                                                  const gchar *key);
135 gboolean        camel_partition_table_remove    (CamelPartitionTable *cpi,
136                                                  const gchar *key);
137
138 /* ********************************************************************** */
139
140 /* CamelKeyTable - index of keyid to key and flag and data mapping */
141
142 typedef struct _CamelKeyBlock CamelKeyBlock;
143 typedef struct _CamelKeyRootBlock CamelKeyRootBlock;
144
145 typedef struct _CamelKeyTable CamelKeyTable;
146 typedef struct _CamelKeyTableClass CamelKeyTableClass;
147 typedef struct _CamelKeyTablePrivate CamelKeyTablePrivate;
148
149 struct _CamelKeyRootBlock {
150         camel_block_t first;
151         camel_block_t last;
152         camel_key_t free;       /* free list */
153 };
154
155 struct _CamelKeyKey {
156         camel_block_t data;
157         guint offset : 10;
158         guint flags : 22;
159 };
160
161 struct _CamelKeyBlock {
162         camel_block_t next;
163         guint32 used;
164         union {
165                 struct _CamelKeyKey keys[(CAMEL_BLOCK_SIZE - 8) / sizeof (struct _CamelKeyKey)];
166                 gchar keydata[CAMEL_BLOCK_SIZE - 8];
167         } u;
168 };
169
170 #define CAMEL_KEY_TABLE_MAX_KEY (128) /* max size of any key */
171
172 struct _CamelKeyTable {
173         CamelObject parent;
174         CamelKeyTablePrivate *priv;
175
176         CamelBlockFile *blocks;
177
178         camel_block_t rootid;
179
180         CamelKeyRootBlock *root;
181         CamelBlock *root_block;
182 };
183
184 struct _CamelKeyTableClass {
185         CamelObjectClass parent;
186 };
187
188 GType           camel_key_table_get_type        (void);
189 CamelKeyTable * camel_key_table_new             (CamelBlockFile *bs,
190                                                  camel_block_t root);
191 gint            camel_key_table_sync            (CamelKeyTable *ki);
192 camel_key_t     camel_key_table_add             (CamelKeyTable *ki,
193                                                  const gchar *key,
194                                                  camel_block_t data,
195                                                  guint flags);
196 gboolean        camel_key_table_set_data        (CamelKeyTable *ki,
197                                                  camel_key_t keyid,
198                                                  camel_block_t data);
199 gboolean        camel_key_table_set_flags       (CamelKeyTable *ki,
200                                                  camel_key_t keyid,
201                                                  guint flags,
202                                                  guint set);
203 camel_block_t   camel_key_table_lookup          (CamelKeyTable *ki,
204                                                  camel_key_t keyid,
205                                                  gchar **key,
206                                                  guint *flags);
207 camel_key_t     camel_key_table_next            (CamelKeyTable *ki,
208                                                  camel_key_t next,
209                                                  gchar **keyp,
210                                                  guint *flagsp,
211                                                  camel_block_t *datap);
212
213 G_END_DECLS
214
215 #endif /* CAMEL_PARTITION_TABLE_H */