Work on main loop

Make a main-loop object with associated helper functions to handle async
methods.
rtloop -> data_loop
Handle async results a lot better.
Remove REMOVE_MEM command. We don't need it.
Handle stream memory updates better.
This commit is contained in:
Wim Taymans 2016-10-20 16:26:55 +02:00
parent 98dbb6424d
commit 8fac22afdb
26 changed files with 926 additions and 583 deletions

View file

@ -1111,8 +1111,6 @@ parse_connection (SpaProxy *this)
case PINOS_CONTROL_CMD_ADD_MEM:
break;
case PINOS_CONTROL_CMD_REMOVE_MEM:
break;
case PINOS_CONTROL_CMD_USE_BUFFERS:
break;
@ -1152,7 +1150,6 @@ parse_rtconnection (SpaProxy *this)
case PINOS_CONTROL_CMD_SET_PROPERTY:
case PINOS_CONTROL_CMD_NODE_COMMAND:
case PINOS_CONTROL_CMD_ADD_MEM:
case PINOS_CONTROL_CMD_REMOVE_MEM:
case PINOS_CONTROL_CMD_USE_BUFFERS:
spa_log_error (this->log, "proxy %p: got unexpected connection %d\n", this, cmd);
break;

View file

@ -33,7 +33,8 @@
#include "pinos/server/dbus-client-node.h"
#include "pinos/server/client.h"
#include "pinos/server/link.h"
#include "pinos/server/rt-loop.h"
#include "pinos/server/data-loop.h"
#include "pinos/server/main-loop.h"
#include "pinos/dbus/org-pinos.h"
@ -52,7 +53,8 @@ struct _PinosDaemonPrivate
GList *nodes;
GHashTable *clients;
PinosRTLoop *loop;
PinosDataLoop *data_loop;
PinosMainLoop *main_loop;
PinosProperties *properties;
@ -60,7 +62,6 @@ struct _PinosDaemonPrivate
SpaSupport support[4];
SpaLog log;
SpaPoll main_loop;
};
enum
@ -71,6 +72,7 @@ enum
PROP_OBJECT_PATH,
};
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this);
static void
handle_client_appeared (PinosClient *client, gpointer user_data)
@ -197,27 +199,30 @@ no_node:
}
}
static void
on_node_remove_signal (PinosNode *node,
PinosDaemon *daemon)
PinosDaemon *this)
{
g_debug ("daemon %p: node %p remove", daemon, node);
g_debug ("daemon %p: node %p remove", this, node);
}
static void
on_link_input_unlinked (PinosLink *link,
PinosPort *port,
PinosDaemon *daemon)
PinosDaemon *this)
{
g_debug ("daemon %p: link %p: input unlinked", daemon, link);
g_debug ("daemon %p: link %p: input unlinked", this, link);
}
static void
on_link_output_unlinked (PinosLink *link,
PinosPort *port,
PinosDaemon *daemon)
PinosDaemon *this)
{
g_debug ("daemon %p: link %p: output unlinked", daemon, link);
g_debug ("daemon %p: link %p: output unlinked", this, link);
try_link_port (link->input->node, link->input, this);
}
static void
@ -245,6 +250,7 @@ on_link_state_notify (GObject *obj,
case PINOS_LINK_STATE_UNLINKED:
g_debug ("daemon %p: link %p: unlinked", daemon, link);
#if 0
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_NODE_LINK,
@ -254,6 +260,7 @@ on_link_state_notify (GObject *obj,
pinos_node_report_error (link->input->node, g_error_copy (error));
if (link->output && link->output->node)
pinos_node_report_error (link->output->node, g_error_copy (error));
#endif
break;
case PINOS_LINK_STATE_INIT:
@ -266,14 +273,13 @@ on_link_state_notify (GObject *obj,
}
static void
on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
{
PinosClient *client;
PinosProperties *props;
const gchar *path;
GError *error = NULL;
PinosLink *link;
PinosDirection direction = port->direction;
props = pinos_node_get_properties (node);
if (props == NULL)
@ -285,16 +291,15 @@ on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
PinosPort *target;
target = pinos_daemon_find_port (this,
pinos_direction_reverse (direction),
port,
path,
NULL,
0,
NULL,
&error);
if (target == NULL)
goto error;
if (direction == PINOS_DIRECTION_OUTPUT)
if (port->direction == PINOS_DIRECTION_OUTPUT)
link = pinos_node_link (node, port, target, NULL, NULL, &error);
else
link = pinos_node_link (target->node, target, port, NULL, NULL, &error);
@ -306,10 +311,10 @@ on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
if (client)
pinos_client_add_object (client, G_OBJECT (link));
g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, daemon);
g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, daemon);
g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, daemon);
g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, daemon);
g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, this);
g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, this);
g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, this);
g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, this);
pinos_link_activate (link);
g_object_unref (link);
@ -324,26 +329,32 @@ error:
}
static void
on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *daemon)
on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
{
try_link_port (node, port, this);
}
static void
on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *this)
{
}
static void
on_node_created (PinosNode *node,
PinosDaemon *daemon)
PinosDaemon *this)
{
GList *ports, *walk;
ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
for (walk = ports; walk; walk = g_list_next (walk))
on_port_added (node, walk->data, daemon);
on_port_added (node, walk->data, this);
ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
for (walk = ports; walk; walk = g_list_next (walk))
on_port_added (node, walk->data, daemon);
on_port_added (node, walk->data, this);
g_signal_connect (node, "port-added", (GCallback) on_port_added, daemon);
g_signal_connect (node, "port-removed", (GCallback) on_port_removed, daemon);
g_signal_connect (node, "port-added", (GCallback) on_port_added, this);
g_signal_connect (node, "port-removed", (GCallback) on_port_removed, this);
}
@ -351,14 +362,14 @@ static void
on_node_state_change (PinosNode *node,
PinosNodeState old,
PinosNodeState state,
PinosDaemon *daemon)
PinosDaemon *this)
{
g_debug ("daemon %p: node %p state change %s -> %s", daemon, node,
g_debug ("daemon %p: node %p state change %s -> %s", this, node,
pinos_node_state_as_string (old),
pinos_node_state_as_string (state));
if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
on_node_created (node, daemon);
on_node_created (node, this);
}
static void
@ -369,7 +380,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node)
g_debug ("daemon %p: node %p added", daemon, node);
g_object_set (node, "rt-loop", priv->loop, NULL);
g_object_set (node, "data-loop", priv->data_loop, NULL);
g_signal_connect (node, "state-change", (GCallback) on_node_state_change, daemon);
@ -727,6 +738,7 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
/**
* pinos_daemon_find_port:
* @daemon: a #PinosDaemon
* @other_port: a port to be compatible with
* @name: a port name
* @props: port properties
* @format_filter: a format filter
@ -738,11 +750,10 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
*/
PinosPort *
pinos_daemon_find_port (PinosDaemon *daemon,
PinosDirection direction,
PinosPort *other_port,
const gchar *name,
PinosProperties *props,
unsigned int n_format_filters,
SpaFormat **format_filters,
GPtrArray *format_filters,
GError **error)
{
PinosDaemonPrivate *priv;
@ -766,7 +777,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
if (g_str_has_suffix (pinos_node_get_object_path (n), name)) {
g_debug ("name \"%s\" matches node %p", name, n);
best = pinos_node_get_free_port (n, direction);
best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction));
if (best)
break;
}
@ -873,7 +884,7 @@ pinos_daemon_finalize (GObject * object)
g_debug ("daemon %p: finalize", object);
g_clear_object (&priv->server_manager);
g_clear_object (&priv->iface);
g_clear_object (&priv->loop);
g_clear_object (&priv->data_loop);
g_hash_table_unref (priv->clients);
g_hash_table_unref (priv->node_factories);
@ -962,74 +973,6 @@ do_log (SpaLog *log,
va_end (args);
}
typedef struct {
PinosDaemonPrivate *priv;
SpaPollItem item;
} PollData;
static gboolean
poll_event (GIOChannel *source,
GIOCondition condition,
gpointer user_data)
{
PollData *data = user_data;
SpaPollNotifyData d;
d.user_data = data->item.user_data;
d.fds = data->item.fds;
d.fds[0].revents = condition;
d.n_fds = data->item.n_fds;
data->item.after_cb (&d);
return TRUE;
}
static SpaResult
do_add_item (SpaPoll *poll,
SpaPollItem *item)
{
PinosDaemonPrivate *priv = SPA_CONTAINER_OF (poll, PinosDaemonPrivate, main_loop);
GIOChannel *channel;
GSource *source;
PollData data;
channel = g_io_channel_unix_new (item->fds[0].fd);
source = g_io_create_watch (channel, G_IO_IN);
g_io_channel_unref (channel);
data.priv = priv;
data.item = *item;
g_source_set_callback (source, (GSourceFunc) poll_event, g_slice_dup (PollData, &data) , NULL);
item->id = g_source_attach (source, g_main_context_get_thread_default ());
g_source_unref (source);
g_debug ("added main poll %d", item->id);
return SPA_RESULT_OK;
}
static SpaResult
do_update_item (SpaPoll *poll,
SpaPollItem *item)
{
g_debug ("update main poll %d", item->id);
return SPA_RESULT_OK;
}
static SpaResult
do_remove_item (SpaPoll *poll,
SpaPollItem *item)
{
GSource *source;
g_debug ("remove main poll %d", item->id);
source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id);
g_source_destroy (source);
return SPA_RESULT_OK;
}
static void
pinos_daemon_init (PinosDaemon * daemon)
{
@ -1047,13 +990,9 @@ pinos_daemon_init (PinosDaemon * daemon)
g_str_equal,
g_free,
g_object_unref);
priv->loop = pinos_rtloop_new();
daemon->main_loop = pinos_main_loop_new();
priv->main_loop.size = sizeof (SpaPoll);
priv->main_loop.info = NULL;
priv->main_loop.add_item = do_add_item;
priv->main_loop.update_item = do_update_item;
priv->main_loop.remove_item = do_remove_item;
priv->data_loop = pinos_data_loop_new();
priv->log.size = sizeof (SpaLog);
priv->log.info = NULL;
@ -1069,9 +1008,9 @@ pinos_daemon_init (PinosDaemon * daemon)
priv->support[1].uri = SPA_LOG_URI;
priv->support[1].data = daemon->log;
priv->support[2].uri = SPA_POLL__DataLoop;
priv->support[2].data = &priv->loop->poll;
priv->support[2].data = &priv->data_loop->poll;
priv->support[3].uri = SPA_POLL__MainLoop;
priv->support[3].data = &priv->main_loop;
priv->support[3].data = &daemon->main_loop->poll;
daemon->support = priv->support;
daemon->n_support = 4;
}

