properties: pass PinosProperties around

Pass PinosProperties around instead of GVariant. This is much easier to
deal with.
This commit is contained in:
Wim Taymans 2015-07-17 16:57:01 +02:00
parent c77d7718a2
commit 31da833069
18 changed files with 248 additions and 120 deletions

View file

@ -75,7 +75,7 @@ pinos_context_get_property (GObject *_object,
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
g_value_set_boxed (value, priv->properties);
break;
case PROP_STATE:
@ -117,8 +117,8 @@ pinos_context_set_property (GObject *_object,
case PROP_PROPERTIES:
if (priv->properties)
g_variant_unref (priv->properties);
priv->properties = g_value_dup_variant (value);
pinos_properties_free (priv->properties);
priv->properties = g_value_dup_boxed (value);
break;
case PROP_SUBSCRIPTION_MASK:
@ -140,7 +140,7 @@ pinos_context_finalize (GObject * object)
g_clear_pointer (&priv->context, g_main_context_unref);
g_free (priv->name);
if (priv->properties)
g_variant_unref (priv->properties);
pinos_properties_free (priv->properties);
g_clear_object (&priv->subscribe);
g_clear_error (&priv->error);
@ -193,13 +193,12 @@ pinos_context_class_init (PinosContextClass * klass)
*/
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"Extra properties",
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_boxed ("properties",
"Properties",
"Extra properties",
PINOS_TYPE_PROPERTIES,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* PinosContext:state
*
@ -287,20 +286,20 @@ pinos_context_init (PinosContext * context)
* Returns: a new unconnected #PinosContext
*/
PinosContext *
pinos_context_new (GMainContext *context,
const gchar *name,
GVariant *properties)
pinos_context_new (GMainContext *context,
const gchar *name,
PinosProperties *properties)
{
g_return_val_if_fail (name != NULL, NULL);
if (properties == NULL) {
GVariantBuilder builder;
if (properties == NULL)
properties = pinos_properties_new ("media.name", name, NULL);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (name));
properties = g_variant_builder_end (&builder);
}
return g_object_new (PINOS_TYPE_CONTEXT, "main-context", context, "name", name, "properties", properties, NULL);
return g_object_new (PINOS_TYPE_CONTEXT,
"main-context", context,
"name", name,
"properties", properties,
NULL);
}
static gboolean
@ -388,12 +387,15 @@ on_daemon_connected (GObject *source_object,
{
PinosContext *context = user_data;
PinosContextPrivate *priv = context->priv;
GVariant *variant;
context_set_state (context, PINOS_CONTEXT_STATE_REGISTERING);
variant = pinos_properties_to_variant (priv->properties);
g_dbus_proxy_call (priv->daemon,
"ConnectClient",
g_variant_new ("(@a{sv})", priv->properties),
g_variant_new ("(@a{sv})", variant),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,

View file

@ -24,6 +24,7 @@
#include <gio/gio.h>
#include <client/subscribe.h>
#include <client/properties.h>
G_BEGIN_DECLS
@ -97,9 +98,9 @@ struct _PinosContextClass {
/* normal GObject stuff */
GType pinos_context_get_type (void);
PinosContext * pinos_context_new (GMainContext *ctx,
const gchar *name,
GVariant *properties);
PinosContext * pinos_context_new (GMainContext *ctx,
const gchar *name,
PinosProperties *properties);
gboolean pinos_context_connect (PinosContext *context, PinosContextFlags flags);
gboolean pinos_context_disconnect (PinosContext *context);

View file

@ -43,7 +43,8 @@ fill_info (PinosSourceInfo *info, GDBusProxy *proxy)
info->name = "Unknown";
}
info->properties = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "Properties");
info->properties = pinos_properties_from_variant (
g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "Properties"));
if ((variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "State"))) {
info->state = g_variant_get_uint32 (variant);
@ -63,10 +64,10 @@ fill_info (PinosSourceInfo *info, GDBusProxy *proxy)
}
static void
clear_info (PinosSourceInfo *info)
client_clear_info (PinosSourceInfo *info)
{
if (info->properties)
g_variant_unref (info->properties);
pinos_properties_free (info->properties);
if (info->formats)
g_bytes_unref (info->formats);
}
@ -99,9 +100,9 @@ pinos_context_list_source_info (PinosContext *context,
GDBusProxy *proxy = walk->data;
PinosSourceInfo info;
fill_info (&info, proxy);
client_fill_info (&info, proxy);
cb (context, &info, user_data);
clear_info (&info);
client_clear_info (&info);
}
cb (context, NULL, user_data);
}
@ -135,9 +136,8 @@ pinos_context_get_source_info_by_id (PinosContext *context,
proxy = G_DBUS_PROXY (id);
fill_info (&info, proxy);
client_fill_info (&info, proxy);
cb (context, &info, user_data);
clear_info (&info);
client_clear_info (&info);
cb (context, NULL, user_data);
}

View file

@ -24,6 +24,7 @@
#include <glib-object.h>
#include <client/context.h>
#include <client/properties.h>
G_BEGIN_DECLS
@ -57,13 +58,14 @@ typedef enum {
* @state: the current state of the source
* @formats: the supported formats
*
* The source information
* The source information. Extra information can be added in later
* versions.
*/
typedef struct {
gpointer id;
const char *source_path;
const char *name;
GVariant *properties;
PinosProperties *properties;
PinosSourceState state;
GBytes *formats;
} PinosSourceInfo;

View file

@ -22,7 +22,7 @@ struct _PinosContextPrivate
GMainContext *context;
gchar *name;
GVariant *properties;
PinosProperties *properties;
guint id;
GDBusConnection *connection;

View file

@ -32,7 +32,7 @@ struct _PinosStreamPrivate
{
PinosContext *context;
gchar *name;
GVariant *properties;
PinosProperties *properties;
guint id;
@ -99,7 +99,7 @@ pinos_stream_get_property (GObject *_object,
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
g_value_set_boxed (value, priv->properties);
break;
case PROP_STATE:
@ -144,8 +144,8 @@ pinos_stream_set_property (GObject *_object,
case PROP_PROPERTIES:
if (priv->properties)
g_variant_unref (priv->properties);
priv->properties = g_value_dup_variant (value);
pinos_properties_free (priv->properties);
priv->properties = g_value_dup_boxed (value);
break;
default:
@ -233,7 +233,7 @@ pinos_stream_finalize (GObject * object)
g_clear_error (&priv->error);
if (priv->properties)
g_variant_unref (priv->properties);
pinos_properties_free (priv->properties);
g_signal_handler_disconnect (priv->context->priv->subscribe, priv->id);
g_clear_object (&priv->context);
g_free (priv->name);
@ -288,14 +288,13 @@ pinos_stream_class_init (PinosStreamClass * klass)
*/
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"The properties of the stream",
G_VARIANT_TYPE_VARIANT,
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_param_spec_boxed ("properties",
"Properties",
"The properties of the stream",
PINOS_TYPE_PROPERTIES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* PinosStream:state
*
@ -393,14 +392,18 @@ pinos_stream_init (PinosStream * stream)
* Returns: a new unconnected #PinosStream
*/
PinosStream *
pinos_stream_new (PinosContext *context,
const gchar *name,
GVariant *props)
pinos_stream_new (PinosContext *context,
const gchar *name,
PinosProperties *props)
{
g_return_val_if_fail (PINOS_IS_CONTEXT (context), NULL);
g_return_val_if_fail (name != NULL, NULL);
return g_object_new (PINOS_TYPE_STREAM, "context", context, "name", name, "properties", props, NULL);
return g_object_new (PINOS_TYPE_STREAM,
"context", context,
"name", name,
"properties", props,
NULL);
}
/**
@ -546,7 +549,7 @@ do_connect_capture (PinosStream *stream)
* @stream: a #PinosStream
* @source_path: the source path to connect to
* @flags: a #PinosStreamFlags
* @spec: a #GVariant
* @accepted_formats: a #GBytes with accepted formats
*
* Connect @stream for capturing from @source_path.
*
@ -606,7 +609,7 @@ do_connect_provide (PinosStream *stream)
* pinos_stream_connect_provide:
* @stream: a #PinosStream
* @flags: a #PinosStreamFlags
* @spec: a #GVariant
* @possible_formats: a #GBytes
*
* Connect @stream for providing data for a new source.
*

View file

@ -93,9 +93,9 @@ struct _PinosStreamClass {
GType pinos_stream_get_type (void);
PinosStream * pinos_stream_new (PinosContext *context,
const gchar *name,
GVariant *props);
PinosStream * pinos_stream_new (PinosContext *context,
const gchar *name,
PinosProperties *props);
PinosStreamState pinos_stream_get_state (PinosStream *stream);
const GError * pinos_stream_get_error (PinosStream *stream);