[gupnp/wip/phako/reusable-service-action: 47/49] ServiceProxyAction: Add method to set parameters




commit 27fd80a68fbc4539dd7e6fed18514af1ad640ce4
Author: Jens Georg <mail jensge org>
Date:   Sat May 29 02:20:31 2021 +0200

    ServiceProxyAction: Add method to set parameters
    
    Fixes #18

 libgupnp/gupnp-service-proxy-action.c | 46 +++++++++++++++++++++++++++++++++++
 libgupnp/gupnp-service-proxy.c        |  3 ++-
 2 files changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/libgupnp/gupnp-service-proxy-action.c b/libgupnp/gupnp-service-proxy-action.c
index 35e2fb9..2ec0496 100644
--- a/libgupnp/gupnp-service-proxy-action.c
+++ b/libgupnp/gupnp-service-proxy-action.c
@@ -756,3 +756,49 @@ gupnp_service_proxy_action_get_result_valist (GUPnPServiceProxyAction *action,
 
         return result;
 }
+
+gboolean
+gupnp_service_proxy_action_set (GUPnPServiceProxyAction *action,
+                                const char *key,
+                                const GValue *value,
+                                GError **error)
+{
+        g_return_val_if_fail (key != NULL, FALSE);
+        g_return_val_if_fail (value != NULL, FALSE);
+        g_return_val_if_fail (error != NULL && *error == NULL, FALSE);
+        gpointer position;
+
+        if (!g_hash_table_lookup_extended (action->arg_map,
+                                           key,
+                                           NULL,
+                                           &position)) {
+                g_propagate_error (error,
+                                   g_error_new (GUPNP_SERVER_ERROR,
+                                                GUPNP_SERVER_ERROR_OTHER,
+                                                "Unknown argument: %s",
+                                                key));
+
+                return FALSE;
+        }
+
+        ActionArgument *arg =
+                g_ptr_array_index (action->args, GPOINTER_TO_UINT (position));
+
+        if (G_VALUE_TYPE (value) != G_VALUE_TYPE (&arg->value)) {
+                g_propagate_error (
+                        error,
+                        g_error_new (
+                                GUPNP_SERVER_ERROR,
+                                GUPNP_SERVER_ERROR_OTHER,
+                                "Type mismatch for %s. Expected %s, got %s",
+                                key,
+                                G_VALUE_TYPE_NAME (&arg->value),
+                                G_VALUE_TYPE_NAME (value)));
+
+                return FALSE;
+        }
+
+        g_value_copy (value, &arg->value);
+
+        return TRUE;
+}
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index b487f7b..637eeae 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -540,7 +540,8 @@ on_legacy_async_callback (GObject *source, GAsyncResult *res, gpointer user_data
         /* Do not perform legacy call-back if action is cancelled, to comply with the old implementation */
         if (action->callback != NULL &&
             !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-                g_propagate_error (&action->error, error);
+                if (error != NULL)
+                        g_propagate_error (&action->error, error);
                 action->callback (action->proxy, action, action->user_data);
         }
 


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