summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2016-11-15 20:12:31 +0100
committerWim Taymans <wtaymans@redhat.com>2016-11-15 20:12:31 +0100
commit1a48bccca0b0102ffe475d120fc8f2e18d6c6a17 (patch)
tree39a1752c59f65604ded204fbac854287318fc826
parentb6ad45bb74c7d6b8e90cabb460d948a80c9d5f18 (diff)
cleanups
Remove hastables, use lists Remove obsolete ringbuffer some small cleanups
-rw-r--r--pinos/client/meson.build2
-rw-r--r--pinos/client/pinos.h1
-rw-r--r--pinos/client/ringbuffer.c391
-rw-r--r--pinos/client/ringbuffer.h96
-rw-r--r--pinos/modules/spa/spa-monitor.c72
-rw-r--r--pinos/server/client.c4
-rw-r--r--pinos/server/client.h2
-rw-r--r--pinos/server/core.c3
-rw-r--r--pinos/server/core.h2
-rw-r--r--pinos/server/daemon.c56
-rw-r--r--pinos/server/daemon.h2
-rw-r--r--pinos/server/link.c4
-rw-r--r--pinos/server/link.h2
-rw-r--r--pinos/server/node-factory.h4
-rw-r--r--pinos/server/node.c4
-rw-r--r--pinos/server/node.h2
16 files changed, 93 insertions, 554 deletions
diff --git a/pinos/client/meson.build b/pinos/client/meson.build
index a73eb64c..f3bcd21e 100644
--- a/pinos/client/meson.build
+++ b/pinos/client/meson.build
@@ -8,7 +8,6 @@ pinos_headers = [
'mem.h',
'pinos.h',
'properties.h',
- 'ringbuffer.h',
'rtkit.h',
'stream.h',
'subscribe.h',
@@ -29,7 +28,6 @@ pinos_sources = [
'serialize.c',
'stream.c',
'pinos.c',
- 'ringbuffer.c',
'rtkit.c',
'subscribe.c',
'thread-mainloop.c',
diff --git a/pinos/client/pinos.h b/pinos/client/pinos.h
index 3cbaf82a..07f786a9 100644
--- a/pinos/client/pinos.h
+++ b/pinos/client/pinos.h
@@ -29,7 +29,6 @@ extern const char g_log_domain_pinos[];
#include <pinos/client/mem.h>
#include <pinos/client/thread-mainloop.h>
#include <pinos/client/properties.h>
-#include <pinos/client/ringbuffer.h>
#include <pinos/client/stream.h>
#include <pinos/client/subscribe.h>
#include <pinos/client/utils.h>
diff --git a/pinos/client/ringbuffer.c b/pinos/client/ringbuffer.c
deleted file mode 100644
index 906a7528..00000000
--- a/pinos/client/ringbuffer.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/* Pinos
- * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/eventfd.h>
-#include <sys/mman.h>
-
-#include <gio/gio.h>
-#include <glib-object.h>
-
-#include <pinos/client/pinos.h>
-#include <pinos/client/enumtypes.h>
-#include <pinos/client/ringbuffer.h>
-
-#include <spa/include/spa/ringbuffer.h>
-
-#define PINOS_RINGBUFFER_GET_PRIVATE(rb) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((rb), PINOS_TYPE_RINGBUFFER, PinosRingbufferPrivate))
-
-typedef struct {
- SpaRingbuffer rbuf;
- /* ringbuffer starts here */
-} PinosRingbufferData;
-
-struct _PinosRingbufferPrivate
-{
- PinosRingbufferMode mode;
- guint size;
- guint fdsize;
- int fd;
- int semaphore;
-
- PinosRingbufferData *data;
-};
-
-G_DEFINE_TYPE (PinosRingbuffer, pinos_ringbuffer, G_TYPE_OBJECT);
-
-enum
-{
- PROP_0,
- PROP_MODE,
- PROP_SIZE,
- PROP_FD,
- PROP_FDSIZE,
- PROP_SEMAPHORE,
-};
-
-enum
-{
- SIGNAL_NONE,
- LAST_SIGNAL
-};
-
-static void
-pinos_ringbuffer_get_property (GObject *_object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PinosRingbuffer *rb = PINOS_RINGBUFFER (_object);
- PinosRingbufferPrivate *priv = rb->priv;
-
- switch (prop_id) {
- case PROP_MODE:
- g_value_set_enum (value, priv->mode);
- break;
-
- case PROP_SIZE:
- g_value_set_uint (value, priv->size);
- break;
-
- case PROP_FD:
- g_value_set_int (value, priv->fd);
- break;
-
- case PROP_FDSIZE:
- g_value_set_uint (value, priv->fdsize);
- break;
-
- case PROP_SEMAPHORE:
- g_value_set_int (value, priv->semaphore);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (rb, prop_id, pspec);
- break;
- }
-}
-
-static void
-pinos_ringbuffer_set_property (GObject *_object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PinosRingbuffer *rb = PINOS_RINGBUFFER (_object);
- PinosRingbufferPrivate *priv = rb->priv;
-
- switch (prop_id) {
- case PROP_MODE:
- priv->mode = g_value_get_enum (value);
- break;
-
- case PROP_SIZE:
- priv->size = g_value_get_uint (value);
- break;
-
- case PROP_FD:
- priv->fd = g_value_get_int (value);
- break;
-
- case PROP_FDSIZE:
- priv->fdsize = g_value_get_uint (value);
- break;
-
- case PROP_SEMAPHORE:
- priv->semaphore = g_value_get_int (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (rb, prop_id, pspec);
- break;
- }
-}
-
-static int
-tmpfile_create (gsize size)
-{
- char filename[] = "/dev/shm/tmpfilepay.XXXXXX";
- int fd, result;
-
- fd = mkostemp (filename, O_CLOEXEC);
- if (fd == -1)
- return -1;
- unlink (filename);
-
- result = ftruncate (fd, size);
- if (result == -1) {
- close (fd);
- return -1;
- }
- return fd;
-}
-
-static void
-pinos_ringbuffer_constructed (GObject * obj)
-{
- PinosRingbuffer *rb = PINOS_RINGBUFFER (obj);
- PinosRingbufferPrivate *priv = rb->priv;
-
- g_debug ("ringbuffer %p: constructed", rb);
-
- if (priv->fd == -1) {
- priv->fdsize = priv->size + sizeof (PinosRingbufferData);
- priv->fd = tmpfile_create (priv->fdsize);
- priv->semaphore = eventfd (0, EFD_CLOEXEC);
- }
- priv->data = mmap (NULL, priv->fdsize, PROT_READ | PROT_WRITE, MAP_SHARED, priv->fd, 0);
-
- spa_ringbuffer_init (&priv->data->rbuf, priv->size);
-
- G_OBJECT_CLASS (pinos_ringbuffer_parent_class)->constructed (obj);
-}
-
-static void
-pinos_ringbuffer_dispose (GObject * obj)
-{
- PinosRingbuffer *rb = PINOS_RINGBUFFER (obj);
-
- g_debug ("ringbuffer %p: dispose", rb);
-
- G_OBJECT_CLASS (pinos_ringbuffer_parent_class)->dispose (obj);
-}
-
-static void
-pinos_ringbuffer_finalize (GObject * obj)
-{
- PinosRingbuffer *rb = PINOS_RINGBUFFER (obj);
-
- g_debug ("ringbuffer %p: finalize", rb);
-
- G_OBJECT_CLASS (pinos_ringbuffer_parent_class)->finalize (obj);
-}
-
-static void
-pinos_ringbuffer_class_init (PinosRingbufferClass * klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (PinosRingbufferPrivate));
-
- gobject_class->constructed = pinos_ringbuffer_constructed;
- gobject_class->dispose = pinos_ringbuffer_dispose;
- gobject_class->finalize = pinos_ringbuffer_finalize;
- gobject_class->set_property = pinos_ringbuffer_set_property;
- gobject_class->get_property = pinos_ringbuffer_get_property;
-
- g_object_class_install_property (gobject_class,
- PROP_MODE,
- g_param_spec_enum ("mode",
- "Mode",
- "The mode of the ringbuffer",
- PINOS_TYPE_RINGBUFFER_MODE,
- PINOS_RINGBUFFER_MODE_READ,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (gobject_class,
- PROP_SIZE,
- g_param_spec_uint ("size",
- "Size",
- "The size of the ringbuffer",
- 1,
- G_MAXUINT,
- 64 * 1024,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (gobject_class,
- PROP_FD,
- g_param_spec_int ("fd",
- "Fd",
- "The file descriptor with memory",
- -1,
- G_MAXINT,
- -1,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (gobject_class,
- PROP_FDSIZE,
- g_param_spec_uint ("fdsize",
- "Fd Size",
- "Size of the memory",
- 1,
- G_MAXUINT,
- -1,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (gobject_class,
- PROP_SEMAPHORE,
- g_param_spec_int ("semaphore",
- "Semaphore",
- "Semaphore file desciptor",
- -1,
- G_MAXINT,
- -1,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
-
-static void
-pinos_ringbuffer_init (PinosRingbuffer * rb)
-{
- PinosRingbufferPrivate *priv = rb->priv = PINOS_RINGBUFFER_GET_PRIVATE (rb);
-
- g_debug ("ringbuffer %p: new %u", rb, priv->size);
-
- priv->mode = PINOS_RINGBUFFER_MODE_READ;
- priv->size = 0;
- priv->fd = -1;
-}
-
-PinosRingbuffer *
-pinos_ringbuffer_new (PinosRingbufferMode mode,
- gsize size)
-{
- PinosRingbuffer *rb;
-
- g_return_val_if_fail (size > 0, NULL);
-
- rb = g_object_new (PINOS_TYPE_RINGBUFFER,
- "size", size,
- "mode", mode,
- NULL);
- return rb;
-}
-
-PinosRingbuffer *
-pinos_ringbuffer_new_import (PinosRingbufferMode mode,
- guint fdsize,
- int fd,
- int semaphore)
-{
- PinosRingbuffer *rb;
-
- g_return_val_if_fail (fdsize > 0, NULL);
- g_return_val_if_fail (fd >= 0, NULL);
-
- rb = g_object_new (PINOS_TYPE_RINGBUFFER,
- "mode", mode,
- "fd", fd,
- "fdsize", fdsize,
- "semaphore", semaphore,
- NULL);
- return rb;
-}
-
-
-gboolean
-pinos_ringbuffer_get_read_areas (PinosRingbuffer *rbuf,
- PinosRingbufferArea areas[2])
-{
- PinosRingbufferPrivate *priv;
-
- g_return_val_if_fail (PINOS_IS_RINGBUFFER (rbuf), FALSE);
- priv = rbuf->priv;
-
- spa_ringbuffer_get_read_areas (&priv->data->rbuf, (SpaRingbufferArea *)areas);
-
- return TRUE;
-}
-
-gboolean
-pinos_ringbuffer_get_write_areas (PinosRingbuffer *rbuf,
- PinosRingbufferArea areas[2])
-{
- PinosRingbufferPrivate *priv;
-
- g_return_val_if_fail (PINOS_IS_RINGBUFFER (rbuf), FALSE);
- priv = rbuf->priv;
-
- spa_ringbuffer_get_write_areas (&priv->data->rbuf, (SpaRingbufferArea *)areas);
-
- return TRUE;
-}
-
-gboolean
-pinos_ringbuffer_read_advance (PinosRingbuffer *rbuf,
- gssize len)
-{
- PinosRingbufferPrivate *priv;
- guint64 val;
-
- g_return_val_if_fail (PINOS_IS_RINGBUFFER (rbuf), FALSE);
- priv = rbuf->priv;
-
- spa_ringbuffer_read_advance (&priv->data->rbuf, len);
-
- if (priv->mode == PINOS_RINGBUFFER_MODE_READ) {
- val = 1;
- if (write (priv->semaphore, &val, 8) != 8)
- g_warning ("error writing semaphore");
- }
-
- return TRUE;
-}
-
-gboolean
-pinos_ringbuffer_write_advance (PinosRingbuffer *rbuf,
- gssize len)
-{
- PinosRingbufferPrivate *priv;
- guint64 val;
-
- g_return_val_if_fail (PINOS_IS_RINGBUFFER (rbuf), FALSE);
- priv = rbuf->priv;
-
- spa_ringbuffer_write_advance (&priv->data->rbuf, len);
-
- if (priv->mode == PINOS_RINGBUFFER_MODE_WRITE) {
- val = 1;
- if (write (priv->semaphore, &val, 8) != 8)
- g_warning ("error writing semaphore");
- }
- return TRUE;
-}
diff --git a/pinos/client/ringbuffer.h b/pinos/client/ringbuffer.h
deleted file mode 100644
index 98b89ece..00000000
--- a/pinos/client/ringbuffer.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Pinos
- * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __PINOS_RINGBUFFER_H__
-#define __PINOS_RINGBUFFER_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-typedef struct _PinosRingbuffer PinosRingbuffer;
-typedef struct _PinosRingbufferClass PinosRingbufferClass;
-typedef struct _PinosRingbufferPrivate PinosRingbufferPrivate;
-
-#include <pinos/client/introspect.h>
-
-#define PINOS_TYPE_RINGBUFFER (pinos_ringbuffer_get_type ())
-#define PINOS_IS_RINGBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_RINGBUFFER))
-#define PINOS_IS_RINGBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_RINGBUFFER))
-#define PINOS_RINGBUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_RINGBUFFER, PinosRingbufferClass))
-#define PINOS_RINGBUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_RINGBUFFER, PinosRingbuffer))
-#define PINOS_RINGBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_RINGBUFFER, PinosRingbufferClass))
-#define PINOS_RINGBUFFER_CAST(obj) ((PinosRingbuffer*)(obj))
-#define PINOS_RINGBUFFER_CLASS_CAST(klass) ((PinosRingbufferClass*)(klass))
-
-/**
- * PinosRingbuffer:
- *
- * Pinos ringbuffer object class.
- */
-struct _PinosRingbuffer {
- GObject object;
-
- PinosRingbufferPrivate *priv;
-};
-
-/**
- * PinosRingbufferClass:
- *
- * Pinos ringbuffer object class.
- */
-struct _PinosRingbufferClass {
- GObjectClass parent_class;
-};
-
-typedef void (*PinosRingbufferCallback) (PinosRingbuffer *rb, gpointer user_data);
-
-typedef enum {
- PINOS_RINGBUFFER_MODE_READ,
- PINOS_RINGBUFFER_MODE_WRITE,
-} PinosRingbufferMode;
-
-typedef struct {
- gpointer data;
- gsize len;
-} PinosRingbufferArea;
-
-/* normal GObject stuff */
-GType pinos_ringbuffer_get_type (void);
-
-PinosRingbuffer * pinos_ringbuffer_new (PinosRingbufferMode mode,
- gsize size);
-PinosRingbuffer * pinos_ringbuffer_new_import (PinosRingbufferMode mode,
- guint fdsize,
- int fd,
- int semaphore);
-
-gboolean pinos_ringbuffer_get_read_areas (PinosRingbuffer *rbuf,
- PinosRingbufferArea areas[2]);
-gboolean pinos_ringbuffer_read_advance (PinosRingbuffer *rbuf,
- gssize len);
-
-gboolean pinos_ringbuffer_get_write_areas (PinosRingbuffer *rbuf,
- PinosRingbufferArea areas[2]);
-gboolean pinos_ringbuffer_write_advance (PinosRingbuffer *rbuf,
- gssize len);
-
-G_END_DECLS
-
-#endif /* __PINOS_RINGBUFFER_H__ */
diff --git a/pinos/modules/spa/spa-monitor.c b/pinos/modules/spa/spa-monitor.c
index f17d03c9..9dd60107 100644
--- a/pinos/modules/spa/spa-monitor.c
+++ b/pinos/modules/spa/spa-monitor.c
@@ -35,13 +35,20 @@
typedef struct
{
+ char *id;
+ SpaList link;
+ PinosNode *node;
+} PinosSpaMonitorItem;
+
+typedef struct
+{
PinosSpaMonitor this;
PinosCore *core;
void *hnd;
- GHashTable *nodes;
+ SpaList item_list;
} PinosSpaMonitorImpl;
static void
@@ -50,7 +57,7 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
SpaResult res;
SpaHandle *handle;
- PinosNode *node;
+ PinosSpaMonitorItem *mitem;
void *node_iface;
void *clock_iface;
PinosProperties *props = NULL;
@@ -85,28 +92,50 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
item->info->items[i].value);
}
- node = pinos_node_new (impl->core,
- item->factory->name,
- node_iface,
- clock_iface,
- props);
+ mitem = calloc (1, sizeof (PinosSpaMonitorItem));
+ mitem->id = strdup (item->id);
+ mitem->node = pinos_node_new (impl->core,
+ item->factory->name,
+ node_iface,
+ clock_iface,
+ props);
- g_hash_table_insert (impl->nodes, strdup (item->id), node);
+ spa_list_insert (impl->item_list.prev, &mitem->link);
+}
+
+static PinosSpaMonitorItem *
+find_item (PinosSpaMonitor *this,
+ const char *id)
+{
+ PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
+ PinosSpaMonitorItem *mitem;
+
+ spa_list_for_each (mitem, &impl->item_list, link) {
+ if (strcmp (mitem->id, id) == 0) {
+ return mitem;
+ }
+ }
+ return NULL;
+}
+
+void
+destroy_item (PinosSpaMonitorItem *mitem)
+{
+ pinos_node_destroy (mitem->node);
+ spa_list_remove (&mitem->link);
+ free (mitem->id);
+ free (mitem);
}
static void
remove_item (PinosSpaMonitor *this, SpaMonitorItem *item)
{
- PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
- PinosNode *node;
+ PinosSpaMonitorItem *mitem;
pinos_log_debug ("monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
-
- node = g_hash_table_lookup (impl->nodes, item->id);
- if (node) {
- pinos_node_destroy (node);
- g_hash_table_remove (impl->nodes, item->id);
- }
+ mitem = find_item (this, item->id);
+ if (mitem)
+ destroy_item (mitem);
}
static void
@@ -200,10 +229,7 @@ pinos_spa_monitor_load (PinosCore *core,
this->factory_name = strdup (factory_name);
this->handle = handle;
- impl->nodes = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- free,
- NULL);
+ spa_list_init (&impl->item_list);
state = NULL;
while (true) {
@@ -236,15 +262,19 @@ void
pinos_spa_monitor_destroy (PinosSpaMonitor * monitor)
{
PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaMonitorImpl, this);
+ PinosSpaMonitorItem *mitem, *tmp;
pinos_log_debug ("spa-monitor %p: dispose", impl);
pinos_signal_emit (&monitor->destroy_signal, monitor);
+ spa_list_for_each_safe (mitem, tmp, &impl->item_list, link)
+ destroy_item (mitem);
+
spa_handle_clear (monitor->handle);
free (monitor->handle);
free (monitor->lib);
free (monitor->factory_name);
- g_hash_table_unref (impl->nodes);
+
dlclose (impl->hnd);
free (impl);
}
diff --git a/pinos/server/client.c b/pinos/server/client.c
index 31771e2b..3ac2d2a5 100644
--- a/pinos/server/client.c
+++ b/pinos/server/client.c
@@ -165,7 +165,7 @@ pinos_client_new (PinosCore *core,
client_watch_name (this);
- spa_list_insert (core->client_list.prev, &this->list);
+ spa_list_insert (core->client_list.prev, &this->link);
return this;
}
@@ -188,7 +188,7 @@ pinos_client_destroy (PinosClient * client)
spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
pinos_client_remove_resource (client, resource);
- spa_list_remove (&client->list);
+ spa_list_remove (&client->link);
free (client->sender);
if (client->properties)
diff --git a/pinos/server/client.h b/pinos/server/client.h
index 820dc34d..d45965d7 100644
--- a/pinos/server/client.h
+++ b/pinos/server/client.h
@@ -54,7 +54,7 @@ struct _PinosResource {
*/
struct _PinosClient {
PinosCore *core;
- SpaList list;
+ SpaList link;
PinosGlobal *global;
char *sender;
diff --git a/pinos/server/core.c b/pinos/server/core.c
index 1917611e..39c3f9db 100644
--- a/pinos/server/core.c
+++ b/pinos/server/core.c
@@ -56,6 +56,7 @@ pinos_core_new (PinosMainLoop *main_loop)
spa_list_init (&this->global_list);
spa_list_init (&this->client_list);
spa_list_init (&this->node_list);
+ spa_list_init (&this->node_factory_list);
spa_list_init (&this->link_list);
pinos_signal_init (&this->destroy_signal);
pinos_signal_init (&this->global_added);
@@ -115,5 +116,7 @@ pinos_core_remove_global (PinosCore *core,
spa_list_remove (&global->link);
pinos_signal_emit (&core->global_removed, core, global);
+ g_clear_object (&global->skel);
+
free (global);
}
diff --git a/pinos/server/core.h b/pinos/server/core.h
index bf24bd52..507253b1 100644
--- a/pinos/server/core.h
+++ b/pinos/server/core.h
@@ -65,9 +65,9 @@ struct _PinosCore {
SpaList global_list;
SpaList client_list;
SpaList node_list;
+ SpaList node_factory_list;
SpaList link_list;
-
PinosMainLoop *main_loop;
PinosDataLoop *data_loop;
diff --git a/pinos/server/daemon.c b/pinos/server/daemon.c
index ea4e0f2a..fa0293c6 100644
--- a/pinos/server/daemon.c
+++ b/pinos/server/daemon.c
@@ -55,9 +55,6 @@ typedef struct {
PinosListener port_unlinked;
PinosListener node_state_changed;
PinosListener link_state_changed;
-
- GHashTable *clients;
- GHashTable *node_factories;
} PinosDaemonImpl;
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
@@ -67,16 +64,29 @@ sender_get_client (PinosDaemon *daemon,
const char *sender,
bool create)
{
- PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
PinosClient *client;
- client = g_hash_table_lookup (impl->clients, sender);
- if (client == NULL && create) {
- client = pinos_client_new (daemon->core, sender, NULL);
+ spa_list_for_each (client, &daemon->core->client_list, link) {
+ if (strcmp (client->sender, sender) == 0)
+ return client;
}
+ client = pinos_client_new (daemon->core, sender, NULL);
return client;
}
+static PinosNodeFactory *
+find_factory_by_name (PinosDaemon *daemon,
+ const char *name)
+{
+ PinosNodeFactory *factory;
+
+ spa_list_for_each (factory, &daemon->core->node_factory_list, link) {
+ if (strcmp (factory->name, name) == 0)
+ return factory;
+ }
+ return NULL;
+}
+
static bool
handle_create_node (PinosDaemon1 *interface,
GDBusMethodInvocation *invocation,
@@ -100,7 +110,7 @@ handle_create_node (PinosDaemon1 *interface,
props = pinos_properties_from_variant (arg_properties);
- factory = g_hash_table_lookup (impl->node_factories, arg_factory_name);
+ factory = find_factory_by_name (this, arg_factory_name);
if (factory == NULL)
goto no_factory;
@@ -490,14 +500,6 @@ on_global_added (PinosListener *listener,
PinosNode *node = global->object;
on_node_added (this, node);
- } else if (global->type == this->core->registry.uri.node_factory) {
- PinosNodeFactory *factory = global->object;
-
- g_hash_table_insert (impl->node_factories, (void *)factory->name, factory);
- } else if (global->type == this->core->registry.uri.client) {
- PinosClient *client = global->object;
-
- g_hash_table_insert (impl->clients, (gpointer) client->sender, client);
}
}
@@ -517,14 +519,6 @@ on_global_removed (PinosListener *listener,
PinosNode *node = global->object;
on_node_removed (this, node);
- } else if (global->type == this->core->registry.uri.node_factory) {
- PinosNodeFactory *factory = global->object;
-
- g_hash_table_remove (impl->node_factories, factory->name);
- } else if (global->type == this->core->registry.uri.client) {
- PinosClient *client = global->object;
-
- g_hash_table_remove (impl->clients, (gpointer) client->sender);
}
}
@@ -559,7 +553,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
pinos_log_debug ("name \"%s\", %d", name, have_name);
- spa_list_for_each (n, &daemon->core->node_list, list) {
+ spa_list_for_each (n, &daemon->core->node_list, link) {
pinos_log_debug ("node path \"%s\"", n->global->object_path);
if (have_name) {
@@ -617,11 +611,6 @@ pinos_daemon_new (PinosCore *core,
pinos_signal_add (&core->link_state_changed, &impl->link_state_changed, on_link_state_changed);
impl->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
- impl->clients = g_hash_table_new (g_str_hash, g_str_equal);
- impl->node_factories = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- NULL,
- NULL);
impl->iface = pinos_daemon1_skeleton_new ();
g_signal_connect (impl->iface, "handle-create-node", (GCallback) handle_create_node, impl);
@@ -658,11 +647,14 @@ pinos_daemon_destroy (PinosDaemon *daemon)
pinos_signal_remove (&impl->global_added);
pinos_signal_remove (&impl->global_removed);
+ pinos_signal_remove (&impl->node_state_changed);
+ pinos_signal_remove (&impl->port_added);
+ pinos_signal_remove (&impl->port_removed);
+ pinos_signal_remove (&impl->port_unlinked);
+ pinos_signal_remove (&impl->link_state_changed);
g_clear_object (&impl->server_manager);
g_clear_object (&impl->iface);
- g_hash_table_unref (impl->clients);
- g_hash_table_unref (impl->node_factories);
free (impl);
}
diff --git a/pinos/server/daemon.h b/pinos/server/daemon.h
index df2f66ac..193ef1b6 100644
--- a/pinos/server/daemon.h
+++ b/pinos/server/daemon.h
@@ -41,7 +41,7 @@ typedef struct _PinosDaemon PinosDaemon;
*/
struct _PinosDaemon {
PinosCore *core;
- SpaList list;
+ SpaList link;
PinosGlobal *global;
PinosProperties *properties;
diff --git a/pinos/server/link.c b/pinos/server/link.c
index 5fcfb1f1..ee861ec7 100644
--- a/pinos/server/link.c
+++ b/pinos/server/link.c
@@ -749,7 +749,7 @@ pinos_link_new (PinosCore *core,
this->output->node, this->output->port_id,
this->input->node, this->input->port_id);
- spa_list_insert (core->link_list.prev, &this->list);
+ spa_list_insert (core->link_list.prev, &this->link);
impl->iface = pinos_link1_skeleton_new ();
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_LINK);
@@ -867,7 +867,7 @@ pinos_link_destroy (PinosLink * this)
pinos_signal_emit (&this->destroy_signal, this);
pinos_core_remove_global (this->core, this->global);
- spa_list_remove (&this->list);
+ spa_list_remove (&this->link);
if (this->input) {
pinos_signal_remove (&impl->input_port_destroy);
diff --git a/pinos/server/link.h b/pinos/server/link.h
index 3e473ad9..2687b613 100644
--- a/pinos/server/link.h
+++ b/pinos/server/link.h
@@ -44,7 +44,7 @@ typedef struct _PinosLink PinosLink;
*/
struct _PinosLink {
PinosCore *core;
- SpaList list;
+ SpaList link;
PinosGlobal *global;
PinosProperties *properties;
diff --git a/pinos/server/node-factory.h b/pinos/server/node-factory.h
index e7341ceb..013aa992 100644
--- a/pinos/server/node-factory.h
+++ b/pinos/server/node-factory.h
@@ -38,6 +38,10 @@ typedef struct _PinosNodeFactory PinosNodeFactory;
* Pinos node factory interface.
*/
struct _PinosNodeFactory {
+ PinosCore *core;
+ SpaList link;
+ PinosGlobal *global;
+
const char *name;
PinosNode * (*create_node) (PinosNodeFactory *factory,
diff --git a/pinos/server/node.c b/pinos/server/node.c
index 11429c53..80d123ee 100644
--- a/pinos/server/node.c
+++ b/pinos/server/node.c
@@ -496,7 +496,7 @@ pinos_node_new (PinosCore *core,
(PinosDeferFunc) init_complete,
NULL);
}
- spa_list_insert (core->node_list.prev, &this->list);
+ spa_list_insert (core->node_list.prev, &this->link);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
pinos_object_skeleton_set_node1 (skel, impl->iface);
@@ -593,7 +593,7 @@ pinos_node_destroy (PinosNode * this)
pinos_log_debug ("node %p: destroy", impl);
pinos_signal_emit (&this->destroy_signal, this);
- spa_list_remove (&this->list);
+ spa_list_remove (&this->link);
pinos_core_remove_global (this->core, this->global);
res = spa_poll_invoke (&this->data_loop->poll,
diff --git a/pinos/server/node.h b/pinos/server/node.h
index 24024a0a..62923540 100644
--- a/pinos/server/node.h
+++ b/pinos/server/node.h
@@ -48,7 +48,7 @@ typedef struct _PinosNode PinosNode;
*/
struct _PinosNode {
PinosCore *core;
- SpaList list;
+ SpaList link;
PinosGlobal *global;
bool unlinking;