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

@ -110,7 +110,7 @@ bus_handler (GstBus *bus,
gchar *debug;
gst_message_parse_error (message, &error, &debug);
g_print ("got error %s (%s)\n", error->message, debug);
g_warning ("got error %s (%s)\n", error->message, debug);
g_free (debug);
pinos_source_report_error (source, error);
@ -404,6 +404,7 @@ pinos_client_source_class_init (PinosClientSourceClass * klass)
"The possible formats of the stream",
G_TYPE_BYTES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
source_class->get_formats = client_get_formats;
@ -425,8 +426,8 @@ pinos_client_source_new (PinosDaemon *daemon,
GBytes *possible_formats)
{
return g_object_new (PINOS_TYPE_CLIENT_SOURCE,
"daemon", daemon,
"name", "client-source",
"possible-formats", possible_formats,
NULL);
"daemon", daemon,
"name", "client-source",
"possible-formats", possible_formats,
NULL);
}

View file

@ -32,7 +32,7 @@ struct _PinosClientPrivate
PinosDaemon *daemon;
gchar *sender;
gchar *object_path;
GVariant *properties;
PinosProperties *properties;
PinosClient1 *client1;
@ -84,7 +84,7 @@ pinos_client_get_property (GObject *_object,
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
g_value_set_boxed (value, priv->properties);
break;
default:
@ -117,8 +117,8 @@ pinos_client_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:
@ -370,7 +370,7 @@ pinos_client_finalize (GObject * object)
PinosClientPrivate *priv = client->priv;
if (priv->properties)
g_variant_unref (priv->properties);
pinos_properties_free (priv->properties);
G_OBJECT_CLASS (pinos_client_parent_class)->finalize (object);
}
@ -430,13 +430,13 @@ pinos_client_class_init (PinosClientClass * klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"Client properties",
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_boxed ("properties",
"Properties",
"Client properties",
PINOS_TYPE_PROPERTIES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
signals[SIGNAL_DISCONNECT] = g_signal_new ("disconnect",
G_TYPE_FROM_CLASS (klass),
@ -461,17 +461,19 @@ pinos_client_init (PinosClient * client)
/**
* pinos_client_new:
* @daemon: a #PinosDaemon
* @sender: the sender id
* @prefix: a prefix
* @properties: extra client properties
*
* Make a new #PinosClient object and register it to @daemon under the @prefix.
*
* Returns: a new #PinosClient
*/
PinosClient *
pinos_client_new (PinosDaemon *daemon,
const gchar *sender,
const gchar *prefix,
GVariant *properties)
pinos_client_new (PinosDaemon *daemon,
const gchar *sender,
const gchar *prefix,
PinosProperties *properties)
{
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
g_return_val_if_fail (g_variant_is_object_path (prefix), NULL);

View file

@ -62,10 +62,10 @@ struct _PinosClientClass {
/* normal GObject stuff */
GType pinos_client_get_type (void);
PinosClient * pinos_client_new (PinosDaemon *daemon,
const gchar *sender,
const gchar *prefix,
GVariant *properties);
PinosClient * pinos_client_new (PinosDaemon *daemon,
const gchar *sender,
const gchar *prefix,
PinosProperties *properties);
const gchar * pinos_client_get_sender (PinosClient *client);
const gchar * pinos_client_get_object_path (PinosClient *client);

View file

@ -40,6 +40,14 @@ struct _PinosDaemonPrivate
GList *sources;
GHashTable *senders;
PinosProperties *properties;
};
enum
{
PROP_0,
PROP_PROPERTIES,
};
typedef struct {
@ -136,10 +144,14 @@ handle_connect_client (PinosDaemon1 *interface,
PinosClient *client;
const gchar *sender, *object_path;
SenderData *data;
PinosProperties *props;
sender = g_dbus_method_invocation_get_sender (invocation);
client = pinos_client_new (daemon, sender, PINOS_DBUS_OBJECT_PREFIX, arg_properties);
props = pinos_properties_from_variant (arg_properties);
client = pinos_client_new (daemon, sender, PINOS_DBUS_OBJECT_PREFIX, props);
pinos_properties_free (props);
g_signal_connect (client, "disconnect", (GCallback) handle_disconnect_client, daemon);
data = g_hash_table_lookup (priv->senders, sender);
@ -159,6 +171,7 @@ static void
export_server_object (PinosDaemon *daemon,
GDBusObjectManagerServer *manager)
{
PinosDaemonPrivate *priv = daemon->priv;
PinosObjectSkeleton *skel;
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SERVER);
@ -171,6 +184,8 @@ export_server_object (PinosDaemon *daemon,
pinos_daemon1_set_host_name (iface, g_get_host_name ());
pinos_daemon1_set_version (iface, PACKAGE_VERSION);
pinos_daemon1_set_name (iface, PACKAGE_NAME);
pinos_daemon1_set_cookie (iface, g_random_int());
pinos_daemon1_set_properties (iface, pinos_properties_to_variant (priv->properties));
pinos_object_skeleton_set_daemon1 (skel, iface);
g_object_unref (iface);
}
@ -217,15 +232,16 @@ name_lost_handler (GDBusConnection *connection,
/**
* pinos_daemon_new:
* @properties: #PinosProperties
*
* Make a new #PinosDaemon object
* Make a new #PinosDaemon object with given @properties
*
* Returns: a new #PinosDaemon
*/
PinosDaemon *
pinos_daemon_new (void)
pinos_daemon_new (PinosProperties *properties)
{
return g_object_new (PINOS_TYPE_DAEMON, NULL);
return g_object_new (PINOS_TYPE_DAEMON, "properties", properties, NULL);
}
/**
@ -311,6 +327,13 @@ pinos_daemon_unexport (PinosDaemon *daemon,
g_dbus_object_manager_server_unexport (daemon->priv->server_manager, object_path);
}
/**
* pinos_daemon_add_source:
* @daemon: a #PinosDaemon
* @source: a #PinosSource
*
* Add @source to @daemon.
*/
void
pinos_daemon_add_source (PinosDaemon *daemon,
PinosSource *source)
@ -324,6 +347,13 @@ pinos_daemon_add_source (PinosDaemon *daemon,
priv->sources = g_list_prepend (priv->sources, source);
}
/**
* pinos_daemon_remove_source:
* @daemon: a #PinosDaemon
* @source: a #PinosSource
*
* Remove @source from @daemon.
*/
void
pinos_daemon_remove_source (PinosDaemon *daemon,
PinosSource *source)
@ -337,12 +367,24 @@ pinos_daemon_remove_source (PinosDaemon *daemon,
priv->sources = g_list_remove (priv->sources, source);
}
/**
* pinos_daemon_find_source:
* @daemon: a #PinosDaemon
* @name: a source name
* @props: source properties
* @format_filter: a format filter
* @error: location for an error
*
* Find the best source in @daemon that matches the given parameters.
*
* Returns: a #PinosSource or %NULL when no source could be found.
*/
PinosSource *
pinos_daemon_find_source (PinosDaemon *daemon,
const gchar *name,
GVariant *props,
GBytes *format_filter,
GError **error)
pinos_daemon_find_source (PinosDaemon *daemon,
const gchar *name,
PinosProperties *props,
GBytes *format_filter,
GError **error)
{
PinosDaemonPrivate *priv;
PinosSource *best = NULL;
@ -371,8 +413,51 @@ pinos_daemon_find_source (PinosDaemon *daemon,
return best;
}
G_DEFINE_TYPE (PinosDaemon, pinos_daemon, G_TYPE_OBJECT);
static void
pinos_daemon_get_property (GObject *_object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PinosDaemon *daemon = PINOS_DAEMON (_object);
PinosDaemonPrivate *priv = daemon->priv;
switch (prop_id) {
case PROP_PROPERTIES:
g_value_set_boxed (value, priv->properties);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec);
break;
}
}
static void
pinos_daemon_set_property (GObject *_object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PinosDaemon *daemon = PINOS_DAEMON (_object);
PinosDaemonPrivate *priv = daemon->priv;
switch (prop_id) {
case PROP_PROPERTIES:
if (priv->properties)
pinos_properties_free (priv->properties);
priv->properties = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec);
break;
}
}
static void
pinos_daemon_dispose (GObject * object)
{
@ -403,6 +488,20 @@ pinos_daemon_class_init (PinosDaemonClass * klass)
gobject_class->dispose = pinos_daemon_dispose;
gobject_class->finalize = pinos_daemon_finalize;
gobject_class->set_property = pinos_daemon_set_property;
gobject_class->get_property = pinos_daemon_get_property;
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_boxed ("properties",
"Properties",
"Client properties",
PINOS_TYPE_PROPERTIES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
}
static void

View file

@ -39,6 +39,7 @@ typedef struct _PinosDaemonClass PinosDaemonClass;
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
#include <server/source.h>
#include <client/properties.h>
/**
* PinosDaemon:
@ -61,23 +62,23 @@ struct _PinosDaemonClass {
};
/* normal GObject stuff */
GType pinos_daemon_get_type (void);
GType pinos_daemon_get_type (void);
PinosDaemon * pinos_daemon_new (void);
PinosDaemon * pinos_daemon_new (PinosProperties *properties);
void pinos_daemon_start (PinosDaemon *daemon);
void pinos_daemon_stop (PinosDaemon *daemon);
void pinos_daemon_start (PinosDaemon *daemon);
void pinos_daemon_stop (PinosDaemon *daemon);
gchar * pinos_daemon_export_uniquely (PinosDaemon *daemon, GDBusObjectSkeleton *skel);
void pinos_daemon_unexport (PinosDaemon *daemon, const gchar *name);
gchar * pinos_daemon_export_uniquely (PinosDaemon *daemon, GDBusObjectSkeleton *skel);
void pinos_daemon_unexport (PinosDaemon *daemon, const gchar *name);
void pinos_daemon_add_source (PinosDaemon *daemon, PinosSource *source);
void pinos_daemon_remove_source (PinosDaemon *daemon, PinosSource *source);
PinosSource * pinos_daemon_find_source (PinosDaemon *daemon,
const gchar *name,
GVariant *props,
GBytes *format_filter,
GError **error);
void pinos_daemon_add_source (PinosDaemon *daemon, PinosSource *source);
void pinos_daemon_remove_source (PinosDaemon *daemon, PinosSource *source);
PinosSource * pinos_daemon_find_source (PinosDaemon *daemon,
const gchar *name,
PinosProperties *props,
GBytes *format_filter,
GError **error);
G_END_DECLS

View file

@ -386,6 +386,7 @@ pinos_source_output_class_init (PinosSourceOutputClass * klass)
"The possbile formats of the stream",
G_TYPE_BYTES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
@ -395,6 +396,7 @@ pinos_source_output_class_init (PinosSourceOutputClass * klass)
"The requested format of the stream",
G_TYPE_BYTES,
G_PARAM_READABLE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,

View file

@ -38,7 +38,7 @@ struct _PinosSourcePrivate
gchar *object_path;
gchar *name;
GVariant *properties;
PinosProperties *properties;
PinosSourceState state;
GError *error;
@ -86,7 +86,7 @@ pinos_source_get_property (GObject *_object,
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
g_value_set_boxed (value, priv->properties);
break;
default:
@ -121,8 +121,8 @@ pinos_source_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:
@ -138,15 +138,21 @@ source_register_object (PinosSource *source)
PinosDaemon *daemon = priv->daemon;
PinosObjectSkeleton *skel;
GBytes *formats;
GVariant *variant;
formats = pinos_source_get_formats (source, NULL);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SOURCE);
if (priv->properties)
variant = pinos_properties_to_variant (priv->properties);
else
variant = NULL;
priv->iface = pinos_source1_skeleton_new ();
g_object_set (priv->iface, "name", priv->name,
"state", priv->state,
"properties", priv->properties,
"properties", variant,
"possible-formats", g_bytes_get_data (formats, NULL),
NULL);
pinos_object_skeleton_set_source1 (skel, priv->iface);
@ -207,7 +213,7 @@ pinos_source_finalize (GObject * object)
g_free (priv->object_path);
g_free (priv->name);
if (priv->properties)
g_variant_unref (priv->properties);
pinos_properties_free (priv->properties);
G_OBJECT_CLASS (pinos_source_parent_class)->finalize (object);
}
@ -303,6 +309,7 @@ pinos_source_class_init (PinosSourceClass * klass)
"The object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
@ -327,13 +334,13 @@ pinos_source_class_init (PinosSourceClass * klass)
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"The properties of the source",
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_boxed ("properties",
"Properties",
"The properties of the source",
PINOS_TYPE_PROPERTIES,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
klass->set_state = default_set_state;