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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -29,12 +29,14 @@ main (gint argc, gchar *argv[])
{ {
PinosDaemon *daemon; PinosDaemon *daemon;
GMainLoop *loop; GMainLoop *loop;
PinosProperties *props;
pinos_init (&argc, &argv); pinos_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
daemon = pinos_daemon_new (); props = pinos_properties_new ("test", "test", NULL);
daemon = pinos_daemon_new (props);
pinos_gst_manager_new (daemon); pinos_gst_manager_new (daemon);
pinos_daemon_start (daemon); pinos_daemon_start (daemon);

View file

@ -18,6 +18,8 @@
<property name='Version' type='s' access='read' /> <property name='Version' type='s' access='read' />
<!-- Name: Name of the daemon --> <!-- Name: Name of the daemon -->
<property name='Name' type='s' access='read' /> <property name='Name' type='s' access='read' />
<!-- Cookie: A random cookie for identifying this instance of Pinos -->
<property name='Cookie' type='u' access='read' />
<!-- Properties: Extra properties of the daemon --> <!-- Properties: Extra properties of the daemon -->
<property name='Properties' type='a{sv}' access='read' /> <property name='Properties' type='a{sv}' access='read' />
<!-- ConnectClient: <!-- ConnectClient:

View file

@ -427,10 +427,13 @@ pinos_gst_source_init (PinosGstSource * source)
PinosSource * PinosSource *
pinos_gst_source_new (PinosDaemon *daemon, pinos_gst_source_new (PinosDaemon *daemon,
const gchar *name, const gchar *name,
PinosProperties *properties,
GstElement *element) GstElement *element)
{ {
return g_object_new (PINOS_TYPE_GST_SOURCE, return g_object_new (PINOS_TYPE_GST_SOURCE,
"daemon", daemon, "daemon", daemon,
"name", name, "name", name,
"element", element, NULL); "properties", properties,
"element", element,
NULL);
} }

View file

@ -55,6 +55,7 @@ GType pinos_gst_source_get_type (void);
PinosSource * pinos_gst_source_new (PinosDaemon *daemon, PinosSource * pinos_gst_source_new (PinosDaemon *daemon,
const gchar *name, const gchar *name,
PinosProperties *properties,
GstElement *element); GstElement *element);
G_END_DECLS G_END_DECLS

View file

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

View file

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

View file

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

View file

@ -40,6 +40,14 @@ struct _PinosDaemonPrivate
GList *sources; GList *sources;
GHashTable *senders; GHashTable *senders;
PinosProperties *properties;
};
enum
{
PROP_0,
PROP_PROPERTIES,
}; };
typedef struct { typedef struct {
@ -136,10 +144,14 @@ handle_connect_client (PinosDaemon1 *interface,
PinosClient *client; PinosClient *client;
const gchar *sender, *object_path; const gchar *sender, *object_path;
SenderData *data; SenderData *data;
PinosProperties *props;
sender = g_dbus_method_invocation_get_sender (invocation); 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); g_signal_connect (client, "disconnect", (GCallback) handle_disconnect_client, daemon);
data = g_hash_table_lookup (priv->senders, sender); data = g_hash_table_lookup (priv->senders, sender);
@ -159,6 +171,7 @@ static void
export_server_object (PinosDaemon *daemon, export_server_object (PinosDaemon *daemon,
GDBusObjectManagerServer *manager) GDBusObjectManagerServer *manager)
{ {
PinosDaemonPrivate *priv = daemon->priv;
PinosObjectSkeleton *skel; PinosObjectSkeleton *skel;
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SERVER); 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_host_name (iface, g_get_host_name ());
pinos_daemon1_set_version (iface, PACKAGE_VERSION); pinos_daemon1_set_version (iface, PACKAGE_VERSION);
pinos_daemon1_set_name (iface, PACKAGE_NAME); 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); pinos_object_skeleton_set_daemon1 (skel, iface);
g_object_unref (iface); g_object_unref (iface);
} }
@ -217,15 +232,16 @@ name_lost_handler (GDBusConnection *connection,
/** /**
* pinos_daemon_new: * pinos_daemon_new:
* @properties: #PinosProperties
* *
* Make a new #PinosDaemon object * Make a new #PinosDaemon object with given @properties
* *
* Returns: a new #PinosDaemon * Returns: a new #PinosDaemon
*/ */
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); 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 void
pinos_daemon_add_source (PinosDaemon *daemon, pinos_daemon_add_source (PinosDaemon *daemon,
PinosSource *source) PinosSource *source)
@ -324,6 +347,13 @@ pinos_daemon_add_source (PinosDaemon *daemon,
priv->sources = g_list_prepend (priv->sources, source); priv->sources = g_list_prepend (priv->sources, source);
} }
/**
* pinos_daemon_remove_source:
* @daemon: a #PinosDaemon
* @source: a #PinosSource
*
* Remove @source from @daemon.
*/
void void
pinos_daemon_remove_source (PinosDaemon *daemon, pinos_daemon_remove_source (PinosDaemon *daemon,
PinosSource *source) PinosSource *source)
@ -337,12 +367,24 @@ pinos_daemon_remove_source (PinosDaemon *daemon,
priv->sources = g_list_remove (priv->sources, source); 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 * PinosSource *
pinos_daemon_find_source (PinosDaemon *daemon, pinos_daemon_find_source (PinosDaemon *daemon,
const gchar *name, const gchar *name,
GVariant *props, PinosProperties *props,
GBytes *format_filter, GBytes *format_filter,
GError **error) GError **error)
{ {
PinosDaemonPrivate *priv; PinosDaemonPrivate *priv;
PinosSource *best = NULL; PinosSource *best = NULL;
@ -371,8 +413,51 @@ pinos_daemon_find_source (PinosDaemon *daemon,
return best; return best;
} }
G_DEFINE_TYPE (PinosDaemon, pinos_daemon, G_TYPE_OBJECT); 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 static void
pinos_daemon_dispose (GObject * object) pinos_daemon_dispose (GObject * object)
{ {
@ -403,6 +488,20 @@ pinos_daemon_class_init (PinosDaemonClass * klass)
gobject_class->dispose = pinos_daemon_dispose; gobject_class->dispose = pinos_daemon_dispose;
gobject_class->finalize = pinos_daemon_finalize; 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 static void

View file

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

View file

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

View file

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