Merge in ruby bindings.
[notmuch] / bindings / ruby / defs.h
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010 Ali Polatel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Ali Polatel <alip@exherbo.org>
19  */
20
21 #ifndef DEFS_H
22 #define DEFS_H
23
24 #include <notmuch.h>
25 #include <ruby.h>
26
27 VALUE notmuch_rb_cDatabase;
28 VALUE notmuch_rb_cDirectory;
29 VALUE notmuch_rb_cFileNames;
30 VALUE notmuch_rb_cQuery;
31 VALUE notmuch_rb_cThreads;
32 VALUE notmuch_rb_cThread;
33 VALUE notmuch_rb_cMessages;
34 VALUE notmuch_rb_cMessage;
35 VALUE notmuch_rb_cTags;
36
37 VALUE notmuch_rb_eBaseError;
38 VALUE notmuch_rb_eDatabaseError;
39 VALUE notmuch_rb_eMemoryError;
40 VALUE notmuch_rb_eReadOnlyError;
41 VALUE notmuch_rb_eXapianError;
42 VALUE notmuch_rb_eFileError;
43 VALUE notmuch_rb_eFileNotEmailError;
44 VALUE notmuch_rb_eNullPointerError;
45 VALUE notmuch_rb_eTagTooLongError;
46 VALUE notmuch_rb_eUnbalancedFreezeThawError;
47
48 ID ID_call;
49 ID ID_db_create;
50 ID ID_db_mode;
51
52 #define Data_Get_Notmuch_Database(obj, ptr)                \
53     do {                                                   \
54         Check_Type(obj, T_DATA);                           \
55         if (DATA_PTR(obj) == NULL)                         \
56             rb_raise(rb_eRuntimeError, "database closed"); \
57         Data_Get_Struct(obj, notmuch_database_t, ptr);     \
58     } while(0)
59
60 #define Data_Get_Notmuch_Directory(obj, ptr)                   \
61     do {                                                       \
62         Check_Type(obj, T_DATA);                               \
63         if (DATA_PTR(obj) == NULL)                             \
64             rb_raise(rb_eRuntimeError, "directory destroyed"); \
65         Data_Get_Struct(obj, notmuch_directory_t, ptr);        \
66     } while(0)
67
68 #define Data_Get_Notmuch_FileNames(obj, ptr)                   \
69     do {                                                       \
70         Check_Type(obj, T_DATA);                               \
71         if (DATA_PTR(obj) == NULL)                             \
72             rb_raise(rb_eRuntimeError, "filenames destroyed"); \
73         Data_Get_Struct(obj, notmuch_filenames_t, ptr);        \
74     } while(0)
75
76 #define Data_Get_Notmuch_Query(obj, ptr)                   \
77     do {                                                   \
78         Check_Type(obj, T_DATA);                           \
79         if (DATA_PTR(obj) == NULL)                         \
80             rb_raise(rb_eRuntimeError, "query destroyed"); \
81         Data_Get_Struct(obj, notmuch_query_t, ptr);        \
82     } while(0)
83
84 #define Data_Get_Notmuch_Threads(obj, ptr)                   \
85     do {                                                     \
86         Check_Type(obj, T_DATA);                             \
87         if (DATA_PTR(obj) == NULL)                           \
88             rb_raise(rb_eRuntimeError, "threads destroyed"); \
89         Data_Get_Struct(obj, notmuch_threads_t, ptr);        \
90     } while(0)
91
92 #define Data_Get_Notmuch_Messages(obj, ptr)                   \
93     do {                                                      \
94         Check_Type(obj, T_DATA);                              \
95         if (DATA_PTR(obj) == NULL)                            \
96             rb_raise(rb_eRuntimeError, "messages destroyed"); \
97         Data_Get_Struct(obj, notmuch_messages_t, ptr);        \
98     } while(0)
99
100 #define Data_Get_Notmuch_Thread(obj, ptr)                   \
101     do {                                                    \
102         Check_Type(obj, T_DATA);                            \
103         if (DATA_PTR(obj) == NULL)                          \
104             rb_raise(rb_eRuntimeError, "thread destroyed"); \
105         Data_Get_Struct(obj, notmuch_thread_t, ptr);        \
106     } while(0)
107
108 #define Data_Get_Notmuch_Message(obj, ptr)                   \
109     do {                                                     \
110         Check_Type(obj, T_DATA);                             \
111         if (DATA_PTR(obj) == NULL)                           \
112             rb_raise(rb_eRuntimeError, "message destroyed"); \
113         Data_Get_Struct(obj, notmuch_message_t, ptr);        \
114     } while(0)
115
116 #define Data_Get_Notmuch_Tags(obj, ptr)                   \
117     do {                                                  \
118         Check_Type(obj, T_DATA);                          \
119         if (DATA_PTR(obj) == NULL)                        \
120             rb_raise(rb_eRuntimeError, "tags destroyed"); \
121         Data_Get_Struct(obj, notmuch_tags_t, ptr);        \
122     } while(0)
123
124 /* status.c */
125 void
126 notmuch_rb_status_raise(notmuch_status_t status);
127
128 /* database.c */
129 VALUE
130 notmuch_rb_database_alloc(VALUE klass);
131
132 VALUE
133 notmuch_rb_database_initialize(int argc, VALUE *argv, VALUE klass);
134
135 VALUE
136 notmuch_rb_database_open(int argc, VALUE *argv, VALUE klass);
137
138 VALUE
139 notmuch_rb_database_close(VALUE self);
140
141 VALUE
142 notmuch_rb_database_path(VALUE self);
143
144 VALUE
145 notmuch_rb_database_version(VALUE self);
146
147 VALUE
148 notmuch_rb_database_needs_upgrade(VALUE self);
149
150 VALUE
151 notmuch_rb_database_upgrade(VALUE self);
152
153 VALUE
154 notmuch_rb_database_get_directory(VALUE self, VALUE pathv);
155
156 VALUE
157 notmuch_rb_database_add_message(VALUE self, VALUE pathv);
158
159 VALUE
160 notmuch_rb_database_remove_message(VALUE self, VALUE pathv);
161
162 VALUE
163 notmuch_rb_database_query_create(VALUE self, VALUE qstrv);
164
165 /* directory.c */
166 VALUE
167 notmuch_rb_directory_destroy(VALUE self);
168
169 VALUE
170 notmuch_rb_directory_get_mtime(VALUE self);
171
172 VALUE
173 notmuch_rb_directory_set_mtime(VALUE self, VALUE mtimev);
174
175 VALUE
176 notmuch_rb_directory_get_child_files(VALUE self);
177
178 VALUE
179 notmuch_rb_directory_get_child_directories(VALUE self);
180
181 /* filenames.c */
182 VALUE
183 notmuch_rb_filenames_destroy(VALUE self);
184
185 VALUE
186 notmuch_rb_filenames_each(VALUE self);
187
188 /* query.c */
189 VALUE
190 notmuch_rb_query_destroy(VALUE self);
191
192 VALUE
193 notmuch_rb_query_set_sort(VALUE self, VALUE sortv);
194
195 VALUE
196 notmuch_rb_query_search_threads(VALUE self);
197
198 VALUE
199 notmuch_rb_query_search_messages(VALUE self);
200
201 /* threads.c */
202 VALUE
203 notmuch_rb_threads_destroy(VALUE self);
204
205 VALUE
206 notmuch_rb_threads_each(VALUE self);
207
208 /* messages.c */
209 VALUE
210 notmuch_rb_messages_destroy(VALUE self);
211
212 VALUE
213 notmuch_rb_messages_each(VALUE self);
214
215 VALUE
216 notmuch_rb_messages_collect_tags(VALUE self);
217
218 /* thread.c */
219 VALUE
220 notmuch_rb_thread_destroy(VALUE self);
221
222 VALUE
223 notmuch_rb_thread_get_thread_id(VALUE self);
224
225 VALUE
226 notmuch_rb_thread_get_total_messages(VALUE self);
227
228 VALUE
229 notmuch_rb_thread_get_toplevel_messages(VALUE self);
230
231 VALUE
232 notmuch_rb_thread_get_matched_messages(VALUE self);
233
234 VALUE
235 notmuch_rb_thread_get_authors(VALUE self);
236
237 VALUE
238 notmuch_rb_thread_get_subject(VALUE self);
239
240 VALUE
241 notmuch_rb_thread_get_oldest_date(VALUE self);
242
243 VALUE
244 notmuch_rb_thread_get_newest_date(VALUE self);
245
246 VALUE
247 notmuch_rb_thread_get_tags(VALUE self);
248
249 /* message.c */
250 VALUE
251 notmuch_rb_message_destroy(VALUE self);
252
253 VALUE
254 notmuch_rb_message_get_message_id(VALUE self);
255
256 VALUE
257 notmuch_rb_message_get_thread_id(VALUE self);
258
259 VALUE
260 notmuch_rb_message_get_replies(VALUE self);
261
262 VALUE
263 notmuch_rb_message_get_filename(VALUE self);
264
265 VALUE
266 notmuch_rb_message_get_flag(VALUE self, VALUE flagv);
267
268 VALUE
269 notmuch_rb_message_set_flag(VALUE self, VALUE flagv, VALUE valuev);
270
271 VALUE
272 notmuch_rb_message_get_date(VALUE self);
273
274 VALUE
275 notmuch_rb_message_get_header(VALUE self, VALUE headerv);
276
277 VALUE
278 notmuch_rb_message_get_tags(VALUE self);
279
280 VALUE
281 notmuch_rb_message_add_tag(VALUE self, VALUE tagv);
282
283 VALUE
284 notmuch_rb_message_remove_tag(VALUE self, VALUE tagv);
285
286 VALUE
287 notmuch_rb_message_remove_all_tags(VALUE self);
288
289 VALUE
290 notmuch_rb_message_freeze(VALUE self);
291
292 VALUE
293 notmuch_rb_message_thaw(VALUE self);
294
295 /* tags.c */
296 VALUE
297 notmuch_rb_tags_destroy(VALUE self);
298
299 VALUE
300 notmuch_rb_tags_each(VALUE self);
301
302 /* init.c */
303 void
304 Init_notmuch(void);
305
306 #endif