From 2c19591ca948fc302508b2afbdd232b219d92e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 11 Jan 2013 19:47:42 -0500 Subject: session: Add API to set the transmitter parameters as a GHashTable --- farstream/fs-stream.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ farstream/fs-stream.h | 5 +++ 2 files changed, 104 insertions(+) (limited to 'farstream') diff --git a/farstream/fs-stream.c b/farstream/fs-stream.c index cde69c25..c81e8788 100644 --- a/farstream/fs-stream.c +++ b/farstream/fs-stream.c @@ -647,6 +647,105 @@ fs_stream_set_transmitter (FsStream *stream, return FALSE; } +/** + * fs_stream_set_transmitter_ht: + * @stream: a #FsStream + * @transmitter: Name of the type of transmitter to use for this stream + * @stream_transmitter_parameters: (element-type utf8 GValue) (allow-none): + * A #GHashTable of GValue) containing the parameters. + * @error: location of a #GError, or %NULL if no error occured + * + * Set the transmitter to use for this stream. This function will only succeed + * once. + * + * The parameters correspond to the varios GObject properties of the + * selected stream transmitter. + * + * This is the same as fs_stream_set_transmitter() except that the parameters + * are passed in a #GHashTable to make it more friendly to GObject introspection + * + * Returns: %TRUE if the transmitter could be set, %FALSE otherwise + */ +gboolean fs_stream_set_transmitter_ht (FsStream *stream, + const gchar *transmitter, + GHashTable *stream_transmitter_parameters, + GError **error) +{ + GParameter *params = NULL; + gboolean ret = FALSE; + guint n_params = 0; + guint i = 0; + + if (stream_transmitter_parameters && + g_hash_table_size (stream_transmitter_parameters) != 0) + { + FsSession *session = NULL; + GType st_type; + GObjectClass *st_class = NULL; + GHashTableIter iter; + gpointer key, value; + + n_params = g_hash_table_size (stream_transmitter_parameters); + + g_object_get (stream, "session", &session, NULL); + + if (!session) { + g_set_error_literal (error, FS_ERROR, FS_ERROR_DISPOSED, + "Stream has already been disposed"); + return FALSE; + } + + st_type = fs_session_get_stream_transmitter_type (session, + transmitter); + g_object_unref (session); + + if (st_type == 0) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Unknown transmitter: %s", transmitter); + return FALSE; + } + + params = g_new0 (GParameter, n_params); + st_class = g_type_class_ref (st_type); + + g_hash_table_iter_init (&iter, stream_transmitter_parameters); + while (g_hash_table_iter_next (&iter, &key, &value)) { + GParamSpec *spec; + gchar *name = key; + const GValue *v = value; + + spec = g_object_class_find_property (st_class, name); + + if (!spec) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Unknown argument %s for transmitter %s", name, transmitter); + goto end; + } + + params[i].name = name; + g_value_init (¶ms[i].value, G_PARAM_SPEC_VALUE_TYPE(spec)); + if (!g_value_transform (v, ¶ms[i].value)) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Invalid type of argument %s for transmitter %s", + name, transmitter); + goto end; + } + i++; + } + } + + ret = fs_stream_set_transmitter (stream, transmitter, params, n_params, + error); + +end: + + for (i = 0; i < n_params; i++) + g_value_unset (¶ms[i].value); + g_free (params); + + return ret; +} + /** * fs_stream_destroy: * @stream: a #FsStream diff --git a/farstream/fs-stream.h b/farstream/fs-stream.h index a3c82158..5239fddf 100644 --- a/farstream/fs-stream.h +++ b/farstream/fs-stream.h @@ -185,6 +185,11 @@ gboolean fs_stream_set_transmitter (FsStream *stream, guint stream_transmitter_n_parameters, GError **error); +gboolean fs_stream_set_transmitter_ht (FsStream *stream, + const gchar *transmitter, + GHashTable *stream_transmitter_parameters, + GError **error); + void fs_stream_destroy (FsStream *stream); gboolean fs_stream_parse_new_local_candidate (FsStream *stream, -- cgit v1.2.1