Commit 7f134c67 authored by Zach Goldberg's avatar Zach Goldberg Committed by Zeeshan Ali (Khattak)
Browse files

Add gupnp_service_action_get/set_values

Variants of gupnp_service_action_get/set that use lists rather than
varargs. This is mainly done to allow PyGI to deal with service actions.
gobject-introspection do not (yet) support vararg and on top of that PyGI
maintainer refuses to handle reference type 'in' parameters correctly
because the only way to do that is 'inefficient'.

Co-author and reviewer: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
parent 6dcef2f7
......@@ -111,9 +111,11 @@ gupnp_service_action_get
gupnp_service_action_get_valist
gupnp_service_action_get_value
gupnp_service_action_get_gvalue
gupnp_service_action_get_values
gupnp_service_action_set
gupnp_service_action_set_valist
gupnp_service_action_set_value
gupnp_service_action_set_values
gupnp_service_action_return
gupnp_service_action_return_error
gupnp_service_action_get_message
......
......@@ -390,6 +390,49 @@ gupnp_service_action_get_valist (GUPnPServiceAction *action,
}
}
/**
* gupnp_service_action_get_values:
* @action: A #GUPnPServiceAction
* @arg_names: (element-type utf8) : A #GList of argument names as string
* @arg_types: (element-type GType): A #GList of argument types as #GType
*
* A variant of #gupnp_service_action_get that uses #GList instead of varargs.
*
* Return value: (element-type GValue) (transfer full): The values as #GList of
* #GValue. #g_list_free the returned list and #g_value_unset and #g_slice_free
* each element.
**/
GList *
gupnp_service_action_get_values (GUPnPServiceAction *action,
GList *arg_names,
GList *arg_types)
{
GList *arg_values;
int i;
g_return_val_if_fail (action != NULL, NULL);
arg_values = NULL;
for (i = 0; i < g_list_length (arg_names); i++) {
const char *arg_name;
GType arg_type;
GValue *arg_value;
arg_name = (const char *) g_list_nth_data (arg_names, i);
arg_type = (GType) g_list_nth_data (arg_types, i);
arg_value = g_slice_new0 (GValue);
g_value_init (arg_value, arg_type);
gupnp_service_action_get_value (action, arg_name, arg_value);
arg_values = g_list_append (arg_values, arg_value);
}
return arg_values;
}
/**
* gupnp_service_action_get_value: (skip)
* @action: A #GUPnPServiceAction
......@@ -522,6 +565,51 @@ gupnp_service_action_set_valist (GUPnPServiceAction *action,
}
}
/**
* gupnp_service_action_set_values:
* @action: A #GUPnPServiceAction
* @arg_names: (element-type utf8) (transfer-none): A #GList of argument names
* @arg_values: (element-type GValue) (transfer-none): The #GList of values (as
* #GValues) that line up with @arg_names.
*
* Sets the specified action return values.
**/
void
gupnp_service_action_set_values (GUPnPServiceAction *action,
GList *arg_names,
GList *arg_values)
{
g_return_if_fail (action != NULL);
g_return_if_fail (arg_names != NULL);
g_return_if_fail (arg_values != NULL);
g_return_if_fail (g_list_length (arg_names) ==
g_list_length (arg_values));
if (action->msg->status_code == SOUP_STATUS_INTERNAL_SERVER_ERROR) {
g_warning ("Calling gupnp_service_action_set_value() after "
"having called gupnp_service_action_return_error() "
"is not allowed.");
return;
}
/* Append to response */
for (; arg_names; arg_names = arg_names->next) {
const char *arg_name;
GValue *value;
arg_name = arg_names->data;
value = arg_values->data;
xml_util_start_element (action->response_str, arg_name);
gvalue_util_value_append_to_xml_string (value,
action->response_str);
xml_util_end_element (action->response_str, arg_name);
arg_values = arg_values->next;
}
}
/**
* gupnp_service_action_set_value
* @action: A #GUPnPServiceAction
......
......@@ -117,6 +117,11 @@ void
gupnp_service_action_get_valist (GUPnPServiceAction *action,
va_list var_args);
GList *
gupnp_service_action_get_values (GUPnPServiceAction *action,
GList *arg_names,
GList *arg_types);
void
gupnp_service_action_get_value (GUPnPServiceAction *action,
const char *argument,
......@@ -135,6 +140,11 @@ void
gupnp_service_action_set_valist (GUPnPServiceAction *action,
va_list var_args);
void
gupnp_service_action_set_values (GUPnPServiceAction *action,
GList *arg_names,
GList *arg_values);
void
gupnp_service_action_set_value (GUPnPServiceAction *action,
const char *argument,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment