Make source and source-output server side only

Move source and source-output to the server side again.
Make the daemon track objects per sender so that we can remove them
when the sender disappears.
This commit is contained in:
Wim Taymans 2015-05-05 18:20:32 +02:00
parent 1b89f2f8ad
commit d9444ab360
17 changed files with 139 additions and 205 deletions

View file

@ -20,8 +20,6 @@
#include "client/pulsevideo.h"
#include "client/pv-enumtypes.h"
#include "client/pv-source.h"
#include "client/pv-source-output.h"
#include "server/pv-client.h"
@ -34,8 +32,6 @@ struct _PvClientPrivate
gchar *object_path;
PvClient1 *client1;
GHashTable *source_outputs;
};
#define PV_CLIENT_GET_PRIVATE(obj) \
@ -133,7 +129,6 @@ client_unregister_object (PvClient *client)
PvClientPrivate *priv = client->priv;
PvDaemon *daemon = priv->daemon;
g_hash_table_unref (priv->source_outputs);
g_clear_object (&priv->client1);
pv_daemon_unexport (daemon, priv->object_path);
@ -207,9 +202,7 @@ pv_client_class_init (PvClientClass * klass)
static void
pv_client_init (PvClient * client)
{
PvClientPrivate *priv = client->priv = PV_CLIENT_GET_PRIVATE (client);
priv->source_outputs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
client->priv = PV_CLIENT_GET_PRIVATE (client);
}

View file

@ -45,7 +45,7 @@ typedef struct {
guint id;
gchar *sender;
PvDaemon *daemon;
GList *clients;
GList *objects;
} SenderData;
static void
@ -109,7 +109,7 @@ data_free (SenderData *data)
{
g_print ("free client %s %p\n", data->sender, data);
g_list_free_full (data->clients, g_object_unref);
g_list_free_full (data->objects, g_object_unref);
g_hash_table_remove (data->daemon->priv->senders, data->sender);
g_free (data->sender);
g_free (data);
@ -148,24 +148,19 @@ handle_connect_client (PvDaemon1 *interface,
gpointer user_data)
{
PvDaemon *daemon = user_data;
PvDaemonPrivate *priv = daemon->priv;
PvClient *client;
const gchar *sender, *object_path;
SenderData *data;
sender = g_dbus_method_invocation_get_sender (invocation);
g_print ("connect client %s\n", sender);
data = g_hash_table_lookup (priv->senders, sender);
if (data == NULL)
data = sender_data_new (daemon, sender);
client = pv_client_new (daemon, sender, PV_DBUS_OBJECT_PREFIX);
pv_daemon_track_object (daemon, sender, G_OBJECT (client));
object_path = pv_client_get_object_path (client);
data->clients = g_list_prepend (data->clients, client);
pv_daemon1_complete_connect_client (interface, invocation, object_path);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
return TRUE;
}
@ -331,39 +326,25 @@ pv_daemon_unexport (PvDaemon *daemon, const gchar *object_path)
g_dbus_object_manager_server_unexport (daemon->priv->server_manager, object_path);
}
/**
* pv_daemon_add_source:
* @daemon: a #PvDaemon
* @source: a #PvSource
*
* Register @source with @daemon so that it becomes available to clients.
*/
void
pv_daemon_add_source (PvDaemon *daemon, PvSource *source)
pv_daemon_track_object (PvDaemon *daemon,
const gchar *sender,
GObject *object)
{
PvDaemonPrivate *priv;
SenderData *data;
g_return_if_fail (PV_IS_DAEMON (daemon));
g_return_if_fail (PV_IS_SOURCE (source));
g_return_if_fail (sender != NULL);
g_return_if_fail (G_IS_OBJECT (object));
priv = daemon->priv;
pv_source_set_manager (source, priv->server_manager);
}
data = g_hash_table_lookup (priv->senders, sender);
if (data == NULL)
data = sender_data_new (daemon, sender);
/**
* pv_daemon_remove_source:
* @daemon: a #PvDaemon
* @source: a #PvSource
*
* Unregister @source from @daemon so that it becomes unavailable to clients.
*/
void
pv_daemon_remove_source (PvDaemon *daemon, PvSource *source)
{
g_return_if_fail (PV_IS_DAEMON (daemon));
g_return_if_fail (PV_IS_SOURCE (source));
pv_source_set_manager (source, NULL);
data->objects = g_list_prepend (data->objects, object);
}
G_DEFINE_TYPE (PvDaemon, pv_daemon, G_TYPE_OBJECT);

