mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-14 20:02:38 +00:00
properties: pass PinosProperties around
Pass PinosProperties around instead of GVariant. This is much easier to deal with.
This commit is contained in:
parent
c77d7718a2
commit
31da833069
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -22,7 +22,7 @@ struct _PinosContextPrivate
|
|||
GMainContext *context;
|
||||
|
||||
gchar *name;
|
||||
GVariant *properties;
|
||||
PinosProperties *properties;
|
||||
|
||||
guint id;
|
||||
GDBusConnection *connection;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -29,12 +29,14 @@ main (gint argc, gchar *argv[])
|
|||
{
|
||||
PinosDaemon *daemon;
|
||||
GMainLoop *loop;
|
||||
PinosProperties *props;
|
||||
|
||||
pinos_init (&argc, &argv);
|
||||
|
||||
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_daemon_start (daemon);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<property name='Version' type='s' access='read' />
|
||||
<!-- Name: Name of the daemon -->
|
||||
<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 -->
|
||||
<property name='Properties' type='a{sv}' access='read' />
|
||||
<!-- ConnectClient:
|
||||
|
|
|
@ -427,10 +427,13 @@ pinos_gst_source_init (PinosGstSource * source)
|
|||
PinosSource *
|
||||
pinos_gst_source_new (PinosDaemon *daemon,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
GstElement *element)
|
||||
{
|
||||
return g_object_new (PINOS_TYPE_GST_SOURCE,
|
||||
"daemon", daemon,
|
||||
"name", name,
|
||||
"element", element, NULL);
|
||||
"properties", properties,
|
||||
"element", element,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ GType pinos_gst_source_get_type (void);
|
|||
|
||||
PinosSource * pinos_gst_source_new (PinosDaemon *daemon,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
GstElement *element);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue