[libgdata] core: Eliminate unnecessary is_async argument from parser functions



commit 52e05dd978ff111ad154b01d0bb3f241b3600325
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Fri Dec 12 19:44:12 2014 +0000

    core: Eliminate unnecessary is_async argument from parser functions
    
    Instead, use g_main_context_invoke(), which guarantees to call the
    callback synchronously if the GMainContext is owned, and in an idle
    callback otherwise. This is exactly what we want for implementing
    callbacks which could come from this thread or a worker thread.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741345

 gdata/gdata-access-handler.c |    8 ++++----
 gdata/gdata-feed.c           |   34 ++++++++++++++++++----------------
 gdata/gdata-private.h        |    7 +++----
 gdata/gdata-service.c        |   13 ++++++-------
 4 files changed, 31 insertions(+), 31 deletions(-)
---
diff --git a/gdata/gdata-access-handler.c b/gdata/gdata-access-handler.c
index 40ef797..a119510 100644
--- a/gdata/gdata-access-handler.c
+++ b/gdata/gdata-access-handler.c
@@ -81,7 +81,7 @@ get_rules_async_data_free (GetRulesAsyncData *self)
 
 static GDataFeed *
 _gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable,
-                                 GDataQueryProgressCallback progress_callback, gpointer progress_user_data, 
gboolean is_async, GError **error)
+                                 GDataQueryProgressCallback progress_callback, gpointer progress_user_data, 
GError **error)
 {
        GDataAccessHandlerIface *iface;
        GDataAuthorizationDomain *domain = NULL;
@@ -104,7 +104,7 @@ _gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service
 
        g_assert (message->response_body->data != NULL);
        feed = _gdata_feed_new_from_xml (GDATA_TYPE_FEED, message->response_body->data, 
message->response_body->length, GDATA_TYPE_ACCESS_RULE,
-                                        progress_callback, progress_user_data, is_async, error);
+                                        progress_callback, progress_user_data, error);
        g_object_unref (message);
 
        return feed;
@@ -118,7 +118,7 @@ get_rules_thread (GSimpleAsyncResult *result, GDataAccessHandler *access_handler
 
        /* Execute the query and return */
        data->feed = _gdata_access_handler_get_rules (access_handler, data->service, cancellable, 
data->progress_callback, data->progress_user_data,
-                                                     TRUE, &error);
+                                                     &error);
        if (data->feed == NULL && error != NULL) {
                g_simple_async_result_set_from_error (result, error);
                g_error_free (error);
@@ -211,5 +211,5 @@ gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service,
        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       return _gdata_access_handler_get_rules (self, service, cancellable, progress_callback, 
progress_user_data, FALSE, error);
+       return _gdata_access_handler_get_rules (self, service, cancellable, progress_callback, 
progress_user_data, error);
 }
diff --git a/gdata/gdata-feed.c b/gdata/gdata-feed.c
index f17174d..0cc6c73 100644
--- a/gdata/gdata-feed.c
+++ b/gdata/gdata-feed.c
@@ -413,7 +413,6 @@ typedef struct {
        GDataQueryProgressCallback progress_callback;
        gpointer progress_user_data;
        guint entry_i;
-       gboolean is_async;
 } ParseData;
 
 static gboolean
