[gtk+/wip/otte/clipboard: 87/107] gdk: Allow setting task data on (de)serializers



commit f2fa93ded2ad59a0a02cce30c0915648dd9e132f
Author: Benjamin Otte <otte redhat com>
Date:   Tue Nov 28 01:58:56 2017 +0100

    gdk: Allow setting task data on (de)serializers
    
    This mirrors GTask.

 gdk/gdkcontentdeserializer.c |   28 ++++++++++++++++++++++++++++
 gdk/gdkcontentdeserializer.h |    6 ++++++
 gdk/gdkcontentserializer.c   |   28 ++++++++++++++++++++++++++++
 gdk/gdkcontentserializer.h   |    6 ++++++
 4 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkcontentdeserializer.c b/gdk/gdkcontentdeserializer.c
index 6c931e0..f6a3f6f 100644
--- a/gdk/gdkcontentdeserializer.c
+++ b/gdk/gdkcontentdeserializer.c
@@ -59,6 +59,9 @@ struct _GdkContentDeserializer
   GAsyncReadyCallback callback;
   gpointer callback_data;
 
+  gpointer task_data;
+  GDestroyNotify task_notify;
+
   GError *error;
   gboolean returned;
 };
@@ -100,6 +103,9 @@ gdk_content_deserializer_finalize (GObject *object)
   g_clear_object (&deserializer->cancellable);
   g_clear_error (&deserializer->error);
 
+  if (deserializer->task_notify)
+    deserializer->task_notify (deserializer->task_data);
+
   G_OBJECT_CLASS (gdk_content_deserializer_parent_class)->finalize (object);
 }
 
@@ -200,6 +206,28 @@ gdk_content_deserializer_get_user_data (GdkContentDeserializer *deserializer)
   return deserializer->user_data;
 }
 
+void
+gdk_content_deserializer_set_task_data (GdkContentDeserializer *deserializer,
+                                        gpointer                data,
+                                        GDestroyNotify          notify)
+{
+  g_return_if_fail (GDK_IS_CONTENT_DESERIALIZER (deserializer));
+
+  if (deserializer->task_notify)
+    deserializer->task_notify (deserializer->task_data);
+
+  deserializer->task_data = data;
+  deserializer->task_notify = notify;
+}
+
+gpointer
+gdk_content_deserializer_get_task_data (GdkContentDeserializer *deserializer)
+{
+  g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (deserializer), NULL);
+
+  return deserializer->task_data;
+}
+
 static gboolean
 gdk_content_deserializer_emit_callback (gpointer data)
 {
diff --git a/gdk/gdkcontentdeserializer.h b/gdk/gdkcontentdeserializer.h
index 102a4bc..671d540 100644
--- a/gdk/gdkcontentdeserializer.h
+++ b/gdk/gdkcontentdeserializer.h
@@ -54,6 +54,12 @@ GDK_AVAILABLE_IN_3_94
 GCancellable *          gdk_content_deserializer_get_cancellable        (GdkContentDeserializer 
*deserializer);
 GDK_AVAILABLE_IN_3_94
 gpointer                gdk_content_deserializer_get_user_data          (GdkContentDeserializer 
*deserializer);
+GDK_AVAILABLE_IN_3_94
+void                    gdk_content_deserializer_set_task_data          (GdkContentDeserializer 
*deserializer,
+                                                                         gpointer                data,
+                                                                         GDestroyNotify          notify);
+GDK_AVAILABLE_IN_3_94
+gpointer                gdk_content_deserializer_get_task_data          (GdkContentDeserializer 
*deserializer);
 
 GDK_AVAILABLE_IN_3_94
 void                    gdk_content_deserializer_return_success         (GdkContentDeserializer 
*deserializer);
diff --git a/gdk/gdkcontentserializer.c b/gdk/gdkcontentserializer.c
index 6860c97..045cd20 100644
--- a/gdk/gdkcontentserializer.c
+++ b/gdk/gdkcontentserializer.c
@@ -60,6 +60,9 @@ struct _GdkContentSerializer
   GAsyncReadyCallback callback;
   gpointer callback_data;
 
+  gpointer task_data;
+  GDestroyNotify task_notify;
+
   GError *error;
   gboolean returned;
 };
@@ -101,6 +104,9 @@ gdk_content_serializer_finalize (GObject *object)
   g_clear_object (&serializer->cancellable);
   g_clear_error (&serializer->error);
 
+  if (serializer->task_notify)
+    serializer->task_notify (serializer->task_data);
+
   G_OBJECT_CLASS (gdk_content_serializer_parent_class)->finalize (object);
 }
 
@@ -202,6 +208,28 @@ gdk_content_serializer_get_user_data (GdkContentSerializer *serializer)
   return serializer->user_data;
 }
 
+void
+gdk_content_serializer_set_task_data (GdkContentSerializer   *serializer,
+                                      gpointer                data,
+                                      GDestroyNotify          notify)
+{
+  g_return_if_fail (GDK_IS_CONTENT_SERIALIZER (serializer));
+
+  if (serializer->task_notify)
+    serializer->task_notify (serializer->task_data);
+
+  serializer->task_data = data;
+  serializer->task_notify = notify;
+}
+
+gpointer
+gdk_content_serializer_get_task_data (GdkContentSerializer *serializer)
+{
+  g_return_val_if_fail (GDK_IS_CONTENT_SERIALIZER (serializer), NULL);
+
+  return serializer->task_data;
+}
+
 static gboolean
 gdk_content_serializer_emit_callback (gpointer data)
 {
diff --git a/gdk/gdkcontentserializer.h b/gdk/gdkcontentserializer.h
index b1acf7f..428ddad 100644
--- a/gdk/gdkcontentserializer.h
+++ b/gdk/gdkcontentserializer.h
@@ -54,6 +54,12 @@ GDK_AVAILABLE_IN_3_94
 GCancellable *          gdk_content_serializer_get_cancellable          (GdkContentSerializer   *serializer);
 GDK_AVAILABLE_IN_3_94
 gpointer                gdk_content_serializer_get_user_data            (GdkContentSerializer   *serializer);
+GDK_AVAILABLE_IN_3_94
+void                    gdk_content_serializer_set_task_data            (GdkContentSerializer   *serializer,
+                                                                         gpointer                data,
+                                                                         GDestroyNotify          notify);
+GDK_AVAILABLE_IN_3_94
+gpointer                gdk_content_serializer_get_task_data            (GdkContentSerializer   *serializer);
 
 GDK_AVAILABLE_IN_3_94
 void                    gdk_content_serializer_return_success           (GdkContentSerializer   *serializer);


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