View file

@ -42,6 +42,7 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
#include <spa/include/spa/id-map.h>
#include <pinos/server/node.h>
#include <pinos/server/node-factory.h>
#include <pinos/server/main-loop.h>
#include <pinos/client/properties.h>
/**
@ -55,6 +56,8 @@ struct _PinosDaemon {
SpaIDMap *map;
SpaLog *log;
PinosMainLoop *main_loop;
SpaSupport *support;
unsigned int n_support;
@ -86,11 +89,10 @@ void pinos_daemon_add_node (PinosDaemon *daemon, PinosNode
void pinos_daemon_remove_node (PinosDaemon *daemon, PinosNode *node);
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
PinosDirection direction,
PinosPort *other_port,
const gchar *name,
PinosProperties *props,
unsigned int n_format_filters,
SpaFormat **format_filters,
GPtrArray *format_filter,
GError **error);
void pinos_daemon_add_node_factory (PinosDaemon *daemon,

View file

@ -26,12 +26,12 @@
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include "pinos/server/rt-loop.h"
#include "pinos/server/data-loop.h"
#define PINOS_RTLOOP_GET_PRIVATE(loop) \
(G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_RTLOOP, PinosRTLoopPrivate))
#define PINOS_DATA_LOOP_GET_PRIVATE(loop) \
(G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_DATA_LOOP, PinosDataLoopPrivate))
struct _PinosRTLoopPrivate
struct _PinosDataLoopPrivate
{
unsigned int n_poll;
SpaPollItem poll[16];
@ -45,7 +45,7 @@ struct _PinosRTLoopPrivate
pthread_t thread;
};
G_DEFINE_TYPE (PinosRTLoop, pinos_rtloop, G_TYPE_OBJECT);
G_DEFINE_TYPE (PinosDataLoop, pinos_data_loop, G_TYPE_OBJECT);
enum
{
@ -60,11 +60,11 @@ enum
static void *
loop (void *user_data)
{
PinosRTLoop *this = user_data;
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoop *this = user_data;
PinosDataLoopPrivate *priv = this->priv;
unsigned int i, j;
g_debug ("rt-loop %p: enter thread", this);
g_debug ("data-loop %p: enter thread", this);
while (priv->running) {
SpaPollNotifyData ndata;
unsigned int n_idle = 0;
@ -87,7 +87,7 @@ loop (void *user_data)
/* rebuild */
if (priv->rebuild_fds) {
g_debug ("rt-loop %p: rebuild fds", this);
g_debug ("data-loop %p: rebuild fds", this);
priv->n_fds = 1;
for (i = 0; i < priv->n_poll; i++) {
SpaPollItem *p = &priv->poll[i];
@ -122,7 +122,7 @@ loop (void *user_data)
break;
}
if (r == 0) {
g_debug ("rt-loop %p: select timeout", this);
g_debug ("data-loop %p: select timeout", this);
break;
}
@ -130,7 +130,7 @@ loop (void *user_data)
if (priv->fds[0].revents & POLLIN) {
uint64_t u;
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
g_warning ("rt-loop %p: failed to read fd", strerror (errno));
g_warning ("data-loop %p: failed to read fd", strerror (errno));
continue;
}
@ -146,40 +146,40 @@ loop (void *user_data)
}
}
}
g_debug ("rt-loop %p: leave thread", this);
g_debug ("data-loop %p: leave thread", this);
return NULL;
}
static void
wakeup_thread (PinosRTLoop *this)
wakeup_thread (PinosDataLoop *this)
{
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoopPrivate *priv = this->priv;
uint64_t u = 1;
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
g_warning ("rt-loop %p: failed to write fd", strerror (errno));
g_warning ("data-loop %p: failed to write fd", strerror (errno));
}
static void
start_thread (PinosRTLoop *this)
start_thread (PinosDataLoop *this)
{
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoopPrivate *priv = this->priv;
int err;
if (!priv->running) {
priv->running = true;
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) {
g_warning ("rt-loop %p: can't create thread", strerror (err));
g_warning ("data-loop %p: can't create thread", strerror (err));
priv->running = false;
}
}
}
static void
stop_thread (PinosRTLoop *this, gboolean in_thread)
stop_thread (PinosDataLoop *this, gboolean in_thread)
{
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoopPrivate *priv = this->priv;
if (priv->running) {
priv->running = false;
@ -194,12 +194,12 @@ static SpaResult
do_add_item (SpaPoll *poll,
SpaPollItem *item)
{
PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv;
gboolean in_thread = pthread_equal (priv->thread, pthread_self());
unsigned int i;
g_debug ("rt-loop %p: %d: add pollid %d, n_poll %d, n_fds %d", this, in_thread, item->id, priv->n_poll, item->n_fds);
g_debug ("data-loop %p: %d: add pollid %d, n_poll %d, n_fds %d", this, in_thread, item->id, priv->n_poll, item->n_fds);
priv->poll[priv->n_poll] = *item;
priv->n_poll++;
if (item->n_fds)
@ -221,8 +221,8 @@ static SpaResult
do_update_item (SpaPoll *poll,
SpaPollItem *item)
{
PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv;
gboolean in_thread = pthread_equal (priv->thread, pthread_self());
unsigned int i;
@ -243,12 +243,12 @@ static SpaResult
do_remove_item (SpaPoll *poll,
SpaPollItem *item)
{
PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv;
gboolean in_thread = pthread_equal (priv->thread, pthread_self());
unsigned int i;
g_debug ("rt-loop %p: remove poll %d %d", this, item->n_fds, priv->n_poll);
g_debug ("data-loop %p: remove poll %d %d", this, item->n_fds, priv->n_poll);
for (i = 0; i < priv->n_poll; i++) {
if (priv->poll[i].id == item->id && priv->poll[i].user_data == item->user_data) {
priv->n_poll--;
@ -273,14 +273,14 @@ do_remove_item (SpaPoll *poll,
}
static void
pinos_rtloop_constructed (GObject * obj)
pinos_data_loop_constructed (GObject * obj)
{
PinosRTLoop *this = PINOS_RTLOOP (obj);
PinosRTLoopPrivate *priv = this->priv;
PinosDataLoop *this = PINOS_DATA_LOOP (obj);
PinosDataLoopPrivate *priv = this->priv;
g_debug ("rt-loop %p: constructed", this);
g_debug ("data-loop %p: constructed", this);
G_OBJECT_CLASS (pinos_rtloop_parent_class)->constructed (obj);
G_OBJECT_CLASS (pinos_data_loop_parent_class)->constructed (obj);
priv->fds[0].fd = eventfd (0, 0);
priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
@ -289,44 +289,44 @@ pinos_rtloop_constructed (GObject * obj)
}
static void
pinos_rtloop_dispose (GObject * obj)
pinos_data_loop_dispose (GObject * obj)
{
PinosRTLoop *this = PINOS_RTLOOP (obj);
PinosDataLoop *this = PINOS_DATA_LOOP (obj);
g_debug ("rt-loop %p: dispose", this);
g_debug ("data-loop %p: dispose", this);
stop_thread (this, FALSE);
G_OBJECT_CLASS (pinos_rtloop_parent_class)->dispose (obj);
G_OBJECT_CLASS (pinos_data_loop_parent_class)->dispose (obj);
}
static void
pinos_rtloop_finalize (GObject * obj)
pinos_data_loop_finalize (GObject * obj)
{
PinosRTLoop *this = PINOS_RTLOOP (obj);
PinosDataLoop *this = PINOS_DATA_LOOP (obj);
g_debug ("rt-loop %p: finalize", this);
g_debug ("data-loop %p: finalize", this);
G_OBJECT_CLASS (pinos_rtloop_parent_class)->finalize (obj);
G_OBJECT_CLASS (pinos_data_loop_parent_class)->finalize (obj);
}
static void
pinos_rtloop_class_init (PinosRTLoopClass * klass)
pinos_data_loop_class_init (PinosDataLoopClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PinosRTLoopPrivate));
g_type_class_add_private (klass, sizeof (PinosDataLoopPrivate));
gobject_class->constructed = pinos_rtloop_constructed;
gobject_class->dispose = pinos_rtloop_dispose;
gobject_class->finalize = pinos_rtloop_finalize;
gobject_class->constructed = pinos_data_loop_constructed;
gobject_class->dispose = pinos_data_loop_dispose;
gobject_class->finalize = pinos_data_loop_finalize;
}
static void
pinos_rtloop_init (PinosRTLoop * this)
pinos_data_loop_init (PinosDataLoop * this)
{
this->priv = PINOS_RTLOOP_GET_PRIVATE (this);
this->priv = PINOS_DATA_LOOP_GET_PRIVATE (this);
g_debug ("rt-loop %p: new", this);
g_debug ("data-loop %p: new", this);
this->poll.size = sizeof (SpaPoll);
this->poll.info = NULL;
@ -336,14 +336,14 @@ pinos_rtloop_init (PinosRTLoop * this)
}
/**
* pinos_rtloop_new:
* pinos_data_loop_new:
*
* Create a new #PinosRTLoop.
* Create a new #PinosDataLoop.
*
* Returns: a new #PinosRTLoop
* Returns: a new #PinosDataLoop
*/
PinosRTLoop *
pinos_rtloop_new (void)
PinosDataLoop *
pinos_data_loop_new (void)
{
return g_object_new (PINOS_TYPE_RTLOOP, NULL);
return g_object_new (PINOS_TYPE_DATA_LOOP, NULL);
}

71
pinos/server/data-loop.h Normal file
View file

@ -0,0 +1,71 @@
/* Pinos
* Copyright (C) 2016 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 __PINOS_DATA_LOOP_H__
#define __PINOS_DATA_LOOP_H__
#include <glib-object.h>
G_BEGIN_DECLS
#include <spa/include/spa/poll.h>
typedef struct _PinosDataLoop PinosDataLoop;
typedef struct _PinosDataLoopClass PinosDataLoopClass;
typedef struct _PinosDataLoopPrivate PinosDataLoopPrivate;
#define PINOS_TYPE_DATA_LOOP (pinos_data_loop_get_type ())
#define PINOS_IS_DATA_LOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_DATA_LOOP))
#define PINOS_IS_DATA_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_DATA_LOOP))
#define PINOS_DATA_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_DATA_LOOP, PinosDataLoopClass))
#define PINOS_DATA_LOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_DATA_LOOP, PinosDataLoop))
#define PINOS_DATA_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_DATA_LOOP, PinosDataLoopClass))
#define PINOS_DATA_LOOP_CAST(obj) ((PinosDataLoop*)(obj))
#define PINOS_DATA_LOOP_CLASS_CAST(klass) ((PinosDataLoopClass*)(klass))
/**
* PinosDataLoop:
*
* Pinos rt-loop class.
*/
struct _PinosDataLoop {
GObject object;
SpaPoll poll;
PinosDataLoopPrivate *priv;
};
/**
* PinosDataLoopClass:
*
* Pinos rt-loop class.
*/
struct _PinosDataLoopClass {
GObjectClass parent_class;
};
/* normal GObject stuff */
GType pinos_data_loop_get_type (void);
PinosDataLoop * pinos_data_loop_new (void);
G_END_DECLS
#endif /* __PINOS_DATA_LOOP_H__ */

View file

@ -46,11 +46,11 @@ struct _PinosLinkPrivate
GPtrArray *format_filter;
PinosProperties *properties;
PinosMainLoop *main_loop;
PinosLinkState state;
GError *error;
uint32_t async_busy;
gboolean allocated;
PinosMemblock buffer_mem;
SpaBuffer **buffers;
@ -656,29 +656,24 @@ do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (in_state == SPA_NODE_STATE_PAUSED) {
pinos_node_set_state (this->input->node, PINOS_NODE_STATE_RUNNING);
if (pinos_node_get_state (this->input->node) != PINOS_NODE_STATE_RUNNING)
res = SPA_RESULT_RETURN_ASYNC (0);
}
if (out_state == SPA_NODE_STATE_PAUSED) {
pinos_node_set_state (this->output->node, PINOS_NODE_STATE_RUNNING);
if (pinos_node_get_state (this->output->node) != PINOS_NODE_STATE_RUNNING)
res = SPA_RESULT_RETURN_ASYNC (0);
}
}
return res;
}
static SpaResult
check_states (PinosLink *this)
check_states (PinosLink *this, SpaResult res)
{
PinosLinkPrivate *priv = this->priv;
SpaResult res;
SpaNodeState in_state, out_state;
PinosLinkPrivate *priv = this->priv;
again:
if (priv->async_busy != SPA_ID_INVALID)
return SPA_RESULT_OK;
if (this->input == NULL || this->output == NULL)
return SPA_RESULT_OK;
in_state = this->input->node->node->state;
out_state = this->output->node->node->state;
@ -702,30 +697,19 @@ again:
return SPA_RESULT_OK;
exit:
if (SPA_RESULT_IS_ASYNC (res)) {
priv->async_busy = SPA_RESULT_ASYNC_SEQ (res);
g_debug ("link %p: waiting for async complete %d", this, priv->async_busy);
}
pinos_main_loop_defer (priv->main_loop, this, res, (PinosDeferFunc) check_states, this, NULL);
return res;
}
static gboolean
do_check_states (PinosLink *this)
{
PinosLinkPrivate *priv = this->priv;
priv->async_busy = SPA_ID_INVALID;
check_states (this);
return G_SOURCE_REMOVE;
}
static void
on_async_complete_notify (PinosNode *node,
guint seq,
guint res,
PinosLink *this)
{
PinosLinkPrivate *priv = this->priv;
g_debug ("link %p: node %p async complete %d %d", this, node, seq, res);
g_idle_add ((GSourceFunc) do_check_states, this);
pinos_main_loop_defer_complete (priv->main_loop, this, seq, res);
}
static void
@ -756,28 +740,75 @@ on_property_notify (GObject *obj,
}
}
typedef struct {
PinosLink *link;
PinosPort *port;
} UnlinkedData;
static void
on_input_unlinked (UnlinkedData *data)
{
g_signal_emit (data->link, signals[SIGNAL_INPUT_UNLINKED], 0, data->port);
}
static void
on_output_unlinked (UnlinkedData *data)
{
g_signal_emit (data->link, signals[SIGNAL_OUTPUT_UNLINKED], 0, data->port);
}
static void
on_node_remove (PinosNode *node, PinosLink *this)
{
PinosLinkPrivate *priv = this->priv;
SpaResult res = SPA_RESULT_OK;
UnlinkedData data;
data.link = this;
g_signal_handlers_disconnect_by_data (node, this);
if (node == this->input->node) {
if (this->input->allocated) {
priv->buffers = NULL;
priv->n_buffers = 0;
if ((res = spa_node_port_use_buffers (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
priv->buffers,
priv->n_buffers)) < 0) {
g_warning ("link %p: failed to clear output buffers: %d", this, res);
}
}
data.port = this->input;
this->input = NULL;
g_object_notify (G_OBJECT (this), "input-port");
g_signal_emit (this, signals[SIGNAL_INPUT_UNLINKED], 0, node);
pinos_main_loop_defer (priv->main_loop,
this,
res,
(PinosDeferFunc) on_input_unlinked,
g_memdup (&data, sizeof (UnlinkedData)),
g_free);
} else {
if (this->output->allocated) {
priv->buffers = NULL;
priv->n_buffers = 0;
if ((res = spa_node_port_use_buffers (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
priv->buffers,
priv->n_buffers)) < 0) {
g_warning ("link %p: failed to clear input buffers: %d", this, res);
}
}
data.port = this->output;
this->output = NULL;
g_object_notify (G_OBJECT (this), "output-port");
g_signal_emit (this, signals[SIGNAL_OUTPUT_UNLINKED], 0, node);
pinos_main_loop_defer (priv->main_loop,
this,
res,
(PinosDeferFunc) on_output_unlinked,
g_memdup (&data, sizeof (UnlinkedData)),
g_free);
}
if (this->input == NULL || this->output == NULL)
@ -788,6 +819,9 @@ static void
pinos_link_constructed (GObject * object)
{
PinosLink *this = PINOS_LINK (object);
PinosLinkPrivate *priv = this->priv;
priv->main_loop = priv->daemon->main_loop;
g_signal_connect (this->input->node, "remove", (GCallback) on_node_remove, this);
g_signal_connect (this->output->node, "remove", (GCallback) on_node_remove, this);
@ -1031,7 +1065,7 @@ pinos_link_activate (PinosLink *this)
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
spa_ringbuffer_init (&this->ringbuffer, SPA_N_ELEMENTS (this->queue));
check_states (this);
check_states (this, SPA_RESULT_OK);
return TRUE;
}

View file

@ -30,6 +30,7 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
#include <pinos/server/daemon.h>
#include <pinos/server/utils.h>
#include <pinos/server/main-loop.h>
#include <spa/include/spa/ringbuffer.h>
#define PINOS_TYPE_LINK (pinos_link_get_type ())

313
pinos/server/main-loop.c Normal file
View file

@ -0,0 +1,313 @@
/* Pinos
* Copyright (C) 2016 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 <string.h>
#include <stdlib.h>
#include <gio/gio.h>
#include "pinos/server/main-loop.h"
#define PINOS_MAIN_LOOP_GET_PRIVATE(loop) \
(G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_MAIN_LOOP, PinosMainLoopPrivate))
struct _PinosMainLoopPrivate
{
gulong counter;
GQueue work;
gulong work_id;
};
G_DEFINE_TYPE (PinosMainLoop, pinos_main_loop, G_TYPE_OBJECT);
enum
{
PROP_0,
};
enum
{
LAST_SIGNAL
};
typedef struct {
PinosMainLoop *loop;
SpaPollItem item;
} PollData;
static gboolean
poll_event (GIOChannel *source,
GIOCondition condition,
gpointer user_data)
{
PollData *data = user_data;
SpaPollNotifyData d;
d.user_data = data->item.user_data;
d.fds = data->item.fds;
d.fds[0].revents = condition;
d.n_fds = data->item.n_fds;
data->item.after_cb (&d);
return TRUE;
}
static SpaResult
do_add_item (SpaPoll *poll,
SpaPollItem *item)
{
PinosMainLoop *this = SPA_CONTAINER_OF (poll, PinosMainLoop, poll);
GIOChannel *channel;
GSource *source;
PollData data;
channel = g_io_channel_unix_new (item->fds[0].fd);
source = g_io_create_watch (channel, G_IO_IN);
g_io_channel_unref (channel);
data.loop = this;
data.item = *item;
g_source_set_callback (source, (GSourceFunc) poll_event, g_slice_dup (PollData, &data) , NULL);
item->id = g_source_attach (source, g_main_context_get_thread_default ());
g_source_unref (source);
g_debug ("added main poll %d", item->id);
return SPA_RESULT_OK;
}
static SpaResult
do_update_item (SpaPoll *poll,
SpaPollItem *item)
{
g_debug ("update main poll %d", item->id);
return SPA_RESULT_OK;
}
static SpaResult
do_remove_item (SpaPoll *poll,
SpaPollItem *item)
{
GSource *source;
g_debug ("remove main poll %d", item->id);
source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id);
g_source_destroy (source);
return SPA_RESULT_OK;
}
static void
pinos_main_loop_constructed (GObject * obj)
{
PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
g_debug ("main-loop %p: constructed", this);
G_OBJECT_CLASS (pinos_main_loop_parent_class)->constructed (obj);
}
static void
pinos_main_loop_dispose (GObject * obj)
{
PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
g_debug ("main-loop %p: dispose", this);
G_OBJECT_CLASS (pinos_main_loop_parent_class)->dispose (obj);
}
static void
pinos_main_loop_finalize (GObject * obj)
{
PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
g_debug ("main-loop %p: finalize", this);
G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (obj);
}
static void
pinos_main_loop_class_init (PinosMainLoopClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PinosMainLoopPrivate));
gobject_class->constructed = pinos_main_loop_constructed;
gobject_class->dispose = pinos_main_loop_dispose;
gobject_class->finalize = pinos_main_loop_finalize;
}
static void
pinos_main_loop_init (PinosMainLoop * this)
{
PinosMainLoopPrivate *priv = this->priv = PINOS_MAIN_LOOP_GET_PRIVATE (this);
g_debug ("main-loop %p: new", this);
this->poll.size = sizeof (SpaPoll);
this->poll.info = NULL;
this->poll.add_item = do_add_item;
this->poll.update_item = do_update_item;
this->poll.remove_item = do_remove_item;
g_queue_init (&priv->work);
}
/**
* pinos_main_loop_new:
*
* Create a new #PinosMainLoop.
*
* Returns: a new #PinosMainLoop
*/
PinosMainLoop *
pinos_main_loop_new (void)
{
return g_object_new (PINOS_TYPE_MAIN_LOOP, NULL);
}
typedef struct {
gulong id;
gpointer obj;
uint32_t seq;
SpaResult res;
PinosDeferFunc func;
gpointer *data;
GDestroyNotify notify;
} WorkItem;
static gboolean
process_work_queue (PinosMainLoop *this)
{
PinosMainLoopPrivate *priv = this->priv;
GList *walk, *next;
for (walk = priv->work.head; walk; walk = next) {
WorkItem *item = walk->data;
next = g_list_next (walk);
g_debug ("main-loop %p: peek work queue item %p seq %d", this, item, item ? item->seq : -1);
if (item->seq != SPA_ID_INVALID)
continue;
g_debug ("main-loop %p: process work item %p", this, item);
if (item->func)
item->func (item->data, item->res, item->id);
if (item->notify)
item->notify (item->data);
g_queue_delete_link (&priv->work, walk);
g_slice_free (WorkItem, item);
}
priv->work_id = 0;
return FALSE;
}
gulong
pinos_main_loop_defer (PinosMainLoop *loop,
gpointer obj,
SpaResult res,
PinosDeferFunc func,
gpointer data,
GDestroyNotify notify)
{
PinosMainLoopPrivate *priv;
WorkItem *item;
gboolean have_work = FALSE;
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), 0);
priv = loop->priv;
item = g_slice_new (WorkItem);
item->id = ++priv->counter;
item->obj = obj;
item->func = func;
item->data = data;
item->notify = notify;
if (SPA_RESULT_IS_ASYNC (res)) {
item->seq = SPA_RESULT_ASYNC_SEQ (res);
item->res = res;
g_debug ("main-loop %p: defer async %d for object %p", loop, item->seq, obj);
} else {
item->seq = SPA_ID_INVALID;
item->res = res;
have_work = TRUE;
g_debug ("main-loop %p: defer object %p", loop, obj);
}
g_queue_push_tail (&priv->work, item);
if (priv->work_id == 0 && have_work)
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
return item->id;
}
void
pinos_main_loop_defer_cancel (PinosMainLoop *loop,
gulong id)
{
GList *walk;
PinosMainLoopPrivate *priv;
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
priv = loop->priv;
for (walk = priv->work.head; walk; walk = g_list_next (walk)) {
WorkItem *i = walk->data;
if (i->id == id) {
i->func = NULL;
}
}
}
void
pinos_main_loop_defer_complete (PinosMainLoop *loop,
gpointer obj,
uint32_t seq,
SpaResult res)
{
GList *walk;
PinosMainLoopPrivate *priv;
gboolean have_work = FALSE;
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
priv = loop->priv;
g_debug ("main-loop %p: async complete %d %d for object %p", loop, seq, res, obj);
for (walk = priv->work.head; walk; walk = g_list_next (walk)) {
WorkItem *i = walk->data;
if (i->obj == obj && i->seq == seq) {
g_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj);
i->seq = SPA_ID_INVALID;
i->res = res;
have_work = TRUE;
}
}
if (priv->work_id == 0 && have_work)
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
}

