summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2021-05-29 02:20:31 +0200
committerJens Georg <mail@jensge.org>2021-07-03 18:47:49 +0200
commit27fd80a68fbc4539dd7e6fed18514af1ad640ce4 (patch)
treef1c47ea72d6f140b4f21db956d6130efb29e93d0
parentb4474f40ce083cc4ff368bc9dee99336290810c7 (diff)
downloadgupnp-27fd80a68fbc4539dd7e6fed18514af1ad640ce4.tar.gz
ServiceProxyAction: Add method to set parameters
Fixes #18
-rw-r--r--libgupnp/gupnp-service-proxy-action.c46
-rw-r--r--libgupnp/gupnp-service-proxy.c3
2 files changed, 48 insertions, 1 deletions
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);
}