mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	cleanups
Remove hastables, use lists Remove obsolete ringbuffer some small cleanups
This commit is contained in:
		
							parent
							
								
									b6ad45bb74
								
							
						
					
					
						commit
						1a48bccca0
					
				
					 16 changed files with 93 additions and 554 deletions
				
			
		| 
						 | 
					@ -8,7 +8,6 @@ pinos_headers = [
 | 
				
			||||||
  'mem.h',
 | 
					  'mem.h',
 | 
				
			||||||
  'pinos.h',
 | 
					  'pinos.h',
 | 
				
			||||||
  'properties.h',
 | 
					  'properties.h',
 | 
				
			||||||
  'ringbuffer.h',
 | 
					 | 
				
			||||||
  'rtkit.h',
 | 
					  'rtkit.h',
 | 
				
			||||||
  'stream.h',
 | 
					  'stream.h',
 | 
				
			||||||
  'subscribe.h',
 | 
					  'subscribe.h',
 | 
				
			||||||
| 
						 | 
					@ -29,7 +28,6 @@ pinos_sources = [
 | 
				
			||||||
  'serialize.c',
 | 
					  'serialize.c',
 | 
				
			||||||
  'stream.c',
 | 
					  'stream.c',
 | 
				
			||||||
  'pinos.c',
 | 
					  'pinos.c',
 | 
				
			||||||
  'ringbuffer.c',
 | 
					 | 
				
			||||||
  'rtkit.c',
 | 
					  'rtkit.c',
 | 
				
			||||||
  'subscribe.c',
 | 
					  'subscribe.c',
 | 
				
			||||||
  'thread-mainloop.c',
 | 
					  'thread-mainloop.c',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,6 @@ extern const char             g_log_domain_pinos[];
 | 
				
			||||||
#include <pinos/client/mem.h>
 | 
					#include <pinos/client/mem.h>
 | 
				
			||||||
#include <pinos/client/thread-mainloop.h>
 | 
					#include <pinos/client/thread-mainloop.h>
 | 
				
			||||||
#include <pinos/client/properties.h>
 | 
					#include <pinos/client/properties.h>
 | 
				
			||||||
#include <pinos/client/ringbuffer.h>
 | 
					 | 
				
			||||||
#include <pinos/client/stream.h>
 | 
					#include <pinos/client/stream.h>
 | 
				
			||||||
#include <pinos/client/subscribe.h>
 | 
					#include <pinos/client/subscribe.h>
 | 
				
			||||||
#include <pinos/client/utils.h>
 | 
					#include <pinos/client/utils.h>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -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__ */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,13 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "spa-monitor.h"
 | 
					#include "spa-monitor.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  char      *id;
 | 
				
			||||||
 | 
					  SpaList    link;
 | 
				
			||||||
 | 
					  PinosNode *node;
 | 
				
			||||||
 | 
					} PinosSpaMonitorItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct
 | 
					typedef struct
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosSpaMonitor this;
 | 
					  PinosSpaMonitor this;
 | 
				
			||||||
| 
						 | 
					@ -41,7 +48,7 @@ typedef struct
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void *hnd;
 | 
					  void *hnd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GHashTable *nodes;
 | 
					  SpaList item_list;
 | 
				
			||||||
} PinosSpaMonitorImpl;
 | 
					} PinosSpaMonitorImpl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -50,7 +57,7 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
 | 
				
			||||||
  PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
 | 
					  PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
 | 
				
			||||||
  SpaResult res;
 | 
					  SpaResult res;
 | 
				
			||||||
  SpaHandle *handle;
 | 
					  SpaHandle *handle;
 | 
				
			||||||
  PinosNode *node;
 | 
					  PinosSpaMonitorItem *mitem;
 | 
				
			||||||
  void *node_iface;
 | 
					  void *node_iface;
 | 
				
			||||||
  void *clock_iface;
 | 
					  void *clock_iface;
 | 
				
			||||||
  PinosProperties *props = NULL;
 | 
					  PinosProperties *props = NULL;
 | 
				
			||||||
