]> git.notmuchmail.org Git - notmuch/blob - thread.cc
Add an initial implementation of a notmuch_thread_t object.
[notmuch] / thread.cc
1 /* thread.cc - Results of thread-based searches from a notmuch database
2  *
3  * Copyright © 2009 Carl Worth
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: Carl Worth <cworth@cworth.org>
19  */
20
21 #include "notmuch-private.h"
22 #include "database-private.h"
23
24 #include <xapian.h>
25
26 struct _notmuch_thread {
27     notmuch_database_t *notmuch;
28     char *thread_id;
29 };
30
31 /* Create a new notmuch_thread_t object for an existing document in
32  * the database.
33  *
34  * Here, 'talloc owner' is an optional talloc context to which the new
35  * thread will belong. This allows for the caller to not bother
36  * calling notmuch_thread_destroy on the thread, and know that all
37  * memory will be reclaimed with 'talloc_owner' is freed. The caller
38  * still can call notmuch_thread_destroy when finished with the
39  * thread if desired.
40  *
41  * The 'talloc_owner' argument can also be NULL, in which case the
42  * caller *is* responsible for calling notmuch_thread_destroy.
43  *
44  * This function returns NULL in the case of any error.
45  */
46 notmuch_thread_t *
47 _notmuch_thread_create (const void *talloc_owner,
48                         notmuch_database_t *notmuch,
49                         const char *thread_id)
50 {
51     notmuch_thread_t *thread;
52
53     thread = talloc (talloc_owner, notmuch_thread_t);
54     if (unlikely (thread == NULL))
55         return NULL;
56
57     thread->notmuch = notmuch;
58     thread->thread_id = talloc_strdup (thread, thread_id);
59
60     return thread;
61 }
62
63 const char *
64 notmuch_thread_get_thread_id (notmuch_thread_t *thread)
65 {
66     return thread->thread_id;
67 }
68
69 void
70 notmuch_thread_destroy (notmuch_thread_t *thread)
71 {
72     talloc_free (thread);
73 }