View file

@ -38,7 +38,7 @@ typedef struct _PvDaemon PvDaemon;
typedef struct _PvDaemonClass PvDaemonClass;
typedef struct _PvDaemonPrivate PvDaemonPrivate;
#include <client/pv-source.h>
#include <server/pv-source.h>
/**
* PvDaemon:
@ -71,8 +71,7 @@ void pv_daemon_stop (PvDaemon *daemon);
gchar * pv_daemon_export_uniquely (PvDaemon *daemon, GDBusObjectSkeleton *skel);
void pv_daemon_unexport (PvDaemon *daemon, const gchar *name);
void pv_daemon_add_source (PvDaemon *daemon, PvSource *source);
void pv_daemon_remove_source (PvDaemon *daemon, PvSource *source);
void pv_daemon_track_object (PvDaemon *daemon, const gchar *sender, GObject *object);
G_END_DECLS

View file

@ -0,0 +1,316 @@
/* Pulsevideo
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <sys/socket.h>
#include <gio/gunixfdlist.h>
#include "client/pv-enumtypes.h"
#include "server/pv-daemon.h"
#include "server/pv-source-output.h"
#include "dbus/org-pulsevideo.h"
struct _PvSourceOutputPrivate
{
PvDaemon *daemon;
gchar *object_path;
gchar *source;
GSocket *socket;
};
#define PV_SOURCE_OUTPUT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PV_TYPE_SOURCE_OUTPUT, PvSourceOutputPrivate))
G_DEFINE_TYPE (PvSourceOutput, pv_source_output, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_DAEMON,
PROP_OBJECT_PATH,
PROP_SOURCE,
PROP_SOCKET,
};
static void
pv_source_output_get_property (GObject *_object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PvSourceOutput *output = PV_SOURCE_OUTPUT (_object);
PvSourceOutputPrivate *priv = output->priv;
switch (prop_id) {
case PROP_DAEMON:
g_value_set_object (value, priv->daemon);
break;
case PROP_OBJECT_PATH:
g_value_set_string (value, priv->object_path);
break;
case PROP_SOURCE:
g_value_set_string (value, priv->source);
break;
case PROP_SOCKET:
g_value_set_object (value, priv->socket);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (output, prop_id, pspec);
break;
}
}
static void
pv_source_output_set_property (GObject *_object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PvSourceOutput *output = PV_SOURCE_OUTPUT (_object);
PvSourceOutputPrivate *priv = output->priv;
switch (prop_id) {
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_OBJECT_PATH:
priv->object_path = g_value_dup_string (value);
break;
case PROP_SOURCE:
priv->source = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (output, prop_id, pspec);
break;
}
}
static gboolean
handle_start (PvSourceOutput1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
gpointer user_data)
{
PvSourceOutput *output = user_data;
PvSourceOutputPrivate *priv = output->priv;
GUnixFDList *fdlist;
GVariantBuilder props;
gint fd[2];
socketpair (AF_UNIX, SOCK_STREAM, 0, fd);
priv->socket = g_socket_new_from_fd (fd[0], NULL);
g_object_notify (G_OBJECT (output), "socket");
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&props, "{sv}", "name", g_variant_new_string ("hello"));
fdlist = g_unix_fd_list_new ();
g_unix_fd_list_append (fdlist, fd[1], NULL);
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
g_variant_new ("(h@a{sv})",
0,
g_variant_builder_end (&props)),
fdlist);
return TRUE;
}
static void
stop_transfer (PvSourceOutput *output)
{
PvSourceOutputPrivate *priv = output->priv;
if (priv->socket) {
g_clear_object (&priv->socket);
g_object_notify (G_OBJECT (output), "socket");
}
}
static gboolean
handle_stop (PvSourceOutput1 *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
PvSourceOutput *output = user_data;
stop_transfer (output);
g_dbus_method_invocation_return_value (invocation, NULL);
return TRUE;
}
static gboolean
handle_remove (PvSourceOutput1 *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
PvSourceOutput *output = user_data;
stop_transfer (output);
g_dbus_method_invocation_return_value (invocation, NULL);
return TRUE;
}
static void
output_register_object (PvSourceOutput *output, const gchar *prefix)
{
PvSourceOutputPrivate *priv = output->priv;
PvObjectSkeleton *skel;
gchar *name;
name = g_strdup_printf ("%s/output", prefix);
skel = pv_object_skeleton_new (name);
g_free (name);
{
PvSourceOutput1 *iface;
iface = pv_source_output1_skeleton_new ();
g_object_set (iface, "source", priv->source, NULL);
g_signal_connect (iface, "handle-start", (GCallback) handle_start, output);
g_signal_connect (iface, "handle-stop", (GCallback) handle_stop, output);
g_signal_connect (iface, "handle-remove", (GCallback) handle_remove, output);
pv_object_skeleton_set_source_output1 (skel, iface);
g_object_unref (iface);
}
g_free (priv->object_path);
priv->object_path = pv_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
}
static void
output_unregister_object (PvSourceOutput *output)
{
PvSourceOutputPrivate *priv = output->priv;
stop_transfer (output);
pv_daemon_unexport (priv->daemon, priv->object_path);
}
static void
pv_source_output_finalize (GObject * object)
{
PvSourceOutput *output = PV_SOURCE_OUTPUT (object);
PvSourceOutputPrivate *priv = output->priv;
output_unregister_object (output);
g_object_unref (priv->daemon);
g_free (priv->object_path);
g_free (priv->source);
G_OBJECT_CLASS (pv_source_output_parent_class)->finalize (object);
}
static void
pv_source_output_constructed (GObject * object)
{
PvSourceOutput *output = PV_SOURCE_OUTPUT (object);
PvSourceOutputPrivate *priv = output->priv;
output_register_object (output, priv->object_path);
G_OBJECT_CLASS (pv_source_output_parent_class)->constructed (object);
}
static void
pv_source_output_class_init (PvSourceOutputClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PvSourceOutputPrivate));
gobject_class->finalize = pv_source_output_finalize;
gobject_class->set_property = pv_source_output_set_property;
gobject_class->get_property = pv_source_output_get_property;
gobject_class->constructed = pv_source_output_constructed;
g_object_class_install_property (gobject_class,
PROP_DAEMON,
g_param_spec_object ("daemon",
"Daemon",
"The Daemon",
PV_TYPE_DAEMON,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_OBJECT_PATH,
g_param_spec_string ("object-path",
"Object Path",
"The object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SOURCE,
g_param_spec_string ("source",
"Source",
"The source object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SOCKET,
g_param_spec_object ("socket",
"Socket",
"The socket with data",
G_TYPE_SOCKET,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}
static void
pv_source_output_init (PvSourceOutput * output)
{
output->priv = PV_SOURCE_OUTPUT_GET_PRIVATE (output);
}
const gchar *
pv_source_output_get_object_path (PvSourceOutput *output)
{
PvSourceOutputPrivate *priv;
g_return_val_if_fail (PV_IS_SOURCE_OUTPUT (output), NULL);
priv = output->priv;
return priv->object_path;
}

View file

@ -0,0 +1,69 @@
/* Pulsevideo
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PV_SOURCE_OUTPUT_H__
#define __PV_SOURCE_OUTPUT_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define PV_TYPE_SOURCE_OUTPUT (pv_source_output_get_type ())
#define PV_IS_SOURCE_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PV_TYPE_SOURCE_OUTPUT))
#define PV_IS_SOURCE_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PV_TYPE_SOURCE_OUTPUT))
#define PV_SOURCE_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PV_TYPE_SOURCE_OUTPUT, PvSourceOutputClass))
#define PV_SOURCE_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PV_TYPE_SOURCE_OUTPUT, PvSourceOutput))
#define PV_SOURCE_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PV_TYPE_SOURCE_OUTPUT, PvSourceOutputClass))
#define PV_SOURCE_OUTPUT_CAST(obj) ((PvSourceOutput*)(obj))
#define PV_SOURCE_OUTPUT_CLASS_CAST(klass) ((PvSourceOutputClass*)(klass))
typedef struct _PvSourceOutput PvSourceOutput;
typedef struct _PvSourceOutputClass PvSourceOutputClass;
typedef struct _PvSourceOutputPrivate PvSourceOutputPrivate;
/**
* PvSourceOutput:
*
* Pulsevideo source output object class.
*/
struct _PvSourceOutput {
GObject object;
PvSourceOutputPrivate *priv;
};
/**
* PvSourceOutputClass:
*
* Pulsevideo source output object class.
*/
struct _PvSourceOutputClass {
GObjectClass parent_class;
};
/* normal GObject stuff */
GType pv_source_output_get_type (void);
const gchar * pv_source_output_get_sender (PvSourceOutput *output);
const gchar * pv_source_output_get_object_path (PvSourceOutput *output);
G_END_DECLS
#endif /* __PV_SOURCE_OUTPUT_H__ */

