summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-11-28 08:35:00 -0500
committerMatthew Barnes <mbarnes@redhat.com>2013-11-29 15:15:39 -0500
commit08453df898706c725045ce0c5c370ae4148329bb (patch)
treefb4cb0e3e3df6829400fe1912eba9c10ad42bf0e
parent5337e035121487d025d8f07a7a7d474d36fcbb2f (diff)
downloadevolution-data-server-08453df898706c725045ce0c5c370ae4148329bb.tar.gz
CamelTransport: Remove all asynchronous class methods.
Rationale: When I originally added Camel's asynchronous API, I thought providers could choose to override the synchronous or asynchronous class methods. Years later, turns out the asynchronous methods were never overridden, and it wouldn't have worked anyway. The asynchronous methods by default invoke an associated synchronous function from a worker thread, but many of Camel's synchronous functions do extra processing around invoking the synchronous class method. camel_store_get_folder_sync() is an example. If a provider tried to implement synchronous methods in terms of the asynchronous methods, then that extra processing in the synchronous functions could potentially get skipped. Removing the asynchronous class methods should help clarify how Camel providers are intended to be written. The removal should have no impact on existing Camel providers, all of which implement only the synchronous class methods. I've even padded the CamelTransportClass struct to keep the binary interface intact.
-rw-r--r--camel/camel-transport.c129
-rw-r--r--camel/camel-transport.h14
2 files changed, 48 insertions, 95 deletions
diff --git a/camel/camel-transport.c b/camel/camel-transport.c
index 66dd0b040..ef9cd9b91 100644
--- a/camel/camel-transport.c
+++ b/camel/camel-transport.c
@@ -80,74 +80,6 @@ transport_finalize (GObject *object)
}
static void
-transport_send_to_thread (GSimpleAsyncResult *simple,
- GObject *object,
- GCancellable *cancellable)
-{
- AsyncContext *async_context;
- GError *error = NULL;
-
- async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
- camel_transport_send_to_sync (
- CAMEL_TRANSPORT (object), async_context->message,
- async_context->from, async_context->recipients,
- cancellable, &error);
-
- if (error != NULL)
- g_simple_async_result_take_error (simple, error);
-}
-
-static void
-transport_send_to (CamelTransport *transport,
- CamelMimeMessage *message,
- CamelAddress *from,
- CamelAddress *recipients,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *simple;
- AsyncContext *async_context;
-
- async_context = g_slice_new0 (AsyncContext);
- async_context->from = g_object_ref (from);
- async_context->recipients = g_object_ref (recipients);
- async_context->message = g_object_ref (message);
-
- simple = g_simple_async_result_new (
- G_OBJECT (transport), callback, user_data, transport_send_to);
-
- g_simple_async_result_set_check_cancellable (simple, cancellable);
-
- g_simple_async_result_set_op_res_gpointer (
- simple, async_context, (GDestroyNotify) async_context_free);
-
- g_simple_async_result_run_in_thread (
- simple, transport_send_to_thread, io_priority, cancellable);
-
- g_object_unref (simple);
-}
-
-static gboolean
-transport_send_to_finish (CamelTransport *transport,
- GAsyncResult *result,
- GError **error)
-{
- GSimpleAsyncResult *simple;
-
- g_return_val_if_fail (
- g_simple_async_result_is_valid (
- result, G_OBJECT (transport), transport_send_to), FALSE);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
-
- /* Assume success unless a GError is set. */
- return !g_simple_async_result_propagate_error (simple, error);
-}
-
-static void
camel_transport_class_init (CamelTransportClass *class)
{
GObjectClass *object_class;
@@ -156,9 +88,6 @@ camel_transport_class_init (CamelTransportClass *class)
object_class = G_OBJECT_CLASS (class);
object_class->finalize = transport_finalize;
-
- class->send_to = transport_send_to;
- class->send_to_finish = transport_send_to_finish;
}
static void
@@ -222,6 +151,26 @@ camel_transport_send_to_sync (CamelTransport *transport,
return success;
}
+/* Helper for camel_transport_send_to() */
+static void
+transport_send_to_thread (GSimpleAsyncResult *simple,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ AsyncContext *async_context;
+ GError *error = NULL;
+
+ async_context = g_simple_async_result_get_op_res_gpointer (simple);
+
+ camel_transport_send_to_sync (
+ CAMEL_TRANSPORT (object), async_context->message,
+ async_context->from, async_context->recipients,
+ cancellable, &error);
+
+ if (error != NULL)
+ g_simple_async_result_take_error (simple, error);
+}
+
/**
* camel_transport_send_to:
* @transport: a #CamelTransport
@@ -252,19 +201,32 @@ camel_transport_send_to (CamelTransport *transport,
GAsyncReadyCallback callback,
gpointer user_data)
{
- CamelTransportClass *class;
+ GSimpleAsyncResult *simple;
+ AsyncContext *async_context;
g_return_if_fail (CAMEL_IS_TRANSPORT (transport));
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
g_return_if_fail (CAMEL_IS_ADDRESS (from));
g_return_if_fail (CAMEL_IS_ADDRESS (recipients));
- class = CAMEL_TRANSPORT_GET_CLASS (transport);
- g_return_if_fail (class->send_to != NULL);
+ async_context = g_slice_new0 (AsyncContext);
+ async_context->from = g_object_ref (from);
+ async_context->recipients = g_object_ref (recipients);
+ async_context->message = g_object_ref (message);
+
+ simple = g_simple_async_result_new (
+ G_OBJECT (transport), callback, user_data,
+ camel_transport_send_to);
- class->send_to (
- transport, message, from, recipients, io_priority,
- cancellable, callback, user_data);
+ g_simple_async_result_set_check_cancellable (simple, cancellable);
+
+ g_simple_async_result_set_op_res_gpointer (
+ simple, async_context, (GDestroyNotify) async_context_free);
+
+ g_simple_async_result_run_in_thread (
+ simple, transport_send_to_thread, io_priority, cancellable);
+
+ g_object_unref (simple);
}
/**
@@ -284,13 +246,14 @@ camel_transport_send_to_finish (CamelTransport *transport,
GAsyncResult *result,
GError **error)
{
- CamelTransportClass *class;
+ GSimpleAsyncResult *simple;
- g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE);
- g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+ g_return_val_if_fail (
+ g_simple_async_result_is_valid (
+ result, G_OBJECT (transport), camel_transport_send_to), FALSE);
- class = CAMEL_TRANSPORT_GET_CLASS (transport);
- g_return_val_if_fail (class->send_to_finish != NULL, FALSE);
+ simple = G_SIMPLE_ASYNC_RESULT (result);
- return class->send_to_finish (transport, result, error);
+ /* Assume success unless a GError is set. */
+ return !g_simple_async_result_propagate_error (simple, error);
}
diff --git a/camel/camel-transport.h b/camel/camel-transport.h
index b5801f5d0..712d5f58f 100644
--- a/camel/camel-transport.h
+++ b/camel/camel-transport.h
@@ -75,18 +75,8 @@ struct _CamelTransportClass {
GCancellable *cancellable,
GError **error);
- /* Asynchronous I/O Methods (all have defaults) */
- void (*send_to) (CamelTransport *transport,
- CamelMimeMessage *message,
- CamelAddress *from,
- CamelAddress *recipients,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
- gboolean (*send_to_finish) (CamelTransport *transport,
- GAsyncResult *result,
- GError **error);
+ /* Reserved slots. */
+ gpointer reserved[2];
};
GType camel_transport_get_type (void);