[gupnp/wip/phako/reusable-service-action: 3/11] ServiceProxy: Change queueing of ProxyAction
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp/wip/phako/reusable-service-action: 3/11] ServiceProxy: Change queueing of ProxyAction
- Date: Mon, 31 May 2021 17:44:57 +0000 (UTC)
commit 88d80de7bb690472f653715c032402797d972329
Author: Jens Georg <mail jensge org>
Date: Sat May 29 01:38:05 2021 +0200
ServiceProxy: Change queueing of ProxyAction
- Take weak reference on async operation only
- Add to pending action list on async only
libgupnp/gupnp-service-proxy.c | 61 +++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index e630747..db0e261 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -633,29 +633,11 @@ on_action_cancelled (GCancellable *cancellable, gpointer user_data)
/* Begins a basic action message */
static void
prepare_action_msg (GUPnPServiceProxy *proxy,
- GUPnPServiceProxyAction *action,
- GCancellable *cancellable)
+ GUPnPServiceProxyAction *action)
{
- GUPnPServiceProxyPrivate *priv;
char *control_url, *full_action;
const char *service_type;
- priv = gupnp_service_proxy_get_instance_private (proxy);
- action->proxy = proxy;
- g_object_add_weak_pointer (G_OBJECT (proxy), (gpointer *)&(action->proxy));
-
- priv->pending_actions = g_list_prepend (priv->pending_actions, action);
-
- if (cancellable != NULL) {
- action->cancellable = g_object_ref (cancellable);
- } else {
- action->cancellable = g_cancellable_new ();
- }
- action->cancellable_connection_id = g_cancellable_connect (action->cancellable,
- G_CALLBACK (on_action_cancelled),
- action,
- NULL);
-
/* Make sure we have a service type */
service_type = gupnp_service_info_get_service_type
(GUPNP_SERVICE_INFO (proxy));
@@ -2080,20 +2062,37 @@ gupnp_service_proxy_call_action_async (GUPnPServiceProxy *proxy,
gpointer user_data)
{
GTask *task;
+ GUPnPServiceProxyPrivate *priv;
g_return_if_fail (GUPNP_IS_SERVICE_PROXY (proxy));
+ priv = gupnp_service_proxy_get_instance_private (proxy);
task = g_task_new (proxy, cancellable, callback, user_data);
g_task_set_task_data (task,
gupnp_service_proxy_action_ref (action),
(GDestroyNotify) gupnp_service_proxy_action_unref);
- prepare_action_msg (proxy, action, cancellable);
+ prepare_action_msg (proxy, action);
if (action->error != NULL) {
g_task_return_error (task, g_error_copy (action->error));
g_object_unref (task);
} else {
+ action->proxy = proxy;
+ g_object_add_weak_pointer (G_OBJECT (proxy), (gpointer *)&(action->proxy));
+
+ priv->pending_actions = g_list_prepend (priv->pending_actions, action);
+
+ if (cancellable != NULL) {
+ action->cancellable = g_object_ref (cancellable);
+ } else {
+ action->cancellable = g_cancellable_new ();
+ }
+ action->cancellable_connection_id = g_cancellable_connect (action->cancellable,
+ G_CALLBACK (on_action_cancelled),
+ action,
+ NULL);
+
gupnp_service_proxy_action_queue_task (task);
}
}
@@ -2116,7 +2115,12 @@ gupnp_service_proxy_call_action_finish (GUPnPServiceProxy *proxy,
{
g_return_val_if_fail (g_task_is_valid (G_TASK (result), proxy), NULL);
- return g_task_propagate_pointer (G_TASK (result), error);
+ GUPnPServiceProxyAction *action =
+ g_task_propagate_pointer (G_TASK (result), error);
+ g_clear_weak_pointer (&action->proxy);
+ action->pending = FALSE;
+
+ return action;
}
/**
@@ -2142,10 +2146,7 @@ gupnp_service_proxy_call_action (GUPnPServiceProxy *proxy,
g_return_val_if_fail (GUPNP_IS_SERVICE_PROXY (proxy), NULL);
- prepare_action_msg (proxy, action, cancellable);
-
- /* prepare_action_msg has queued the message, so remove it */
- gupnp_service_proxy_remove_action (proxy, action);
+ prepare_action_msg (proxy, action);
if (action->error != NULL) {
g_propagate_error (error, g_error_copy (action->error));
@@ -2153,6 +2154,16 @@ gupnp_service_proxy_call_action (GUPnPServiceProxy *proxy,
return NULL;
}
+ if (cancellable != NULL) {
+ action->cancellable = g_object_ref (cancellable);
+ } else {
+ action->cancellable = g_cancellable_new ();
+ }
+ action->cancellable_connection_id = g_cancellable_connect (action->cancellable,
+ G_CALLBACK (on_action_cancelled),
+ action,
+ NULL);
+
context = gupnp_service_info_get_context (GUPNP_SERVICE_INFO (proxy));
session = gupnp_context_get_session (context);
soup_session_send_message (session, action->msg);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]