aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-03-24 03:57:31 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-03-24 03:57:31 +0800
commit6a766351410912acde101b6fa01488338efca5c8 (patch)
treec07e09a90d70b9438999f698c3d82682fbe7d857 /camel
parentd2e39f53aef475f9747aae84dcb22baf26c72b78 (diff)
downloadgsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar.gz
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar.bz2
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar.lz
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar.xz
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.tar.zst
gsoc2013-evolution-6a766351410912acde101b6fa01488338efca5c8.zip
Added async search api.
2000-03-22 NotZed <NotZed@HelixCode.com> * camel-folder.[ch]: Added async search api. * providers/mbox/camel-mbox-search.c (camel_mbox_folder_search_by_expression): Changed to use an asynchronous interface. (camel_mbox_folder_search_cancel): Cancel function for async interface. svn path=/trunk/; revision=2155
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog10
-rw-r--r--camel/camel-folder.c28
-rw-r--r--camel/camel-folder.h14
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c12
-rw-r--r--camel/providers/mbox/camel-mbox-folder.h2
-rw-r--r--camel/providers/mbox/camel-mbox-search.c120
-rw-r--r--camel/providers/mbox/camel-mbox-search.h6
7 files changed, 148 insertions, 44 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 3bb7c1529b..eeb96cb2dc 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,13 @@
+2000-03-22 NotZed <NotZed@HelixCode.com>
+
+ * camel-folder.[ch]: Added async search api.
+
+ * providers/mbox/camel-mbox-search.c
+ (camel_mbox_folder_search_by_expression): Changed to use an
+ asynchronous interface.
+ (camel_mbox_folder_search_cancel): Cancel function for async
+ interface.
+
2000-03-23 Dan Winship <danw@helixcode.com>
* camel-stream-buffer.c (camel_stream_buffer_read_line): Function
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index d272d42a22..f26921526f 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -1399,14 +1399,32 @@ camel_folder_has_search_capability (CamelFolder *folder)
return folder->has_search_capability;
}
-GList *camel_folder_search_by_expression (CamelFolder *folder,
- const char *expression,
- CamelException *ex)
+int camel_folder_search_by_expression (CamelFolder *folder,
+ const char *expression,
+ CamelSearchFunc *func,
+ void *data,
+ CamelException *ex)
{
g_assert (folder != NULL);
- g_return_val_if_fail (folder->has_search_capability, NULL);
+ g_return_val_if_fail (folder->has_search_capability, -1);
- return CF_CLASS (folder)->search_by_expression (folder, expression, ex);
+ return CF_CLASS (folder)->search_by_expression (folder, expression, func, data, ex);
+}
+
+gboolean camel_folder_search_complete(CamelFolder *folder, int searchid, gboolean wait, CamelException *ex)
+{
+ g_assert (folder != NULL);
+ g_return_if_fail (folder->has_search_capability);
+
+ return CF_CLASS (folder)->search_complete (folder, searchid, wait, ex);
+}
+
+void camel_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex)
+{
+ g_assert (folder != NULL);
+ g_return_if_fail (folder->has_search_capability);
+
+ return CF_CLASS (folder)->search_cancel (folder, searchid, ex);
}
/* **** */
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index 67de66a83e..68a6c8f214 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -56,7 +56,7 @@ typedef enum {
typedef void (*CamelFolderAsyncCallback) ();
-
+typedef void (CamelSearchFunc)(CamelFolder *folder, int id, gboolean complete, GList *matches, void *data);
struct _CamelFolder
{
@@ -195,7 +195,10 @@ typedef struct {
gboolean (*has_search_capability) (CamelFolder *folder);
- GList *(*search_by_expression) (CamelFolder *folder, const char *expression, CamelException *ex);
+ int (*search_by_expression) (CamelFolder *folder, const char *expression,
+ CamelSearchFunc *func, void *data, CamelException *ex);
+ gboolean (*search_complete)(CamelFolder *folder, int searchid, gboolean wait, CamelException *ex);
+ void (*search_cancel) (CamelFolder *folder, int searchid, CamelException *ex);
} CamelFolderClass;
@@ -301,9 +304,10 @@ GList * camel_folder_get_uid_list (CamelFolder *folder,
/* search api */
gboolean camel_folder_has_search_capability (CamelFolder *folder);
-GList * camel_folder_search_by_expression (CamelFolder *folder,
- const char *expression,
- CamelException *ex);
+int camel_folder_search_by_expression(CamelFolder *folder, const char *expression,
+ CamelSearchFunc *func, void *data, CamelException *ex);
+gboolean camel_folder_search_complete(CamelFolder *folder, int searchid, gboolean wait, CamelException *ex);
+void camel_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex);
#ifdef __cplusplus
}
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index fdba8279b3..8c7303924e 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -83,8 +83,6 @@ static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, Ca
static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
#endif
-static GList *search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex);
-
static void _finalize (GtkObject *object);
static void
@@ -118,7 +116,9 @@ camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class)
#endif
camel_folder_class->get_message_by_uid = _get_message_by_uid;
- camel_folder_class->search_by_expression = search_by_expression;
+ camel_folder_class->search_by_expression = camel_mbox_folder_search_by_expression;
+ camel_folder_class->search_complete = camel_mbox_folder_search_complete;
+ camel_folder_class->search_cancel = camel_mbox_folder_search_cancel;
gtk_object_class->finalize = _finalize;
@@ -1073,9 +1073,3 @@ _get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
CAMEL_LOG_FULL_DEBUG ("Leaving CamelMboxFolder::get_uid_list\n");
return message;
}
-
-static GList *
-search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex)
-{
- return camel_mbox_folder_search_by_expression(folder, expression, ex);
-}
diff --git a/camel/providers/mbox/camel-mbox-folder.h b/camel/providers/mbox/camel-mbox-folder.h
index 76288d5c3c..4caa28fd6a 100644
--- a/camel/providers/mbox/camel-mbox-folder.h
+++ b/camel/providers/mbox/camel-mbox-folder.h
@@ -59,6 +59,8 @@ typedef struct {
CamelMboxSummary *internal_summary; /* internal summary object */
GList *uid_array;
+ int search_id; /* next search id */
+ GList *searches; /* current searches */
} CamelMboxFolder;
diff --git a/camel/providers/mbox/camel-mbox-search.c b/camel/providers/mbox/camel-mbox-search.c
index 47d4012c4c..22aa599709 100644
--- a/camel/providers/mbox/camel-mbox-search.c
+++ b/camel/providers/mbox/camel-mbox-search.c
@@ -76,7 +76,8 @@
struct _searchcontext {
- int whatever;
+ int id; /* id of this search */
+ int cancelled; /* search cancelled? */
CamelFolder *folder;
@@ -268,11 +269,11 @@ static struct {
{ "header-contains", func_header_contains, 0 },
};
-GList *
-camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex)
+int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression,
+ CamelSearchFunc *func, void *data, CamelException *ex)
{
int i;
- struct _searchcontext ctx;
+ struct _searchcontext *ctx;
GList *matches = NULL;
ESExp *f;
ESExpResult *r;
@@ -280,31 +281,39 @@ camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expressi
/* setup our expression evaluator */
f = e_sexp_new();
+ ctx = g_malloc0(sizeof(*ctx));
+
+ ctx->id = ((CamelMboxFolder *)folder)->search_id++;
+
/* setup out context */
- ctx.folder = folder;
- ctx.summary = camel_folder_get_summary(folder, ex);
- gtk_object_ref((GtkObject *)ctx.summary);
+ ctx->folder = folder;
+ ctx->summary = camel_folder_get_summary(folder, ex);
- if (camel_exception_get_id (ex)) {
+ if (ctx->summary == NULL || camel_exception_get_id (ex)) {
printf ("Cannot get summary\n"
"Full description : %s\n", camel_exception_get_description (ex));
- /* FIXME: free shit */
- return NULL;
+ g_free(ctx);
+ gtk_object_unref((GtkObject *)f);
+ return -1;
}
+ gtk_object_ref((GtkObject *)ctx->summary);
- ctx.message_info = camel_folder_summary_get_message_info_list(ctx.summary);
- ctx.message_current = NULL;
- ctx.index = ibex_open(CAMEL_MBOX_FOLDER(folder)->index_file_path, FALSE);
- if (!ctx.index) {
- perror("Cannot open index file");
+ /* FIXME: the index should be global to the folder */
+ ctx->message_info = camel_folder_summary_get_message_info_list(ctx->summary);
+ ctx->message_current = NULL;
+ ctx->index = ibex_open(CAMEL_MBOX_FOLDER(folder)->index_file_path, FALSE);
+ if (!ctx->index) {
+ perror("Cannot open index file (ignored)");
}
+ ((CamelMboxFolder *)folder)->searches = g_list_append(((CamelMboxFolder *)folder)->searches, ctx);
+
for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) {
if (symbols[i].type == 1) {
- e_sexp_add_ifunction(f, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, &ctx);
+ e_sexp_add_ifunction(f, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, ctx);
} else {
- e_sexp_add_function(f, 0, symbols[i].name, symbols[i].func, &ctx);
+ e_sexp_add_function(f, 0, symbols[i].name, symbols[i].func, ctx);
}
}
@@ -320,26 +329,89 @@ camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expressi
d(printf("adding match: %s\n", (char *)g_ptr_array_index(r->value.ptrarray, i)));
matches = g_list_prepend(matches, g_strdup(g_ptr_array_index(r->value.ptrarray, i)));
}
+ if (!ctx->cancelled) {
+ func(folder, ctx->id, TRUE, matches, data);
+ }
+ g_list_free(matches);
e_sexp_result_free(r);
} else {
printf("no result!\n");
}
- if (ctx.index)
- ibex_close(ctx.index);
+ if (ctx->index)
+ ibex_close(ctx->index);
- gtk_object_unref((GtkObject *)ctx.summary);
+ gtk_object_unref((GtkObject *)ctx->summary);
gtk_object_unref((GtkObject *)f);
+ i = ctx->id;
- return matches;
+ ((CamelMboxFolder *)folder)->searches = g_list_remove(((CamelMboxFolder *)folder)->searches, ctx);
+
+ g_free(ctx);
+
+ return i;
+}
+
+static struct _searchcontext *
+find_context(CamelMboxFolder *f, int id)
+{
+ struct _searchcontext *ctx;
+ GList *l;
+
+ l = f->searches;
+ while (l) {
+ ctx = l->data;
+ if (ctx->id == id) {
+ return ctx;
+ }
+ l = g_list_next(l);
+ }
+
+ return NULL;
+}
+
+gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, int wait, CamelException *ex)
+{
+ struct _searchcontext *ctx;
+
+ ctx = find_context((CamelMboxFolder *)folder, searchid);
+
+ if (ctx)
+ return ctx->cancelled;
+
+ /* if its been removed, its complete ... */
+ return TRUE;
+}
+
+void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex)
+{
+ struct _searchcontext *ctx;
+
+ ctx = find_context((CamelMboxFolder *)folder, searchid);
+ if (ctx) {
+ ctx->cancelled = TRUE;
+ return;
+ }
+
+ /* FIXME: set exception, return */
}
#else /* HAVE_FILTER */
-GList *
-camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex)
+int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression,
+ CamelSearchFunc *func, void *data, CamelException *ex)
{
- return NULL;
+ return -1;
+}
+
+gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, int wait, CamelException *ex)
+{
+ return TRUE;
+}
+
+void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex)
+{
+ /* empty */
}
#endif /*! HAVE_FILTER */
diff --git a/camel/providers/mbox/camel-mbox-search.h b/camel/providers/mbox/camel-mbox-search.h
index d232624386..d3fe328a2c 100644
--- a/camel/providers/mbox/camel-mbox-search.h
+++ b/camel/providers/mbox/camel-mbox-search.h
@@ -2,9 +2,13 @@
#ifndef _CAMEL_MBOX_SEARCH_H
#define _CAMEL_MBOX_SEARCH_H
+#include <glib.h>
#include "camel-mbox-folder.h"
-GList *camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex);
+int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression,
+ CamelSearchFunc *func, void *data, CamelException *ex);
+gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, gboolean wait, CamelException *ex);
+void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex);
#endif /* ! _CAMEL_MBOX_SEARCH_H */