89
pinos/server/main-loop.h Normal file
View file

@ -0,0 +1,89 @@
/* Pinos
* Copyright (C) 2016 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 __PINOS_MAIN_LOOP_H__
#define __PINOS_MAIN_LOOP_H__
#include <glib-object.h>
G_BEGIN_DECLS
#include <spa/include/spa/poll.h>
typedef struct _PinosMainLoop PinosMainLoop;
typedef struct _PinosMainLoopClass PinosMainLoopClass;
typedef struct _PinosMainLoopPrivate PinosMainLoopPrivate;
#define PINOS_TYPE_MAIN_LOOP (pinos_main_loop_get_type ())
#define PINOS_IS_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_MAIN_LOOP))
#define PINOS_IS_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_MAIN_LOOP))
#define PINOS_MAIN_LOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoopClass))
#define PINOS_MAIN_LOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoop))
#define PINOS_MAIN_LOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_MAIN_LOOP, PinosMainLoopClass))
#define PINOS_MAIN_LOOP_CAST(obj) ((PinosMainLoop*)(obj))
#define PINOS_MAIN_LOOP_CLASS_CAST(klass) ((PinosMainLoopClass*)(klass))
/**
* PinosMainLoop:
*
* Pinos rt-loop class.
*/
struct _PinosMainLoop {
GObject object;
SpaPoll poll;
PinosMainLoopPrivate *priv;
};
/**
* PinosMainLoopClass:
*
* Pinos rt-loop class.
*/
struct _PinosMainLoopClass {
GObjectClass parent_class;
};
typedef void (*PinosDeferFunc) (gpointer data,
SpaResult res,
gulong id);
/* normal GObject stuff */
GType pinos_main_loop_get_type (void);
PinosMainLoop * pinos_main_loop_new (void);
gulong pinos_main_loop_defer (PinosMainLoop *loop,
gpointer obj,
SpaResult res,
PinosDeferFunc func,
gpointer data,
GDestroyNotify notify);
void pinos_main_loop_defer_cancel (PinosMainLoop *loop,
gulong id);
void pinos_main_loop_defer_complete (PinosMainLoop *loop,
gpointer obj,
uint32_t seq,
SpaResult res);
G_END_DECLS
#endif /* __PINOS_MAIN_LOOP_H__ */

