Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-block-file.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_BLOCK_FILE_H
26 #define CAMEL_BLOCK_FILE_H
27
28 #include <camel/camel-object.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31
32 /* Standard GObject macros */
33 #define CAMEL_TYPE_BLOCK_FILE \
34         (camel_block_file_get_type ())
35 #define CAMEL_BLOCK_FILE(obj) \
36         (G_TYPE_CHECK_INSTANCE_CAST \
37         ((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFile))
38 #define CAMEL_BLOCK_FILE_CLASS(cls) \
39         (G_TYPE_CHECK_CLASS_CAST \
40         ((cls), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
41 #define CAMEL_IS_BLOCK_FILE(obj) \
42         (G_TYPE_CHECK_INSTANCE_TYPE \
43         ((obj), CAMEL_TYPE_BLOCK_FILE))
44 #define CAMEL_IS_BLOCK_FILE_CLASS(cls) \
45         (G_TYPE_CHECK_CLASS_TYPE \
46         ((cls), CAMEL_TYPE_BLOCK_FILE))
47 #define CAMEL_BLOCK_FILE_GET_CLASS(obj) \
48         (G_TYPE_INSTANCE_GET_CLASS \
49         ((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
50
51 #define CAMEL_TYPE_KEY_FILE \
52         (camel_key_file_get_type ())
53 #define CAMEL_KEY_FILE(obj) \
54         (G_TYPE_CHECK_INSTANCE_CAST \
55         ((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFile))
56 #define CAMEL_KEY_FILE_CLASS(cls) \
57         (G_TYPE_CHECK_CLASS_CAST \
58         ((cls), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
59 #define CAMEL_IS_KEY_FILE(obj) \
60         (G_TYPE_CHECK_INSTANCE_TYPE \
61         ((obj), CAMEL_TYPE_KEY_FILE))
62 #define CAMEL_IS_KEY_FILE_CLASS(cls) \
63         (G_TYPE_CHECK_CLASS_TYPE \
64         ((cls), CAMEL_TYPE_KEY_FILE))
65 #define CAMEL_KEY_FILE_GET_CLASS(obj) \
66         (G_TYPE_INSTANCE_GET_CLASS \
67         ((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
68
69 G_BEGIN_DECLS
70
71 typedef guint32 camel_block_t;  /* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
72 typedef guint32 camel_key_t;    /* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */
73
74 typedef struct _CamelBlockRoot CamelBlockRoot;
75 typedef struct _CamelBlock CamelBlock;
76 typedef struct _CamelBlockFile CamelBlockFile;
77 typedef struct _CamelBlockFileClass CamelBlockFileClass;
78 typedef struct _CamelBlockFilePrivate CamelBlockFilePrivate;
79
80 typedef enum {
81         CAMEL_BLOCK_FILE_SYNC = 1 << 0
82 } CamelBlockFileFlags;
83
84 #define CAMEL_BLOCK_SIZE (1024)
85 #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */
86
87 typedef enum {
88         CAMEL_BLOCK_DIRTY    = 1 << 0,
89         CAMEL_BLOCK_DETACHED = 1 << 1
90 } CamelBlockFlags;
91
92 struct _CamelBlockRoot {
93         gchar version[8];       /* version number */
94
95         guint32 flags;          /* flags for file */
96         guint32 block_size;     /* block size of this file */
97         camel_block_t free;     /* free block list */
98         camel_block_t last;     /* pointer to end of blocks */
99
100         /* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
101 };
102
103 /* LRU cache of blocks */
104 struct _CamelBlock {
105         camel_block_t id;
106         CamelBlockFlags flags;
107         guint32 refcount;
108         guint32 align00;
109
110         guchar data[CAMEL_BLOCK_SIZE];
111 };
112
113 struct _CamelBlockFile {
114         CamelObject parent;
115         CamelBlockFilePrivate *priv;
116
117         gchar version[8];
118         gchar *path;
119         CamelBlockFileFlags flags;
120
121         gint fd;
122         gsize block_size;
123
124         CamelBlockRoot *root;
125         CamelBlock *root_block;
126
127         /* make private? */
128         gint block_cache_limit;
129         gint block_cache_count;
130         GQueue block_cache;
131         GHashTable *blocks;
132 };
133
134 struct _CamelBlockFileClass {
135         CamelObjectClass parent;
136
137         gint (*validate_root)(CamelBlockFile *);
138         gint (*init_root)(CamelBlockFile *);
139 };
140
141 GType           camel_block_file_get_type       (void);
142 CamelBlockFile *camel_block_file_new            (const gchar *path,
143                                                  gint flags,
144                                                  const gchar version[8],
145                                                  gsize block_size);
146 gint            camel_block_file_rename         (CamelBlockFile *bs,
147                                                  const gchar *path);
148 gint            camel_block_file_delete         (CamelBlockFile *kf);
149 CamelBlock *    camel_block_file_new_block      (CamelBlockFile *bs);
150 gint            camel_block_file_free_block     (CamelBlockFile *bs,
151                                                  camel_block_t id);
152 CamelBlock *    camel_block_file_get_block      (CamelBlockFile *bs,
153                                                  camel_block_t id);
154 void            camel_block_file_detach_block   (CamelBlockFile *bs,
155                                                  CamelBlock *bl);
156 void            camel_block_file_attach_block   (CamelBlockFile *bs,
157                                                  CamelBlock *bl);
158 void            camel_block_file_touch_block    (CamelBlockFile *bs,
159                                                  CamelBlock *bl);
160 void            camel_block_file_unref_block    (CamelBlockFile *bs,
161                                                  CamelBlock *bl);
162 gint            camel_block_file_sync_block     (CamelBlockFile *bs,
163                                                  CamelBlock *bl);
164 gint            camel_block_file_sync           (CamelBlockFile *bs);
165
166 /* ********************************************************************** */
167
168 typedef struct _CamelKeyFile CamelKeyFile;
169 typedef struct _CamelKeyFileClass CamelKeyFileClass;
170 typedef struct _CamelKeyFilePrivate CamelKeyFilePrivate;
171
172 struct _CamelKeyFile {
173         CamelObject parent;
174         CamelKeyFilePrivate *priv;
175
176         FILE *fp;
177         gchar *path;
178         gint flags;
179         goffset last;
180 };
181
182 struct _CamelKeyFileClass {
183         CamelObjectClass parent;
184 };
185
186 GType      camel_key_file_get_type (void);
187
188 CamelKeyFile * camel_key_file_new (const gchar *path, gint flags, const gchar version[8]);
189 gint           camel_key_file_rename (CamelKeyFile *kf, const gchar *path);
190 gint           camel_key_file_delete (CamelKeyFile *kf);
191
192 gint            camel_key_file_write (CamelKeyFile *kf, camel_block_t *parent, gsize len, camel_key_t *records);
193 gint            camel_key_file_read (CamelKeyFile *kf, camel_block_t *start, gsize *len, camel_key_t **records);
194
195 G_END_DECLS
196
197 #endif /* CAMEL_BLOCK_FILE_H */