[gupnp/wip/fix-gi] WIP



commit 6cf9b6c7b3d8e6fa0699c29fcf652fdb69f25631
Author: Jens Georg <mail jensge org>
Date:   Sat Apr 28 17:03:51 2012 +0200

    WIP

 libgupnp/gupnp-service-proxy.c |  201 +++++++++++++++++++++++++++++++++++++---
 libgupnp/gupnp-service-proxy.h |   45 +++++++++
 2 files changed, 231 insertions(+), 15 deletions(-)
---
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index 10da9ac..94d0259 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -81,6 +81,7 @@ enum {
 static guint signals[LAST_SIGNAL];
 
 struct _GUPnPServiceProxyAction {
+        volatile gint ref_count;
         GUPnPServiceProxy *proxy;
 
         SoupMessage *msg;
@@ -120,18 +121,40 @@ subscribe (GUPnPServiceProxy *proxy);
 static void
 unsubscribe (GUPnPServiceProxy *proxy);
 
-static void
-gupnp_service_proxy_action_free (GUPnPServiceProxyAction *action)
+GUPnPServiceProxyAction *
+gupnp_service_proxy_action_ref (GUPnPServiceProxyAction *action)
 {
-        action->proxy->priv->pending_actions =
-                g_list_remove (action->proxy->priv->pending_actions, action);
+        g_return_val_if_fail (action, NULL);
+        g_return_val_if_fail (action->ref_count > 0, NULL);
 
-        if (action->msg != NULL)
-                g_object_unref (action->msg);
+        g_atomic_int_inc (&action->ref_count);
+        g_debug ("ref: action->ref_count: %d", action->ref_count);
 
-        g_slice_free (GUPnPServiceProxyAction, action);
+        return action;
 }
 
+void
+gupnp_service_proxy_action_unref (GUPnPServiceProxyAction *action)
+{
+
+        g_return_if_fail (action);
+        g_return_if_fail (action->ref_count > 0);
+
+        if (g_atomic_int_dec_and_test (&action->ref_count)) {
+                action->proxy->priv->pending_actions =
+                        g_list_remove (action->proxy->priv->pending_actions, action);
+
+                if (action->msg != NULL)
+                        g_object_unref (action->msg);
+
+                g_slice_free (GUPnPServiceProxyAction, action);
+                g_debug ("unref: freed");
+        }
+        else g_debug ("unref: action->ref_count: %d", action->ref_count);
+}
+
+G_DEFINE_BOXED_TYPE (GUPnPServiceProxyAction, gupnp_service_proxy_action, gupnp_service_proxy_action_ref, 
gupnp_service_proxy_action_unref)
+
 static void
 notify_data_free (NotifyData *data)
 {
@@ -619,6 +642,33 @@ out:
 }
 
 /**
+ * gupnp_service_proxy_send_action_hash_gi:
+ * @proxy: A #GUPnPServiceProxy
+ * @action: An action
+ * @error: The location where to store any error, or %NULL
+ * @in_hash: (element-type utf8 GValue) (transfer none): A #GHashTable of in
+ * parameter name and #GValue pairs
+ * @out_hash: (inout) (element-type utf8 GValue) (transfer full): A #GHashTable
+ * of out parameter name and initialized #GValue pairs
+ *
+ * See gupnp_service_proxy_send_action(); this version takes a pair of
+ * #GHashTable<!-- -->s for runtime determined parameter lists.
+ *
+ * Return value: %TRUE if sending the action was succesful.
+ * Rename To: gupnp_service_proxy_send_action_hash
+ **/
+gboolean
+gupnp_service_proxy_send_action_hash_gi (GUPnPServiceProxy *proxy,
+                                         const char        *action,
+                                         GHashTable        *in_hash,
+                                         GHashTable        *out_hash,
+                                         GError           **error)
+{
+    return gupnp_service_proxy_send_action_hash (proxy, action, error, in_hash, out_hash);
+}
+
+
+/**
  * gupnp_service_proxy_send_action_hash:
  * @proxy: A #GUPnPServiceProxy
  * @action: An action
@@ -632,6 +682,7 @@ out:
  * #GHashTable<!-- -->s for runtime determined parameter lists.
  *
  * Return value: %TRUE if sending the action was succesful.
+ * (skip)
  **/
 gboolean
 gupnp_service_proxy_send_action_hash (GUPnPServiceProxy *proxy,
@@ -676,6 +727,41 @@ gupnp_service_proxy_send_action_hash (GUPnPServiceProxy *proxy,
 }
 
 /**
+ * gupnp_service_proxy_send_action_list_gi:
+ * @proxy: (transfer none) : A #GUPnPServiceProxy
+ * @action: An action
+ * @error: The location where to store any error, or %NULL
+ * @in_names: (element-type utf8) (transfer none): #GList of 'in' parameter
+ * names (as strings)
+ * @in_values: (element-type GValue) (transfer none): #GList of values (as
+ * #GValue) that line up with @in_names
+ * @out_names: (element-type utf8) (transfer none): #GList of 'out' parameter
+ * names (as strings)
+ * @out_types: (element-type GType) (transfer none): #GList of types (as #GType)
+ * that line up with @out_names
+ * @out_values: (element-type GValue) (transfer full) (out): #GList of values
+ * (as #GValue) that line up with @out_names and @out_types.
+ *
+ * The synchronous variant of #gupnp_service_proxy_begin_action_list and
+ * #gupnp_service_proxy_end_action_list.
+ *
+ * Return value: %TRUE if sending the action was succesful.
+ * Rename To: gupnp_service_proxy_send_action_list
+ **/
+gboolean
+gupnp_service_proxy_send_action_list_gi (GUPnPServiceProxy *proxy,
+                                         const char        *action,
+                                         GList             *in_names,
+                                         GList             *in_values,
+                                         GList             *out_names,
+                                         GList             *out_types,
+                                         GList            **out_values,
+                                         GError           **error)
+{
+    return gupnp_service_proxy_send_action_list (proxy, action, error, in_names, in_values, out_names, 
out_types, out_values);
+}
+
+/**
  * gupnp_service_proxy_send_action_list:
  * @proxy: (transfer none) : A #GUPnPServiceProxy
  * @action: An action
@@ -797,6 +883,7 @@ begin_action_msg (GUPnPServiceProxy              *proxy,
 
         /* Create action structure */
         ret = g_slice_new (GUPnPServiceProxyAction);
+        ret->ref_count = 1;
 
         ret->proxy = proxy;
 
@@ -1082,6 +1169,34 @@ gupnp_service_proxy_begin_action_list
 }
 
 /**
+ * gupnp_service_proxy_begin_action_hash_gi:
+ * @proxy: A #GUPnPServiceProxy
+ * @action: An action
+ * @callback: (scope async): The callback to call when sending the action has succeeded
+ * or failed
+ * @user_data: User data for @callback
+ * @hash: (element-type utf8 GValue): A #GHashTable of in parameter name and #GValue pairs
+ *
+ * See gupnp_service_proxy_begin_action(); this version takes a #GHashTable
+ * for runtime generated parameter lists.
+ *
+ * Return value: (transfer none): A #GUPnPServiceProxyAction handle. This will
+ * be freed when calling gupnp_service_proxy_cancel_action() or
+ * gupnp_service_proxy_end_action_hash().
+ * Rename To: gupnp_service_proxy_begin_action_hash
+ **/
+GUPnPServiceProxyAction *
+gupnp_service_proxy_begin_action_hash_gi
+                                   (GUPnPServiceProxy              *proxy,
+                                    const char                     *action,
+                                    GUPnPServiceProxyActionCallback callback,
+                                    GHashTable                     *hash,
+                                    gpointer                        user_data)
+{
+    return gupnp_service_proxy_begin_action_hash (proxy, action, callback, user_data, hash);
+}
+
+/**
  * gupnp_service_proxy_begin_action_hash:
  * @proxy: A #GUPnPServiceProxy
  * @action: An action
@@ -1367,6 +1482,38 @@ gupnp_service_proxy_end_action_valist (GUPnPServiceProxy       *proxy,
 }
 
 /**
+ * gupnp_service_proxy_end_action_list_gi:
+ * @proxy: A #GUPnPServiceProxy
+ * @action: A #GUPnPServiceProxyAction handle
+ * @error: The location where to store any error, or %NULL
+ * @out_names: (element-type utf8) (transfer none): #GList of 'out' parameter
+ * names (as strings)
+ * @out_types: (element-type GType) (transfer none): #GList of types (as #GType)
+ * that line up with @out_names
+ * @out_values: (element-type GValue) (transfer full) (out): #GList of values
+ * (as #GValue) that line up with @out_names and @out_types.
+ *
+ * A variant of #gupnp_service_proxy_end_action that takes lists of
+ * out-parameter names, types and place-holders for values. The returned list
+ * in @out_values must be freed using #g_list_free and each element in it using
+ * #g_value_unset and #g_slice_free.
+ *
+ * Return value : %TRUE on success.
+ *
+ * Rename To: gupnp_service_proxy_end_action_list
+ **/
+gboolean
+gupnp_service_proxy_end_action_list_gi (GUPnPServiceProxy       *proxy,
+                                        GUPnPServiceProxyAction *action,
+                                        GList                   *out_names,
+                                        GList                   *out_types,
+                                        GList                  **out_values,
+                                        GError                 **error)
+{
+    return gupnp_service_proxy_end_action_list (proxy, action, error, out_names, out_types, out_values);
+}
+
+/**
  * gupnp_service_proxy_end_action_list:
  * @proxy: A #GUPnPServiceProxy
  * @action: A #GUPnPServiceProxyAction handle
@@ -1384,6 +1531,7 @@ gupnp_service_proxy_end_action_valist (GUPnPServiceProxy       *proxy,
  * #g_value_unset and #g_slice_free.
  *
  * Returns: %TRUE on success.
+ * (skip)
  **/
 gboolean
 gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
@@ -1412,7 +1560,7 @@ gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
                 else
                         g_error_free (action->error);
 
-                gupnp_service_proxy_action_free (action);
+                gupnp_service_proxy_action_unref (action);
 
                 return FALSE;
         }
@@ -1420,7 +1568,7 @@ gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
         /* Check response for errors and do initial parsing */
         response = check_action_response (proxy, action, &params, error);
         if (response == NULL) {
-                gupnp_service_proxy_action_free (action);
+                gupnp_service_proxy_action_unref (action);
 
                 return FALSE;
         }
@@ -1443,7 +1591,7 @@ gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
         *out_values = out_values_list;
 
         /* Cleanup */
-        gupnp_service_proxy_action_free (action);
+        gupnp_service_proxy_action_unref (action);
 
         xmlFreeDoc (response);
 
@@ -1451,7 +1599,7 @@ gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
 }
 
 /**
- * gupnp_service_proxy_end_action_hash:
+ * gupnp_service_proxy_end_action_hash_gi:
  * @proxy: A #GUPnPServiceProxy
  * @action: A #GUPnPServiceProxyAction handle
  * @error: The location where to store any error, or %NULL
@@ -1462,6 +1610,29 @@ gupnp_service_proxy_end_action_list (GUPnPServiceProxy       *proxy,
  * runtime generated parameter lists.
  *
  * Return value: %TRUE on success.
+ * Rename To: gupnp_service_proxy_end_action_hash
+ **/
+gboolean
+gupnp_service_proxy_end_action_hash_gi (GUPnPServiceProxy       *proxy,
+                                        GUPnPServiceProxyAction *action,
+                                        GHashTable              *hash,
+                                        GError                 **error)
+{
+    return gupnp_service_proxy_end_action_hash (proxy, action, error, hash);
+}
+
+/**
+ * gupnp_service_proxy_end_action_hash:
+ * @proxy: A #GUPnPServiceProxy
+ * @action: A #GUPnPServiceProxyAction handle
+ * @error: The location where to store any error, or %NULL
+ * @hash: (element-type utf8 GValue) (out caller-allocates) (transfer none): A #GHashTable of
+ * out parameter name and initialised #GValue pairs
+ *
+ * See gupnp_service_proxy_end_action(); this version takes a #GHashTable for
+ * runtime generated parameter lists.
+ *
+ * Return value: %TRUE on success.
  **/
 gboolean
 gupnp_service_proxy_end_action_hash (GUPnPServiceProxy       *proxy,
@@ -1483,7 +1654,7 @@ gupnp_service_proxy_end_action_hash (GUPnPServiceProxy       *proxy,
                 else
                         g_error_free (action->error);
 
-                gupnp_service_proxy_action_free (action);
+                gupnp_service_proxy_action_unref (action);
 
                 return FALSE;
         }
@@ -1491,7 +1662,7 @@ gupnp_service_proxy_end_action_hash (GUPnPServiceProxy       *proxy,
         /* Check response for errors and do initial parsing */
         response = check_action_response (proxy, action, &params, error);
         if (response == NULL) {
-                gupnp_service_proxy_action_free (action);
+                gupnp_service_proxy_action_unref (action);
 
                 return FALSE;
         }
@@ -1500,7 +1671,7 @@ gupnp_service_proxy_end_action_hash (GUPnPServiceProxy       *proxy,
         g_hash_table_foreach (hash, (GHFunc) read_out_parameter, params);
 
         /* Cleanup */
-        gupnp_service_proxy_action_free (action);
+        gupnp_service_proxy_action_unref (action);
 
         xmlFreeDoc (response);
 
@@ -1538,7 +1709,7 @@ gupnp_service_proxy_cancel_action (GUPnPServiceProxy       *proxy,
         if (action->error != NULL)
                 g_error_free (action->error);
 
-        gupnp_service_proxy_action_free (action);
+        gupnp_service_proxy_action_unref (action);
 }
 
 /**
diff --git a/libgupnp/gupnp-service-proxy.h b/libgupnp/gupnp-service-proxy.h
index a11057a..4d34592 100644
--- a/libgupnp/gupnp-service-proxy.h
+++ b/libgupnp/gupnp-service-proxy.h
@@ -30,6 +30,9 @@ G_BEGIN_DECLS
 GType
 gupnp_service_proxy_get_type (void) G_GNUC_CONST;
 
+GType
+gupnp_service_proxy_action_get_type (void) G_GNUC_CONST;
+
 #define GUPNP_TYPE_SERVICE_PROXY \
                 (gupnp_service_proxy_get_type ())
 #define GUPNP_SERVICE_PROXY(obj) \
@@ -138,6 +141,13 @@ gupnp_service_proxy_send_action_hash
                                     GHashTable                     *in_hash,
                                     GHashTable                     *out_hash);
 
+gboolean
+gupnp_service_proxy_send_action_hash_gi
+                                   (GUPnPServiceProxy              *proxy,
+                                    const char                     *action,
+                                    GHashTable                     *in_hash,
+                                    GHashTable                     *out_hash,
+                                    GError                        **error);
 
 gboolean
 gupnp_service_proxy_send_action_list (GUPnPServiceProxy *proxy,
@@ -149,6 +159,16 @@ gupnp_service_proxy_send_action_list (GUPnPServiceProxy *proxy,
                                       GList             *out_types,
                                       GList            **out_values);
 
+gboolean
+gupnp_service_proxy_send_action_list_gi (GUPnPServiceProxy *proxy,
+                                         const char        *action,
+                                         GList             *in_names,
+                                         GList             *in_values,
+                                         GList             *out_names,
+                                         GList             *out_types,
+                                         GList            **out_values,
+                                         GError           **error);
+
 
 GUPnPServiceProxyAction *
 gupnp_service_proxy_begin_action   (GUPnPServiceProxy              *proxy,
@@ -175,6 +195,14 @@ gupnp_service_proxy_begin_action_list
                                     gpointer                        user_data);
 
 GUPnPServiceProxyAction *
+gupnp_service_proxy_begin_action_hash_gi
+                                   (GUPnPServiceProxy              *proxy,
+                                    const char                     *action,
+                                    GUPnPServiceProxyActionCallback callback,
+                                    GHashTable                     *hash,
+                                    gpointer                        user_data);
+
+GUPnPServiceProxyAction *
 gupnp_service_proxy_begin_action_hash
                                    (GUPnPServiceProxy              *proxy,
                                     const char                     *action,
@@ -205,6 +233,22 @@ gupnp_service_proxy_end_action_list
                                    GList                  **out_values);
 
 gboolean
+gupnp_service_proxy_end_action_list_gi
+                                  (GUPnPServiceProxy       *proxy,
+                                   GUPnPServiceProxyAction *action,
+                                   GList                   *out_names,
+                                   GList                   *out_types,
+                                   GList                  **out_values,
+                                   GError                  **error);
+
+gboolean
+gupnp_service_proxy_end_action_hash_gi
+                                   (GUPnPServiceProxy              *proxy,
+                                    GUPnPServiceProxyAction        *action,
+                                    GHashTable                     *hash,
+                                    GError                        **error);
+
+gboolean
 gupnp_service_proxy_end_action_hash
                                    (GUPnPServiceProxy              *proxy,
                                     GUPnPServiceProxyAction        *action,
@@ -235,6 +279,7 @@ gupnp_service_proxy_set_subscribed (GUPnPServiceProxy              *proxy,
 gboolean
 gupnp_service_proxy_get_subscribed (GUPnPServiceProxy              *proxy);
 
+
 G_END_DECLS
 
 #endif /* __GUPNP_SERVICE_PROXY_H__ */


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