2 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4 * Authors: Michael Zucchi <notzed@ximian.com>
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.
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.
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.
21 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
22 #error "Only <camel/camel.h> can be included directly."
25 #ifndef CAMEL_PARTITION_TABLE_H
26 #define CAMEL_PARTITION_TABLE_H
28 #include <camel/camel-object.h>
30 #include "camel-block-file.h"
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))
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))
71 /* ********************************************************************** */
73 /* CamelPartitionTable - index of key to keyid */
75 typedef guint32 camel_hash_t; /* a hashed key */
77 typedef struct _CamelPartitionKey CamelPartitionKey;
78 typedef struct _CamelPartitionKeyBlock CamelPartitionKeyBlock;
79 typedef struct _CamelPartitionMap CamelPartitionMap;
80 typedef struct _CamelPartitionMapBlock CamelPartitionMapBlock;
82 typedef struct _CamelPartitionTable CamelPartitionTable;
83 typedef struct _CamelPartitionTableClass CamelPartitionTableClass;
84 typedef struct _CamelPartitionTablePrivate CamelPartitionTablePrivate;
86 struct _CamelPartitionKey {
91 struct _CamelPartitionKeyBlock {
93 struct _CamelPartitionKey keys[(CAMEL_BLOCK_SIZE - 4) / sizeof (struct _CamelPartitionKey)];
96 struct _CamelPartitionMap {
98 camel_block_t blockid;
101 struct _CamelPartitionMapBlock {
104 struct _CamelPartitionMap partition[(CAMEL_BLOCK_SIZE - 8) / sizeof (struct _CamelPartitionMap)];
107 struct _CamelPartitionTable {
109 CamelPartitionTablePrivate *priv;
111 CamelBlockFile *blocks;
112 camel_block_t rootid;
114 gint (*is_key)(CamelPartitionTable *cpi, const gchar *key, camel_key_t keyid, gpointer data);
115 gpointer is_key_data;
117 /* we keep a list of partition blocks active at all times */
121 struct _CamelPartitionTableClass {
122 CamelObjectClass parent;
125 GType camel_partition_table_get_type (void);
126 CamelPartitionTable *
127 camel_partition_table_new (struct _CamelBlockFile *bs,
129 gint camel_partition_table_sync (CamelPartitionTable *cpi);
130 gint camel_partition_table_add (CamelPartitionTable *cpi,
133 camel_key_t camel_partition_table_lookup (CamelPartitionTable *cpi,
135 gboolean camel_partition_table_remove (CamelPartitionTable *cpi,
138 /* ********************************************************************** */
140 /* CamelKeyTable - index of keyid to key and flag and data mapping */
142 typedef struct _CamelKeyBlock CamelKeyBlock;
143 typedef struct _CamelKeyRootBlock CamelKeyRootBlock;
145 typedef struct _CamelKeyTable CamelKeyTable;
146 typedef struct _CamelKeyTableClass CamelKeyTableClass;
147 typedef struct _CamelKeyTablePrivate CamelKeyTablePrivate;
149 struct _CamelKeyRootBlock {
152 camel_key_t free; /* free list */
155 struct _CamelKeyKey {
161 struct _CamelKeyBlock {
165 struct _CamelKeyKey keys[(CAMEL_BLOCK_SIZE - 8) / sizeof (struct _CamelKeyKey)];
166 gchar keydata[CAMEL_BLOCK_SIZE - 8];
170 #define CAMEL_KEY_TABLE_MAX_KEY (128) /* max size of any key */
172 struct _CamelKeyTable {
174 CamelKeyTablePrivate *priv;
176 CamelBlockFile *blocks;
178 camel_block_t rootid;
180 CamelKeyRootBlock *root;
181 CamelBlock *root_block;
184 struct _CamelKeyTableClass {
185 CamelObjectClass parent;
188 GType camel_key_table_get_type (void);
189 CamelKeyTable * camel_key_table_new (CamelBlockFile *bs,
191 gint camel_key_table_sync (CamelKeyTable *ki);
192 camel_key_t camel_key_table_add (CamelKeyTable *ki,
196 gboolean camel_key_table_set_data (CamelKeyTable *ki,
199 gboolean camel_key_table_set_flags (CamelKeyTable *ki,
203 camel_block_t camel_key_table_lookup (CamelKeyTable *ki,
207 camel_key_t camel_key_table_next (CamelKeyTable *ki,
211 camel_block_t *datap);
215 #endif /* CAMEL_PARTITION_TABLE_H */