]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/defs.h
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / bindings / ruby / defs.h
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010, 2011, 2012 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 https://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 #include <talloc.h>
27
28 extern VALUE notmuch_rb_cDatabase;
29 extern VALUE notmuch_rb_cDirectory;
30 extern VALUE notmuch_rb_cFileNames;
31 extern VALUE notmuch_rb_cQuery;
32 extern VALUE notmuch_rb_cThreads;
33 extern VALUE notmuch_rb_cThread;
34 extern VALUE notmuch_rb_cMessages;
35 extern VALUE notmuch_rb_cMessage;
36
37 extern VALUE notmuch_rb_eBaseError;
38 extern VALUE notmuch_rb_eDatabaseError;
39 extern VALUE notmuch_rb_eMemoryError;
40 extern VALUE notmuch_rb_eReadOnlyError;
41 extern VALUE notmuch_rb_eXapianError;
42 extern VALUE notmuch_rb_eFileError;
43 extern VALUE notmuch_rb_eFileNotEmailError;
44 extern VALUE notmuch_rb_eNullPointerError;
45 extern VALUE notmuch_rb_eTagTooLongError;
46 extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
47 extern VALUE notmuch_rb_eUnbalancedAtomicError;
48
49 extern ID ID_call;
50
51 /* RSTRING_PTR() is new in ruby-1.9 */
52 #if !defined(RSTRING_PTR)
53 # define RSTRING_PTR(v) (RSTRING((v))->ptr)
54 #endif /* !defined (RSTRING_PTR) */
55
56 extern const rb_data_type_t notmuch_rb_object_type;
57 extern const rb_data_type_t notmuch_rb_database_type;
58 extern const rb_data_type_t notmuch_rb_directory_type;
59 extern const rb_data_type_t notmuch_rb_query_type;
60 extern const rb_data_type_t notmuch_rb_threads_type;
61 extern const rb_data_type_t notmuch_rb_thread_type;
62 extern const rb_data_type_t notmuch_rb_messages_type;
63 extern const rb_data_type_t notmuch_rb_message_type;
64 extern const rb_data_type_t notmuch_rb_tags_type;
65
66 #define Data_Get_Notmuch_Rb_Object(obj, type, ptr)                                  \
67     do {                                                                            \
68         (ptr) = rb_check_typeddata ((obj), (type));                                 \
69         if (RB_UNLIKELY (!(ptr))) {                                                 \
70             VALUE cname = rb_class_name (CLASS_OF ((obj)));                         \
71             rb_raise (rb_eRuntimeError, "%"PRIsVALUE" object destroyed", cname);    \
72         }                                                                           \
73     } while (0)
74
75 #define Data_Get_Notmuch_Object(obj, type, ptr)                 \
76     do {                                                        \
77         notmuch_rb_object_t *rb_wrapper;                        \
78         Data_Get_Notmuch_Rb_Object ((obj), (type), rb_wrapper); \
79         (ptr) = rb_wrapper->nm_object;                          \
80     } while (0)
81
82 #define Data_Wrap_Notmuch_Object(klass, type, ptr) \
83     TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr), "notmuch_rb_object: " __location__))
84
85 #define Data_Get_Notmuch_Database(obj, ptr) \
86     Data_Get_Notmuch_Object ((obj), &notmuch_rb_database_type, (ptr))
87
88 #define Data_Get_Notmuch_Directory(obj, ptr) \
89     Data_Get_Notmuch_Object ((obj), &notmuch_rb_directory_type, (ptr))
90
91 #define Data_Get_Notmuch_Query(obj, ptr) \
92     Data_Get_Notmuch_Object ((obj), &notmuch_rb_query_type, (ptr))
93
94 #define Data_Get_Notmuch_Threads(obj, ptr) \
95     Data_Get_Notmuch_Object ((obj), &notmuch_rb_threads_type, (ptr))
96
97 #define Data_Get_Notmuch_Messages(obj, ptr) \
98     Data_Get_Notmuch_Object ((obj), &notmuch_rb_messages_type, (ptr))
99
100 #define Data_Get_Notmuch_Thread(obj, ptr) \
101     Data_Get_Notmuch_Object ((obj), &notmuch_rb_thread_type, (ptr))
102
103 #define Data_Get_Notmuch_Message(obj, ptr) \
104     Data_Get_Notmuch_Object ((obj), &notmuch_rb_message_type, (ptr))
105
106 #define Data_Get_Notmuch_Tags(obj, ptr) \
107     Data_Get_Notmuch_Object ((obj), &notmuch_rb_tags_type, (ptr))
108
109 typedef struct {
110     void *nm_object;
111 } notmuch_rb_object_t;
112
113 static inline void *
114 notmuch_rb_object_create (void *nm_object, const char *name)
115 {
116     notmuch_rb_object_t *rb_wrapper = talloc_named_const (NULL, sizeof (*rb_wrapper), name);
117
118     if (RB_UNLIKELY (!rb_wrapper))
119         return NULL;
120
121     rb_wrapper->nm_object = nm_object;
122     talloc_steal (rb_wrapper, nm_object);
123     return rb_wrapper;
124 }
125
126 static inline void
127 notmuch_rb_object_free (void *rb_wrapper)
128 {
129     talloc_free (rb_wrapper);
130 }
131
132 static inline void
133 notmuch_rb_object_destroy (VALUE rb_object, const rb_data_type_t *type)
134 {
135     notmuch_rb_object_t *rb_wrapper;
136
137     Data_Get_Notmuch_Rb_Object (rb_object, type, rb_wrapper);
138
139     /* Call the corresponding notmuch_*_destroy function */
140     ((void (*)(void *)) type->data) (rb_wrapper->nm_object);
141     notmuch_rb_object_free (rb_wrapper);
142     DATA_PTR (rb_object) = NULL;
143 }
144
145 /* status.c */
146 void
147 notmuch_rb_status_raise (notmuch_status_t status);
148
149 /* database.c */
150 VALUE
151 notmuch_rb_database_alloc (VALUE klass);
152
153 VALUE
154 notmuch_rb_database_destroy (VALUE self);
155
156 VALUE
157 notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE klass);
158
159 VALUE
160 notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass);
161
162 VALUE
163 notmuch_rb_database_close (VALUE self);
164
165 VALUE
166 notmuch_rb_database_path (VALUE self);
167
168 VALUE
169 notmuch_rb_database_version (VALUE self);
170
171 VALUE
172 notmuch_rb_database_needs_upgrade (VALUE self);
173
174 VALUE
175 notmuch_rb_database_upgrade (VALUE self);
176
177 VALUE
178 notmuch_rb_database_begin_atomic (VALUE self);
179
180 VALUE
181 notmuch_rb_database_end_atomic (VALUE self);
182
183 VALUE
184 notmuch_rb_database_get_directory (VALUE self, VALUE pathv);
185
186 VALUE
187 notmuch_rb_database_add_message (VALUE self, VALUE pathv);
188
189 VALUE
190 notmuch_rb_database_remove_message (VALUE self, VALUE pathv);
191
192 VALUE
193 notmuch_rb_database_find_message (VALUE self, VALUE idv);
194
195 VALUE
196 notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv);
197
198 VALUE
199 notmuch_rb_database_get_all_tags (VALUE self);
200
201 VALUE
202 notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
203
204 /* directory.c */
205 VALUE
206 notmuch_rb_directory_destroy (VALUE self);
207
208 VALUE
209 notmuch_rb_directory_get_mtime (VALUE self);
210
211 VALUE
212 notmuch_rb_directory_set_mtime (VALUE self, VALUE mtimev);
213
214 VALUE
215 notmuch_rb_directory_get_child_files (VALUE self);
216
217 VALUE
218 notmuch_rb_directory_get_child_directories (VALUE self);
219
220 /* filenames.c */
221 VALUE
222 notmuch_rb_filenames_get (notmuch_filenames_t *fnames);
223
224 /* query.c */
225 VALUE
226 notmuch_rb_query_destroy (VALUE self);
227
228 VALUE
229 notmuch_rb_query_get_sort (VALUE self);
230
231 VALUE
232 notmuch_rb_query_set_sort (VALUE self, VALUE sortv);
233
234 VALUE
235 notmuch_rb_query_get_string (VALUE self);
236
237 VALUE
238 notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
239
240 VALUE
241 notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv);
242
243 VALUE
244 notmuch_rb_query_search_threads (VALUE self);
245
246 VALUE
247 notmuch_rb_query_search_messages (VALUE self);
248
249 VALUE
250 notmuch_rb_query_count_messages (VALUE self);
251
252 VALUE
253 notmuch_rb_query_count_threads (VALUE self);
254
255 /* threads.c */
256 VALUE
257 notmuch_rb_threads_destroy (VALUE self);
258
259 VALUE
260 notmuch_rb_threads_each (VALUE self);
261
262 /* messages.c */
263 VALUE
264 notmuch_rb_messages_destroy (VALUE self);
265
266 VALUE
267 notmuch_rb_messages_each (VALUE self);
268
269 VALUE
270 notmuch_rb_messages_collect_tags (VALUE self);
271
272 /* thread.c */
273 VALUE
274 notmuch_rb_thread_destroy (VALUE self);
275
276 VALUE
277 notmuch_rb_thread_get_thread_id (VALUE self);
278
279 VALUE
280 notmuch_rb_thread_get_total_messages (VALUE self);
281
282 VALUE
283 notmuch_rb_thread_get_toplevel_messages (VALUE self);
284
285 VALUE
286 notmuch_rb_thread_get_messages (VALUE self);
287
288 VALUE
289 notmuch_rb_thread_get_matched_messages (VALUE self);
290
291 VALUE
292 notmuch_rb_thread_get_authors (VALUE self);
293
294 VALUE
295 notmuch_rb_thread_get_subject (VALUE self);
296
297 VALUE
298 notmuch_rb_thread_get_oldest_date (VALUE self);
299
300 VALUE
301 notmuch_rb_thread_get_newest_date (VALUE self);
302
303 VALUE
304 notmuch_rb_thread_get_tags (VALUE self);
305
306 /* message.c */
307 VALUE
308 notmuch_rb_message_destroy (VALUE self);
309
310 VALUE
311 notmuch_rb_message_get_message_id (VALUE self);
312
313 VALUE
314 notmuch_rb_message_get_thread_id (VALUE self);
315
316 VALUE
317 notmuch_rb_message_get_replies (VALUE self);
318
319 VALUE
320 notmuch_rb_message_get_filename (VALUE self);
321
322 VALUE
323 notmuch_rb_message_get_filenames (VALUE self);
324
325 VALUE
326 notmuch_rb_message_get_flag (VALUE self, VALUE flagv);
327
328 VALUE
329 notmuch_rb_message_set_flag (VALUE self, VALUE flagv, VALUE valuev);
330
331 VALUE
332 notmuch_rb_message_get_date (VALUE self);
333
334 VALUE
335 notmuch_rb_message_get_header (VALUE self, VALUE headerv);
336
337 VALUE
338 notmuch_rb_message_get_tags (VALUE self);
339
340 VALUE
341 notmuch_rb_message_add_tag (VALUE self, VALUE tagv);
342
343 VALUE
344 notmuch_rb_message_remove_tag (VALUE self, VALUE tagv);
345
346 VALUE
347 notmuch_rb_message_remove_all_tags (VALUE self);
348
349 VALUE
350 notmuch_rb_message_maildir_flags_to_tags (VALUE self);
351
352 VALUE
353 notmuch_rb_message_tags_to_maildir_flags (VALUE self);
354
355 VALUE
356 notmuch_rb_message_freeze (VALUE self);
357
358 VALUE
359 notmuch_rb_message_thaw (VALUE self);
360
361 /* tags.c */
362 VALUE
363 notmuch_rb_tags_get (notmuch_tags_t *tags);
364
365 /* init.c */
366 void
367 Init_notmuch (void);
368
369 #endif