@@ -677,7 +676,7 @@ _gdata_feed_new (const gchar *title, const gchar *id, gint64 updated)
 
 GDataFeed *
 _gdata_feed_new_from_xml (GType feed_type, const gchar *xml, gint length, GType entry_type,
-                          GDataQueryProgressCallback progress_callback, gpointer progress_user_data, 
gboolean is_async, GError **error)
+                          GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError 
**error)
 {
        ParseData *data;
        GDataFeed *feed;
@@ -687,7 +686,7 @@ _gdata_feed_new_from_xml (GType feed_type, const gchar *xml, gint length, GType
        g_return_val_if_fail (g_type_is_a (entry_type, GDATA_TYPE_ENTRY), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       data = _gdata_feed_parse_data_new (entry_type, progress_callback, progress_user_data, is_async);
+       data = _gdata_feed_parse_data_new (entry_type, progress_callback, progress_user_data);
        feed = GDATA_FEED (_gdata_parsable_new_from_xml (feed_type, xml, length, data, error));
        _gdata_feed_parse_data_free (data);
 
@@ -696,7 +695,7 @@ _gdata_feed_new_from_xml (GType feed_type, const gchar *xml, gint length, GType
 
 GDataFeed *
 _gdata_feed_new_from_json (GType feed_type, const gchar *json, gint length, GType entry_type,
-                          GDataQueryProgressCallback progress_callback, gpointer progress_user_data, 
gboolean is_async, GError **error)
+                          GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError 
**error)
 {
        ParseData *data;
        GDataFeed *feed;
@@ -706,7 +705,7 @@ _gdata_feed_new_from_json (GType feed_type, const gchar *json, gint length, GTyp
        g_return_val_if_fail (g_type_is_a (entry_type, GDATA_TYPE_ENTRY), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       data = _gdata_feed_parse_data_new (entry_type, progress_callback, progress_user_data, is_async);
+       data = _gdata_feed_parse_data_new (entry_type, progress_callback, progress_user_data);
        feed = GDATA_FEED (_gdata_parsable_new_from_json (feed_type, json, length, data, error));
        _gdata_feed_parse_data_free (data);
 
@@ -1049,7 +1048,7 @@ _gdata_feed_add_entry (GDataFeed *self, GDataEntry *entry)
 }
 
 gpointer
-_gdata_feed_parse_data_new (GType entry_type, GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data, gboolean is_async)
+_gdata_feed_parse_data_new (GType entry_type, GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data)
 {
        ParseData *data;
        data = g_slice_new (ParseData);
@@ -1057,7 +1056,6 @@ _gdata_feed_parse_data_new (GType entry_type, GDataQueryProgressCallback progres
        data->progress_callback = progress_callback;
        data->progress_user_data = progress_user_data;
        data->entry_i = 0;
-       data->is_async = is_async;
 
        return data;
 }
@@ -1072,9 +1070,15 @@ static gboolean
 progress_callback_idle (ProgressCallbackData *data)
 {
        data->progress_callback (data->entry, data->entry_i, data->total_results, data->progress_user_data);
+
+       return G_SOURCE_REMOVE;
+}
+
+static void
+progress_callback_data_free (ProgressCallbackData *data)
+{
        g_object_unref (data->entry);
        g_slice_free (ProgressCallbackData, data);
-       return FALSE;
 }
 
 void
@@ -1093,14 +1097,12 @@ _gdata_feed_call_progress_callback (GDataFeed *self, gpointer user_data, GDataEn
                progress_data->entry_i = data->entry_i;
                progress_data->total_results = MIN (self->priv->items_per_page, self->priv->total_results);
 
-               if (data->is_async == TRUE) {
-                       /* Send the callback; use G_PRIORITY_DEFAULT rather than G_PRIORITY_DEFAULT_IDLE
-                       * to contend with the priorities used by the callback functions in GAsyncResult */
-                       g_idle_add_full (G_PRIORITY_DEFAULT, (GSourceFunc) progress_callback_idle, 
progress_data, NULL);
-               } else {
-                       /* If we're running synchronously, just call the callbacks directly */
-                       progress_callback_idle (progress_data);
-               }
+               /* Send the callback; use G_PRIORITY_DEFAULT rather than G_PRIORITY_DEFAULT_IDLE
+                * to contend with the priorities used by the callback functions in GAsyncResult */
+               g_main_context_invoke_full (NULL, G_PRIORITY_DEFAULT,
+                                           (GSourceFunc) progress_callback_idle,
+                                           progress_data,
+                                           (GDestroyNotify) progress_callback_data_free);
        }
        data->entry_i++;
 }
diff --git a/gdata/gdata-private.h b/gdata/gdata-private.h
index 7e51760..ed19520 100644
--- a/gdata/gdata-private.h
+++ b/gdata/gdata-private.h
@@ -91,14 +91,13 @@ G_GNUC_INTERNAL gboolean _gdata_parsable_is_constructed_from_xml (GDataParsable
 #include "gdata-feed.h"
 G_GNUC_INTERNAL GDataFeed *_gdata_feed_new (const gchar *title, const gchar *id, gint64 updated) 
G_GNUC_WARN_UNUSED_RESULT;
 G_GNUC_INTERNAL GDataFeed *_gdata_feed_new_from_xml (GType feed_type, const gchar *xml, gint length, GType 
entry_type,
-                                                     GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data, gboolean is_async,
+                                                     GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data,
                                                      GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
 G_GNUC_INTERNAL GDataFeed *_gdata_feed_new_from_json (GType feed_type, const gchar *json, gint length, GType 
entry_type,
-                                                     GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data, gboolean is_async,
+                                                     GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data,
                                                      GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
 G_GNUC_INTERNAL void _gdata_feed_add_entry (GDataFeed *self, GDataEntry *entry);
-G_GNUC_INTERNAL gpointer _gdata_feed_parse_data_new (GType entry_type, GDataQueryProgressCallback 
progress_callback, gpointer progress_user_data,
-                                                     gboolean is_async);
+G_GNUC_INTERNAL gpointer _gdata_feed_parse_data_new (GType entry_type, GDataQueryProgressCallback 
progress_callback, gpointer progress_user_data);
 G_GNUC_INTERNAL void _gdata_feed_parse_data_free (gpointer data);
 G_GNUC_INTERNAL void _gdata_feed_call_progress_callback (GDataFeed *self, gpointer user_data, GDataEntry 
*entry);
 
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index f0effa8..cc3ff71 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -75,7 +75,7 @@ static void soup_log_printer (SoupLogger *logger, SoupLoggerLogLevel level, char
 
 static GDataFeed *__gdata_service_query (GDataService *self, GDataAuthorizationDomain *domain, const gchar 
*feed_uri, GDataQuery *query,
                                          GType entry_type, GCancellable *cancellable, 
GDataQueryProgressCallback progress_callback,
-                                         gpointer progress_user_data, GError **error, gboolean is_async);
+                                         gpointer progress_user_data, GError **error);
 
 static SoupURI *_get_proxy_uri (GDataService *self);
 static void _set_proxy_uri (GDataService *self, SoupURI *proxy_uri);
@@ -803,7 +803,7 @@ query_thread (GSimpleAsyncResult *result, GDataService *service, GCancellable *c
 
        /* Execute the query and return */
        data->feed = __gdata_service_query (service, data->domain, data->feed_uri, data->query, 
data->entry_type, cancellable,
-                                           data->progress_callback, data->progress_user_data, &error, TRUE);
+                                           data->progress_callback, data->progress_user_data, &error);
        if (data->feed == NULL && error != NULL) {
                g_simple_async_result_set_from_error (result, error);
                g_error_free (error);
@@ -946,8 +946,7 @@ _gdata_service_query (GDataService *self, GDataAuthorizationDomain *domain, cons
 
 static GDataFeed *
 __gdata_service_query (GDataService *self, GDataAuthorizationDomain *domain, const gchar *feed_uri, 
GDataQuery *query, GType entry_type,
-                       GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data, GError **error,
-                       gboolean is_async)
+                       GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer 
progress_user_data, GError **error)
 {
        GDataServiceClass *klass;
        GDataFeed *feed = NULL;
@@ -969,13 +968,13 @@ __gdata_service_query (GDataService *self, GDataAuthorizationDomain *domain, con
                /* Definitely JSON. */
                g_debug("JSON content type detected.");
                feed = _gdata_feed_new_from_json (klass->feed_type, message->response_body->data, 
message->response_body->length, entry_type,
-                                                 progress_callback, progress_user_data, is_async, error);
+                                                 progress_callback, progress_user_data, error);
        } else {
                /* Potentially XML. Don't bother checking the Content-Type, since the parser
                 * will fail gracefully if the response body is not valid XML. */
                g_debug("XML content type detected.");
                feed = _gdata_feed_new_from_xml (klass->feed_type, message->response_body->data, 
message->response_body->length, entry_type,
-                                                progress_callback, progress_user_data, is_async, error);
+                                                progress_callback, progress_user_data, error);
        }
 
        g_object_unref (message);
@@ -1049,7 +1048,7 @@ gdata_service_query (GDataService *self, GDataAuthorizationDomain *domain, const
        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       return __gdata_service_query (self, domain, feed_uri, query, entry_type, cancellable, 
progress_callback, progress_user_data, error, FALSE);
+       return __gdata_service_query (self, domain, feed_uri, query, entry_type, cancellable, 
progress_callback, progress_user_data, error);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]