rework: make client and server nodes

work on making nodes and ports on the client.
This commit is contained in:
Wim Taymans 2016-05-12 17:03:28 +02:00
parent c67d3d7f04
commit 8407430891
34 changed files with 1500 additions and 3844 deletions

View file

@ -22,6 +22,7 @@
#include "pinos/client/context.h"
#include "pinos/client/enumtypes.h"
#include "pinos/client/subscribe.h"
#include "pinos/client/client-node.h"
#include "pinos/client/private.h"
@ -150,7 +151,6 @@ pinos_context_finalize (GObject * object)
g_list_free (priv->nodes);
g_list_free (priv->ports);
g_list_free (priv->clients);
g_list_free (priv->channels);
g_clear_object (&priv->subscribe);
g_clear_error (&priv->error);
@ -501,13 +501,6 @@ subscription_cb (PinosSubscribe *subscribe,
else if (event == PINOS_SUBSCRIPTION_EVENT_REMOVE)
priv->ports = g_list_remove (priv->ports, object);
break;
case PINOS_SUBSCRIPTION_FLAG_CHANNEL:
if (event == PINOS_SUBSCRIPTION_EVENT_NEW)
priv->channels = g_list_prepend (priv->channels, object);
else if (event == PINOS_SUBSCRIPTION_EVENT_REMOVE)
priv->channels = g_list_remove (priv->channels, object);
break;
}
if (flags & priv->subscription_mask)
@ -761,3 +754,171 @@ pinos_context_get_error (PinosContext *context)
return priv->error;
}
typedef struct {
gchar *name;
PinosProperties *properties;
} CreateNodeData;
static void
create_node_data_free (CreateNodeData *data)
{
g_free (data->name);
if (data->properties)
pinos_properties_free (data->properties);
g_slice_free (CreateNodeData, data);
}
static void
on_node_proxy (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GTask *task = user_data;
PinosContext *context = g_task_get_source_object (task);
GError *error = NULL;
GDBusProxy *proxy;
PinosNode *node;
proxy = pinos_subscribe_get_proxy_finish (context->priv->subscribe,
res,
&error);
if (proxy == NULL)
goto node_failed;
node = g_object_new (PINOS_TYPE_CLIENT_NODE,
"context", context,
"proxy", proxy,
NULL);
g_task_return_pointer (task, node, (GDestroyNotify) g_object_unref);
return;
node_failed:
{
g_warning ("failed to get node proxy: %s", error->message);
g_task_return_error (task, error);
return;
}
}
static void
on_node_created (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GTask *task = user_data;
PinosContext *context = g_task_get_source_object (task);
GVariant *ret;
GError *error = NULL;
const gchar *node_path;
g_assert (context->priv->client == G_DBUS_PROXY (source_object));
ret = g_dbus_proxy_call_finish (context->priv->client, res, &error);
if (ret == NULL)
goto create_failed;
g_variant_get (ret, "(&o)", &node_path);
pinos_subscribe_get_proxy (context->priv->subscribe,
PINOS_DBUS_SERVICE,
node_path,
"org.pinos.Node1",
NULL,
on_node_proxy,
task);
g_variant_unref (ret);
return;
/* ERRORS */
create_failed:
{
g_warning ("failed to create node: %s", error->message);
g_task_return_error (task, error);
return;
}
}
static gboolean
do_create_node (GTask *task)
{
PinosContext *context = g_task_get_source_object (task);
CreateNodeData *data = g_task_get_task_data (task);
g_dbus_proxy_call (context->priv->client,
"CreateNode",
g_variant_new ("(s@a{sv})",
"client-node",
pinos_properties_to_variant (data->properties)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
on_node_created,
task);
return FALSE;
}
/**
* pinos_context_create_node:
* @context: a #PinosContext
* @name: the name of the Node
* @properties: properties of the node
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback
* @user_data: user data.
*
* Asynchronously create a new node in @context.
*/
void
pinos_context_create_node (PinosContext *context,
const gchar *name,
PinosProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
CreateNodeData *data;
g_return_if_fail (PINOS_IS_CONTEXT (context));
task = g_task_new (context,
cancellable,
callback,
user_data);
data = g_slice_new (CreateNodeData);
data->name = g_strdup (name);
data->properties = properties ? pinos_properties_copy (properties) : NULL;
g_task_set_task_data (task, data, (GDestroyNotify) create_node_data_free);
g_main_context_invoke (context->priv->context,
(GSourceFunc) do_create_node,
task);
}
/**
* pinos_context_create_node_finish:
* @context: a #PinosContext
* @res: a #GAsyncResult
* @error: a #GError or %NULL
*
* Get the newly created #PinosNode. This function should be called in the callback
* of pinos_context_create_node() to get the result or error.
*
* Returns: a new #PinosNode. If %NULL is returned, @error will
* be set.
*/
PinosNode *
pinos_context_create_node_finish (PinosContext *context,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_pointer (G_TASK (res), error);
}

View file

@ -22,11 +22,17 @@
#include <glib-object.h>
#include <pinos/client/subscribe.h>
#include <pinos/client/properties.h>
G_BEGIN_DECLS
typedef struct _PinosContext PinosContext;
typedef struct _PinosContextClass PinosContextClass;
typedef struct _PinosContextPrivate PinosContextPrivate;
#include <pinos/client/subscribe.h>
#include <pinos/client/properties.h>
#include <pinos/client/node.h>
#define PINOS_TYPE_CONTEXT (pinos_context_get_type ())
#define PINOS_IS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_CONTEXT))
#define PINOS_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_CONTEXT))
@ -36,10 +42,6 @@ G_BEGIN_DECLS
#define PINOS_CONTEXT_CAST(obj) ((PinosContext*)(obj))
#define PINOS_CONTEXT_CLASS_CAST(klass) ((PinosContextClass*)(klass))
typedef struct _PinosContext PinosContext;
typedef struct _PinosContextClass PinosContextClass;
typedef struct _PinosContextPrivate PinosContextPrivate;
/**
* PinosContextFlags:
* @PINOS_CONTEXT_FLAGS_NONE: no flags
@ -106,6 +108,16 @@ PinosContext * pinos_context_new (GMainContext *ctx,
gboolean pinos_context_connect (PinosContext *context, PinosContextFlags flags);
gboolean pinos_context_disconnect (PinosContext *context);
void pinos_context_create_node (PinosContext *context,
const gchar *name,
PinosProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
PinosNode * pinos_context_create_node_finish (PinosContext *context,
GAsyncResult *res,
GError **error);
PinosContextState pinos_context_get_state (PinosContext *context);
const GError * pinos_context_get_error (PinosContext *context);

View file

@ -532,74 +532,63 @@ pinos_context_get_port_info_by_id (PinosContext *context,
}
/**
* pinos_channel_state_as_string:
* @state: a #PinosChannelState
* pinos_port_state_as_string:
* @state: a #PinosPortState
*
* Return the string representation of @state.
*
* Returns: the string representation of @state.
*/
const gchar *
pinos_channel_state_as_string (PinosChannelState state)
pinos_port_state_as_string (PinosPortState state)
{
GEnumValue *val;
val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_CHANNEL_STATE)),
val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_PORT_STATE)),
state);
return val == NULL ? "invalid-state" : val->value_nick;
}
static void
channel_fill_info (PinosChannelInfo *info, GDBusProxy *proxy)
connection_fill_info (PinosConnectionInfo *info, GDBusProxy *proxy)
{
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy;
info->channel_path = g_dbus_proxy_get_object_path (proxy);
SET_UINT32 ("Direction", direction, 2, PINOS_DIRECTION_INVALID);
SET_STRING ("Client", client_path, 0);
info->connection_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0;
SET_STRING ("Port", port_path, 0);
SET_PROPERTIES ("Properties", properties, 1);
SET_UINT32 ("State", state, 2, PINOS_CHANNEL_STATE_ERROR);
SET_BYTES ("PossibleFormats", possible_formats, 3);
SET_BYTES ("Format", format, 4);
SET_STRING ("SourcePort", source_port_path, 0);
SET_STRING ("DestinationPort", destination_port_path, 1);
if (changed)
g_hash_table_remove_all (changed);
}
static void
channel_clear_info (PinosChannelInfo *info)
connection_clear_info (PinosConnectionInfo *info)
{
if (info->possible_formats)
g_bytes_unref (info->possible_formats);
if (info->format)
g_bytes_unref (info->format);
if (info->properties)
pinos_properties_free (info->properties);
}
/**
* pinos_context_list_channel_info:
* pinos_context_list_connection_info:
* @context: a connected #PinosContext
* @flags: extra #PinosChannelInfoFlags
* @cb: a #PinosChannelInfoCallback
* @flags: extra #PinosConnectionInfoFlags
* @cb: a #PinosConnectionInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for each channel.
* Call @cb for each connection.
*/
void
pinos_context_list_channel_info (PinosContext *context,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
pinos_context_list_connection_info (PinosContext *context,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosContextPrivate *priv;
GList *walk;
@ -612,13 +601,13 @@ pinos_context_list_channel_info (PinosContext *context,
priv = context->priv;
for (walk = priv->channels; walk; walk = g_list_next (walk)) {
for (walk = priv->connections; walk; walk = g_list_next (walk)) {
GDBusProxy *proxy = walk->data;
PinosChannelInfo info;
PinosConnectionInfo info;
channel_fill_info (&info, proxy);
connection_fill_info (&info, proxy);
cb (context, &info, user_data);
channel_clear_info (&info);
connection_clear_info (&info);
}
g_task_return_boolean (task, TRUE);
@ -626,27 +615,27 @@ pinos_context_list_channel_info (PinosContext *context,
}
/**
* pinos_context_get_channel_info_by_id:
* pinos_context_get_connection_info_by_id:
* @context: a connected #PinosContext
* @id: a channel id
* @flags: extra #PinosChannelInfoFlags
* @cb: a #PinosChannelInfoCallback
* @id: a connection id
* @flags: extra #PinosConnectionInfoFlags
* @cb: a #PinosConnectionInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for the channel with @id.
* Call @cb for the connection with @id.
*/
void
pinos_context_get_channel_info_by_id (PinosContext *context,
gpointer id,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
pinos_context_get_connection_info_by_id (PinosContext *context,
gpointer id,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosChannelInfo info;
PinosConnectionInfo info;
GDBusProxy *proxy;
GTask *task;
@ -658,9 +647,9 @@ pinos_context_get_channel_info_by_id (PinosContext *context,
proxy = G_DBUS_PROXY (id);
channel_fill_info (&info, proxy);
connection_fill_info (&info, proxy);
cb (context, &info, user_data);
channel_clear_info (&info);
connection_clear_info (&info);
g_task_return_boolean (task, TRUE);
g_object_unref (task);

View file

@ -23,11 +23,68 @@
#include <gio/gio.h>
#include <glib-object.h>
G_BEGIN_DECLS
/**
* PinosNodeState:
* @PINOS_NODE_STATE_ERROR: the node is in error
* @PINOS_NODE_STATE_SUSPENDED: the node is suspended, the device might
* be closed
* @PINOS_NODE_STATE_INITIALIZING: the node is initializing, the device is
* being opened and the capabilities are queried
* @PINOS_NODE_STATE_IDLE: the node is running but there is no active
* port
* @PINOS_NODE_STATE_RUNNING: the node is running
*
* The different node states
*/
typedef enum {
PINOS_NODE_STATE_ERROR = -1,
PINOS_NODE_STATE_SUSPENDED = 0,
PINOS_NODE_STATE_INITIALIZING = 1,
PINOS_NODE_STATE_IDLE = 2,
PINOS_NODE_STATE_RUNNING = 3,
} PinosNodeState;
const gchar * pinos_node_state_as_string (PinosNodeState state);
/**
* PinosDirection:
* @PINOS_DIRECTION_INVALID: invalid direction
* @PINOS_DIRECTION_INPUT: an input port
* @PINOS_DIRECTION_OUTPUT: an output port
*
* The direction of a port
*/
typedef enum {
PINOS_DIRECTION_INVALID = -1,
PINOS_DIRECTION_INPUT = 0,
PINOS_DIRECTION_OUTPUT = 1
} PinosDirection;
const gchar * pinos_direction_as_string (PinosDirection direction);
/**
* PinosPortState:
* @PINOS_PORT_STATE_ERROR: the port is in error
* @PINOS_PORT_STATE_STOPPED: the port is stopped
* @PINOS_PORT_STATE_STARTING: the port is starting
* @PINOS_PORT_STATE_STREAMING: the port is streaming
*
* The different port states
*/
typedef enum {
PINOS_PORT_STATE_ERROR = -1,
PINOS_PORT_STATE_STOPPED = 0,
PINOS_PORT_STATE_STARTING = 1,
PINOS_PORT_STATE_STREAMING = 2,
} PinosPortState;
const gchar * pinos_port_state_as_string (PinosPortState state);
#include <pinos/client/context.h>
#include <pinos/client/properties.h>
G_BEGIN_DECLS
gboolean pinos_context_info_finish (GObject *object,
GAsyncResult *res,
GError **error);
@ -143,29 +200,6 @@ void pinos_context_get_client_info_by_id (PinosContext *context,
GAsyncReadyCallback callback,
gpointer user_data);
/**
* PinosNodeState:
* @PINOS_NODE_STATE_ERROR: the node is in error
* @PINOS_NODE_STATE_SUSPENDED: the node is suspended, the device might
* be closed
* @PINOS_NODE_STATE_INITIALIZING: the node is initializing, the device is
* being opened and the capabilities are queried
* @PINOS_NODE_STATE_IDLE: the node is running but there is no active
* channel
* @PINOS_NODE_STATE_RUNNING: the node is running
*
* The different node states
*/
typedef enum {
PINOS_NODE_STATE_ERROR = -1,
PINOS_NODE_STATE_SUSPENDED = 0,
PINOS_NODE_STATE_INITIALIZING = 1,
PINOS_NODE_STATE_IDLE = 2,
PINOS_NODE_STATE_RUNNING = 3,
} PinosNodeState;
const gchar * pinos_node_state_as_string (PinosNodeState state);
/**
* PinosNodeInfo:
* @id: generic id of the node
@ -223,21 +257,6 @@ void pinos_context_get_node_info_by_id (PinosContext *context,
GAsyncReadyCallback callback,
gpointer user_data);
/**
* PinosDirection:
* @PINOS_DIRECTION_INVALID: invalid direction
* @PINOS_DIRECTION_INPUT: an input port/channel
* @PINOS_DIRECTION_OUTPUT: an output port/channel
*
* The direction of a port or channel
*/
typedef enum {
PINOS_DIRECTION_INVALID = -1,
PINOS_DIRECTION_INPUT = 0,
PINOS_DIRECTION_OUTPUT = 1
} PinosDirection;
const gchar * pinos_direction_as_string (PinosDirection direction);
/**
* PinosPortInfo:
@ -302,92 +321,60 @@ void pinos_context_get_port_info_by_id (PinosContext *context,
GAsyncReadyCallback callback,
gpointer user_data);
/**
* PinosChannelState:
* @PINOS_CHANNEL_STATE_ERROR: the channel is in error
* @PINOS_CHANNEL_STATE_STOPPED: the channel is stopped
* @PINOS_CHANNEL_STATE_STARTING: the channel is starting
* @PINOS_CHANNEL_STATE_STREAMING: the channel is streaming
*
* The different channel states
*/
typedef enum {
PINOS_CHANNEL_STATE_ERROR = -1,
PINOS_CHANNEL_STATE_STOPPED = 0,
PINOS_CHANNEL_STATE_STARTING = 1,
PINOS_CHANNEL_STATE_STREAMING = 2,
} PinosChannelState;
const gchar * pinos_channel_state_as_string (PinosChannelState state);
/**
* PinosChannelInfo:
* @id: generic id of the channel_
* @channel_path: the unique path of the channel
* @direction: the channel direction
* @client_path: the owner client
* PinosConnectionInfo:
* @id: generic id of the connection
* @connection_path: the unique path of the connection
* @change_mask: bitfield of changed fields since last call
* @port_path: the owner port
* @properties: the properties of the channel
* @state: the state
* @possible_formats: the possible formats
* @format: when streaming, the current format
* @source_port_path: the source port
* @destination_port_path: the destination port
*
* The channel information. Extra information can be added in later
* The connection information. Extra information can be added in later
* versions.
*/
typedef struct {
gpointer id;
const char *channel_path;
PinosDirection direction;
const char *client_path;
const char *connection_path;
guint64 change_mask;
const char *port_path;
PinosProperties *properties;
PinosChannelState state;
GBytes *possible_formats;
GBytes *format;
} PinosChannelInfo;
const char *source_port_path;
const char *destination_port_path;
} PinosConnectionInfo;
/**
* PinosChannelInfoFlags:
* @PINOS_CHANNEL_INFO_FLAGS_NONE: no flags
* @PINOS_CHANNEL_INFO_FLAGS_NO_INPUT: don't list input channels
* @PINOS_CHANNEL_INFO_FLAGS_NO_OUTPUT: don't list output channels
* PinosConnectionInfoFlags:
* @PINOS_CONNECTION_INFO_FLAGS_NONE: no flags
*
* Extra flags to pass to pinos_context_list_channel_info() and
* pinos_context_get_channel_info_by_id().
* Extra flags to pass to pinos_context_list_connection_info() and
* pinos_context_get_connection_info_by_id().
*/
typedef enum {
PINOS_CHANNEL_INFO_FLAGS_NONE = 0,
PINOS_CHANNEL_INFO_FLAGS_NO_INPUT = (1 << 0),
PINOS_CHANNEL_INFO_FLAGS_NO_OUTPUT = (1 << 1),
} PinosChannelInfoFlags;
PINOS_CONNECTION_INFO_FLAGS_NONE = 0,
} PinosConnectionInfoFlags;
/**
* PinosChannelInfoCallback:
* PinosConnectionInfoCallback:
* @c: a #PinosContext
* @info: a #PinosChannelInfo
* @info: a #PinosConnectionInfo
* @user_data: user data
*
* Callback with information about the Pinos channel in @info.
* Callback with information about the Pinos connection in @info.
*/
typedef void (*PinosChannelInfoCallback) (PinosContext *c,
const PinosChannelInfo *info,
gpointer user_data);
typedef void (*PinosConnectionInfoCallback) (PinosContext *c,
const PinosConnectionInfo *info,
gpointer user_data);
void pinos_context_list_channel_info (PinosContext *context,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void pinos_context_get_channel_info_by_id (PinosContext *context,
gpointer id,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void pinos_context_list_connection_info (PinosContext *context,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void pinos_context_get_connection_info_by_id (PinosContext *context,
gpointer id,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
G_END_DECLS
#endif /* __PINOS_INTROSPECT_H__ */

View file

@ -42,7 +42,7 @@ struct _PinosContextPrivate
GList *clients;
GList *nodes;
GList *ports;
GList *channels;
GList *connections;
};
void pinos_subscribe_get_proxy (PinosSubscribe *subscribe,

View file

@ -49,7 +49,8 @@ struct _PinosStreamPrivate
GBytes *format;
GDBusProxy *channel;
PinosNode *node;
PinosPort *port;
gboolean disconnecting;
PinosStreamMode mode;
@ -197,14 +198,14 @@ subscription_cb (PinosSubscribe *subscribe,
PinosStreamPrivate *priv = stream->priv;
switch (flags) {
case PINOS_SUBSCRIPTION_FLAG_CHANNEL:
case PINOS_SUBSCRIPTION_FLAG_NODE:
if (event == PINOS_SUBSCRIPTION_EVENT_REMOVE) {
if (object == priv->channel && !priv->disconnecting) {
if (object == priv->node && !priv->disconnecting) {
stream_set_state (stream,
PINOS_STREAM_STATE_ERROR,
g_error_new_literal (G_IO_ERROR,
G_IO_ERROR_CLOSED,
"Channel disappeared"));
"Node disappeared"));
}
}
break;
@ -237,7 +238,8 @@ pinos_stream_finalize (GObject * object)
g_debug ("free stream %p", stream);
g_clear_object (&priv->socket);
g_clear_object (&priv->channel);
g_clear_object (&priv->node);
g_clear_object (&priv->port);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
@ -493,64 +495,31 @@ pinos_stream_get_error (PinosStream *stream)
}
static void
on_channel_proxy (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
on_port_created (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
PinosContext *context = priv->context;
GVariant *v;
gchar *str;
GError *error = NULL;
priv->channel = pinos_subscribe_get_proxy_finish (context->priv->subscribe,
res,
&error);
if (priv->channel == NULL)
goto channel_failed;
g_assert (priv->node == PINOS_NODE (source_object));
/* get the port we are connected to */
v = g_dbus_proxy_get_cached_property (priv->channel, "Port");
if (v) {
gsize len;
str = g_variant_dup_string (v, &len);
g_variant_unref (v);
g_free (priv->path);
priv->path = str;
}
v = g_dbus_proxy_get_cached_property (priv->channel, "PossibleFormats");
if (v) {
gsize len;
str = g_variant_dup_string (v, &len);
g_variant_unref (v);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
priv->possible_formats = g_bytes_new_take (str, len + 1);
g_object_notify (G_OBJECT (stream), "possible-formats");
}
v = g_dbus_proxy_get_cached_property (priv->channel, "Properties");
if (v) {
if (priv->properties)
pinos_properties_free (priv->properties);
priv->properties = pinos_properties_from_variant (v);
g_variant_unref (v);
g_object_notify (G_OBJECT (stream), "properties");
}
priv->port = pinos_node_create_port_finish (priv->node,
res,
&error);
if (priv->port == NULL)
goto create_failed;
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
g_object_unref (stream);
return;
channel_failed:
/* ERRORS */
create_failed:
{
g_warning ("failed to get channel proxy: %s", error->message);
g_warning ("failed to create port: %s", error->message);
stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream);
return;
@ -558,40 +527,33 @@ channel_failed:
}
static void
on_channel_created (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
on_node_created (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
PinosContext *context = priv->context;
GVariant *ret;
GError *error = NULL;
const gchar *channel_path;
g_assert (context->priv->client == G_DBUS_PROXY (source_object));
ret = g_dbus_proxy_call_finish (context->priv->client, res, &error);
if (ret == NULL)
priv->node = pinos_context_create_node_finish (context, res, &error);
if (priv->node == NULL)
goto create_failed;
g_variant_get (ret, "(&o)", &channel_path);
pinos_subscribe_get_proxy (context->priv->subscribe,
PINOS_DBUS_SERVICE,
channel_path,
"org.pinos.Channel1",
NULL,
on_channel_proxy,
pinos_node_create_port (priv->node,
priv->direction,
"client-port",
priv->possible_formats,
priv->properties,
NULL, /* GCancellable *cancellable */
on_port_created,
stream);
g_variant_unref (ret);
return;
/* ERRORS */
create_failed:
{
g_warning ("failed to get connect capture: %s", error->message);
g_warning ("failed to create node: %s", error->message);
stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream);
return;
@ -604,19 +566,12 @@ do_connect (PinosStream *stream)
PinosStreamPrivate *priv = stream->priv;
PinosContext *context = priv->context;
g_dbus_proxy_call (context->priv->client,
"CreateChannel",
g_variant_new ("(uss@a{sv})",
priv->direction,
(priv->path ? priv->path : ""),
g_bytes_get_data (priv->possible_formats, NULL),
pinos_properties_to_variant (priv->properties)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
on_channel_created,
stream);
pinos_context_create_node (context,
"client-node",
priv->properties,
NULL, /* GCancellable *cancellable */
on_node_created,
stream);
return FALSE;
}
@ -670,6 +625,7 @@ pinos_stream_connect (PinosStream *stream,
static gboolean
do_connect_provide (PinosStream *stream)
{
#if 0
PinosStreamPrivate *priv = stream->priv;
PinosContext *context = priv->context;
@ -683,6 +639,7 @@ do_connect_provide (PinosStream *stream)
NULL, /* GCancellable *cancellable */
on_channel_created,
stream);
#endif
return FALSE;
}
@ -726,39 +683,88 @@ pinos_stream_connect_provide (PinosStream *stream,
return TRUE;
}
static void
on_channel_removed (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
static gboolean
do_start (PinosStream *stream)
{
PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
GVariant *ret;
GError *error = NULL;
g_assert (priv->channel == G_DBUS_PROXY (source_object));
priv->disconnecting = FALSE;
g_clear_object (&priv->channel);
ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
if (ret == NULL)
goto proxy_failed;
g_variant_unref (ret);
stream_set_state (stream, PINOS_STREAM_STATE_UNCONNECTED, NULL);
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
g_object_unref (stream);
return;
/* ERRORS */
proxy_failed:
{
g_warning ("failed to disconnect: %s", error->message);
stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream);
return;
}
return FALSE;
}
/**
* pinos_stream_start:
* @stream: a #PinosStream
* @format: (transfer full): a #GBytes with format
* @mode: a #PinosStreamMode
*
* Start capturing from @stream in @format.
*
* When @mode is #PINOS_STREAM_MODE_SOCKET, you should connect to the notify::socket
* signal to obtain a readable socket with metadata and data.
*
* When @mode is #PINOS_STREAM_MODE_BUFFER, you should connect to the new-buffer
* signal and use pinos_stream_capture_buffer() to get the latest metadata and
* data.
*
* Returns: %TRUE on success.
*/
gboolean
pinos_stream_start (PinosStream *stream,
GBytes *format,
PinosStreamMode mode)
{
PinosStreamPrivate *priv;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_READY, FALSE);
priv->mode = mode;
priv->format = format;
stream_set_state (stream, PINOS_STREAM_STATE_STARTING, NULL);
g_main_context_invoke (priv->context->priv->context,
(GSourceFunc) do_start,
g_object_ref (stream));
return TRUE;
}
static gboolean
do_stop (PinosStream *stream)
{
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
g_object_unref (stream);
return FALSE;
}
/**
* pinos_stream_stop:
* @stream: a #PinosStream
*
* Stop capturing from @stream.
*
* Returns: %TRUE on success.
*/
gboolean
pinos_stream_stop (PinosStream *stream)
{
PinosStreamPrivate *priv;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_STREAMING, FALSE);
g_main_context_invoke (priv->context->priv->context,
(GSourceFunc) do_stop,
g_object_ref (stream));
return TRUE;
}
static gboolean
@ -766,14 +772,7 @@ do_disconnect (PinosStream *stream)
{
PinosStreamPrivate *priv = stream->priv;
g_dbus_proxy_call (priv->channel,
"Remove",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
on_channel_removed,
stream);
pinos_node_remove (priv->node);
return FALSE;
}
@ -795,7 +794,7 @@ pinos_stream_disconnect (PinosStream *stream)
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (priv->state >= PINOS_STREAM_STATE_READY, FALSE);
g_return_val_if_fail (priv->channel != NULL, FALSE);
g_return_val_if_fail (priv->node != NULL, FALSE);
context = priv->context;
g_return_val_if_fail (pinos_context_get_state (context) >= PINOS_CONTEXT_STATE_READY, FALSE);
g_return_val_if_fail (!priv->disconnecting, FALSE);
@ -976,212 +975,6 @@ unhandle_socket (PinosStream *stream)
}
}
static void
on_stream_started (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
GUnixFDList *out_fd_list;
gint fd_idx, fd;
gchar *format;
GError *error = NULL;
GVariant *result, *properties;
result = g_dbus_proxy_call_with_unix_fd_list_finish (priv->channel,
&out_fd_list,
res,
&error);
if (result == NULL)
goto start_failed;
g_variant_get (result,
"(hs@a{sv})",
&fd_idx,
&format,
&properties);
g_variant_unref (result);
if (priv->format)
g_bytes_unref (priv->format);
priv->format = g_bytes_new_take (format, strlen (format) + 1);
g_object_notify (G_OBJECT (stream), "format");
if (priv->properties)
pinos_properties_free (priv->properties);
priv->properties = pinos_properties_from_variant (properties);
g_variant_unref (properties);
g_object_notify (G_OBJECT (stream), "properties");
if ((fd = g_unix_fd_list_get (out_fd_list, fd_idx, &error)) < 0)
goto fd_failed;
g_object_unref (out_fd_list);
handle_socket (stream, fd);
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
g_object_unref (stream);
return;
/* ERRORS */
start_failed:
{
g_warning ("failed to start: %s", error->message);
goto exit_error;
}
fd_failed:
{
g_warning ("failed to get FD: %s", error->message);
g_object_unref (out_fd_list);
goto exit_error;
}
exit_error:
{
stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream);
return;
}
}
static gboolean
do_start (PinosStream *stream)
{
PinosStreamPrivate *priv = stream->priv;
g_dbus_proxy_call (priv->channel,
"Start",
g_variant_new ("(s)", g_bytes_get_data (priv->format, NULL)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
on_stream_started,
stream);
return FALSE;
}
/**
* pinos_stream_start:
* @stream: a #PinosStream
* @format: (transfer full): a #GBytes with format
* @mode: a #PinosStreamMode
*
* Start capturing from @stream in @format.
*
* When @mode is #PINOS_STREAM_MODE_SOCKET, you should connect to the notify::socket
* signal to obtain a readable socket with metadata and data.
*
* When @mode is #PINOS_STREAM_MODE_BUFFER, you should connect to the new-buffer
* signal and use pinos_stream_capture_buffer() to get the latest metadata and
* data.
*
* Returns: %TRUE on success.
*/
gboolean
pinos_stream_start (PinosStream *stream,
GBytes *format,
PinosStreamMode mode)
{
PinosStreamPrivate *priv;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_READY, FALSE);
priv->mode = mode;
priv->format = format;
stream_set_state (stream, PINOS_STREAM_STATE_STARTING, NULL);
g_main_context_invoke (priv->context->priv->context,
(GSourceFunc) do_start,
g_object_ref (stream));
return TRUE;
}
static void
on_stream_stopped (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
GVariant *ret;
GError *error = NULL;
ret = g_dbus_proxy_call_finish (priv->channel, res, &error);
if (ret == NULL)
goto call_failed;
g_variant_unref (ret);
unhandle_socket (stream);
g_clear_pointer (&priv->format, g_bytes_unref);
g_object_notify (G_OBJECT (stream), "format");
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
g_object_unref (stream);
return;
/* ERRORS */
call_failed:
{
g_warning ("failed to release: %s", error->message);
stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream);
return;
}
}
static gboolean
do_stop (PinosStream *stream)
{
PinosStreamPrivate *priv = stream->priv;
g_dbus_proxy_call (priv->channel,
"Stop",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
on_stream_stopped,
stream);
return FALSE;
}
/**
* pinos_stream_stop:
* @stream: a #PinosStream
*
* Stop capturing from @stream.
*
* Returns: %TRUE on success.
*/
gboolean
pinos_stream_stop (PinosStream *stream)
{
PinosStreamPrivate *priv;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_STREAMING, FALSE);
g_main_context_invoke (priv->context->priv->context,
(GSourceFunc) do_stop,
g_object_ref (stream));
return TRUE;
}
/**
* pinos_stream_peek_buffer:
* @stream: a #PinosStream

View file

@ -111,9 +111,6 @@ notify_event (PinosSubscribe *subscribe,
else if (g_strcmp0 (interface_name, "org.pinos.Port1") == 0) {
flags = PINOS_SUBSCRIPTION_FLAG_PORT;
}
else if (g_strcmp0 (interface_name, "org.pinos.Channel1") == 0) {
flags = PINOS_SUBSCRIPTION_FLAG_CHANNEL;
}
g_signal_emit (subscribe, signals[SIGNAL_SUBSCRIPTION_EVENT], 0,
event, flags, data->proxy);
}

View file

@ -48,11 +48,10 @@ typedef enum {
PINOS_SUBSCRIPTION_FLAG_DAEMON = (1 << 0),
PINOS_SUBSCRIPTION_FLAG_CLIENT = (1 << 1),
PINOS_SUBSCRIPTION_FLAG_NODE = (1 << 2),
PINOS_SUBSCRIPTION_FLAG_PORT = (1 << 3),
PINOS_SUBSCRIPTION_FLAG_CHANNEL = (1 << 4),
PINOS_SUBSCRIPTION_FLAG_PORT = (1 << 3)
} PinosSubscriptionFlags;
#define PINOS_SUBSCRIPTION_FLAGS_ALL 0x1f
#define PINOS_SUBSCRIPTION_FLAGS_ALL 0x0f
typedef enum {
PINOS_SUBSCRIPTION_EVENT_NEW = 0,