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




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

    ServiceProxyAction: Add method to set parameters

 libgupnp/gupnp-service-proxy-action.c | 46 +++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
---
diff --git a/libgupnp/gupnp-service-proxy-action.c b/libgupnp/gupnp-service-proxy-action.c
index d2af09b..f603c46 100644
--- a/libgupnp/gupnp-service-proxy-action.c
+++ b/libgupnp/gupnp-service-proxy-action.c
@@ -588,3 +588,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;
+}


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