| 
						 | 
					@ -85,28 +92,50 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
 | 
				
			||||||
                            item->info->items[i].value);
 | 
					                            item->info->items[i].value);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  node = pinos_node_new (impl->core,
 | 
					  mitem = calloc (1, sizeof (PinosSpaMonitorItem));
 | 
				
			||||||
                         item->factory->name,
 | 
					  mitem->id = strdup (item->id);
 | 
				
			||||||
                         node_iface,
 | 
					  mitem->node = pinos_node_new (impl->core,
 | 
				
			||||||
                         clock_iface,
 | 
					                                item->factory->name,
 | 
				
			||||||
                         props);
 | 
					                                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
 | 
					static void
 | 
				
			||||||
remove_item (PinosSpaMonitor *this, SpaMonitorItem *item)
 | 
					remove_item (PinosSpaMonitor *this, SpaMonitorItem *item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
 | 
					  PinosSpaMonitorItem *mitem;
 | 
				
			||||||
  PinosNode *node;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_log_debug ("monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
 | 
					  pinos_log_debug ("monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
 | 
				
			||||||
 | 
					  mitem = find_item (this, item->id);
 | 
				
			||||||
  node = g_hash_table_lookup (impl->nodes, item->id);
 | 
					  if (mitem)
 | 
				
			||||||
  if (node) {
 | 
					    destroy_item (mitem);
 | 
				
			||||||
    pinos_node_destroy (node);
 | 
					 | 
				
			||||||
    g_hash_table_remove (impl->nodes, item->id);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -200,10 +229,7 @@ pinos_spa_monitor_load (PinosCore  *core,
 | 
				
			||||||
  this->factory_name = strdup (factory_name);
 | 
					  this->factory_name = strdup (factory_name);
 | 
				
			||||||
  this->handle = handle;
 | 
					  this->handle = handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  impl->nodes = g_hash_table_new_full (g_str_hash,
 | 
					  spa_list_init (&impl->item_list);
 | 
				
			||||||
                                       g_str_equal,
 | 
					 | 
				
			||||||
                                       free,
 | 
					 | 
				
			||||||
                                       NULL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  state = NULL;
 | 
					  state = NULL;
 | 
				
			||||||
  while (true) {
 | 
					  while (true) {
 | 
				
			||||||
| 
						 | 
					@ -236,15 +262,19 @@ void
 | 
				
			||||||
pinos_spa_monitor_destroy (PinosSpaMonitor * monitor)
 | 
					pinos_spa_monitor_destroy (PinosSpaMonitor * monitor)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaMonitorImpl, this);
 | 
					  PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaMonitorImpl, this);
 | 
				
			||||||
 | 
					  PinosSpaMonitorItem *mitem, *tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_log_debug ("spa-monitor %p: dispose", impl);
 | 
					  pinos_log_debug ("spa-monitor %p: dispose", impl);
 | 
				
			||||||
  pinos_signal_emit (&monitor->destroy_signal, monitor);
 | 
					  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);
 | 
					  spa_handle_clear (monitor->handle);
 | 
				
			||||||
  free (monitor->handle);
 | 
					  free (monitor->handle);
 | 
				
			||||||
  free (monitor->lib);
 | 
					  free (monitor->lib);
 | 
				
			||||||
  free (monitor->factory_name);
 | 
					  free (monitor->factory_name);
 | 
				
			||||||
  g_hash_table_unref (impl->nodes);
 | 
					
 | 
				
			||||||
  dlclose (impl->hnd);
 | 
					  dlclose (impl->hnd);
 | 
				
			||||||
  free (impl);
 | 
					  free (impl);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -165,7 +165,7 @@ pinos_client_new (PinosCore       *core,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client_watch_name (this);
 | 
					  client_watch_name (this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  spa_list_insert (core->client_list.prev, &this->list);
 | 
					  spa_list_insert (core->client_list.prev, &this->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return this;
 | 
					  return this;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -188,7 +188,7 @@ pinos_client_destroy (PinosClient * client)
 | 
				
			||||||
  spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
 | 
					  spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
 | 
				
			||||||
    pinos_client_remove_resource (client, resource);
 | 
					    pinos_client_remove_resource (client, resource);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  spa_list_remove (&client->list);
 | 
					  spa_list_remove (&client->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  free (client->sender);
 | 
					  free (client->sender);
 | 
				
			||||||
  if (client->properties)
 | 
					  if (client->properties)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,7 @@ struct _PinosResource {
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosClient {
 | 
					struct _PinosClient {
 | 
				
			||||||
  PinosCore   *core;
 | 
					  PinosCore   *core;
 | 
				
			||||||
  SpaList      list;
 | 
					  SpaList      link;
 | 
				
			||||||
  PinosGlobal *global;
 | 
					  PinosGlobal *global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  char *sender;
 | 
					  char *sender;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@ pinos_core_new (PinosMainLoop *main_loop)
 | 
				
			||||||
  spa_list_init (&this->global_list);
 | 
					  spa_list_init (&this->global_list);
 | 
				
			||||||
  spa_list_init (&this->client_list);
 | 
					  spa_list_init (&this->client_list);
 | 
				
			||||||
  spa_list_init (&this->node_list);
 | 
					  spa_list_init (&this->node_list);
 | 
				
			||||||
 | 
					  spa_list_init (&this->node_factory_list);
 | 
				
			||||||
  spa_list_init (&this->link_list);
 | 
					  spa_list_init (&this->link_list);
 | 
				
			||||||
  pinos_signal_init (&this->destroy_signal);
 | 
					  pinos_signal_init (&this->destroy_signal);
 | 
				
			||||||
  pinos_signal_init (&this->global_added);
 | 
					  pinos_signal_init (&this->global_added);
 | 
				
			||||||
| 
						 | 
					@ -115,5 +116,7 @@ pinos_core_remove_global (PinosCore      *core,
 | 
				
			||||||
  spa_list_remove (&global->link);
 | 
					  spa_list_remove (&global->link);
 | 
				
			||||||
  pinos_signal_emit (&core->global_removed, core, global);
 | 
					  pinos_signal_emit (&core->global_removed, core, global);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_clear_object (&global->skel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  free (global);
 | 
					  free (global);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,9 +65,9 @@ struct _PinosCore {
 | 
				
			||||||
  SpaList global_list;
 | 
					  SpaList global_list;
 | 
				
			||||||
  SpaList client_list;
 | 
					  SpaList client_list;
 | 
				
			||||||
  SpaList node_list;
 | 
					  SpaList node_list;
 | 
				
			||||||
 | 
					  SpaList node_factory_list;
 | 
				
			||||||
  SpaList link_list;
 | 
					  SpaList link_list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  PinosMainLoop *main_loop;
 | 
					  PinosMainLoop *main_loop;
 | 
				
			||||||
  PinosDataLoop *data_loop;
 | 
					  PinosDataLoop *data_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,9 +55,6 @@ typedef struct {
 | 
				
			||||||
  PinosListener port_unlinked;
 | 
					  PinosListener port_unlinked;
 | 
				
			||||||
  PinosListener node_state_changed;
 | 
					  PinosListener node_state_changed;
 | 
				
			||||||
  PinosListener link_state_changed;
 | 
					  PinosListener link_state_changed;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  GHashTable *clients;
 | 
					 | 
				
			||||||
  GHashTable *node_factories;
 | 
					 | 
				
			||||||
} PinosDaemonImpl;
 | 
					} PinosDaemonImpl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
 | 
					static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
 | 
				
			||||||
| 
						 | 
					@ -67,16 +64,29 @@ sender_get_client (PinosDaemon *daemon,
 | 
				
			||||||
                   const char  *sender,
 | 
					                   const char  *sender,
 | 
				
			||||||
                   bool create)
 | 
					                   bool create)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
 | 
					 | 
				
			||||||
  PinosClient *client;
 | 
					  PinosClient *client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client = g_hash_table_lookup (impl->clients, sender);
 | 
					  spa_list_for_each (client, &daemon->core->client_list, link) {
 | 
				
			||||||
  if (client == NULL && create) {
 | 
					    if (strcmp (client->sender, sender) == 0)
 | 
				
			||||||
    client = pinos_client_new (daemon->core, sender, NULL);
 | 
					      return client;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  client = pinos_client_new (daemon->core, sender, NULL);
 | 
				
			||||||
  return client;
 | 
					  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
 | 
					static bool
 | 
				
			||||||
handle_create_node (PinosDaemon1           *interface,
 | 
					handle_create_node (PinosDaemon1           *interface,
 | 
				
			||||||
                    GDBusMethodInvocation  *invocation,
 | 
					                    GDBusMethodInvocation  *invocation,
 | 
				
			||||||
| 
						 | 
					@ -100,7 +110,7 @@ handle_create_node (PinosDaemon1           *interface,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  props = pinos_properties_from_variant (arg_properties);
 | 
					  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)
 | 
					  if (factory == NULL)
 | 
				
			||||||
    goto no_factory;
 | 
					    goto no_factory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -490,14 +500,6 @@ on_global_added (PinosListener *listener,
 | 
				
			||||||
    PinosNode *node = global->object;
 | 
					    PinosNode *node = global->object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    on_node_added (this, node);
 | 
					    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;
 | 
					    PinosNode *node = global->object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    on_node_removed (this, node);
 | 
					    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);
 | 
					  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);
 | 
					    pinos_log_debug ("node path \"%s\"", n->global->object_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (have_name) {
 | 
					    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);
 | 
					  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->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 ();
 | 
					  impl->iface = pinos_daemon1_skeleton_new ();
 | 
				
			||||||
  g_signal_connect (impl->iface, "handle-create-node", (GCallback) handle_create_node, impl);
 | 
					  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_added);
 | 
				
			||||||
  pinos_signal_remove (&impl->global_removed);
 | 
					  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->server_manager);
 | 
				
			||||||
  g_clear_object (&impl->iface);
 | 
					  g_clear_object (&impl->iface);
 | 
				
			||||||
  g_hash_table_unref (impl->clients);
 | 
					 | 
				
			||||||
  g_hash_table_unref (impl->node_factories);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  free (impl);
 | 
					  free (impl);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ typedef struct _PinosDaemon PinosDaemon;
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosDaemon {
 | 
					struct _PinosDaemon {
 | 
				
			||||||
  PinosCore   *core;
 | 
					  PinosCore   *core;
 | 
				
			||||||
  SpaList      list;
 | 
					  SpaList      link;
 | 
				
			||||||
  PinosGlobal *global;
 | 
					  PinosGlobal *global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosProperties *properties;
 | 
					  PinosProperties *properties;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -749,7 +749,7 @@ pinos_link_new (PinosCore       *core,
 | 
				
			||||||
                                                  this->output->node, this->output->port_id,
 | 
					                                                  this->output->node, this->output->port_id,
 | 
				
			||||||
                                                  this->input->node, this->input->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 ();
 | 
					  impl->iface = pinos_link1_skeleton_new ();
 | 
				
			||||||
  skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_LINK);
 | 
					  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_signal_emit (&this->destroy_signal, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_core_remove_global (this->core, this->global);
 | 
					  pinos_core_remove_global (this->core, this->global);
 | 
				
			||||||
  spa_list_remove (&this->list);
 | 
					  spa_list_remove (&this->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (this->input) {
 | 
					  if (this->input) {
 | 
				
			||||||
    pinos_signal_remove (&impl->input_port_destroy);
 | 
					    pinos_signal_remove (&impl->input_port_destroy);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ typedef struct _PinosLink PinosLink;
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosLink {
 | 
					struct _PinosLink {
 | 
				
			||||||
  PinosCore   *core;
 | 
					  PinosCore   *core;
 | 
				
			||||||
  SpaList      list;
 | 
					  SpaList      link;
 | 
				
			||||||
  PinosGlobal *global;
 | 
					  PinosGlobal *global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosProperties *properties;
 | 
					  PinosProperties *properties;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,10 @@ typedef struct _PinosNodeFactory PinosNodeFactory;
 | 
				
			||||||
 * Pinos node factory interface.
 | 
					 * Pinos node factory interface.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosNodeFactory {
 | 
					struct _PinosNodeFactory {
 | 
				
			||||||
 | 
					  PinosCore   *core;
 | 
				
			||||||
 | 
					  SpaList      link;
 | 
				
			||||||
 | 
					  PinosGlobal *global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const char *name;
 | 
					  const char *name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosNode *      (*create_node) (PinosNodeFactory *factory,
 | 
					  PinosNode *      (*create_node) (PinosNodeFactory *factory,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -496,7 +496,7 @@ pinos_node_new (PinosCore       *core,
 | 
				
			||||||
                           (PinosDeferFunc) init_complete,
 | 
					                           (PinosDeferFunc) init_complete,
 | 
				
			||||||
                           NULL);
 | 
					                           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);
 | 
					  skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
 | 
				
			||||||
  pinos_object_skeleton_set_node1 (skel, impl->iface);
 | 
					  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_log_debug ("node %p: destroy", impl);
 | 
				
			||||||
  pinos_signal_emit (&this->destroy_signal, this);
 | 
					  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);
 | 
					  pinos_core_remove_global (this->core, this->global);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  res = spa_poll_invoke (&this->data_loop->poll,
 | 
					  res = spa_poll_invoke (&this->data_loop->poll,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ typedef struct _PinosNode PinosNode;
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosNode {
 | 
					struct _PinosNode {
 | 
				
			||||||
  PinosCore   *core;
 | 
					  PinosCore   *core;
 | 
				
			||||||
  SpaList      list;
 | 
					  SpaList      link;
 | 
				
			||||||
  PinosGlobal *global;
 | 
					  PinosGlobal *global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool unlinking;
 | 
					  bool unlinking;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue