[gupnp] Add _add_notify_full variant with a GDestroyNotify



commit 9ffedf49b5793429c27ca0e8aa124b6438dbfc33
Author: Jens Georg <mail jensge org>
Date:   Sat Nov 30 16:04:09 2013 +0100

    Add _add_notify_full variant with a GDestroyNotify
    
    This is to help introspection with the call-back.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701446

 doc/gupnp-sections.txt         |    1 +
 libgupnp/gupnp-service-proxy.c |   44 ++++++++++++++++++++++++++++++++++++++-
 libgupnp/gupnp-service-proxy.h |    8 +++++++
 vala/GUPnP-1.0.metadata        |    1 +
 4 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/doc/gupnp-sections.txt b/doc/gupnp-sections.txt
index 70f2c37..7b3ff1c 100644
--- a/doc/gupnp-sections.txt
+++ b/doc/gupnp-sections.txt
@@ -85,6 +85,7 @@ gupnp_service_proxy_end_action_hash
 gupnp_service_proxy_end_action_list
 gupnp_service_proxy_cancel_action
 gupnp_service_proxy_add_notify
+gupnp_service_proxy_add_notify_full
 gupnp_service_proxy_remove_notify
 gupnp_service_proxy_set_subscribed
 gupnp_service_proxy_get_subscribed
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index ed8cc6c..c0bbcfe 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -102,6 +102,7 @@ typedef struct {
 
 typedef struct {
         GUPnPServiceProxyNotifyCallback callback;
+        GDestroyNotify notify;
         gpointer user_data;
 } CallbackData;
 
@@ -136,6 +137,9 @@ gupnp_service_proxy_action_free (GUPnPServiceProxyAction *action)
 static void
 callback_data_free (CallbackData *data)
 {
+        if (data->notify)
+                data->notify (data->user_data);
+
         g_slice_free (CallbackData, data);
 }
 
@@ -1575,7 +1579,7 @@ gupnp_service_proxy_cancel_action (GUPnPServiceProxy       *proxy,
 }
 
 /**
- * gupnp_service_proxy_add_notify:
+ * gupnp_service_proxy_add_notify: (skip)
  * @proxy: A #GUPnPServiceProxy
  * @variable: The variable to add notification for
  * @type: The type of the variable
@@ -1593,6 +1597,40 @@ gupnp_service_proxy_add_notify (GUPnPServiceProxy              *proxy,
                                 GType                           type,
                                 GUPnPServiceProxyNotifyCallback callback,
                                 gpointer                        user_data)
+
+{
+        return gupnp_service_proxy_add_notify_full (proxy,
+                                                    variable,
+                                                    type,
+                                                    callback,
+                                                    user_data,
+                                                    NULL);
+}
+
+/**
+ * gupnp_service_proxy_add_notify_full:
+ * @proxy: A #GUPnPServiceProxy
+ * @variable: The variable to add notification for
+ * @type: The type of the variable
+ * @callback: (scope notified): The callback to call when @variable changes
+ * @user_data: User data for @callback
+ * @notify: (allow-none): Function to call when the notification is removed, or %NULL
+ *
+ * Sets up @callback to be called whenever a change notification for
+ * @variable is recieved.
+ *
+ * Since: 0.20.9
+ *
+ * Return value: %TRUE on success.
+ * Rename to: gupnp_service_proxy_add_notify
+ **/
+gboolean
+gupnp_service_proxy_add_notify_full (GUPnPServiceProxy              *proxy,
+                                     const char                     *variable,
+                                     GType                           type,
+                                     GUPnPServiceProxyNotifyCallback callback,
+                                     gpointer                        user_data,
+                                     GDestroyNotify                  notify)
 {
         NotifyData *data;
         CallbackData *callback_data;
@@ -1633,6 +1671,7 @@ gupnp_service_proxy_add_notify (GUPnPServiceProxy              *proxy,
 
         callback_data->callback  = callback;
         callback_data->user_data = user_data;
+        callback_data->notify    = notify;
 
         data->callbacks = g_list_append (data->callbacks, callback_data);
 
@@ -1691,8 +1730,9 @@ gupnp_service_proxy_remove_notify (GUPnPServiceProxy              *proxy,
 
                 if (callback_data->callback  == callback &&
                     callback_data->user_data == user_data) {
+
                         /* Gotcha! */
-                        g_slice_free (CallbackData, callback_data);
+                        callback_data_free (callback_data);
 
                         if (data->next_emit == l)
                                 data->next_emit = data->next_emit->next;
diff --git a/libgupnp/gupnp-service-proxy.h b/libgupnp/gupnp-service-proxy.h
index 6444c3f..47bf442 100644
--- a/libgupnp/gupnp-service-proxy.h
+++ b/libgupnp/gupnp-service-proxy.h
@@ -227,6 +227,14 @@ gupnp_service_proxy_add_notify     (GUPnPServiceProxy              *proxy,
                                     gpointer                        user_data);
 
 gboolean
+gupnp_service_proxy_add_notify_full (GUPnPServiceProxy              *proxy,
+                                     const char                     *variable,
+                                     GType                           type,
+                                     GUPnPServiceProxyNotifyCallback callback,
+                                     gpointer                        user_data,
+                                     GDestroyNotify                  notify);
+
+gboolean
 gupnp_service_proxy_remove_notify  (GUPnPServiceProxy              *proxy,
                                     const char                     *variable,
                                     GUPnPServiceProxyNotifyCallback callback,
diff --git a/vala/GUPnP-1.0.metadata b/vala/GUPnP-1.0.metadata
index a8ab94c..ee4dc8c 100644
--- a/vala/GUPnP-1.0.metadata
+++ b/vala/GUPnP-1.0.metadata
@@ -23,6 +23,7 @@ ServiceIntrospection
     .get_state_variable nullable=true unowned=true
     .scpd skip
 ServiceProxy
+    .add_notify skip=false
     .begin_action skip=false
     .end_action_hash skip
     .end_action_list skip


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