pass the client object around

Pass the client object around, it's easier to deal with than the sender
id.
Fix the ASYNC return check
Don't overwrite the fds of a pollitem, instead keep an index of their
position in the global fd array.
This commit is contained in:
Wim Taymans 2016-09-27 16:59:45 +02:00
parent 7b53fa8685
commit c6861845a7
14 changed files with 123 additions and 79 deletions

View file

@ -274,7 +274,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
/** /**
* pinos_client_node_new: * pinos_client_node_new:
* @daemon: a #PinosDaemon * @daemon: a #PinosDaemon
* @sender: the path of the owner * @client: the client owner
* @name: a name * @name: a name
* @properties: extra properties * @properties: extra properties
* *
@ -284,7 +284,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
*/ */
PinosNode * PinosNode *
pinos_client_node_new (PinosDaemon *daemon, pinos_client_node_new (PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *properties) PinosProperties *properties)
{ {
@ -302,7 +302,7 @@ pinos_client_node_new (PinosDaemon *daemon,
return g_object_new (PINOS_TYPE_CLIENT_NODE, return g_object_new (PINOS_TYPE_CLIENT_NODE,
"daemon", daemon, "daemon", daemon,
"sender", sender, "client", client,
"name", name, "name", name,
"properties", properties, "properties", properties,
"node", n, "node", n,

View file

@ -63,7 +63,7 @@ struct _PinosClientNodeClass {
GType pinos_client_node_get_type (void); GType pinos_client_node_get_type (void);
PinosNode * pinos_client_node_new (PinosDaemon *daemon, PinosNode * pinos_client_node_new (PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *properties); PinosProperties *properties);

View file

@ -22,10 +22,14 @@
#include <glib-object.h> #include <glib-object.h>
#include <pinos/server/daemon.h>
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _PinosClient PinosClient;
typedef struct _PinosClientClass PinosClientClass;
typedef struct _PinosClientPrivate PinosClientPrivate;
#include <pinos/server/daemon.h>
#define PINOS_TYPE_CLIENT (pinos_client_get_type ()) #define PINOS_TYPE_CLIENT (pinos_client_get_type ())
#define PINOS_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_CLIENT)) #define PINOS_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_CLIENT))
#define PINOS_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_CLIENT)) #define PINOS_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_CLIENT))
@ -35,10 +39,6 @@ G_BEGIN_DECLS
#define PINOS_CLIENT_CAST(obj) ((PinosClient*)(obj)) #define PINOS_CLIENT_CAST(obj) ((PinosClient*)(obj))
#define PINOS_CLIENT_CLASS_CAST(klass) ((PinosClientClass*)(klass)) #define PINOS_CLIENT_CLASS_CAST(klass) ((PinosClientClass*)(klass))
typedef struct _PinosClient PinosClient;
typedef struct _PinosClientClass PinosClientClass;
typedef struct _PinosClientPrivate PinosClientPrivate;
/** /**
* PinosClient: * PinosClient:
* *

View file

@ -45,6 +45,8 @@ struct _PinosDaemonPrivate
GDBusConnection *connection; GDBusConnection *connection;
GDBusObjectManagerServer *server_manager; GDBusObjectManagerServer *server_manager;
gchar *object_path;
GList *nodes; GList *nodes;
GHashTable *clients; GHashTable *clients;
@ -60,6 +62,7 @@ enum
PROP_0, PROP_0,
PROP_CONNECTION, PROP_CONNECTION,
PROP_PROPERTIES, PROP_PROPERTIES,
PROP_OBJECT_PATH,
}; };
static void static void
@ -135,6 +138,7 @@ handle_create_node (PinosDaemon1 *interface,
PinosProperties *props; PinosProperties *props;
sender = g_dbus_method_invocation_get_sender (invocation); sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (daemon, sender, TRUE);
g_debug ("daemon %p: create node: %s", daemon, sender); g_debug ("daemon %p: create node: %s", daemon, sender);
@ -144,12 +148,12 @@ handle_create_node (PinosDaemon1 *interface,
if (factory != NULL) { if (factory != NULL) {
node = pinos_node_factory_create_node (factory, node = pinos_node_factory_create_node (factory,
daemon, daemon,
sender, client,
arg_name, arg_name,
props); props);
} else { } else {
node = pinos_node_new (daemon, node = pinos_node_new (daemon,
sender, client,
arg_name, arg_name,
props, props,
NULL); NULL);
@ -160,7 +164,6 @@ handle_create_node (PinosDaemon1 *interface,
if (node == NULL) if (node == NULL)
goto no_node; goto no_node;
client = sender_get_client (daemon, sender, TRUE);
pinos_client_add_object (client, G_OBJECT (node)); pinos_client_add_object (client, G_OBJECT (node));
g_signal_connect (node, g_signal_connect (node,
@ -189,7 +192,7 @@ no_node:
static void static void
on_link_state_notify (GObject *obj, on_link_state_notify (GObject *obj,
GParamSpec *pspec, GParamSpec *pspec,
PinosClient *client) PinosDaemon *daemon)
{ {
PinosLink *link = PINOS_LINK (obj); PinosLink *link = PINOS_LINK (obj);
GError *error = NULL; GError *error = NULL;
@ -198,17 +201,20 @@ on_link_state_notify (GObject *obj,
state = pinos_link_get_state (link, &error); state = pinos_link_get_state (link, &error);
switch (state) { switch (state) {
case PINOS_LINK_STATE_ERROR: case PINOS_LINK_STATE_ERROR:
g_warning ("link %p: state error: %s", link, error->message); {
g_warning ("daemon %p: link %p: state error: %s", daemon, link, error->message);
if (link->input_node && pinos_client_has_object (client, G_OBJECT (link->input_node))) { if (link->input_node) {
pinos_node_report_error (link->input_node, g_error_copy (error)); pinos_node_report_error (link->input_node, g_error_copy (error));
} }
if (link->output_node && pinos_client_has_object (client, G_OBJECT (link->output_node))) { if (link->output_node) {
pinos_node_report_error (link->output_node, g_error_copy (error)); pinos_node_report_error (link->output_node, g_error_copy (error));
} }
break; break;
}
case PINOS_LINK_STATE_UNLINKED: case PINOS_LINK_STATE_UNLINKED:
g_warning ("link %p: unlinked", link); g_warning ("daemon %p: link %p: unlinked", daemon, link);
break; break;
case PINOS_LINK_STATE_INIT: case PINOS_LINK_STATE_INIT:
case PINOS_LINK_STATE_NEGOTIATING: case PINOS_LINK_STATE_NEGOTIATING:
@ -236,7 +242,6 @@ on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
path = pinos_properties_get (props, "pinos.target.node"); path = pinos_properties_get (props, "pinos.target.node");
if (path) { if (path) {
const gchar *sender;
guint target_port; guint target_port;
guint node_port; guint node_port;
@ -275,8 +280,8 @@ on_port_added (PinosNode *node, PinosDirection direction, PinosDaemon *this)
if (link == NULL) if (link == NULL)
goto error; goto error;
sender = pinos_node_get_sender (node); client = pinos_node_get_client (node);
if (sender && (client = sender_get_client (this, sender, FALSE))) { if (client) {
pinos_client_add_object (client, G_OBJECT (link)); pinos_client_add_object (client, G_OBJECT (link));
} }
@ -370,12 +375,13 @@ handle_create_client_node (PinosDaemon1 *interface,
gint fdidx; gint fdidx;
sender = g_dbus_method_invocation_get_sender (invocation); sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (daemon, sender, TRUE);
g_debug ("daemon %p: create client-node: %s", daemon, sender); g_debug ("daemon %p: create client-node: %s", daemon, sender);
props = pinos_properties_from_variant (arg_properties); props = pinos_properties_from_variant (arg_properties);
node = pinos_client_node_new (daemon, node = pinos_client_node_new (daemon,
sender, client,
arg_name, arg_name,
props); props);
pinos_properties_free (props); pinos_properties_free (props);
@ -384,7 +390,6 @@ handle_create_client_node (PinosDaemon1 *interface,
if (socket == NULL) if (socket == NULL)
goto no_socket; goto no_socket;
client = sender_get_client (daemon, sender, TRUE);
pinos_client_add_object (client, G_OBJECT (node)); pinos_client_add_object (client, G_OBJECT (node));
object_path = pinos_node_get_object_path (PINOS_NODE (node)); object_path = pinos_node_get_object_path (PINOS_NODE (node));
@ -427,6 +432,8 @@ export_server_object (PinosDaemon *daemon,
pinos_object_skeleton_set_daemon1 (skel, priv->iface); pinos_object_skeleton_set_daemon1 (skel, priv->iface);
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (skel)); g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (skel));
g_free (priv->object_path);
priv->object_path = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (skel)));
g_object_unref (skel); g_object_unref (skel);
} }
@ -464,6 +471,7 @@ name_lost_handler (GDBusConnection *connection,
g_dbus_object_manager_server_unexport (manager, PINOS_DBUS_OBJECT_SERVER); g_dbus_object_manager_server_unexport (manager, PINOS_DBUS_OBJECT_SERVER);
g_dbus_object_manager_server_set_connection (manager, connection); g_dbus_object_manager_server_set_connection (manager, connection);
g_clear_pointer (&priv->object_path, g_free);
priv->connection = connection; priv->connection = connection;
} }
@ -482,20 +490,14 @@ pinos_daemon_new (PinosProperties *properties)
} }
const gchar * const gchar *
pinos_daemon_get_sender (PinosDaemon *daemon) pinos_daemon_get_object_path (PinosDaemon *daemon)
{ {
PinosDaemonPrivate *priv; PinosDaemonPrivate *priv;
const gchar *res;
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL); g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
priv = daemon->priv; priv = daemon->priv;
if (priv->connection) return priv->object_path;
res = g_dbus_connection_get_unique_name (priv->connection);
else
res = NULL;
return res;
} }
/** /**
@ -702,6 +704,10 @@ pinos_daemon_get_property (GObject *_object,
g_value_set_object (value, priv->connection); g_value_set_object (value, priv->connection);
break; break;
case PROP_OBJECT_PATH:
g_value_set_string (value, priv->object_path);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec);
break; break;
@ -808,6 +814,15 @@ pinos_daemon_class_init (PinosDaemonClass * klass)
G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS)); 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_READABLE |
G_PARAM_STATIC_STRINGS));
} }
static void static void

View file

@ -65,7 +65,7 @@ struct _PinosDaemonClass {
GType pinos_daemon_get_type (void); GType pinos_daemon_get_type (void);
PinosDaemon * pinos_daemon_new (PinosProperties *properties); PinosDaemon * pinos_daemon_new (PinosProperties *properties);
const gchar * pinos_daemon_get_sender (PinosDaemon *daemon); const gchar * pinos_daemon_get_object_path (PinosDaemon *daemon);
void pinos_daemon_start (PinosDaemon *daemon); void pinos_daemon_start (PinosDaemon *daemon);
void pinos_daemon_stop (PinosDaemon *daemon); void pinos_daemon_stop (PinosDaemon *daemon);

View file

@ -153,7 +153,7 @@ pinos_node_factory_get_name (PinosNodeFactory *factory)
* pinos_node_factory_create_node: * pinos_node_factory_create_node:
* @factory: A #PinosNodeFactory * @factory: A #PinosNodeFactory
* @daemon: a #PinosDaemon * @daemon: a #PinosDaemon
* @sender: the path of the owner * @client: the owner client
* @name: node name * @name: node name
* @props: #PinosProperties for the node * @props: #PinosProperties for the node
* *
@ -164,7 +164,7 @@ pinos_node_factory_get_name (PinosNodeFactory *factory)
PinosNode * PinosNode *
pinos_node_factory_create_node (PinosNodeFactory *factory, pinos_node_factory_create_node (PinosNodeFactory *factory,
PinosDaemon *daemon, PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *props) PinosProperties *props)
{ {
@ -177,5 +177,5 @@ pinos_node_factory_create_node (PinosNodeFactory *factory,
return NULL; return NULL;
g_debug ("node factory %p: create node", factory); g_debug ("node factory %p: create node", factory);
return klass->create_node (factory, daemon, sender, name, props); return klass->create_node (factory, daemon, client, name, props);
} }

View file

@ -29,6 +29,7 @@ typedef struct _PinosNodeFactoryClass PinosNodeFactoryClass;
typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate; typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate;
#include <pinos/server/daemon.h> #include <pinos/server/daemon.h>
#include <pinos/server/client.h>
#define PINOS_TYPE_NODE_FACTORY (pinos_node_factory_get_type ()) #define PINOS_TYPE_NODE_FACTORY (pinos_node_factory_get_type ())
#define PINOS_IS_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE_FACTORY)) #define PINOS_IS_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE_FACTORY))
@ -61,7 +62,7 @@ struct _PinosNodeFactoryClass {
PinosNode * (*create_node) (PinosNodeFactory *factory, PinosNode * (*create_node) (PinosNodeFactory *factory,
PinosDaemon *daemon, PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *properties); PinosProperties *properties);
}; };
@ -69,13 +70,14 @@ struct _PinosNodeFactoryClass {
/* normal GObject stuff */ /* normal GObject stuff */
GType pinos_node_factory_get_type (void); GType pinos_node_factory_get_type (void);
const gchar * pinos_node_factory_get_name (PinosNodeFactory *node_factory);
PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory, PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory,
PinosDaemon *daemon, PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *props); PinosProperties *props);
const gchar * pinos_node_factory_get_name (PinosNodeFactory *node_factory);
G_END_DECLS G_END_DECLS
#endif /* __PINOS_NODE_FACTORY_H__ */ #endif /* __PINOS_NODE_FACTORY_H__ */

View file

@ -42,7 +42,7 @@ struct _PinosNodePrivate
PinosDaemon *daemon; PinosDaemon *daemon;
PinosNode1 *iface; PinosNode1 *iface;
gchar *sender; PinosClient *client;
gchar *object_path; gchar *object_path;
gchar *name; gchar *name;
@ -78,7 +78,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_DAEMON, PROP_DAEMON,
PROP_SENDER, PROP_CLIENT,
PROP_RTLOOP, PROP_RTLOOP,
PROP_OBJECT_PATH, PROP_OBJECT_PATH,
PROP_NAME, PROP_NAME,
@ -513,8 +513,8 @@ pinos_node_get_property (GObject *_object,
g_value_set_object (value, priv->daemon); g_value_set_object (value, priv->daemon);
break; break;
case PROP_SENDER: case PROP_CLIENT:
g_value_set_string (value, priv->sender); g_value_set_object (value, priv->client);
break; break;
case PROP_RTLOOP: case PROP_RTLOOP:
@ -557,8 +557,8 @@ pinos_node_set_property (GObject *_object,
priv->daemon = g_value_dup_object (value); priv->daemon = g_value_dup_object (value);
break; break;
case PROP_SENDER: case PROP_CLIENT:
priv->sender = g_value_dup_string (value); priv->client = g_value_get_object (value);
break; break;
case PROP_RTLOOP: case PROP_RTLOOP:
@ -640,8 +640,11 @@ on_property_notify (GObject *obj,
PinosNode *this = user_data; PinosNode *this = user_data;
PinosNodePrivate *priv = this->priv; PinosNodePrivate *priv = this->priv;
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "sender") == 0) { if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "client") == 0) {
pinos_node1_set_owner (priv->iface, priv->sender); if (priv->client)
pinos_node1_set_owner (priv->iface, pinos_client_get_object_path (priv->client));
else
pinos_node1_set_owner (priv->iface, pinos_daemon_get_object_path (priv->daemon));
} }
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) { if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) {
pinos_node1_set_name (priv->iface, pinos_node_get_name (this)); pinos_node1_set_name (priv->iface, pinos_node_get_name (this));
@ -687,9 +690,6 @@ pinos_node_constructed (GObject * obj)
this->node->info->items[i].value); this->node->info->items[i].value);
} }
if (priv->sender == NULL)
priv->sender = g_strdup (pinos_daemon_get_sender (priv->daemon));
if (this->node->state > SPA_NODE_STATE_INIT) { if (this->node->state > SPA_NODE_STATE_INIT) {
init_complete (this); init_complete (this);
} else { } else {
@ -725,7 +725,6 @@ pinos_node_finalize (GObject * obj)
g_clear_object (&priv->daemon); g_clear_object (&priv->daemon);
g_clear_object (&priv->iface); g_clear_object (&priv->iface);
g_clear_object (&priv->loop); g_clear_object (&priv->loop);
g_free (priv->sender);
g_free (priv->name); g_free (priv->name);
g_clear_error (&priv->error); g_clear_error (&priv->error);
if (priv->properties) if (priv->properties)
@ -761,11 +760,11 @@ pinos_node_class_init (PinosNodeClass * klass)
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_SENDER, PROP_CLIENT,
g_param_spec_string ("sender", g_param_spec_object ("client",
"Sender", "Client",
"The Sender", "The Client",
NULL, PINOS_TYPE_CLIENT,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
@ -894,7 +893,7 @@ pinos_node_init (PinosNode * node)
/** /**
* pinos_node_new: * pinos_node_new:
* @daemon: a #PinosDaemon * @daemon: a #PinosDaemon
* @sender: the path of the owner * @client: the client owner
* @name: a name * @name: a name
* @properties: extra properties * @properties: extra properties
* *
@ -904,7 +903,7 @@ pinos_node_init (PinosNode * node)
*/ */
PinosNode * PinosNode *
pinos_node_new (PinosDaemon *daemon, pinos_node_new (PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *properties, PinosProperties *properties,
SpaNode *node) SpaNode *node)
@ -913,7 +912,7 @@ pinos_node_new (PinosDaemon *daemon,
return g_object_new (PINOS_TYPE_NODE, return g_object_new (PINOS_TYPE_NODE,
"daemon", daemon, "daemon", daemon,
"sender", sender, "client", client,
"name", name, "name", name,
"properties", properties, "properties", properties,
"node", node, "node", node,
@ -997,22 +996,22 @@ pinos_node_get_daemon (PinosNode *node)
} }
/** /**
* pinos_node_get_sender: * pinos_node_get_client:
* @node: a #PinosNode * @node: a #PinosNode
* *
* Get the owner path of @node. * Get the owner client of @node.
* *
* Returns: the owner path of @node. * Returns: the owner client of @node.
*/ */
const gchar * PinosClient *
pinos_node_get_sender (PinosNode *node) pinos_node_get_client (PinosNode *node)
{ {
PinosNodePrivate *priv; PinosNodePrivate *priv;
g_return_val_if_fail (PINOS_IS_NODE (node), NULL); g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
priv = node->priv; priv = node->priv;
return priv->sender; return priv->client;
} }
/** /**
* pinos_node_get_object_path: * pinos_node_get_object_path:

View file

@ -33,6 +33,7 @@ typedef struct _PinosNodePrivate PinosNodePrivate;
#include <pinos/client/introspect.h> #include <pinos/client/introspect.h>
#include <pinos/server/daemon.h> #include <pinos/server/daemon.h>
#include <pinos/server/link.h> #include <pinos/server/link.h>
#include <pinos/server/client.h>
#define PINOS_TYPE_NODE (pinos_node_get_type ()) #define PINOS_TYPE_NODE (pinos_node_get_type ())
#define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE)) #define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE))
@ -79,7 +80,7 @@ struct _PinosNodeClass {
GType pinos_node_get_type (void); GType pinos_node_get_type (void);
PinosNode * pinos_node_new (PinosDaemon *daemon, PinosNode * pinos_node_new (PinosDaemon *daemon,
const gchar *sender, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *properties, PinosProperties *properties,
SpaNode *node); SpaNode *node);
@ -89,7 +90,7 @@ const gchar * pinos_node_get_name (PinosNode *node);
PinosProperties * pinos_node_get_properties (PinosNode *node); PinosProperties * pinos_node_get_properties (PinosNode *node);
PinosDaemon * pinos_node_get_daemon (PinosNode *node); PinosDaemon * pinos_node_get_daemon (PinosNode *node);
const gchar * pinos_node_get_sender (PinosNode *node); PinosClient * pinos_node_get_client (PinosNode *node);
const gchar * pinos_node_get_object_path (PinosNode *node); const gchar * pinos_node_get_object_path (PinosNode *node);
guint pinos_node_get_free_port (PinosNode *node, guint pinos_node_get_free_port (PinosNode *node,

View file

@ -35,9 +35,10 @@ struct _PinosRTLoopPrivate
{ {
unsigned int n_poll; unsigned int n_poll;
SpaPollItem poll[16]; SpaPollItem poll[16];
int idx[16];
bool rebuild_fds; bool rebuild_fds;
SpaPollFd fds[16]; SpaPollFd fds[32];
unsigned int n_fds; unsigned int n_fds;
gboolean running; gboolean running;
@ -81,8 +82,8 @@ loop (void *user_data)
n_idle++; n_idle++;
} }
} }
if (n_idle > 0) // if (n_idle > 0)
continue; // continue;
/* rebuild */ /* rebuild */
if (priv->rebuild_fds) { if (priv->rebuild_fds) {
@ -96,7 +97,7 @@ loop (void *user_data)
for (j = 0; j < p->n_fds; j++) for (j = 0; j < p->n_fds; j++)
priv->fds[priv->n_fds + j] = p->fds[j]; priv->fds[priv->n_fds + j] = p->fds[j];
p->fds = &priv->fds[priv->n_fds]; priv->idx[i] = priv->n_fds;
priv->n_fds += p->n_fds; priv->n_fds += p->n_fds;
} }
priv->rebuild_fds = false; priv->rebuild_fds = false;
@ -107,7 +108,7 @@ loop (void *user_data)
SpaPollItem *p = &priv->poll[i]; SpaPollItem *p = &priv->poll[i];
if (p->enabled && p->before_cb) { if (p->enabled && p->before_cb) {
ndata.fds = p->fds; ndata.fds = &priv->fds[priv->idx[i]];
ndata.n_fds = p->n_fds; ndata.n_fds = p->n_fds;
ndata.user_data = p->user_data; ndata.user_data = p->user_data;
p->before_cb (&ndata); p->before_cb (&ndata);
@ -138,7 +139,7 @@ loop (void *user_data)
SpaPollItem *p = &priv->poll[i]; SpaPollItem *p = &priv->poll[i];
if (p->enabled && p->after_cb) { if (p->enabled && p->after_cb) {
ndata.fds = p->fds; ndata.fds = &priv->fds[priv->idx[i]];
ndata.n_fds = p->n_fds; ndata.n_fds = p->n_fds;
ndata.user_data = p->user_data; ndata.user_data = p->user_data;
p->after_cb (&ndata); p->after_cb (&ndata);

View file

@ -64,11 +64,13 @@ typedef enum {
SPA_RESULT_ASYNC_BUSY = -30, SPA_RESULT_ASYNC_BUSY = -30,
} SpaResult; } SpaResult;
#define SPA_ASYNC_MASK (3 << 30)
#define SPA_ASYNC_SEQ_MASK (SPA_RESULT_ASYNC - 1)
#define SPA_RESULT_IS_OK(res) ((res) >= 0) #define SPA_RESULT_IS_OK(res) ((res) >= 0)
#define SPA_RESULT_IS_ERROR(res) ((res) < 0) #define SPA_RESULT_IS_ERROR(res) ((res) < 0)
#define SPA_RESULT_IS_ASYNC(res) (((res) & SPA_RESULT_ASYNC) == SPA_RESULT_ASYNC) #define SPA_RESULT_IS_ASYNC(res) (((res) & SPA_ASYNC_MASK) == SPA_RESULT_ASYNC)
#define SPA_ASYNC_SEQ_MASK (SPA_RESULT_ASYNC - 1)
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK) #define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_RESULT_ASYNC | ((seq) & SPA_ASYNC_SEQ_MASK)) #define SPA_RESULT_RETURN_ASYNC(seq) (SPA_RESULT_ASYNC | ((seq) & SPA_ASYNC_SEQ_MASK))

View file

@ -74,7 +74,7 @@ struct _SpaMemoryChunk {
* SpaMemory: * SpaMemory:
* @refcount: a refcount * @refcount: a refcount
* @notify: notify when refcount is 0 * @notify: notify when refcount is 0
* @user_data: owner specific used data * @user_data: owner specific user data
* @pool_id: the id of the pool * @pool_id: the id of the pool
* @id: the memory id * @id: the memory id
* @flags: extra memory flags * @flags: extra memory flags

View file

@ -99,7 +99,7 @@ struct _SpaAudioTestSrc {
#define DEFAULT_WAVE 0 #define DEFAULT_WAVE 0
#define DEFAULT_VOLUME 1.0 #define DEFAULT_VOLUME 1.0
#define DEFAULT_FREQ 440.0 #define DEFAULT_FREQ 440.0
#define DEFAULT_LIVE false #define DEFAULT_LIVE true
static const double min_volume = 0.0; static const double min_volume = 0.0;
static const double max_volume = 10.0; static const double max_volume = 10.0;
@ -534,6 +534,9 @@ clear_buffers (SpaAudioTestSrc *this)
this->alloc_buffers = NULL; this->alloc_buffers = NULL;
this->n_buffers = 0; this->n_buffers = 0;
this->have_buffers = false; this->have_buffers = false;
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
SPA_QUEUE_INIT (&this->empty);
SPA_QUEUE_INIT (&this->ready);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -719,6 +722,9 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
} }
this->n_buffers = n_buffers; this->n_buffers = n_buffers;
this->have_buffers = true; this->have_buffers = true;
this->info.flags |= SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
} else {
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
} }
if (this->have_buffers) { if (this->have_buffers) {
@ -739,6 +745,7 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
uint32_t *n_buffers) uint32_t *n_buffers)
{ {
SpaAudioTestSrc *this; SpaAudioTestSrc *this;
unsigned int i;
if (node == NULL || node->handle == NULL) if (node == NULL || node->handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -754,7 +761,12 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
if (!this->have_buffers) if (!this->have_buffers)
return SPA_RESULT_NO_BUFFERS; return SPA_RESULT_NO_BUFFERS;
return SPA_RESULT_NOT_IMPLEMENTED; *n_buffers = SPA_MIN (*n_buffers, this->n_buffers);
for (i = 0; i < *n_buffers; i++)
buffers[i] = this->alloc_buffers[i].outbuf;
return SPA_RESULT_OK;
} }
static SpaResult static SpaResult

View file

@ -99,7 +99,7 @@ struct _SpaVideoTestSrc {
SpaQueue ready; SpaQueue ready;
}; };
#define DEFAULT_LIVE false #define DEFAULT_LIVE true
enum { enum {
PROP_ID_LIVE, PROP_ID_LIVE,
@ -482,6 +482,9 @@ clear_buffers (SpaVideoTestSrc *this)
this->alloc_buffers = NULL; this->alloc_buffers = NULL;
this->n_buffers = 0; this->n_buffers = 0;
this->have_buffers = false; this->have_buffers = false;
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
SPA_QUEUE_INIT (&this->empty);
SPA_QUEUE_INIT (&this->ready);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -668,6 +671,9 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
} }
this->n_buffers = n_buffers; this->n_buffers = n_buffers;
this->have_buffers = true; this->have_buffers = true;
this->info.flags |= SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
} else {
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
} }
if (this->have_buffers) { if (this->have_buffers) {
@ -688,6 +694,7 @@ spa_videotestsrc_node_port_alloc_buffers (SpaNode *node,
uint32_t *n_buffers) uint32_t *n_buffers)
{ {
SpaVideoTestSrc *this; SpaVideoTestSrc *this;
unsigned int i;
if (node == NULL || node->handle == NULL) if (node == NULL || node->handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -703,7 +710,12 @@ spa_videotestsrc_node_port_alloc_buffers (SpaNode *node,
if (!this->have_buffers) if (!this->have_buffers)
return SPA_RESULT_NO_BUFFERS; return SPA_RESULT_NO_BUFFERS;
return SPA_RESULT_NOT_IMPLEMENTED; *n_buffers = SPA_MIN (*n_buffers, this->n_buffers);
for (i = 0; i < *n_buffers; i++)
buffers[i] = this->alloc_buffers[i].outbuf;
return SPA_RESULT_OK;
} }
static SpaResult static SpaResult