[gupnp] Add gupnp_service_proxy_*_raw_notify functions



commit 5e7039a66632bd666894d58829bc4e9f5b9b9c92
Author: Jens Georg <mail jensge org>
Date:   Fri Aug 16 14:26:04 2013 +0200

    Add gupnp_service_proxy_*_raw_notify functions
    
    These functions allow access to the xmlDoc of the notification that was
    sent from the peer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706127

 doc/gupnp-sections.txt         |    2 +
 libgupnp/gupnp-service-proxy.c |   77 ++++++++++++++++++++++++++++++++++++++++
 libgupnp/gupnp-service-proxy.h |   12 ++++++
 3 files changed, 91 insertions(+), 0 deletions(-)
---
diff --git a/doc/gupnp-sections.txt b/doc/gupnp-sections.txt
index 7b3ff1c..81df876 100644
--- a/doc/gupnp-sections.txt
+++ b/doc/gupnp-sections.txt
@@ -86,7 +86,9 @@ 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_add_raw_notify
 gupnp_service_proxy_remove_notify
+gupnp_service_proxy_remove_raw_notify
 gupnp_service_proxy_set_subscribed
 gupnp_service_proxy_get_subscribed
 <SUBSECTION Standard>
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index d1d1c6a..7a48ac9 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -1674,6 +1674,37 @@ gupnp_service_proxy_add_notify_full (GUPnPServiceProxy              *proxy,
 }
 
 /**
+ * gupnp_service_proxy_add_raw_notify:
+ * @proxy: A #GUPnPServiceProxy
+ * @callback: (scope notified): The callback to call when the peer issues any
+ * variable notification.
+ * @user_data: User data for @callback
+ * @notify: (allow-none): A #GDestroyNotify for @user_data
+ *
+ * Get a notification for anything that happens on the peer. @value in
+ * @callback will be of type #G_TYPE_POINTER and contain the pre-parsed
+ * #xmlDoc. Do NOT free or modify this document.
+ *
+ * Return value: %TRUE on success.
+ *
+ * Since: 0.20.12
+ **/
+gboolean
+gupnp_service_proxy_add_raw_notify (GUPnPServiceProxy              *proxy,
+                                    GUPnPServiceProxyNotifyCallback callback,
+                                    gpointer                        user_data,
+                                    GDestroyNotify                  notify)
+{
+        return gupnp_service_proxy_add_notify_full (proxy,
+                                                    "*",
+                                                    G_TYPE_NONE,
+                                                    callback,
+                                                    user_data,
+                                                    notify);
+}
+
+
+/**
  * gupnp_service_proxy_remove_notify:
  * @proxy: A #GUPnPServiceProxy
  * @variable: The variable to add notification for
@@ -1749,6 +1780,31 @@ gupnp_service_proxy_remove_notify (GUPnPServiceProxy              *proxy,
         return found;
 }
 
+/**
+ * gupnp_service_proxy_remove_raw_notify:
+ * @proxy: A #GUPnPServiceProxy
+ * @callback: (scope call): The callback to call when @variable changes
+ * @user_data: User data for @callback
+ *
+ * Cancels the variable change notification for @callback and @user_data.
+ *
+ * This function must not be called directly or indirectly from a
+ * #GUPnPServiceProxyNotifyCallback associated with this service proxy, even
+ * if it is for another variable.
+ *
+ * Return value: %TRUE on success.
+ **/
+gboolean
+gupnp_service_proxy_remove_raw_notify (GUPnPServiceProxy              *proxy,
+                                       GUPnPServiceProxyNotifyCallback callback,
+                                       gpointer                        user_data)
+{
+        return gupnp_service_proxy_remove_notify (proxy,
+                                                  "*",
+                                                  callback,
+                                                  user_data);
+}
+
 static void
 emit_notification (GUPnPServiceProxy *proxy,
                    xmlNode           *var_node)
@@ -1792,6 +1848,7 @@ static void
 emit_notifications_for_doc (GUPnPServiceProxy *proxy,
                             xmlDoc            *doc)
 {
+        NotifyData *data = NULL;
         xmlNode *node;
 
         node = xmlDocGetRootElement (doc);
@@ -1812,6 +1869,26 @@ emit_notifications_for_doc (GUPnPServiceProxy *proxy,
                                 emit_notification (proxy, var_node);
                 }
         }
+
+        data = g_hash_table_lookup (proxy->priv->notify_hash, "*");
+        if (data != NULL) {
+                GValue value = {0, };
+                GList *it = NULL;
+
+                g_value_init (&value, G_TYPE_POINTER);
+                g_value_set_pointer (&value, doc);
+
+                for (it = data->callbacks; it != NULL; it = it->next) {
+                        CallbackData *callback_data = it->data;
+
+                        callback_data->callback (proxy,
+                                                 "*",
+                                                 &value,
+                                                 callback_data->user_data);
+                }
+
+                g_value_unset (&value);
+        }
 }
 
 /* Emit pending notifications. See comment below on why we do this. */
diff --git a/libgupnp/gupnp-service-proxy.h b/libgupnp/gupnp-service-proxy.h
index 47bf442..be7d240 100644
--- a/libgupnp/gupnp-service-proxy.h
+++ b/libgupnp/gupnp-service-proxy.h
@@ -235,11 +235,23 @@ gupnp_service_proxy_add_notify_full (GUPnPServiceProxy              *proxy,
                                      GDestroyNotify                  notify);
 
 gboolean
+gupnp_service_proxy_add_raw_notify (GUPnPServiceProxy              *proxy,
+                                    GUPnPServiceProxyNotifyCallback callback,
+                                    gpointer                        user_data,
+                                    GDestroyNotify                  notify);
+
+gboolean
 gupnp_service_proxy_remove_notify  (GUPnPServiceProxy              *proxy,
                                     const char                     *variable,
                                     GUPnPServiceProxyNotifyCallback callback,
                                     gpointer                        user_data);
 
+gboolean
+gupnp_service_proxy_remove_raw_notify
+                                   (GUPnPServiceProxy              *proxy,
+                                    GUPnPServiceProxyNotifyCallback callback,
+                                    gpointer                        user_data);
+
 void
 gupnp_service_proxy_set_subscribed (GUPnPServiceProxy              *proxy,
                                     gboolean                        subscribed);


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