[totem-pl-parser] plparse: Port from GSimpleAsyncResult to GTask



commit 456640376604641745ce2ca6a3cc7da6e52b765b
Author: Philip Withnall <withnall endlessm com>
Date:   Mon Dec 19 10:50:02 2016 +0000

    plparse: Port from GSimpleAsyncResult to GTask
    
    GSimpleAsyncResult was deprecated in version 2.36 of GLib, and replaced
    by GTask. Bump our GLib dependency to 2.36 and start using GTask instead
    to avoid deprecated function warnings from the compiler.
    
    Furthermore, as we are targetting GNOME 3.10 and later versions, and
    GNOME 3.10 shipped with GLib 2.38, we don't need to worry about
    leaving older versions in the dust.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776259

 configure.ac              |    2 +-
 plparse/tests/disc.c      |    3 ---
 plparse/tests/parser.c    |    3 ---
 plparse/totem-pl-parser.c |   32 ++++++++++++++------------------
 4 files changed, 15 insertions(+), 25 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5b115de..425f79d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,7 @@ AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
 AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
 
 # Requirements
-GLIB_REQS=2.31.0
+GLIB_REQS=2.36.0
 GIO_REQS=2.24.0
 QUVI_REQS=0.9.1
 LIBARCHIVE_REQS=3.0
diff --git a/plparse/tests/disc.c b/plparse/tests/disc.c
index c35ebc1..13d30f3 100644
--- a/plparse/tests/disc.c
+++ b/plparse/tests/disc.c
@@ -108,9 +108,6 @@ main (int argc, char *argv[])
 
        setlocale (LC_ALL, "");
 
-#if !GLIB_CHECK_VERSION(2, 36, 0)
-       g_type_init ();
-#endif
        g_test_init (&argc, &argv, NULL);
        g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
 
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 62b336a..cc930ff 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -1253,9 +1253,6 @@ main (int argc, char *argv[])
 
        setlocale (LC_ALL, "");
 
-#if !GLIB_CHECK_VERSION (2, 36, 0)
-       g_type_init ();
-#endif
        g_test_init (&argc, &argv, NULL);
        g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
 
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index 727940d..3cb579d 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -2030,23 +2030,22 @@ parse_async_data_free (ParseAsyncData *data)
 }
 
 static void
-parse_thread (GSimpleAsyncResult *result, GObject *object, GCancellable *cancellable)
+parse_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable)
 {
+       TotemPlParser *parser = TOTEM_PL_PARSER (source_object);
        TotemPlParserResult parse_result;
        GError *error = NULL;
-       ParseAsyncData *data = g_simple_async_result_get_op_res_gpointer (result);
+       ParseAsyncData *data = task_data;
 
        /* Check to see if it's been cancelled already */
        if (g_cancellable_set_error_if_cancelled (cancellable, &error) == TRUE) {
-               g_simple_async_result_set_from_error (result, error);
-               g_simple_async_result_set_op_res_gpointer (result, GUINT_TO_POINTER 
(TOTEM_PL_PARSER_RESULT_CANCELLED), NULL);
-               g_error_free (error);
+               g_task_return_error (task, error);
                return;
        }
 
        /* Parse and return */
-       parse_result = totem_pl_parser_parse_with_base (TOTEM_PL_PARSER (object), data->uri, data->base, 
data->fallback);
-       g_simple_async_result_set_op_res_gpointer (result, GUINT_TO_POINTER (parse_result), NULL);
+       parse_result = totem_pl_parser_parse_with_base (parser, data->uri, data->base, data->fallback);
+       g_task_return_int (task, parse_result);
 }
 
 /**
@@ -2072,7 +2071,7 @@ void
 totem_pl_parser_parse_with_base_async (TotemPlParser *parser, const char *uri, const char *base, gboolean 
fallback,
                                       GCancellable *cancellable, GAsyncReadyCallback callback, gpointer 
user_data)
 {
-       GSimpleAsyncResult *result;
+       GTask *task;
        ParseAsyncData *data;
 
        g_return_if_fail (TOTEM_IS_PL_PARSER (parser));
@@ -2084,10 +2083,10 @@ totem_pl_parser_parse_with_base_async (TotemPlParser *parser, const char *uri, c
        data->base = g_strdup (base);
        data->fallback = fallback;
 
-       result = g_simple_async_result_new (G_OBJECT (parser), callback, user_data, 
totem_pl_parser_parse_with_base_async);
-       g_simple_async_result_set_op_res_gpointer (result, data, (GDestroyNotify) parse_async_data_free);
-       g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) parse_thread, 
G_PRIORITY_DEFAULT, cancellable);
-       g_object_unref (result);
+       task = g_task_new (parser, cancellable, callback, user_data);
+       g_task_set_task_data (task, data, (GDestroyNotify) parse_async_data_free);
+       g_task_run_in_thread (task, parse_thread);
+       g_object_unref (task);
 }
 
 /**
@@ -2184,16 +2183,13 @@ totem_pl_parser_parse_async (TotemPlParser *parser, const char *uri, gboolean fa
 TotemPlParserResult
 totem_pl_parser_parse_finish (TotemPlParser *parser, GAsyncResult *async_result, GError **error)
 {
-       GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
+       GTask *task = G_TASK (async_result);
 
        g_return_val_if_fail (TOTEM_IS_PL_PARSER (parser), FALSE);
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), FALSE);
-
-       g_warn_if_fail (g_simple_async_result_get_source_tag (result) == 
totem_pl_parser_parse_with_base_async);
+       g_return_val_if_fail (g_task_is_valid (async_result, parser), FALSE);
 
        /* Propagate any errors which were caught and return the result; otherwise just return the result */
-       g_simple_async_result_propagate_error (result, error);
-       return GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (result));
+       return g_task_propagate_int (task, error);
 }
 
 /**


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