mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-20 06:59:58 -05:00
Cleanups
Hide GDBus from RTKit API Remove register node from dbus API Add signal Add object and register objects in the registry Add some preregistered types to the registry Let the daemon listen to the registry
This commit is contained in:
parent
e88a376d7c
commit
89bc235924
27 changed files with 568 additions and 462 deletions
|
|
@ -86,9 +86,7 @@ typedef struct {
|
|||
ProxyBuffer buffers[MAX_BUFFERS];
|
||||
|
||||
uint32_t buffer_mem_id;
|
||||
int buffer_mem_fd;
|
||||
size_t buffer_mem_size;
|
||||
void *buffer_mem_ptr;
|
||||
PinosMemblock buffer_mem;
|
||||
|
||||
SpaQueue ready;
|
||||
} SpaProxyPort;
|
||||
|
|
@ -168,8 +166,7 @@ clear_buffers (SpaProxy *this, SpaProxyPort *port)
|
|||
if (port->n_buffers) {
|
||||
spa_log_info (this->log, "proxy %p: clear buffers", this);
|
||||
|
||||
munmap (port->buffer_mem_ptr, port->buffer_mem_size);
|
||||
close (port->buffer_mem_fd);
|
||||
pinos_memblock_free (&port->buffer_mem);
|
||||
|
||||
port->n_buffers = 0;
|
||||
SPA_QUEUE_INIT (&port->ready);
|
||||
|
|
@ -718,23 +715,15 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
if (n_buffers > 0) {
|
||||
/* make mem for the buffers */
|
||||
port->buffer_mem_id = n_mem++;
|
||||
port->buffer_mem_size = size;
|
||||
port->buffer_mem_fd = memfd_create ("spa-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||
|
||||
if (ftruncate (port->buffer_mem_fd, size) < 0) {
|
||||
spa_log_error (this->log, "Failed to truncate temporary file: %s", strerror (errno));
|
||||
close (port->buffer_mem_fd);
|
||||
if (pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD |
|
||||
PINOS_MEMBLOCK_FLAG_MAP_READWRITE |
|
||||
PINOS_MEMBLOCK_FLAG_SEAL,
|
||||
size,
|
||||
&port->buffer_mem) < 0) {
|
||||
spa_log_error (this->log, "Failed to allocate buffer memory");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
|
||||
if (fcntl (port->buffer_mem_fd, F_ADD_SEALS, seals) == -1) {
|
||||
spa_log_error (this->log, "Failed to add seals: %s", strerror (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
p = port->buffer_mem_ptr = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, port->buffer_mem_fd, 0);
|
||||
p = port->buffer_mem.ptr;
|
||||
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
ProxyBuffer *b = &port->buffers[i];
|
||||
|
|
@ -763,7 +752,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
am.port_id = port_id;
|
||||
am.mem_id = port->buffer_mem_id;
|
||||
am.type = SPA_DATA_TYPE_MEMFD;
|
||||
am.fd_index = pinos_connection_add_fd (this->conn, port->buffer_mem_fd, false);
|
||||
am.fd_index = pinos_connection_add_fd (this->conn, port->buffer_mem.fd, false);
|
||||
am.flags = 0;
|
||||
am.offset = 0;
|
||||
am.size = size;
|
||||
|
|
@ -1049,8 +1038,6 @@ parse_connection (SpaProxy *this)
|
|||
spa_log_info (this->log, "proxy %p: got node update %d, max_in %u, max_out %u", this, type,
|
||||
this->max_inputs, this->max_outputs);
|
||||
|
||||
#if 0
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,8 +186,6 @@ client_register_object (PinosClient *client)
|
|||
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
client->id = pinos_map_insert_new (&daemon->registry.clients, client);
|
||||
|
||||
pinos_log_debug ("client %p: register %s", client, priv->object_path);
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +197,6 @@ client_unregister_object (PinosClient *client)
|
|||
|
||||
pinos_log_debug ("client %p: unregister", client);
|
||||
pinos_daemon_unexport (daemon, priv->object_path);
|
||||
pinos_map_remove (&daemon->registry.clients, client->id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -214,6 +211,7 @@ pinos_client_dispose (GObject * object)
|
|||
g_list_free_full (copy, g_object_unref);
|
||||
g_list_free (priv->objects);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &client->object);
|
||||
client_unregister_object (client);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_parent_class)->dispose (object);
|
||||
|
|
@ -240,8 +238,17 @@ static void
|
|||
pinos_client_constructed (GObject * object)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
pinos_log_debug ("client %p: constructed", client);
|
||||
|
||||
pinos_object_init (&client->object,
|
||||
priv->daemon->registry.uri.client,
|
||||
client,
|
||||
NULL);
|
||||
|
||||
pinos_registry_add_object (&priv->daemon->registry, &client->object);
|
||||
|
||||
client_watch_name (client);
|
||||
client_register_object (client);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,14 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_CLIENT_URI "http://pinos.org/ns/client"
|
||||
#define PINOS_CLIENT_PREFIX PINOS_CLIENT_URI "#"
|
||||
|
||||
typedef struct _PinosClient PinosClient;
|
||||
typedef struct _PinosClientClass PinosClientClass;
|
||||
typedef struct _PinosClientPrivate PinosClientPrivate;
|
||||
|
||||
#include <pinos/client/object.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
#define PINOS_TYPE_CLIENT (pinos_client_get_type ())
|
||||
|
|
@ -45,9 +49,9 @@ typedef struct _PinosClientPrivate PinosClientPrivate;
|
|||
* Pinos client object class.
|
||||
*/
|
||||
struct _PinosClient {
|
||||
GObject object;
|
||||
GObject obj;
|
||||
|
||||
uint32_t id;
|
||||
PinosObject object;
|
||||
|
||||
PinosClientPrivate *priv;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@
|
|||
|
||||
struct _PinosDaemonPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
||||
PinosDaemon1 *iface;
|
||||
guint id;
|
||||
GDBusConnection *connection;
|
||||
|
|
@ -57,6 +59,9 @@ struct _PinosDaemonPrivate
|
|||
|
||||
PinosProperties *properties;
|
||||
|
||||
PinosListener object_added;
|
||||
PinosListener object_removed;
|
||||
|
||||
GHashTable *node_factories;
|
||||
|
||||
SpaSupport support[4];
|
||||
|
|
@ -447,66 +452,6 @@ exit_error:
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_register_client_node (PinosDaemon1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
GVariant *arg_properties,
|
||||
const gchar *arg_path,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosDaemon *daemon = user_data;
|
||||
PinosNode *node;
|
||||
PinosClient *client;
|
||||
const gchar *sender;
|
||||
PinosProperties *props;
|
||||
GError *error = NULL;
|
||||
GUnixFDList *fdlist;
|
||||
gint fdidx;
|
||||
GSocket *socket;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
client = sender_get_client (daemon, sender, TRUE);
|
||||
|
||||
pinos_log_debug ("daemon %p: register client-node: %s", daemon, sender);
|
||||
props = pinos_properties_from_variant (arg_properties);
|
||||
|
||||
node = pinos_dbus_client_node_new (daemon,
|
||||
client,
|
||||
arg_path,
|
||||
props);
|
||||
pinos_properties_free (props);
|
||||
|
||||
socket = pinos_dbus_client_node_get_socket_pair (PINOS_DBUS_CLIENT_NODE (node), &error);
|
||||
if (socket == NULL)
|
||||
goto no_socket;
|
||||
|
||||
pinos_client_add_object (client, G_OBJECT (node));
|
||||
g_object_unref (node);
|
||||
|
||||
fdlist = g_unix_fd_list_new ();
|
||||
fdidx = g_unix_fd_list_append (fdlist, g_socket_get_fd (socket), &error);
|
||||
g_object_unref (socket);
|
||||
|
||||
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
|
||||
g_variant_new ("(h)", fdidx), fdlist);
|
||||
g_object_unref (fdlist);
|
||||
|
||||
return TRUE;
|
||||
|
||||
no_socket:
|
||||
{
|
||||
pinos_log_debug ("daemon %p: could not create socket %s", daemon, error->message);
|
||||
g_object_unref (node);
|
||||
goto exit_error;
|
||||
}
|
||||
exit_error:
|
||||
{
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
g_clear_error (&error);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
export_server_object (PinosDaemon *daemon,
|
||||
GDBusObjectManagerServer *manager)
|
||||
|
|
@ -674,38 +619,47 @@ pinos_daemon_unexport (PinosDaemon *daemon,
|
|||
g_dbus_object_manager_server_unexport (daemon->priv->server_manager, object_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_add_node:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Add @node to @daemon.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_add_node (PinosDaemon *daemon,
|
||||
PinosNode *node)
|
||||
static void
|
||||
on_registry_object_added (PinosListener *listener,
|
||||
void *data)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
PinosObject *object = data;
|
||||
PinosDaemonPrivate *priv = SPA_CONTAINER_OF (listener, PinosDaemonPrivate, object_added);
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
|
||||
on_node_added (daemon, node);
|
||||
if (object->type == daemon->registry.uri.node) {
|
||||
PinosNode *node = object->implementation;
|
||||
|
||||
on_node_added (daemon, node);
|
||||
} else if (object->type == daemon->registry.uri.node_factory) {
|
||||
PinosNodeFactory *factory = object->implementation;
|
||||
gchar *name;
|
||||
|
||||
g_object_get (factory, "name", &name, NULL);
|
||||
g_hash_table_insert (priv->node_factories, name, g_object_ref (factory));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_remove_node:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Remove @node from @daemon.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_remove_node (PinosDaemon *daemon,
|
||||
PinosNode *node)
|
||||
static void
|
||||
on_registry_object_removed (PinosListener *listener,
|
||||
void *data)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
PinosObject *object = data;
|
||||
PinosDaemonPrivate *priv = SPA_CONTAINER_OF (listener, PinosDaemonPrivate, object_added);
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
|
||||
on_node_removed (daemon, node);
|
||||
if (object->type == daemon->registry.uri.node) {
|
||||
PinosNode *node = object->implementation;
|
||||
|
||||
on_node_removed (daemon, node);
|
||||
} else if (object->type == daemon->registry.uri.node_factory) {
|
||||
PinosNodeFactory *factory = object->implementation;
|
||||
gchar *name;
|
||||
|
||||
g_object_get (factory, "name", &name, NULL);
|
||||
g_hash_table_remove (priv->node_factories, name);
|
||||
g_free (name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -739,9 +693,14 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
|
||||
pinos_log_debug ("name \"%s\", %d", name, have_name);
|
||||
|
||||
for (i = 0; i < pinos_map_get_size (&daemon->registry.nodes); i++) {
|
||||
PinosNode *n = pinos_map_lookup (&daemon->registry.nodes, i);
|
||||
for (i = 0; i < pinos_map_get_size (&daemon->registry.objects); i++) {
|
||||
PinosObject *o = pinos_map_lookup (&daemon->registry.objects, i);
|
||||
PinosNode *n;
|
||||
|
||||
if (o->type != daemon->registry.uri.node)
|
||||
continue;
|
||||
|
||||
n = o->implementation;
|
||||
if (n == NULL || n->flags & PINOS_NODE_FLAG_REMOVING)
|
||||
continue;
|
||||
|
||||
|
|
@ -823,8 +782,8 @@ pinos_daemon_set_property (GObject *_object,
|
|||
static void
|
||||
pinos_daemon_constructed (GObject * object)
|
||||
{
|
||||
PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
PinosDaemon *this = PINOS_DAEMON_CAST (object);
|
||||
PinosDaemonPrivate *priv = this->priv;
|
||||
|
||||
pinos_log_debug ("daemon %p: constructed", object);
|
||||
pinos_daemon1_set_user_name (priv->iface, g_get_user_name ());
|
||||
|
|
@ -835,16 +794,24 @@ pinos_daemon_constructed (GObject * object)
|
|||
pinos_daemon1_set_properties (priv->iface, pinos_properties_to_variant (priv->properties));
|
||||
|
||||
G_OBJECT_CLASS (pinos_daemon_parent_class)->constructed (object);
|
||||
|
||||
pinos_object_init (&this->object,
|
||||
this->registry.uri.daemon,
|
||||
this,
|
||||
NULL);
|
||||
pinos_registry_add_object (&this->registry, &this->object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_daemon_dispose (GObject * object)
|
||||
{
|
||||
PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
|
||||
PinosDaemon *this = PINOS_DAEMON_CAST (object);
|
||||
|
||||
pinos_log_debug ("daemon %p: dispose", object);
|
||||
|
||||
pinos_daemon_stop (daemon);
|
||||
pinos_daemon_stop (this);
|
||||
|
||||
pinos_registry_remove_object (&this->registry, &this->object);
|
||||
|
||||
G_OBJECT_CLASS (pinos_daemon_parent_class)->dispose (object);
|
||||
}
|
||||
|
|
@ -914,13 +881,19 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
{
|
||||
PinosDaemonPrivate *priv = daemon->priv = PINOS_DAEMON_GET_PRIVATE (daemon);
|
||||
|
||||
priv->daemon = daemon;
|
||||
|
||||
pinos_log_debug ("daemon %p: new", daemon);
|
||||
priv->iface = pinos_daemon1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-create-node", (GCallback) handle_create_node, daemon);
|
||||
g_signal_connect (priv->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon);
|
||||
g_signal_connect (priv->iface, "handle-register-client-node", (GCallback) handle_register_client_node, daemon);
|
||||
|
||||
priv->object_added.notify = on_registry_object_added;
|
||||
priv->object_removed.notify = on_registry_object_removed;
|
||||
|
||||
pinos_registry_init (&daemon->registry);
|
||||
pinos_signal_add (&daemon->registry.object_added, &priv->object_added);
|
||||
pinos_signal_add (&daemon->registry.object_removed, &priv->object_removed);
|
||||
|
||||
priv->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
|
||||
priv->clients = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
|
@ -932,11 +905,10 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
daemon->main_loop = pinos_main_loop_new (g_main_context_get_thread_default ());
|
||||
priv->data_loop = pinos_data_loop_new();
|
||||
|
||||
daemon->map = pinos_id_map_get_default();
|
||||
daemon->log = pinos_log_get();
|
||||
|
||||
priv->support[0].uri = SPA_ID_MAP_URI;
|
||||
priv->support[0].data = daemon->map;
|
||||
priv->support[0].data = daemon->registry.map;
|
||||
priv->support[1].uri = SPA_LOG_URI;
|
||||
priv->support[1].data = daemon->log;
|
||||
priv->support[2].uri = SPA_POLL__DataLoop;
|
||||
|
|
@ -946,46 +918,3 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
daemon->support = priv->support;
|
||||
daemon->n_support = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_add_node_factory:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @factory: a #PinosNodeFactory
|
||||
*
|
||||
* Add a #PinosNodeFactory in the daemon that will be used for creating nodes.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_add_node_factory (PinosDaemon *daemon,
|
||||
PinosNodeFactory *factory)
|
||||
{
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
gchar *name;
|
||||
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_NODE_FACTORY (factory));
|
||||
|
||||
g_object_get (factory, "name", &name, NULL);
|
||||
g_hash_table_insert (priv->node_factories, name, g_object_ref (factory));
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_daemon_add_node_factory:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @factory: a #PinosNodeFactory
|
||||
*
|
||||
* Remove a #PinosNodeFactory from the daemon.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_remove_node_factory (PinosDaemon *daemon,
|
||||
PinosNodeFactory *factory)
|
||||
{
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
gchar *name;
|
||||
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_NODE_FACTORY (factory));
|
||||
|
||||
g_object_get (factory, "name", &name, NULL);
|
||||
g_hash_table_remove (priv->node_factories, name);
|
||||
g_free (name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_DAEMON_URI "http://pinos.org/ns/daemon"
|
||||
#define PINOS_DAEMON_PREFIX PINOS_DAEMON_URI "#"
|
||||
|
||||
#define PINOS_TYPE_DAEMON (pinos_daemon_get_type ())
|
||||
#define PINOS_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_DAEMON))
|
||||
#define PINOS_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_DAEMON))
|
||||
|
|
@ -52,9 +55,10 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
|||
* Pinos daemon object class.
|
||||
*/
|
||||
struct _PinosDaemon {
|
||||
GObject object;
|
||||
GObject obj;
|
||||
|
||||
PinosObject object;
|
||||
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
PinosMainLoop *main_loop;
|
||||
|
|
@ -88,9 +92,6 @@ void pinos_daemon_stop (PinosDaemon *daemon);
|
|||
gchar * pinos_daemon_export_uniquely (PinosDaemon *daemon, GDBusObjectSkeleton *skel);
|
||||
void pinos_daemon_unexport (PinosDaemon *daemon, const gchar *name);
|
||||
|
||||
void pinos_daemon_add_node (PinosDaemon *daemon, PinosNode *node);
|
||||
void pinos_daemon_remove_node (PinosDaemon *daemon, PinosNode *node);
|
||||
|
||||
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosPort *other_port,
|
||||
const gchar *name,
|
||||
|
|
@ -98,11 +99,6 @@ PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
GPtrArray *format_filter,
|
||||
GError **error);
|
||||
|
||||
void pinos_daemon_add_node_factory (PinosDaemon *daemon,
|
||||
PinosNodeFactory *factory);
|
||||
void pinos_daemon_remove_node_factory (PinosDaemon *daemon,
|
||||
PinosNodeFactory *factory);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_DAEMON_H__ */
|
||||
|
|
|
|||
|
|
@ -83,8 +83,7 @@ static void
|
|||
make_realtime (PinosDataLoop *this)
|
||||
{
|
||||
struct sched_param sp;
|
||||
GDBusConnection *system_bus;
|
||||
GError *error = NULL;
|
||||
PinosRTKitBus *system_bus;
|
||||
struct rlimit rl;
|
||||
int r, rtprio;
|
||||
long long rttime;
|
||||
|
|
@ -99,7 +98,7 @@ make_realtime (PinosDataLoop *this)
|
|||
pinos_log_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked.");
|
||||
return;
|
||||
}
|
||||
system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
|
||||
system_bus = pinos_rtkit_bus_get_system ();
|
||||
|
||||
rl.rlim_cur = rl.rlim_max = rttime;
|
||||
if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0)
|
||||
|
|
@ -116,13 +115,12 @@ make_realtime (PinosDataLoop *this)
|
|||
}
|
||||
}
|
||||
|
||||
if (!pinos_rtkit_make_realtime (system_bus, 0, rtprio, &error)) {
|
||||
pinos_log_debug ("could not make thread realtime: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
if ((r = pinos_rtkit_make_realtime (system_bus, 0, rtprio)) < 0) {
|
||||
pinos_log_debug ("could not make thread realtime: %s", strerror (r));
|
||||
} else {
|
||||
pinos_log_debug ("thread made realtime");
|
||||
}
|
||||
g_object_unref (system_bus);
|
||||
pinos_rtkit_bus_free (system_bus);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *
|
|||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (*handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
daemon->registry.uri.spa_node,
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -180,9 +180,7 @@ link_register_object (PinosLink *this)
|
|||
priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
this->id = pinos_map_insert_new (&priv->daemon->registry.links, this);
|
||||
|
||||
pinos_log_debug ("link %p: register object %s, id %u", this, priv->object_path, this->id);
|
||||
pinos_log_debug ("link %p: register object %s, id %u", this, priv->object_path, this->object.id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -192,7 +190,6 @@ link_unregister_object (PinosLink *this)
|
|||
|
||||
pinos_log_debug ("link %p: unregister object", this);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
pinos_map_remove (&priv->daemon->registry.links, this->id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -852,6 +849,12 @@ pinos_link_constructed (GObject * object)
|
|||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
||||
|
||||
pinos_object_init (&this->object,
|
||||
priv->daemon->registry.uri.link,
|
||||
this,
|
||||
NULL);
|
||||
pinos_registry_add_object (&priv->daemon->registry, &this->object);
|
||||
|
||||
on_property_notify (G_OBJECT (this), NULL, this);
|
||||
pinos_log_debug ("link %p: constructed %p:%d -> %p:%d", this,
|
||||
this->output->node, this->output->port,
|
||||
|
|
@ -879,6 +882,8 @@ pinos_link_dispose (GObject * object)
|
|||
if (this->output)
|
||||
pinos_port_unlink (this->output, this);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &this->object);
|
||||
|
||||
link_unregister_object (this);
|
||||
|
||||
pinos_main_loop_defer_cancel (priv->main_loop, this, 0);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_LINK_URI "http://pinos.org/ns/link"
|
||||
#define PINOS_LINK_PREFIX PINOS_LINK_URI "#"
|
||||
|
||||
typedef struct _PinosLink PinosLink;
|
||||
typedef struct _PinosLinkClass PinosLinkClass;
|
||||
typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
||||
|
|
@ -31,6 +34,7 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
|||
#include <spa/include/spa/ringbuffer.h>
|
||||
|
||||
#include <pinos/client/mem.h>
|
||||
#include <pinos/client/object.h>
|
||||
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/main-loop.h>
|
||||
|
|
@ -50,9 +54,9 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
|||
* Pinos link object class.
|
||||
*/
|
||||
struct _PinosLink {
|
||||
GObject object;
|
||||
GObject obj;
|
||||
|
||||
uint32_t id;
|
||||
PinosObject object;
|
||||
|
||||
PinosPort *output;
|
||||
PinosPort *input;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,12 @@ pinos_node_factory_constructed (GObject * obj)
|
|||
|
||||
g_debug ("node factory %p: constructed", factory);
|
||||
|
||||
factory->id = pinos_map_insert_new (&priv->daemon->registry.node_factories, factory);
|
||||
pinos_object_init (&factory->object,
|
||||
priv->daemon->registry.uri.node_factory,
|
||||
factory,
|
||||
NULL);
|
||||
|
||||
pinos_registry_add_object (&priv->daemon->registry, &factory->object);
|
||||
|
||||
G_OBJECT_CLASS (pinos_node_factory_parent_class)->constructed (obj);
|
||||
}
|
||||
|
|
@ -107,7 +112,7 @@ pinos_node_factory_finalize (GObject * obj)
|
|||
PinosNodeFactoryPrivate *priv = factory->priv;
|
||||
|
||||
g_debug ("node factory %p: finalize", factory);
|
||||
pinos_map_remove (&priv->daemon->registry.node_factories, factory->id);
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &factory->object);
|
||||
|
||||
g_free (priv->name);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_NODE_FACTORY_URI "http://pinos.org/ns/node-factory"
|
||||
#define PINOS_NODE_FACTORY_PREFIX PINOS_NODE_FACTORY_URI "#"
|
||||
|
||||
typedef struct _PinosNodeFactory PinosNodeFactory;
|
||||
typedef struct _PinosNodeFactoryClass PinosNodeFactoryClass;
|
||||
typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate;
|
||||
|
|
@ -46,9 +49,9 @@ typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate;
|
|||
* Pinos node factory class.
|
||||
*/
|
||||
struct _PinosNodeFactory {
|
||||
GObject object;
|
||||
GObject obj;
|
||||
|
||||
uint32_t id;
|
||||
PinosObject object;
|
||||
|
||||
PinosNodeFactoryPrivate *priv;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -603,10 +603,7 @@ node_register_object (PinosNode *this)
|
|||
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
this->id = pinos_map_insert_new (&daemon->registry.nodes, this);
|
||||
pinos_log_debug ("node %p: register object %s, id %u", this, priv->object_path, this->id);
|
||||
|
||||
pinos_daemon_add_node (daemon, this);
|
||||
pinos_log_debug ("node %p: register object %s, id %u", this, priv->object_path, this->object.id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -619,8 +616,6 @@ node_unregister_object (PinosNode *this)
|
|||
pinos_log_debug ("node %p: unregister object %s", this, priv->object_path);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
g_clear_pointer (&priv->object_path, g_free);
|
||||
pinos_daemon_remove_node (priv->daemon, this);
|
||||
pinos_map_remove (&priv->daemon->registry.nodes, this->id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -671,6 +666,13 @@ pinos_node_constructed (GObject * obj)
|
|||
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
|
||||
|
||||
pinos_object_init (&this->object,
|
||||
priv->daemon->registry.uri.node,
|
||||
this,
|
||||
NULL);
|
||||
|
||||
pinos_registry_add_object (&priv->daemon->registry, &this->object);
|
||||
|
||||
if (this->node->info) {
|
||||
unsigned int i;
|
||||
|
||||
|
|
@ -706,6 +708,7 @@ pinos_node_dispose (GObject * obj)
|
|||
pinos_log_debug ("node %p: dispose", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &node->object);
|
||||
node_unregister_object (node);
|
||||
|
||||
pinos_main_loop_defer_cancel (priv->main_loop, node, 0);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_NODE_URI "http://pinos.org/ns/node"
|
||||
#define PINOS_NODE_PREFIX PINOS_NODE_URI "#"
|
||||
|
||||
#define PINOS_PORT_URI PINOS_NODE_PREFIX "Port"
|
||||
|
||||
typedef struct _PinosPort PinosPort;
|
||||
typedef struct _PinosNode PinosNode;
|
||||
typedef struct _PinosNodeClass PinosNodeClass;
|
||||
|
|
@ -46,7 +51,7 @@ typedef enum {
|
|||
#include <pinos/server/client.h>
|
||||
|
||||
struct _PinosPort {
|
||||
uint32_t id;
|
||||
PinosObject object;
|
||||
PinosNode *node;
|
||||
PinosDirection direction;
|
||||
uint32_t port;
|
||||
|
|
@ -72,9 +77,9 @@ struct _PinosPort {
|
|||
* Pinos node class.
|
||||
*/
|
||||
struct _PinosNode {
|
||||
GObject object;
|
||||
GObject obj;
|
||||
|
||||
uint32_t id;
|
||||
PinosObject object;
|
||||
|
||||
PinosNodeFlags flags;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,17 +20,33 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/registry.h"
|
||||
#include "pinos/server/node.h"
|
||||
#include "pinos/server/node-factory.h"
|
||||
#include "pinos/server/client.h"
|
||||
|
||||
#include "spa/include/spa/monitor.h"
|
||||
|
||||
void
|
||||
pinos_registry_init (PinosRegistry *reg)
|
||||
{
|
||||
reg->map = pinos_id_map_get_default();
|
||||
|
||||
pinos_map_init (®->clients, 64);
|
||||
pinos_map_init (®->nodes, 128);
|
||||
pinos_map_init (®->ports, 512);
|
||||
pinos_map_init (®->links, 256);
|
||||
pinos_map_init (®->modules, 128);
|
||||
pinos_map_init (®->monitors, 64);
|
||||
reg->uri.daemon = spa_id_map_get_id (reg->map, PINOS_DAEMON_URI);
|
||||
reg->uri.registry = spa_id_map_get_id (reg->map, PINOS_REGISTRY_URI);
|
||||
reg->uri.node = spa_id_map_get_id (reg->map, PINOS_NODE_URI);
|
||||
reg->uri.port = spa_id_map_get_id (reg->map, PINOS_PORT_URI);
|
||||
reg->uri.link = spa_id_map_get_id (reg->map, PINOS_LINK_URI);
|
||||
reg->uri.node_factory = spa_id_map_get_id (reg->map, PINOS_NODE_FACTORY_URI);
|
||||
reg->uri.client = spa_id_map_get_id (reg->map, PINOS_CLIENT_URI);
|
||||
|
||||
reg->uri.spa_node = spa_id_map_get_id (reg->map, SPA_NODE_URI);
|
||||
reg->uri.spa_clock = spa_id_map_get_id (reg->map, SPA_CLOCK_URI);
|
||||
reg->uri.spa_monitor = spa_id_map_get_id (reg->map, SPA_MONITOR_URI);
|
||||
|
||||
pinos_map_init (®->objects, 512);
|
||||
|
||||
pinos_signal_init (®->object_added);
|
||||
pinos_signal_init (®->object_removed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,38 +20,69 @@
|
|||
#ifndef __PINOS_REGISTRY_H__
|
||||
#define __PINOS_REGISTRY_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
#define PINOS_REGISTRY_URI "http://pinos.org/ns/registry"
|
||||
#define PINOS_REGISTRY_PREFIX PINOS_REGISTRY_URI "#"
|
||||
|
||||
#include <pinos/client/map.h>
|
||||
#include <pinos/client/signal.h>
|
||||
#include <pinos/client/object.h>
|
||||
#include <spa/include/spa/id-map.h>
|
||||
|
||||
typedef struct _PinosRegistry PinosRegistry;
|
||||
|
||||
typedef struct {
|
||||
uint32_t daemon;
|
||||
uint32_t registry;
|
||||
uint32_t node;
|
||||
uint32_t port;
|
||||
uint32_t link;
|
||||
uint32_t node_factory;
|
||||
uint32_t client;
|
||||
uint32_t spa_node;
|
||||
uint32_t spa_clock;
|
||||
uint32_t spa_monitor;
|
||||
} PinosURI;
|
||||
|
||||
/**
|
||||
* PinosRegistry:
|
||||
*
|
||||
* Pinos registry struct.
|
||||
*/
|
||||
struct _PinosRegistry {
|
||||
SpaIDMap *map;
|
||||
PinosObject object;
|
||||
|
||||
SpaIDMap *map;
|
||||
PinosURI uri;
|
||||
PinosMap objects;
|
||||
|
||||
PinosMap clients;
|
||||
PinosMap node_factories;
|
||||
PinosMap nodes;
|
||||
PinosMap ports;
|
||||
PinosMap links;
|
||||
PinosMap modules;
|
||||
PinosMap monitors;
|
||||
PinosMap devices;
|
||||
PinosSignal object_added;
|
||||
PinosSignal object_removed;
|
||||
};
|
||||
|
||||
void pinos_registry_init (PinosRegistry *reg);
|
||||
|
||||
void pinos_registry_init (PinosRegistry *reg);
|
||||
static inline void
|
||||
pinos_registry_add_object (PinosRegistry *reg,
|
||||
PinosObject *object)
|
||||
{
|
||||
object->id = pinos_map_insert_new (®->objects, object);
|
||||
pinos_signal_emit (®->object_added, object);
|
||||
}
|
||||
|
||||
G_END_DECLS
|
||||
static inline void
|
||||
pinos_registry_remove_object (PinosRegistry *reg,
|
||||
PinosObject *object)
|
||||
{
|
||||
pinos_signal_emit (®->object_removed, object);
|
||||
pinos_map_remove (®->objects, object->id);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PINOS_REGISTRY_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue