[gupnp-tools] av-cp: Remove deprecated gupnp calls



commit e4039c5eba16d1754b99191297f704329878e5f8
Author: Jens Georg <mail jensge org>
Date:   Thu Jul 23 22:01:42 2020 +0200

    av-cp: Remove deprecated gupnp calls

 src/av-cp/entry-completion.c  |  34 ++--
 src/av-cp/entry-completion.h  |   4 +-
 src/av-cp/renderer-combo.c    | 241 +++++++++++++++----------
 src/av-cp/renderer-controls.c | 237 ++++++++++++++-----------
 src/av-cp/search-dialog.c     |  16 +-
 src/av-cp/server-device.c     | 400 +++++++++++++++++++++++++-----------------
 src/av-cp/server-device.h     |   2 +-
 7 files changed, 546 insertions(+), 388 deletions(-)
---
diff --git a/src/av-cp/entry-completion.c b/src/av-cp/entry-completion.c
index c2ef8e0..c0e7330 100644
--- a/src/av-cp/entry-completion.c
+++ b/src/av-cp/entry-completion.c
@@ -1,5 +1,7 @@
 #include "entry-completion.h"
 
+#include <libgupnp-av/gupnp-av.h>
+
 static void
 entry_completion_constructed (GObject *self);
 
@@ -10,16 +12,10 @@ struct _EntryCompletion
         GtkListStore *store;
 };
 
-G_DEFINE_TYPE (EntryCompletion, entry_completion, GTK_TYPE_ENTRY_COMPLETION)
-
-enum {
-        PROP_0,
-        N_PROPS
-};
 
-static GParamSpec *properties [N_PROPS];
+G_DEFINE_TYPE (EntryCompletion, entry_completion, GTK_TYPE_ENTRY_COMPLETION)
 
-EntryCompletion *
+GtkEntryCompletion *
 entry_completion_new (void)
 {
         return g_object_new (ENTRY_TYPE_COMPLETION, NULL);
@@ -58,10 +54,14 @@ entry_completion_set_property (GObject      *object,
 }
 
 static gboolean
-entry_completion_on_match_selected (GtkEntryCompletion *self, GtkTreeModel *model, GtkTreeIter *iter, 
gpointer user_data)
+entry_completion_on_match_selected (GtkEntryCompletion *self,
+                                    GtkTreeModel       *model,
+                                    GtkTreeIter        *iter)
 {
         char *match = NULL;
-        GtkEntry *entry = gtk_entry_completion_get_entry (self);
+        GtkEntry *entry;
+
+        entry = GTK_ENTRY (gtk_entry_completion_get_entry (self));
         gtk_tree_model_get (model, iter, 0, &match, -1);
         
         char *old_text = g_strdup (gtk_entry_get_text (entry));
@@ -71,7 +71,10 @@ entry_completion_on_match_selected (GtkEntryCompletion *self, GtkTreeModel *mode
                 *needle = '\0';
         }
 
-        char *new_text = g_strconcat (needle == NULL ? "" : old_text, match, NULL);
+        char *new_text = g_strconcat (needle == NULL ? ""
+                                                     : old_text,
+                                      match,
+                                      NULL);
         gtk_entry_set_text (entry, new_text);
         gtk_editable_set_position (GTK_EDITABLE (entry), strlen (new_text));
         g_free (new_text);
@@ -99,12 +102,13 @@ entry_completion_on_match (GtkEntryCompletion *self, const char *key, GtkTreeIte
 {
         GtkTreeModel *model = gtk_entry_completion_get_model (self);
         char *candidate;
-        GtkEntry *entry = gtk_entry_completion_get_entry (self);
+        GtkWidget *entry;
         gboolean retval = FALSE;
 
+        entry  = gtk_entry_completion_get_entry (self);
         gtk_tree_model_get (model, iter, 0, &candidate, -1);
 
-        char *needle = strrchr (key, ' ');
+        const char *needle = strrchr (key, ' ');
         if (needle != NULL) {
                 if ((needle - key)> gtk_editable_get_position (GTK_EDITABLE (entry))) {
                         g_print ("Position wrong\n");
@@ -166,13 +170,13 @@ static const char *keywords[] = {
 };
 
 void
-entry_completion_set_search_criteria (EntryCompletion *self, char** criteria)
+entry_completion_set_search_criteria (EntryCompletion *self, char const * const * criteria)
 {
         GtkTreeIter iter;
         gtk_list_store_clear (self->store);
 
         // Prefill ListStore with the search expression keywords
-        char **it = keywords;
+        char const * const *it = keywords;
         while (*it != NULL) {
                 gtk_list_store_insert_with_values (self->store,
                                                    &iter,
diff --git a/src/av-cp/entry-completion.h b/src/av-cp/entry-completion.h
index f999c41..2919d80 100644
--- a/src/av-cp/entry-completion.h
+++ b/src/av-cp/entry-completion.h
@@ -9,7 +9,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EntryCompletion, entry_completion, ENTRY, COMPLETION, GtkEntryCompletion)
 
-EntryCompletion *entry_completion_new (void);
-void entry_completion_set_search_criteria (EntryCompletion *self, char** criteria);
+GtkEntryCompletion *entry_completion_new (void);
+void entry_completion_set_search_criteria (EntryCompletion *self, char const * const * criteria);
 
 G_END_DECLS
diff --git a/src/av-cp/renderer-combo.c b/src/av-cp/renderer-combo.c
index 2aef43b..962e5b0 100644
--- a/src/av-cp/renderer-combo.c
+++ b/src/av-cp/renderer-combo.c
@@ -552,29 +552,35 @@ get_rendering_control (GUPnPDeviceProxy *proxy)
 }
 
 static void
-get_protocol_info_cb (GUPnPServiceProxy       *cm,
-                      GUPnPServiceProxyAction *action,
-                      gpointer                 user_data)
+get_protocol_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         gchar      *sink_protocol_info;
         const gchar *udn;
-        GError      *error;
-
-        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (cm));
-
-        error = NULL;
-        if (!gupnp_service_proxy_end_action (cm,
-                                             action,
-                                             &error,
-                                             "Sink",
-                                             G_TYPE_STRING,
-                                             &sink_protocol_info,
-                                             NULL)) {
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
+
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        if (error != NULL) {
+                g_warning ("Failed to get sink protocl info from "
+                           "media renderer '%s': %s",
+                           udn,
+                           error->message);
+
+                goto return_point;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action,
+                                                    &error,
+                                                    "Sink",
+                                                    G_TYPE_STRING,
+                                                    &sink_protocol_info,
+                                                    NULL)) {
                 g_warning ("Failed to get sink protocol info from "
                            "media renderer '%s':%s\n",
                            udn,
                            error->message);
-                g_error_free (error);
 
                 goto return_point;
         }
@@ -598,33 +604,40 @@ get_protocol_info_cb (GUPnPServiceProxy       *cm,
         }
 
 return_point:
-        g_object_unref (cm);
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 static void
-get_transport_info_cb (GUPnPServiceProxy       *av_transport,
-                      GUPnPServiceProxyAction *action,
-                      gpointer                 user_data)
+get_transport_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         gchar       *state_name;
         const gchar *udn;
-        GError      *error;
-
-        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (av_transport));
-
-        error = NULL;
-        if (!gupnp_service_proxy_end_action (av_transport,
-                                             action,
-                                             &error,
-                                             "CurrentTransportState",
-                                             G_TYPE_STRING,
-                                             &state_name,
-                                             NULL)) {
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
+
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
+        if (error != NULL) {
+                g_warning ("Failed to get transport info from media renderer"
+                           " '%s':%s",
+                           udn,
+                           error->message);
+
+                goto return_point;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action,
+                                                    &error,
+                                                    "CurrentTransportState",
+                                                    G_TYPE_STRING,
+                                                    &state_name,
+                                                    NULL)) {
                 g_warning ("Failed to get transport info from media renderer"
                            " '%s':%s\n",
                            udn,
                            error->message);
-                g_error_free (error);
 
                 goto return_point;
         }
@@ -636,34 +649,40 @@ get_transport_info_cb (GUPnPServiceProxy       *av_transport,
         }
 
 return_point:
-        g_object_unref (av_transport);
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 static void
-get_volume_cb (GUPnPServiceProxy       *rendering_control,
-               GUPnPServiceProxyAction *action,
-               gpointer                 user_data)
+get_volume_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         guint        volume;
         const gchar *udn;
-        GError      *error;
-
-        udn = gupnp_service_info_get_udn
-                                (GUPNP_SERVICE_INFO (rendering_control));
-
-        error = NULL;
-        if (!gupnp_service_proxy_end_action (rendering_control,
-                                             action,
-                                             &error,
-                                             "CurrentVolume",
-                                             G_TYPE_UINT,
-                                             &volume,
-                                             NULL)) {
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
+
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        if (error != NULL) {
+                g_warning ("Failed to get volume info from media renderer"
+                           " '%s':%s",
+                           udn,
+                           error->message);
+
+                goto return_point;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action,
+                                                    &error,
+                                                    "CurrentVolume",
+                                                    G_TYPE_UINT,
+                                                    &volume,
+                                                    NULL)) {
                 g_warning ("Failed to get volume from media renderer"
                            " '%s':%s\n",
                            udn,
                            error->message);
-                g_error_free (error);
 
                 goto return_point;
         }
@@ -671,33 +690,41 @@ get_volume_cb (GUPnPServiceProxy       *rendering_control,
         set_volume (udn, volume);
 
 return_point:
-        g_object_unref (rendering_control);
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 static void
-get_media_info_cb (GUPnPServiceProxy       *av_transport,
-                   GUPnPServiceProxyAction *action,
-                   gpointer                 user_data)
+
+get_media_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         gchar       *duration;
         const gchar *udn;
-        GError      *error;
-
-        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (av_transport));
-
-        error = NULL;
-        if (!gupnp_service_proxy_end_action (av_transport,
-                                             action,
-                                             &error,
-                                             "MediaDuration",
-                                             G_TYPE_STRING,
-                                             &duration,
-                                             NULL)) {
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
+
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
+        if (error != NULL) {
+                g_warning ("Failed to get media info from media renderer"
+                           " '%s':%s",
+                           udn,
+                           error->message);
+
+                goto return_point;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action,
+                                                    &error,
+                                                    "MediaDuration",
+                                                    G_TYPE_STRING,
+                                                    &duration,
+                                                    NULL)) {
                 g_warning ("Failed to get current media duration"
                            "from media renderer '%s':%s\n",
                            udn,
                            error->message);
-                g_error_free (error);
 
                 goto return_point;
         }
@@ -706,7 +733,8 @@ get_media_info_cb (GUPnPServiceProxy       *av_transport,
         g_free (duration);
 
 return_point:
-        g_object_unref (av_transport);
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 void
@@ -743,33 +771,54 @@ add_media_renderer (GUPnPDeviceProxy *proxy)
                                                rendering_control,
                                                udn);
 
-        gupnp_service_proxy_begin_action (g_object_ref (cm),
-                                          "GetProtocolInfo",
-                                          get_protocol_info_cb,
-                                          NULL,
-                                          NULL);
-
-        gupnp_service_proxy_begin_action (g_object_ref (av_transport),
-                                          "GetTransportInfo",
-                                          get_transport_info_cb,
-                                          NULL,
-                                          "InstanceID", G_TYPE_UINT, 0,
-                                          NULL);
-
-        gupnp_service_proxy_begin_action (g_object_ref (av_transport),
-                                          "GetMediaInfo",
-                                          get_media_info_cb,
-                                          NULL,
-                                          "InstanceID", G_TYPE_UINT, 0,
-                                          NULL);
-
-        gupnp_service_proxy_begin_action (g_object_ref (rendering_control),
-                                          "GetVolume",
-                                          get_volume_cb,
-                                          NULL,
-                                          "InstanceID", G_TYPE_UINT, 0,
-                                          "Channel", G_TYPE_STRING, "Master",
-                                          NULL);
+        GUPnPServiceProxyAction *action;
+
+        action = gupnp_service_proxy_action_new ("GetProtocolInfo", NULL);
+        gupnp_service_proxy_call_action_async (g_object_ref (cm),
+                                               action,
+                                               NULL,
+                                               get_protocol_info_cb,
+                                               NULL);
+        gupnp_service_proxy_action_unref (action);
+
+        action = gupnp_service_proxy_action_new ("GetTransportInfo",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 NULL);
+        gupnp_service_proxy_call_action_async (g_object_ref (av_transport),
+                                               action,
+                                               NULL,
+                                               get_transport_info_cb,
+                                               NULL);
+        gupnp_service_proxy_action_unref (action);
+
+        action = gupnp_service_proxy_action_new ("GetMediaInfo",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 NULL);
+        gupnp_service_proxy_call_action_async (g_object_ref (av_transport),
+                                               action,
+                                               NULL,
+                                               get_media_info_cb,
+                                               NULL);
+        gupnp_service_proxy_action_unref (action);
+
+        action = gupnp_service_proxy_action_new ("GetVolume",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 "Channel",
+                                                 G_TYPE_STRING,
+                                                 "Master",
+                                                 NULL);
+        gupnp_service_proxy_call_action_async (g_object_ref (rendering_control),
+                                               action,
+                                               NULL,
+                                               get_volume_cb,
+                                               NULL);
+        gupnp_service_proxy_action_unref (action);
 
         g_object_unref (rendering_control);
 no_rendering_control:
diff --git a/src/av-cp/renderer-controls.c b/src/av-cp/renderer-controls.c
index 7a0e58d..ccfb4ce 100644
--- a/src/av-cp/renderer-controls.c
+++ b/src/av-cp/renderer-controls.c
@@ -100,34 +100,39 @@ set_av_transport_uri_data_free (SetAVTransportURIData *data)
 }
 
 static void
-av_transport_action_cb (GUPnPServiceProxy       *av_transport,
-                        GUPnPServiceProxyAction *action,
-                        gpointer                 user_data)
+av_transport_action_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         const char *action_name;
-        GError *error;
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        const char *udn;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
 
         action_name = (const char *) user_data;
 
         error = NULL;
-        if (!gupnp_service_proxy_end_action (av_transport,
-                                             action,
-                                             &error,
-                                             NULL)) {
-                const char *udn;
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        if (error != NULL) {
+                g_warning ("Failed to send action '%s' to '%s': %s",
+                           action_name,
+                           udn,
+                           error->message);
 
-                udn = gupnp_service_info_get_udn
-                                        (GUPNP_SERVICE_INFO (av_transport));
+                goto out;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action, &error, NULL)) {
 
                 g_warning ("Failed to send action '%s' to '%s': %s",
                            action_name,
                            udn,
                            error->message);
-
-                g_error_free (error);
         }
 
-        g_object_unref (av_transport);
+out:
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 static void
@@ -171,11 +176,11 @@ create_av_transport_args (char **additional_args, GList **out_values)
 }
 
 void
-av_transport_send_action (const char *action,
-                          char *additional_args[])
+av_transport_send_action (const char *action_name, char *additional_args[])
 {
         GUPnPServiceProxy *av_transport;
         GList             *names, *values;
+        GUPnPServiceProxyAction *action;
 
         av_transport = get_selected_av_transport (NULL);
         if (av_transport == NULL) {
@@ -184,13 +189,17 @@ av_transport_send_action (const char *action,
         }
 
         names = create_av_transport_args (additional_args, &values);
+        action = gupnp_service_proxy_action_new_from_list (action_name,
+                                                           names,
+                                                           values);
 
-        gupnp_service_proxy_begin_action_list (av_transport,
+        gupnp_service_proxy_call_action_async (av_transport,
                                                action,
-                                               names,
-                                               values,
+                                               NULL,
                                                av_transport_action_cb,
-                                               (char *) action);
+                                               (char *) action_name);
+
+        gupnp_service_proxy_action_unref (action);
         g_list_free_full (names, g_free);
         g_list_free_full (values, g_value_free);
 }
@@ -204,20 +213,24 @@ play (void)
 }
 
 static void
-set_av_transport_uri_cb (GUPnPServiceProxy       *av_transport,
-                         GUPnPServiceProxyAction *action,
-                         gpointer                 user_data)
+set_av_transport_uri_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
-        SetAVTransportURIData *data;
-        GError                *error;
+        SetAVTransportURIData *data = (SetAVTransportURIData *) user_data;
+        GError *error = NULL;
+        const char *udn;
 
-        data = (SetAVTransportURIData *) user_data;
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
 
-        error = NULL;
-        if (gupnp_service_proxy_end_action (av_transport,
-                                            action,
-                                            &error,
-                                            NULL)) {
+        gupnp_service_proxy_call_action_finish (GUPNP_SERVICE_PROXY (object),
+                                                res,
+                                                &error);
+
+        if (error != NULL) {
+                g_warning ("Failed to set URI '%s' on %s: %s",
+                           gupnp_didl_lite_resource_get_uri (data->resource),
+                           udn,
+                           error->message);
+        } else {
                 long duration ;
                 if (data->callback) {
                         data->callback ();
@@ -230,22 +243,11 @@ set_av_transport_uri_cb (GUPnPServiceProxy       *av_transport,
                                              0.0,
                                              duration);
                 }
-        } else {
-                const char *udn;
-
-                udn = gupnp_service_info_get_udn
-                                        (GUPNP_SERVICE_INFO (av_transport));
-
-                g_warning ("Failed to set URI '%s' on %s: %s",
-                           gupnp_didl_lite_resource_get_uri (data->resource),
-                           udn,
-                           error->message);
-
-                g_error_free (error);
         }
 
+        g_clear_error (&error);
         set_av_transport_uri_data_free (data);
-        g_object_unref (av_transport);
+        g_object_unref (object);
 }
 
 G_MODULE_EXPORT
@@ -334,6 +336,7 @@ set_av_transport_uri (const char *metadata,
         SetAVTransportURIData *data;
         GUPnPDIDLLiteResource *resource;
         const char            *uri;
+        GUPnPServiceProxyAction *action;
 
         av_transport = get_selected_av_transport (NULL);
         if (av_transport == NULL) {
@@ -353,20 +356,24 @@ set_av_transport_uri (const char *metadata,
         data = set_av_transport_uri_data_new (callback, resource);
         uri = gupnp_didl_lite_resource_get_uri (resource);
 
-        gupnp_service_proxy_begin_action (av_transport,
-                                          "SetAVTransportURI",
-                                          set_av_transport_uri_cb,
-                                          data,
-                                          "InstanceID",
-                                          G_TYPE_UINT,
-                                          0,
-                                          "CurrentURI",
-                                          G_TYPE_STRING,
-                                          uri,
-                                          "CurrentURIMetaData",
-                                          G_TYPE_STRING,
-                                          metadata,
-                                          NULL);
+        action = gupnp_service_proxy_action_new ("SetAVTransportURI",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 "CurrentURI",
+                                                 G_TYPE_STRING,
+                                                 uri,
+                                                 "CurrentURIMetaData",
+                                                 G_TYPE_STRING,
+                                                 metadata,
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async (av_transport,
+                                               action,
+                                               NULL,
+                                               set_av_transport_uri_cb,
+                                               data);
+        gupnp_service_proxy_action_unref (action);
 }
 
 G_MODULE_EXPORT
@@ -517,33 +524,40 @@ set_position_scale_position (const char *position_str)
 }
 
 static void
-get_position_info_cb (GUPnPServiceProxy       *av_transport,
-                      GUPnPServiceProxyAction *action,
-                      gpointer                 user_data)
+get_position_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         gchar       *position;
         gchar       *duration;
         const gchar *udn;
-        GError      *error;
+        GError *error = NULL;
+        GUPnPServiceProxyAction *action;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
 
-        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (av_transport));
+        udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
 
-        error = NULL;
-        if (!gupnp_service_proxy_end_action (av_transport,
-                                             action,
-                                             &error,
-                                             "AbsTime",
-                                             G_TYPE_STRING,
-                                             &position,
-                                             "TrackDuration",
-                                             G_TYPE_STRING,
-                                             &duration,
-                                             NULL)) {
+        action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
+        if (error != NULL) {
+                g_warning ("Failed to get current media position"
+                           "from media renderer '%s':%s\n",
+                           udn,
+                           error->message);
+
+                goto return_point;
+        }
+
+        if (!gupnp_service_proxy_action_get_result (action,
+                                                    &error,
+                                                    "AbsTime",
+                                                    G_TYPE_STRING,
+                                                    &position,
+                                                    "TrackDuration",
+                                                    G_TYPE_STRING,
+                                                    &duration,
+                                                    NULL)) {
                 g_warning ("Failed to get current media position"
                            "from media renderer '%s':%s\n",
                            udn,
                            error->message);
-                g_error_free (error);
 
                 goto return_point;
         }
@@ -557,25 +571,35 @@ get_position_info_cb (GUPnPServiceProxy       *av_transport,
         g_free (duration);
 
 return_point:
-        g_object_unref (av_transport);
+        g_clear_error (&error);
+        g_object_unref (object);
 }
 
 static gboolean
 update_position (gpointer data)
 {
         GUPnPServiceProxy *av_transport;
+        GUPnPServiceProxyAction *action;
 
         av_transport = get_selected_av_transport (NULL);
         if (av_transport == NULL) {
                 return FALSE;
         }
 
-        gupnp_service_proxy_begin_action (av_transport,
-                                          "GetPositionInfo",
-                                          get_position_info_cb,
-                                          NULL,
-                                          "InstanceID", G_TYPE_UINT, 0,
-                                          NULL);
+        action = gupnp_service_proxy_action_new ("GetPositionInfo",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async (av_transport,
+                                               action,
+                                               NULL,
+                                               get_position_info_cb,
+                                               NULL);
+
+        gupnp_service_proxy_action_unref (action);
+
         return TRUE;
 }
 
@@ -678,21 +702,16 @@ prepare_controls_for_state (PlaybackState state)
 }
 
 static void
-set_volume_cb (GUPnPServiceProxy       *rendering_control,
-               GUPnPServiceProxyAction *action,
-               gpointer                 user_data)
+set_volume_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
         GError *error;
+        GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
 
         error = NULL;
-        if (!gupnp_service_proxy_end_action (rendering_control,
-                                             action,
-                                             &error,
-                                             NULL)) {
+        if (!gupnp_service_proxy_call_action_finish (proxy, res, &error)) {
                 const char *udn;
 
-                udn = gupnp_service_info_get_udn
-                        (GUPNP_SERVICE_INFO (rendering_control));
+                udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
 
                 g_warning ("Failed to set volume of %s: %s",
                            udn,
@@ -704,7 +723,7 @@ set_volume_cb (GUPnPServiceProxy       *rendering_control,
                 set_volume_scale (get_selected_renderer_volume ());
         }
 
-        g_object_unref (rendering_control);
+        g_object_unref (object);
 }
 
 G_MODULE_EXPORT
@@ -714,6 +733,7 @@ on_volume_scale_value_changed (GtkRange *range,
 {
         GUPnPServiceProxy *rendering_control;
         guint              desired_volume;
+        GUPnPServiceProxyAction *action;
 
         rendering_control = get_selected_rendering_control ();
         if (rendering_control == NULL) {
@@ -723,20 +743,25 @@ on_volume_scale_value_changed (GtkRange *range,
 
         desired_volume = (guint) gtk_range_get_value (range);
 
-        gupnp_service_proxy_begin_action (rendering_control,
-                                          "SetVolume",
-                                          set_volume_cb,
-                                          NULL,
-                                          "InstanceID",
-                                          G_TYPE_UINT,
-                                          0,
-                                          "Channel",
-                                          G_TYPE_STRING,
-                                          "Master",
-                                          "DesiredVolume",
-                                          G_TYPE_UINT,
-                                          desired_volume,
-                                          NULL);
+        action = gupnp_service_proxy_action_new ("SetVolume",
+                                                 "InstanceID",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 "Channel",
+                                                 G_TYPE_STRING,
+                                                 "Master",
+                                                 "DesiredVolume",
+                                                 G_TYPE_UINT,
+                                                 desired_volume,
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async (rendering_control,
+                                               action,
+                                               NULL,
+                                               set_volume_cb,
+                                               NULL);
+
+        gupnp_service_proxy_action_unref (action);
 
         return TRUE;
 }
diff --git a/src/av-cp/search-dialog.c b/src/av-cp/search-dialog.c
index c61bb78..29937bc 100644
--- a/src/av-cp/search-dialog.c
+++ b/src/av-cp/search-dialog.c
@@ -377,20 +377,28 @@ search_dialog_init (SearchDialog *self)
         priv = search_dialog_get_instance_private (self);
 
         priv->parser = gupnp_search_criteria_parser_new ();
-        gtk_entry_set_completion (priv->search_dialog_entry, entry_completion_new ());
+        gtk_entry_set_completion (priv->search_dialog_entry,
+                                  entry_completion_new ());
 
         GMenu *menu = g_menu_new ();
         g_menu_insert (menu, 0, _("Show _DIDL…"), "search.show-didl");
         priv->popup_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
         g_object_unref (menu);
 
-        gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), GTK_WIDGET (self), NULL);
+        gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
+                                   GTK_WIDGET (self),
+                                   NULL);
         GSimpleActionGroup *group = g_simple_action_group_new ();
         GSimpleAction *action = g_simple_action_new ("show-didl", NULL);
-        g_signal_connect_swapped (G_OBJECT (action), "activate", G_CALLBACK 
(search_dialog_on_didl_popup_activate), self);
+        g_signal_connect_swapped (G_OBJECT (action),
+                                  "activate",
+                                  G_CALLBACK (search_dialog_on_didl_popup_activate),
+                                  self);
         g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action));
 
-        gtk_widget_insert_action_group (GTK_WIDGET (self), "search", G_ACTION_GROUP (group));
+        gtk_widget_insert_action_group (GTK_WIDGET (self),
+                                        "search",
+                                        G_ACTION_GROUP (group));
         g_object_unref (group);
         g_object_unref (action);
 }
diff --git a/src/av-cp/server-device.c b/src/av-cp/server-device.c
index 19b990b..5941480 100644
--- a/src/av-cp/server-device.c
+++ b/src/av-cp/server-device.c
@@ -55,8 +55,8 @@ static void
 av_cp_media_server_introspect_finish (AVCPMediaServer *self);
 
 static void
-av_cp_media_server_on_get_search_caps (GUPnPServiceProxy *proxy,
-                                       GUPnPServiceProxyAction *action,
+av_cp_media_server_on_get_search_caps (GObject *object,
+                                       GAsyncResult *res,
                                        gpointer user_data);
 
 enum _AVCPMediaServerInitState {
@@ -154,80 +154,107 @@ av_cp_media_server_on_icon_updated (GUPnPDeviceInfo *info,
                                     GdkPixbuf       *icon);
 
 static void
-av_cp_media_server_on_get_sort_caps (GUPnPServiceProxy *proxy,
-                                     GUPnPServiceProxyAction *action,
-                                     gpointer user_data)
+av_cp_media_server_on_get_sort_caps (GObject      *object,
+                                     GAsyncResult *res,
+                                     gpointer      user_data)
 {
         AVCPMediaServer *self = AV_CP_MEDIA_SERVER (user_data);
         AVCPMediaServerPrivate *priv = av_cp_media_server_get_instance_private (self);
-
+        GUPnPServiceProxyAction *action;
 
         GError *error = NULL;
         char *sort_caps = NULL;
 
-        gupnp_service_proxy_end_action (proxy,
-                                        action,
-                                        &error,
-                                        "SortCaps",
-                                        G_TYPE_STRING,
-                                        &sort_caps,
-                                        NULL);
+        action = gupnp_service_proxy_call_action_finish
+                                                (GUPNP_SERVICE_PROXY (object),
+                                                 res,
+                                                 &error);
+
         if (error != NULL) {
-                g_warning ("Failed to get sort caps from server: %s",
+                g_warning ("GetSortCapabilities call failed: %s",
                            error->message);
-                g_error_free (error);
-        } else if (sort_caps != NULL) {
-                GString *default_sort_order = g_string_new (NULL);
-                if (strstr (sort_caps, "upnp:class") != NULL) {
-                        g_string_append (default_sort_order, "+upnp:class,");
-                }
-
-                if (strstr (sort_caps, "dc:title") != NULL) {
-                        g_string_append (default_sort_order, "+dc:title");
+                g_clear_error (&error);
+        } else {
+                gupnp_service_proxy_action_get_result (action,
+                                                       &error,
+                                                       "SortCaps",
+                                                       G_TYPE_STRING,
+                                                       &sort_caps,
+                                                       NULL);
+                if (error != NULL) {
+                        g_warning ("Failed to get sort caps from server: %s",
+                                error->message);
+                        g_error_free (error);
+                } else if (sort_caps != NULL) {
+                        GString *default_sort_order = g_string_new (NULL);
+                        if (strstr (sort_caps, "upnp:class") != NULL) {
+                                g_string_append (default_sort_order,
+                                                 "+upnp:class,");
+                        }
+
+                        if (strstr (sort_caps, "dc:title") != NULL) {
+                                g_string_append (default_sort_order,
+                                                 "+dc:title");
+                        }
+
+                        priv->default_sort_order =
+                                        g_string_free (default_sort_order, FALSE);
+
+                        g_free (sort_caps);
                 }
-
-                priv->default_sort_order =
-                                g_string_free (default_sort_order, FALSE);
-
-                g_free (sort_caps);
         }
         g_object_notify (G_OBJECT (self), "sort-order");
 
-        gupnp_service_proxy_begin_action
-                        (priv->content_directory,
-                                "GetSearchCapabilities",
-                                av_cp_media_server_on_get_search_caps,
-                                self,
-                                NULL);
+        action = gupnp_service_proxy_action_new ("GetSearchCapabilities",
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async
+                                       (priv->content_directory,
+                                        action,
+                                        NULL,
+                                        av_cp_media_server_on_get_search_caps,
+                                        self);
+
+        gupnp_service_proxy_action_unref (action);
 }
 
 static void
-av_cp_media_server_on_get_search_caps (GUPnPServiceProxy *proxy,
-                                       GUPnPServiceProxyAction *action,
-                                       gpointer user_data)
+av_cp_media_server_on_get_search_caps (GObject      *object,
+                                       GAsyncResult *res,
+                                       gpointer      user_data)
 {
         AVCPMediaServer *self = AV_CP_MEDIA_SERVER (user_data);
         AVCPMediaServerPrivate *priv = av_cp_media_server_get_instance_private (self);
-
+        GUPnPServiceProxyAction *action;
 
         GError *error = NULL;
         char *search_caps = NULL;
 
-        gupnp_service_proxy_end_action (proxy,
-                                        action,
-                                        &error,
-                                        "SearchCaps",
-                                        G_TYPE_STRING,
-                                        &search_caps,
-                                        NULL);
+        action = gupnp_service_proxy_call_action_finish
+                                                (GUPNP_SERVICE_PROXY (object),
+                                                 res,
+                                                 &error);
+
         if (error != NULL) {
-                g_warning ("Failed to get sort caps from server: %s",
+                g_warning ("GetSearchCapabilites call failed: %s",
                            error->message);
-                g_error_free (error);
-        } else if (search_caps != NULL) {
-                priv->search_caps = g_strsplit (search_caps, ",", -1);
+                g_clear_error (&error);
         } else {
-                priv->search_caps = g_strsplit ("upnp:class,@id", ",", -1);
+                gupnp_service_proxy_action_get_result (action,
+                                                       &error,
+                                                       "SearchCaps",
+                                                       G_TYPE_STRING,
+                                                       &search_caps,
+                                                       NULL);
+                if (error != NULL) {
+                        g_warning ("Failed to get sort caps from server: %s",
+                                error->message);
+                        g_error_free (error);
+                } else if (search_caps != NULL) {
+                        priv->search_caps = g_strsplit (search_caps, ",", -1);
+                } else {
+                        priv->search_caps = g_strsplit ("upnp:class,@id", ",", -1);
+                }
         }
         g_object_notify (G_OBJECT (self), "search-caps");
 
@@ -289,12 +316,19 @@ av_cp_media_server_on_icon_updated (GUPnPDeviceInfo *info,
         av_cp_media_server_get_content_directory (self);
 
         if (priv->content_directory != NULL) {
-                gupnp_service_proxy_begin_action
-                                (priv->content_directory,
-                                 "GetSortCapabilities",
-                                 av_cp_media_server_on_get_sort_caps,
-                                 g_object_ref (self),
-                                 NULL);
+                GUPnPServiceProxyAction *action;
+
+                action = gupnp_service_proxy_action_new ("GetSortCapabilities",
+                                                         NULL);
+
+                gupnp_service_proxy_call_action_async
+                                        (priv->content_directory,
+                                         action,
+                                         NULL,
+                                         av_cp_media_server_on_get_sort_caps,
+                                         g_object_ref (self));
+
+                gupnp_service_proxy_action_unref (action);
         } else {
                 g_debug ("Invalid MediaServer device without ContentDirectory");
                 priv->state = INIT_FAILED;
@@ -421,9 +455,9 @@ typedef struct _BrowseReturn {
 } BrowseReturn;
 
 static void
-av_cp_media_server_on_browse (GUPnPServiceProxy       *content_dir,
-                              GUPnPServiceProxyAction *action,
-                              gpointer                 user_data)
+av_cp_media_server_on_browse (GObject      *source,
+                              GAsyncResult *result,
+                              gpointer      user_data)
 {
         GTask   *task = G_TASK (user_data);
         GError  *error = NULL;
@@ -431,28 +465,39 @@ av_cp_media_server_on_browse (GUPnPServiceProxy       *content_dir,
         guint32  number_returned;
         guint32  total_matches;
 
-        gupnp_service_proxy_end_action (content_dir,
-                                        action,
-                                        &error,
-                                        /* OUT args */
-                                        "Result",
-                                        G_TYPE_STRING,
-                                        &didl_xml,
-                                        "NumberReturned",
-                                        G_TYPE_UINT,
-                                        &number_returned,
-                                        "TotalMatches",
-                                        G_TYPE_UINT,
-                                        &total_matches,
-                                        NULL);
+        GUPnPServiceProxyAction *action;
+
+        action = gupnp_service_proxy_call_action_finish
+                                                (GUPNP_SERVICE_PROXY (source),
+                                                 result,
+                                                 &error);
         if (error != NULL) {
                 g_task_return_error (task, error);
         } else {
-                BrowseReturn *ret = g_new0 (BrowseReturn, 1);
-                ret->didl_xml = didl_xml;
-                ret->number_returned = number_returned;
-                ret->total_matches = total_matches;
-                g_task_return_pointer (task, ret, g_free);
+                gupnp_service_proxy_action_get_result (action,
+                                                       &error,
+                                                       /* OUT args */
+                                                       "Result",
+                                                       G_TYPE_STRING,
+                                                       &didl_xml,
+                                                       "NumberReturned",
+                                                       G_TYPE_UINT,
+                                                       &number_returned,
+                                                       "TotalMatches",
+                                                       G_TYPE_UINT,
+                                                       &total_matches,
+                                                       NULL);
+
+                if (error != NULL) {
+                        g_task_return_error (task, error);
+                } else {
+                        BrowseReturn *ret = g_new0 (BrowseReturn, 1);
+                        ret->didl_xml = didl_xml;
+                        ret->number_returned = number_returned;
+                        ret->total_matches = total_matches;
+
+                        g_task_return_pointer (task, ret, g_free);
+                }
         }
 
         g_object_unref (task);
@@ -472,31 +517,37 @@ av_cp_media_server_browse_async (AVCPMediaServer     *self,
         const char *sort_order =  priv->default_sort_order == NULL ?
                                          "" :
                                          priv->default_sort_order;
-
-        gupnp_service_proxy_begin_action (priv->content_directory,
-                                          "Browse",
-                                          av_cp_media_server_on_browse,
-                                          task,
-                                          /* IN args */
-                                          "ObjectID",
-                                          G_TYPE_STRING,
-                                          container_id,
-                                          "BrowseFlag",
-                                          G_TYPE_STRING,
-                                          "BrowseDirectChildren",
-                                          "Filter",
-                                          G_TYPE_STRING,
-                                          "@childCount",
-                                          "StartingIndex",
-                                          G_TYPE_UINT,
-                                          starting_index,
-                                          "RequestedCount",
-                                          G_TYPE_UINT,
-                                          requested_count,
-                                          "SortCriteria",
-                                          G_TYPE_STRING,
-                                          sort_order,
-                                          NULL);
+        GUPnPServiceProxyAction *action = NULL;
+
+        action = gupnp_service_proxy_action_new ("Browse",
+                                                 /* IN args */
+                                                 "ObjectID",
+                                                 G_TYPE_STRING,
+                                                 container_id,
+                                                 "BrowseFlag",
+                                                 G_TYPE_STRING,
+                                                 "BrowseDirectChildren",
+                                                 "Filter",
+                                                 G_TYPE_STRING,
+                                                 "@childCount",
+                                                 "StartingIndex",
+                                                 G_TYPE_UINT,
+                                                 starting_index,
+                                                 "RequestedCount",
+                                                 G_TYPE_UINT,
+                                                 requested_count,
+                                                 "SortCriteria",
+                                                 G_TYPE_STRING,
+                                                 sort_order,
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async (priv->content_directory,
+                                               action,
+                                               g_task_get_cancellable (task),
+                                               av_cp_media_server_on_browse,
+                                               task);
+
+        gupnp_service_proxy_action_unref (action);
 }
 
 gboolean
@@ -536,26 +587,35 @@ av_cp_media_server_browse_finish (AVCPMediaServer  *self,
 }
 
 static void
-av_cp_media_server_on_browse_metadata (GUPnPServiceProxy       *content_dir,
-                                       GUPnPServiceProxyAction *action,
-                                       gpointer                 user_data)
+av_cp_media_server_on_browse_metadata (GObject      *object,
+                                       GAsyncResult *res,
+                                       gpointer      user_data)
 {
         GTask   *task = G_TASK (user_data);
         GError  *error = NULL;
         char    *didl_xml = NULL;
+        GUPnPServiceProxyAction *action = NULL;
+
+        action = gupnp_service_proxy_call_action_finish
+                                                (GUPNP_SERVICE_PROXY (object),
+                                                                      res,
+                                                                      &error);
 
-        gupnp_service_proxy_end_action (content_dir,
-                                        action,
-                                        &error,
-                                        /* OUT args */
-                                        "Result",
-                                        G_TYPE_STRING,
-                                        &didl_xml,
-                                        NULL);
         if (error != NULL) {
                 g_task_return_error (task, error);
         } else {
-                g_task_return_pointer (task, didl_xml, g_free);
+                gupnp_service_proxy_action_get_result (action,
+                                                       &error,
+                                                       /* OUT args */
+                                                       "Result",
+                                                       G_TYPE_STRING,
+                                                       &didl_xml,
+                                                       NULL);
+                if (error != NULL) {
+                        g_task_return_error (task, error);
+                } else {
+                        g_task_return_pointer (task, didl_xml, g_free);
+                }
         }
 
         g_object_unref (task);
@@ -570,31 +630,37 @@ av_cp_media_server_browse_metadata_async (AVCPMediaServer     *self,
 {
         GTask *task = g_task_new (self, cancellable, callback, user_data);
         AVCPMediaServerPrivate *priv = av_cp_media_server_get_instance_private (self);
-
-        gupnp_service_proxy_begin_action
+        GUPnPServiceProxyAction *action;
+
+        action = gupnp_service_proxy_action_new ("Browse",
+                                                 /* IN args */
+                                                 "ObjectID",
+                                                 G_TYPE_STRING,
+                                                 id,
+                                                 "BrowseFlag",
+                                                 G_TYPE_STRING,
+                                                 "BrowseMetadata",
+                                                 "Filter",
+                                                 G_TYPE_STRING,
+                                                 "*",
+                                                 "StartingIndex",
+                                                 G_TYPE_UINT,
+                                                 0,
+                                                 "RequestedCount",
+                                                 G_TYPE_UINT, 0,
+                                                 "SortCriteria",
+                                                 G_TYPE_STRING,
+                                                 "",
+                                                 NULL);
+
+        gupnp_service_proxy_call_action_async
                                 (priv->content_directory,
-                                 "Browse",
+                                 action,
+                                 g_task_get_cancellable (task),
                                  av_cp_media_server_on_browse_metadata,
-                                 task,
-                                 /* IN args */
-                                 "ObjectID",
-                                 G_TYPE_STRING,
-                                 id,
-                                 "BrowseFlag",
-                                 G_TYPE_STRING,
-                                 "BrowseMetadata",
-                                 "Filter",
-                                 G_TYPE_STRING,
-                                 "*",
-                                 "StartingIndex",
-                                 G_TYPE_UINT,
-                                 0,
-                                 "RequestedCount",
-                                 G_TYPE_UINT, 0,
-                                 "SortCriteria",
-                                 G_TYPE_STRING,
-                                 "",
-                                 NULL);
+                                 task);
+
+        gupnp_service_proxy_action_unref (action);
 }
 
 gboolean
@@ -635,30 +701,36 @@ av_cp_media_server_search_async (AVCPMediaServer     *self,
         GTask *task = g_task_new (self, cancellable, callback, user_data);
         AVCPMediaServerPrivate *priv = av_cp_media_server_get_instance_private (self);
 
-        gupnp_service_proxy_begin_action (priv->content_directory,
-                                          "Search",
-                                          av_cp_media_server_on_browse,
-                                          task,
-                                          /* IN args */
-                                          "ContainerID",
-                                          G_TYPE_STRING,
-                                          container_id,
-                                          "SearchCriteria",
-                                          G_TYPE_STRING,
-                                          search_criteria,
-                                          "Filter",
-                                          G_TYPE_STRING,
-                                          "*",
-                                          "StartingIndex",
-                                          G_TYPE_UINT,
-                                          starting_index,
-                                          "RequestedCount",
-                                          G_TYPE_UINT,
-                                          requested_count,
-                                          "SortCriteria",
-                                          G_TYPE_STRING,
-                                          "",
-                                          NULL);
+        GUPnPServiceProxyAction *action;
+        action = gupnp_service_proxy_action_new ("Search",
+                                                /* IN args */
+                                                "ContainerID",
+                                                G_TYPE_STRING,
+                                                container_id,
+                                                "SearchCriteria",
+                                                G_TYPE_STRING,
+                                                search_criteria,
+                                                "Filter",
+                                                G_TYPE_STRING,
+                                                "*",
+                                                "StartingIndex",
+                                                G_TYPE_UINT,
+                                                starting_index,
+                                                "RequestedCount",
+                                                G_TYPE_UINT,
+                                                requested_count,
+                                                "SortCriteria",
+                                                G_TYPE_STRING,
+                                                "",
+                                                NULL);
+
+        gupnp_service_proxy_call_action_async (priv->content_directory,
+                                               action,
+                                               g_task_get_cancellable (task),
+                                               av_cp_media_server_on_browse,
+                                               task);
+
+        gupnp_service_proxy_action_unref (action);
 }
 
 gboolean
@@ -673,9 +745,9 @@ av_cp_media_server_search_finish (AVCPMediaServer  *self,
                 total_matches, number_returned, error);
 }
 
-char**
+char const * const *
 av_cp_media_server_get_search_caps (AVCPMediaServer *self) {
         AVCPMediaServerPrivate *priv = av_cp_media_server_get_instance_private (self);
 
-        return priv->search_caps;
+        return (char const * const *) priv->search_caps;
 }
diff --git a/src/av-cp/server-device.h b/src/av-cp/server-device.h
index 3a68403..a5b48f6 100644
--- a/src/av-cp/server-device.h
+++ b/src/av-cp/server-device.h
@@ -111,7 +111,7 @@ av_cp_media_server_search_finish (AVCPMediaServer  *self,
                                   guint32          *number_returned,
                                   GError          **error);
 
-char**
+char const * const *
 av_cp_media_server_get_search_caps (AVCPMediaServer *self);
 
 G_END_DECLS


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