438
src/server/pv-source.c Normal file
View file

@ -0,0 +1,438 @@
/* Pulsevideo
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <gio/gio.h>
#include "client/pulsevideo.h"
#include "client/pv-enumtypes.h"
#include "server/pv-source.h"
#include "server/pv-daemon.h"
#include "dbus/org-pulsevideo.h"
#define PV_SOURCE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PV_TYPE_SOURCE, PvSourcePrivate))
struct _PvSourcePrivate
{
PvDaemon *daemon;
PvSource1 *iface;
gchar *object_path;
gchar *name;
PvSourceState state;
GVariant *properties;
GError *error;
};
G_DEFINE_ABSTRACT_TYPE (PvSource, pv_source, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_DAEMON,
PROP_OBJECT_PATH,
PROP_NAME,
PROP_STATE,
PROP_PROPERTIES
};
static void
pv_source_get_property (GObject *_object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PvSource *source = PV_SOURCE (_object);
PvSourcePrivate *priv = source->priv;
switch (prop_id) {
case PROP_DAEMON:
g_value_set_object (value, priv->daemon);
break;
case PROP_OBJECT_PATH:
g_value_set_string (value, priv->object_path);
break;
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
case PROP_STATE:
g_value_set_enum (value, priv->state);
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
break;
}
}
static void
pv_source_set_property (GObject *_object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PvSource *source = PV_SOURCE (_object);
PvSourcePrivate *priv = source->priv;
switch (prop_id) {
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_OBJECT_PATH:
g_free (priv->object_path);
priv->object_path = g_value_dup_string (value);
break;
case PROP_NAME:
g_free (priv->name);
priv->name = g_value_dup_string (value);
break;
case PROP_PROPERTIES:
if (priv->properties)
g_variant_unref (priv->properties);
priv->properties = g_value_dup_variant (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
break;
}
}
static gboolean
handle_create_source_output (PvSource1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
gpointer user_data)
{
PvSource *source = user_data;
PvSourcePrivate *priv = source->priv;
PvSourceOutput *output;
const gchar *object_path, *sender;
output = pv_source_create_source_output (source, arg_properties, priv->object_path);
if (output == NULL)
goto no_output;
sender = g_dbus_method_invocation_get_sender (invocation);
pv_daemon_track_object (priv->daemon, sender, G_OBJECT (output));
object_path = pv_source_output_get_object_path (output);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
return TRUE;
/* ERRORS */
no_output:
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pulsevideo.Error", "Can't create output");
return TRUE;
}
}
static gboolean
handle_get_capabilities (PvSource1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
gpointer user_data)
{
PvSource *source = user_data;
GVariant *out_caps;
out_caps = pv_source_get_capabilities (source, arg_properties);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(@aa{sv})", out_caps));
return TRUE;
}
static void
source_register_object (PvSource *source)
{
PvSourcePrivate *priv = source->priv;
PvDaemon *daemon = priv->daemon;
PvObjectSkeleton *skel;
skel = pv_object_skeleton_new (PV_DBUS_OBJECT_SOURCE);
priv->iface = pv_source1_skeleton_new ();
g_object_set (priv->iface, "name", priv->name,
"state", priv->state,
"properties", priv->properties,
NULL);
g_signal_connect (priv->iface, "handle-create-source-output",
(GCallback) handle_create_source_output,
source);
g_signal_connect (priv->iface, "handle-get-capabilities",
(GCallback) handle_get_capabilities,
source);
pv_object_skeleton_set_source1 (skel, priv->iface);
g_free (priv->object_path);
priv->object_path = pv_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
return;
}
static void
source_unregister_object (PvSource *source)
{
PvSourcePrivate *priv = source->priv;
pv_daemon_unexport (priv->daemon, priv->object_path);
g_clear_object (&priv->iface);
}
static void
pv_source_constructed (GObject * object)
{
PvSource *source = PV_SOURCE (object);
source_register_object (source);
G_OBJECT_CLASS (pv_source_parent_class)->constructed (object);
}
static void
pv_source_finalize (GObject * object)
{
PvSource *source = PV_SOURCE (object);
PvSourcePrivate *priv = source->priv;
source_unregister_object (source);
g_free (priv->object_path);
g_free (priv->name);
g_variant_unref (priv->properties);
G_OBJECT_CLASS (pv_source_parent_class)->finalize (object);
}
static PvSourceOutput *
default_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
{
PvSourcePrivate *priv = source->priv;
return g_object_new (PV_TYPE_SOURCE_OUTPUT, "daemon", priv->daemon,
"object-path", prefix,
"source", priv->object_path, NULL);
}
static gboolean
default_release_source_output (PvSource *source, PvSourceOutput *output)
{
g_object_unref (output);
return TRUE;
}
static void
pv_source_class_init (PvSourceClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PvSourcePrivate));
gobject_class->finalize = pv_source_finalize;
gobject_class->constructed = pv_source_constructed;
gobject_class->set_property = pv_source_set_property;
gobject_class->get_property = pv_source_get_property;
g_object_class_install_property (gobject_class,
PROP_DAEMON,
g_param_spec_object ("daemon",
"Daemon",
"The Daemon",
PV_TYPE_DAEMON,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_OBJECT_PATH,
g_param_spec_string ("object-path",
"Object Path",
"The object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"The source name",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_STATE,
g_param_spec_enum ("state",
"State",
"The state of the source",
PV_TYPE_SOURCE_STATE,
PV_SOURCE_STATE_INIT,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"The properties of the source",
G_VARIANT_TYPE_VARIANT,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
klass->create_source_output = default_create_source_output;
klass->release_source_output = default_release_source_output;
}
static void
pv_source_init (PvSource * source)
{
source->priv = PV_SOURCE_GET_PRIVATE (source);
}
GVariant *
pv_source_get_capabilities (PvSource *source, GVariant *props)
{
PvSourceClass *klass;
GVariant *res;
g_return_val_if_fail (PV_IS_SOURCE (source), NULL);
klass = PV_SOURCE_GET_CLASS (source);
if (klass->get_capabilities)
res = klass->get_capabilities (source, props);
else
res = NULL;
return res;
}
gboolean
pv_source_set_state (PvSource *source, PvSourceState state)
{
PvSourceClass *klass;
gboolean res;
g_return_val_if_fail (PV_IS_SOURCE (source), FALSE);
klass = PV_SOURCE_GET_CLASS (source);
if (klass->set_state)
res = klass->set_state (source, state);
else
res = FALSE;
return res;
}
void
pv_source_update_state (PvSource *source, PvSourceState state)
{
PvSourcePrivate *priv;
g_return_if_fail (PV_IS_SOURCE (source));
priv = source->priv;
if (priv->state != state) {
priv->state = state;
g_print ("source changed state %d\n", state);
if (priv->iface)
pv_source1_set_state (priv->iface, state);
g_object_notify (G_OBJECT (source), "state");
}
}
void
pv_source_report_error (PvSource *source, GError *error)
{
PvSourcePrivate *priv;
g_return_if_fail (PV_IS_SOURCE (source));
priv = source->priv;
g_clear_error (&priv->error);
priv->error = error;
priv->state = PV_SOURCE_STATE_ERROR;
g_object_notify (G_OBJECT (source), "state");
}
PvSourceOutput *
pv_source_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
{
PvSourceClass *klass;
PvSourceOutput *res;
g_return_val_if_fail (PV_IS_SOURCE (source), NULL);
klass = PV_SOURCE_GET_CLASS (source);
if (klass->create_source_output)
res = klass->create_source_output (source, props, prefix);
else
res = NULL;
return res;
}
gboolean
pv_source_release_source_output (PvSource *source, PvSourceOutput *output)
{
PvSourceClass *klass;
gboolean res;
g_return_val_if_fail (PV_IS_SOURCE (source), FALSE);
g_return_val_if_fail (PV_IS_SOURCE_OUTPUT (output), FALSE);
klass = PV_SOURCE_GET_CLASS (source);
if (klass->release_source_output)
res = klass->release_source_output (source, output);
else
res = FALSE;
return res;
}

90
src/server/pv-source.h Normal file
View file

@ -0,0 +1,90 @@
/* Pulsevideo
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PV_SOURCE_H__
#define __PV_SOURCE_H__
#include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS
typedef struct _PvSource PvSource;
typedef struct _PvSourceClass PvSourceClass;
typedef struct _PvSourcePrivate PvSourcePrivate;
#include "client/pv-introspect.h"
#include "server/pv-source-output.h"
#define PV_TYPE_SOURCE (pv_source_get_type ())
#define PV_IS_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PV_TYPE_SOURCE))
#define PV_IS_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PV_TYPE_SOURCE))
#define PV_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PV_TYPE_SOURCE, PvSourceClass))
#define PV_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PV_TYPE_SOURCE, PvSource))
#define PV_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PV_TYPE_SOURCE, PvSourceClass))
#define PV_SOURCE_CAST(obj) ((PvSource*)(obj))
#define PV_SOURCE_CLASS_CAST(klass) ((PvSourceClass*)(klass))
/**
* PvSource:
*
* Pulsevideo source object class.
*/
struct _PvSource {
GObject object;
PvSourcePrivate *priv;
};
/**
* PvSourceClass:
* @get_capabilities: called to get a list of supported formats from the source
* @set_state: called to change the current state of the source
* @create_source_output: called to create a new source-output object
* @release_source_output: called to release a source-output object
*
* Pulsevideo source object class.
*/
struct _PvSourceClass {
GObjectClass parent_class;
GVariant * (*get_capabilities) (PvSource *source, GVariant *props);
gboolean (*set_state) (PvSource *source, PvSourceState);
PvSourceOutput * (*create_source_output) (PvSource *source, GVariant *props, const gchar *prefix);
gboolean (*release_source_output) (PvSource *source, PvSourceOutput *output);
};
/* normal GObject stuff */
GType pv_source_get_type (void);
GVariant * pv_source_get_capabilities (PvSource *source, GVariant *props);
gboolean pv_source_set_state (PvSource *source, PvSourceState state);
void pv_source_update_state (PvSource *source, PvSourceState state);
void pv_source_report_error (PvSource *source, GError *error);
PvSourceOutput * pv_source_create_source_output (PvSource *source, GVariant *props, const gchar *prefix);
gboolean pv_source_release_source_output (PvSource *source, PvSourceOutput *output);
G_END_DECLS
#endif /* __PV_SOURCE_H__ */