From: Matthew Barnes Date: Sat, 19 May 2012 13:38:04 +0000 (-0400) Subject: Camel: Use camel_session_idle_add() for idle callbacks. X-Git-Tag: upstream/3.7.4~913 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16cd764733e169aeb3c98a27bb26a9c83023d3f8;p=platform%2Fupstream%2Fevolution-data-server.git Camel: Use camel_session_idle_add() for idle callbacks. Ensures all idle callbacks are dispatched from the same GMainContext, especially important for scheduling signal emissions. --- diff --git a/camel/camel-folder.c b/camel/camel-folder.c index 125387c..633a41a 100644 --- a/camel/camel-folder.c +++ b/camel/camel-folder.c @@ -167,27 +167,28 @@ async_context_free (AsyncContext *async_context) } static void -signal_data_free (SignalData *data) +signal_data_free (SignalData *signal_data) { - if (data->folder != NULL) - g_object_unref (data->folder); + if (signal_data->folder != NULL) + g_object_unref (signal_data->folder); - g_free (data->folder_name); + g_free (signal_data->folder_name); - g_slice_free (SignalData, data); + g_slice_free (SignalData, signal_data); } static gboolean -folder_emit_changed_cb (SignalData *data) +folder_emit_changed_cb (gpointer user_data) { + SignalData *signal_data = user_data; CamelFolderChangeInfo *changes; - camel_folder_lock (data->folder, CAMEL_FOLDER_CHANGE_LOCK); - changes = data->folder->priv->pending_changes; - data->folder->priv->pending_changes = NULL; - camel_folder_unlock (data->folder, CAMEL_FOLDER_CHANGE_LOCK); + camel_folder_lock (signal_data->folder, CAMEL_FOLDER_CHANGE_LOCK); + changes = signal_data->folder->priv->pending_changes; + signal_data->folder->priv->pending_changes = NULL; + camel_folder_unlock (signal_data->folder, CAMEL_FOLDER_CHANGE_LOCK); - g_signal_emit (data->folder, signals[CHANGED], 0, changes); + g_signal_emit (signal_data->folder, signals[CHANGED], 0, changes); camel_folder_change_info_free (changes); @@ -195,17 +196,24 @@ folder_emit_changed_cb (SignalData *data) } static gboolean -folder_emit_deleted_cb (SignalData *data) +folder_emit_deleted_cb (gpointer user_data) { - g_signal_emit (data->folder, signals[DELETED], 0); + SignalData *signal_data = user_data; + + g_signal_emit (signal_data->folder, signals[DELETED], 0); return FALSE; } static gboolean -folder_emit_renamed_cb (SignalData *data) +folder_emit_renamed_cb (gpointer user_data) { - g_signal_emit (data->folder, signals[RENAMED], 0, data->folder_name); + SignalData *signal_data = user_data; + + g_signal_emit ( + signal_data->folder, + signals[RENAMED], 0, + signal_data->folder_name); return FALSE; } @@ -2767,7 +2775,9 @@ camel_folder_delete (CamelFolder *folder) { CamelFolderClass *class; CamelStore *parent_store; - SignalData *data; + CamelService *service; + CamelSession *session; + SignalData *signal_data; const gchar *full_name; g_return_if_fail (CAMEL_IS_FOLDER (folder)); @@ -2792,13 +2802,16 @@ camel_folder_delete (CamelFolder *folder) parent_store = camel_folder_get_parent_store (folder); camel_db_delete_folder (parent_store->cdb_w, full_name, NULL); - data = g_slice_new0 (SignalData); - data->folder = g_object_ref (folder); + service = CAMEL_SERVICE (parent_store); + session = camel_service_get_session (service); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) folder_emit_deleted_cb, - data, (GDestroyNotify) signal_data_free); + signal_data = g_slice_new0 (SignalData); + signal_data->folder = g_object_ref (folder); + + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + folder_emit_deleted_cb, + signal_data, (GDestroyNotify) signal_data_free); } /** @@ -2820,7 +2833,9 @@ camel_folder_rename (CamelFolder *folder, { CamelFolderClass *class; CamelStore *parent_store; - SignalData *data; + CamelService *service; + CamelSession *session; + SignalData *signal_data; gchar *old_name; g_return_if_fail (CAMEL_IS_FOLDER (folder)); @@ -2836,14 +2851,17 @@ camel_folder_rename (CamelFolder *folder, parent_store = camel_folder_get_parent_store (folder); camel_db_rename_folder (parent_store->cdb_w, old_name, new_name, NULL); - data = g_slice_new0 (SignalData); - data->folder = g_object_ref (folder); - data->folder_name = old_name; /* transfer ownership */ + service = CAMEL_SERVICE (parent_store); + session = camel_service_get_session (service); + + signal_data = g_slice_new0 (SignalData); + signal_data->folder = g_object_ref (folder); + signal_data->folder_name = old_name; /* transfer ownership */ - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) folder_emit_renamed_cb, - data, (GDestroyNotify) signal_data_free); + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + folder_emit_renamed_cb, + signal_data, (GDestroyNotify) signal_data_free); } /** @@ -2883,18 +2901,26 @@ camel_folder_changed (CamelFolder *folder, pending_changes = folder->priv->pending_changes; if (pending_changes == NULL) { - SignalData *data; + CamelStore *parent_store; + CamelService *service; + CamelSession *session; + SignalData *signal_data; + + parent_store = camel_folder_get_parent_store (folder); + + service = CAMEL_SERVICE (parent_store); + session = camel_service_get_session (service); pending_changes = camel_folder_change_info_new (); folder->priv->pending_changes = pending_changes; - data = g_slice_new0 (SignalData); - data->folder = g_object_ref (folder); + signal_data = g_slice_new0 (SignalData); + signal_data->folder = g_object_ref (folder); - g_idle_add_full ( - G_PRIORITY_LOW, - (GSourceFunc) folder_emit_changed_cb, - data, (GDestroyNotify) signal_data_free); + camel_session_idle_add ( + session, G_PRIORITY_LOW, + folder_emit_changed_cb, + signal_data, (GDestroyNotify) signal_data_free); } camel_folder_change_info_cat (pending_changes, changes); diff --git a/camel/camel-session.c b/camel/camel-session.c index 57d060a..f86fca0 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -172,8 +172,9 @@ session_do_job_cb (GSimpleAsyncResult *simple, } static gboolean -session_start_job_cb (JobData *job_data) +session_start_job_cb (gpointer user_data) { + JobData *job_data = user_data; GSimpleAsyncResult *simple; g_signal_emit ( @@ -1446,7 +1447,6 @@ camel_session_submit_job (CamelSession *session, gpointer user_data, GDestroyNotify notify) { - GSource *source; JobData *job_data; g_return_if_fail (CAMEL_IS_SESSION (session)); @@ -1459,13 +1459,10 @@ camel_session_submit_job (CamelSession *session, job_data->user_data = user_data; job_data->notify = notify; - source = g_idle_source_new (); - g_source_set_priority (source, JOB_PRIORITY); - g_source_set_callback ( - source, (GSourceFunc) session_start_job_cb, + camel_session_idle_add ( + session, JOB_PRIORITY, + session_start_job_cb, job_data, (GDestroyNotify) NULL); - g_source_attach (source, job_data->session->priv->main_context); - g_source_unref (source); } /** diff --git a/camel/camel-store.c b/camel/camel-store.c index 9f98123..8e55069 100644 --- a/camel/camel-store.c +++ b/camel/camel-store.c @@ -111,63 +111,71 @@ async_context_free (AsyncContext *async_context) } static void -signal_data_free (SignalData *data) +signal_data_free (SignalData *signal_data) { - if (data->store != NULL) - g_object_unref (data->store); + if (signal_data->store != NULL) + g_object_unref (signal_data->store); - if (data->folder != NULL) - g_object_unref (data->folder); + if (signal_data->folder != NULL) + g_object_unref (signal_data->folder); - if (data->folder_info != NULL) - camel_folder_info_free (data->folder_info); + if (signal_data->folder_info != NULL) + camel_folder_info_free (signal_data->folder_info); - g_free (data->folder_name); + g_free (signal_data->folder_name); - g_slice_free (SignalData, data); + g_slice_free (SignalData, signal_data); } static gboolean -store_emit_folder_created_cb (SignalData *data) +store_emit_folder_created_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( - data->store, + signal_data->store, signals[FOLDER_CREATED], 0, - data->folder_info); + signal_data->folder_info); return FALSE; } static gboolean -store_emit_folder_deleted_cb (SignalData *data) +store_emit_folder_deleted_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( - data->store, + signal_data->store, signals[FOLDER_DELETED], 0, - data->folder_info); + signal_data->folder_info); return FALSE; } static gboolean -store_emit_folder_opened_cb (SignalData *data) +store_emit_folder_opened_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( - data->store, + signal_data->store, signals[FOLDER_OPENED], 0, - data->folder); + signal_data->folder); return FALSE; } static gboolean -store_emit_folder_renamed_cb (SignalData *data) +store_emit_folder_renamed_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( - data->store, + signal_data->store, signals[FOLDER_RENAMED], 0, - data->folder_name, - data->folder_info); + signal_data->folder_name, + signal_data->folder_info); return FALSE; } @@ -1266,19 +1274,22 @@ void camel_store_folder_created (CamelStore *store, CamelFolderInfo *folder_info) { - SignalData *data; + CamelSession *session; + SignalData *signal_data; g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (folder_info != NULL); - data = g_slice_new0 (SignalData); - data->store = g_object_ref (store); - data->folder_info = camel_folder_info_clone (folder_info); + session = camel_service_get_session (CAMEL_SERVICE (store)); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) store_emit_folder_created_cb, - data, (GDestroyNotify) signal_data_free); + signal_data = g_slice_new0 (SignalData); + signal_data->store = g_object_ref (store); + signal_data->folder_info = camel_folder_info_clone (folder_info); + + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + store_emit_folder_created_cb, + signal_data, (GDestroyNotify) signal_data_free); } /** @@ -1297,19 +1308,22 @@ void camel_store_folder_deleted (CamelStore *store, CamelFolderInfo *folder_info) { - SignalData *data; + CamelSession *session; + SignalData *signal_data; g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (folder_info != NULL); - data = g_slice_new0 (SignalData); - data->store = g_object_ref (store); - data->folder_info = camel_folder_info_clone (folder_info); + session = camel_service_get_session (CAMEL_SERVICE (store)); + + signal_data = g_slice_new0 (SignalData); + signal_data->store = g_object_ref (store); + signal_data->folder_info = camel_folder_info_clone (folder_info); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) store_emit_folder_deleted_cb, - data, (GDestroyNotify) signal_data_free); + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + store_emit_folder_deleted_cb, + signal_data, (GDestroyNotify) signal_data_free); } /** @@ -1328,19 +1342,22 @@ void camel_store_folder_opened (CamelStore *store, CamelFolder *folder) { - SignalData *data; + CamelSession *session; + SignalData *signal_data; g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (CAMEL_IS_FOLDER (folder)); - data = g_slice_new0 (SignalData); - data->store = g_object_ref (store); - data->folder = g_object_ref (folder); + session = camel_service_get_session (CAMEL_SERVICE (store)); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) store_emit_folder_opened_cb, - data, (GDestroyNotify) signal_data_free); + signal_data = g_slice_new0 (SignalData); + signal_data->store = g_object_ref (store); + signal_data->folder = g_object_ref (folder); + + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + store_emit_folder_opened_cb, + signal_data, (GDestroyNotify) signal_data_free); } /** @@ -1361,21 +1378,24 @@ camel_store_folder_renamed (CamelStore *store, const gchar *old_name, CamelFolderInfo *folder_info) { - SignalData *data; + CamelSession *session; + SignalData *signal_data; g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (old_name != NULL); g_return_if_fail (folder_info != NULL); - data = g_slice_new0 (SignalData); - data->store = g_object_ref (store); - data->folder_info = camel_folder_info_clone (folder_info); - data->folder_name = g_strdup (old_name); + session = camel_service_get_session (CAMEL_SERVICE (store)); + + signal_data = g_slice_new0 (SignalData); + signal_data->store = g_object_ref (store); + signal_data->folder_info = camel_folder_info_clone (folder_info); + signal_data->folder_name = g_strdup (old_name); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) store_emit_folder_renamed_cb, - data, (GDestroyNotify) signal_data_free); + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + store_emit_folder_renamed_cb, + signal_data, (GDestroyNotify) signal_data_free); } static void diff --git a/camel/camel-subscribable.c b/camel/camel-subscribable.c index 7d1f3c4..0bb193b 100644 --- a/camel/camel-subscribable.c +++ b/camel/camel-subscribable.c @@ -19,6 +19,7 @@ #include "camel-subscribable.h" #include "camel-debug.h" +#include "camel-session.h" #include "camel-vtrash-folder.h" typedef struct _AsyncContext AsyncContext; @@ -64,8 +65,10 @@ signal_data_free (SignalData *signal_data) } static gboolean -subscribable_emit_folder_subscribed_cb (SignalData *signal_data) +subscribable_emit_folder_subscribed_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( signal_data->subscribable, signals[FOLDER_SUBSCRIBED], 0, @@ -75,8 +78,10 @@ subscribable_emit_folder_subscribed_cb (SignalData *signal_data) } static gboolean -subscribable_emit_folder_unsubscribed_cb (SignalData *signal_data) +subscribable_emit_folder_unsubscribed_cb (gpointer user_data) { + SignalData *signal_data = user_data; + g_signal_emit ( signal_data->subscribable, signals[FOLDER_UNSUBSCRIBED], 0, @@ -591,18 +596,23 @@ void camel_subscribable_folder_subscribed (CamelSubscribable *subscribable, CamelFolderInfo *folder_info) { + CamelService *service; + CamelSession *session; SignalData *signal_data; g_return_if_fail (CAMEL_IS_SUBSCRIBABLE (subscribable)); g_return_if_fail (folder_info != NULL); + service = CAMEL_SERVICE (subscribable); + session = camel_service_get_session (service); + signal_data = g_slice_new0 (SignalData); signal_data->subscribable = g_object_ref (subscribable); signal_data->folder_info = camel_folder_info_clone (folder_info); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) subscribable_emit_folder_subscribed_cb, + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + subscribable_emit_folder_subscribed_cb, signal_data, (GDestroyNotify) signal_data_free); } @@ -622,18 +632,23 @@ void camel_subscribable_folder_unsubscribed (CamelSubscribable *subscribable, CamelFolderInfo *folder_info) { + CamelService *service; + CamelSession *session; SignalData *signal_data; g_return_if_fail (CAMEL_IS_SUBSCRIBABLE (subscribable)); g_return_if_fail (folder_info != NULL); + service = CAMEL_SERVICE (subscribable); + session = camel_service_get_session (service); + signal_data = g_slice_new0 (SignalData); signal_data->subscribable = g_object_ref (subscribable); signal_data->folder_info = camel_folder_info_clone (folder_info); - g_idle_add_full ( - G_PRIORITY_DEFAULT_IDLE, - (GSourceFunc) subscribable_emit_folder_unsubscribed_cb, + camel_session_idle_add ( + session, G_PRIORITY_DEFAULT_IDLE, + subscribable_emit_folder_unsubscribed_cb, signal_data, (GDestroyNotify) signal_data_free); }