View file

@ -3,12 +3,13 @@ pinoscore_headers = [
'client-node.h',
'command.h',
'daemon.h',
'data-loop.h',
'dbus-client-node.h',
'link.h',
'main-loop.h',
'module.h',
'node.h',
'node-factory.h',
'rt-loop.h',
'utils.h',
]
@ -17,12 +18,13 @@ pinoscore_sources = [
'client-node.c',
'command.c',
'daemon.c',
'data-loop.c',
'dbus-client-node.c',
'link.c',
'main-loop.c',
'module.c',
'node.c',
'node-factory.c',
'rt-loop.c',
'utils.c',
]

View file

@ -25,7 +25,8 @@
#include "pinos/client/enumtypes.h"
#include "pinos/server/node.h"
#include "pinos/server/rt-loop.h"
#include "pinos/server/data-loop.h"
#include "pinos/server/main-loop.h"
#include "pinos/server/daemon.h"
#include "pinos/dbus/org-pinos.h"
@ -89,11 +90,8 @@ struct _PinosNodePrivate
PinosProperties *properties;
PinosRTLoop *loop;
SpaNodeEventAsyncComplete ac;
uint32_t pending_state_seq;
PinosNodeState pending_state;
PinosDataLoop *data_loop;
PinosMainLoop *main_loop;
};
G_DEFINE_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
@ -103,7 +101,7 @@ enum
PROP_0,
PROP_DAEMON,
PROP_CLIENT,
PROP_RTLOOP,
PROP_DATA_LOOP,
PROP_OBJECT_PATH,
PROP_NAME,
PROP_PROPERTIES,
@ -330,12 +328,24 @@ send_clock_update (PinosNode *this)
g_debug ("got error %d", res);
}
typedef struct {
PinosNode *node;
PinosNodeState state;
} StateData;
static void
on_state_complete (StateData *data)
{
pinos_node_update_state (data->node, data->state);
}
static gboolean
node_set_state (PinosNode *this,
PinosNodeState state)
{
PinosNodePrivate *priv = this->priv;
SpaResult res = SPA_RESULT_OK;
StateData data;
g_debug ("node %p: set state %s", this, pinos_node_state_as_string (state));
@ -365,12 +375,15 @@ node_set_state (PinosNode *this,
if (SPA_RESULT_IS_ERROR (res))
return FALSE;
if (SPA_RESULT_IS_ASYNC (res)) {
priv->pending_state_seq = SPA_RESULT_ASYNC_SEQ (res);
priv->pending_state = state;
} else {
pinos_node_update_state (this, state);
}
data.node = this;
data.state = state;
pinos_main_loop_defer (priv->main_loop,
this,
res,
(PinosDeferFunc) on_state_complete,
g_memdup (&data, sizeof (StateData)),
g_free);
return TRUE;
}
@ -387,7 +400,7 @@ do_read_link (PinosNode *this, PinosLink *link)
if (areas[0].len > 0) {
SpaPortInputInfo iinfo[1];
if (link->in_ready <= 0)
if (link->in_ready <= 0 || link->input == NULL)
return FALSE;
link->in_ready--;
@ -406,24 +419,6 @@ do_read_link (PinosNode *this, PinosLink *link)
return pushed;
}
static void
do_handle_async_complete (PinosNode *this)
{
PinosNodePrivate *priv = this->priv;
SpaNodeEventAsyncComplete *ac = &priv->ac;
g_debug ("node %p: async complete %u %d", this, ac->seq, ac->res);
if (priv->async_init) {
init_complete (this);
priv->async_init = FALSE;
}
if (priv->pending_state_seq == ac->seq) {
pinos_node_update_state (this, priv->pending_state);
}
g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
}
static void
on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
{
@ -443,10 +438,9 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
{
SpaNodeEventAsyncComplete *ac = event->data;
priv->ac = *ac;
g_main_context_invoke (NULL,
(GSourceFunc) do_handle_async_complete,
this);
g_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res);
pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res);
g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
break;
}
@ -518,6 +512,9 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
for (i = 0; i < p->links->len; i++) {
PinosLink *link = g_ptr_array_index (p->links, i);
if (link->output == NULL)
continue;
if ((res = spa_node_port_reuse_buffer (link->output->node->node,
link->output->port,
rb->buffer_id)) < 0)
@ -564,8 +561,8 @@ pinos_node_get_property (GObject *_object,
g_value_set_object (value, priv->client);
break;
case PROP_RTLOOP:
g_value_set_object (value, priv->loop);
case PROP_DATA_LOOP:
g_value_set_object (value, priv->data_loop);
break;
case PROP_OBJECT_PATH:
@ -612,15 +609,15 @@ pinos_node_set_property (GObject *_object,
priv->client = g_value_get_object (value);
break;
case PROP_RTLOOP:
case PROP_DATA_LOOP:
{
SpaResult res;
if (priv->loop)
g_object_unref (priv->loop);
priv->loop = g_value_dup_object (value);
if (priv->data_loop)
g_object_unref (priv->data_loop);
priv->data_loop = g_value_dup_object (value);
if (priv->loop) {
if (priv->data_loop) {
if ((res = spa_node_set_event_callback (this->node, on_node_event, this)) < 0)
g_warning ("node %p: error setting callback", this);
}
@ -640,13 +637,6 @@ pinos_node_set_property (GObject *_object,
case PROP_NODE:
{
this->node = g_value_get_pointer (value);
#if 0
void *iface;
if (this->node->handle->get_interface (this->node->handle,
spa_id_map_get_id (priv->daemon->map, SPA_CLOCK_URI),
&iface) >= 0)
this->clock = iface;
#endif
break;
}
case PROP_CLOCK:
@ -734,6 +724,8 @@ pinos_node_constructed (GObject * obj)
g_debug ("node %p: constructed", this);
priv->main_loop = priv->daemon->main_loop;
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
@ -753,6 +745,12 @@ pinos_node_constructed (GObject * obj)
init_complete (this);
} else {
priv->async_init = TRUE;
pinos_main_loop_defer (priv->main_loop,
this,
SPA_RESULT_RETURN_ASYNC (0),
(PinosDeferFunc) init_complete,
this,
NULL);
}
node_register_object (this);
}
@ -780,7 +778,7 @@ pinos_node_finalize (GObject * obj)
g_debug ("node %p: finalize", node);
g_clear_object (&priv->daemon);
g_clear_object (&priv->iface);
g_clear_object (&priv->loop);
g_clear_object (&priv->data_loop);
g_free (priv->name);
g_clear_error (&priv->error);
if (priv->properties)
@ -869,11 +867,11 @@ pinos_node_class_init (PinosNodeClass * klass)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_RTLOOP,
g_param_spec_object ("rt-loop",
"RTLoop",
"The RTLoop",
PINOS_TYPE_RTLOOP,
PROP_DATA_LOOP,
g_param_spec_object ("data-loop",
"Data Loop",
"The Data Loop",
PINOS_TYPE_DATA_LOOP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
@ -945,7 +943,6 @@ pinos_node_init (PinosNode * node)
(GCallback) handle_remove,
node);
priv->state = PINOS_NODE_STATE_CREATING;
priv->pending_state_seq = SPA_ID_INVALID;
pinos_node1_set_state (priv->iface, priv->state);
}

View file

@ -1,79 +0,0 @@
/* Pinos
* Copyright (C) 2016 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 __PINOS_RTLOOP_H__
#define __PINOS_RTLOOP_H__
#include <glib-object.h>
G_BEGIN_DECLS
#include <spa/include/spa/poll.h>
typedef struct _PinosRTLoop PinosRTLoop;
typedef struct _PinosRTLoopClass PinosRTLoopClass;
typedef struct _PinosRTLoopPrivate PinosRTLoopPrivate;
#define PINOS_TYPE_RTLOOP (pinos_rtloop_get_type ())
#define PINOS_IS_RTLOOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_RTLOOP))
#define PINOS_IS_RTLOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_RTLOOP))
#define PINOS_RTLOOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_RTLOOP, PinosRTLoopClass))
#define PINOS_RTLOOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_RTLOOP, PinosRTLoop))
#define PINOS_RTLOOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_RTLOOP, PinosRTLoopClass))
#define PINOS_RTLOOP_CAST(obj) ((PinosRTLoop*)(obj))
#define PINOS_RTLOOP_CLASS_CAST(klass) ((PinosRTLoopClass*)(klass))
/**
* PinosRTLoop:
*
* Pinos rt-loop class.
*/
struct _PinosRTLoop {
GObject object;
SpaPoll poll;
PinosRTLoopPrivate *priv;
};
/**
* PinosRTLoopClass:
*
* Pinos rt-loop class.
*/
struct _PinosRTLoopClass {
GObjectClass parent_class;
};
/* normal GObject stuff */
GType pinos_rtloop_get_type (void);
PinosRTLoop * pinos_rtloop_new (void);
gboolean pinos_rtloop_add_poll (PinosRTLoop *loop,
SpaPollItem *item);
gboolean pinos_rtloop_update_poll (PinosRTLoop *loop,
SpaPollItem *item);
gboolean pinos_rtloop_remove_poll (PinosRTLoop *loop,
SpaPollItem *item);
G_END_DECLS
#endif /* __PINOS_RTLOOP_H__ */