mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-17 08:56:49 -05:00
Remove dynamic types
Do not use dynamic types anymore. The reason is that it's difficult: - to maintain a shared type database over a network. - the extra overhead when translating between processes and for maintaining the translation tables. - race conditions in translating in RT-threads, this is a problem because we want to make event streams. We now have simple enums with types and extension points for all types. This is also nicer to use in general. We don't need the mapper anymore or pass strings around as types. There is a parallel type info system to get more info about ids and enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
parent
e6977fa178
commit
fca3e1d85d
162 changed files with 5200 additions and 7461 deletions
|
|
@ -27,29 +27,17 @@
|
|||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/dbus.h>
|
||||
|
||||
#define NAME "dbus"
|
||||
|
||||
struct type {
|
||||
uint32_t dbus;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->dbus = spa_type_map_get_id(map, SPA_TYPE__DBus);
|
||||
}
|
||||
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_dbus dbus;
|
||||
|
||||
struct type type;
|
||||
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop_utils *utils;
|
||||
|
||||
|
|
@ -339,7 +327,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (interface_id == this->type.dbus)
|
||||
if (interface_id == SPA_ID_INTERFACE_DBus)
|
||||
*interface = &this->dbus;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -382,22 +370,15 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->dbus = impl_dbus;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_Log)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__LoopUtils) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_LoopUtils)
|
||||
this->utils = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(this->log, "a type-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (this->utils == NULL) {
|
||||
spa_log_error(this->log, "a LoopUtils is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: initialized", this);
|
||||
|
||||
|
|
@ -405,7 +386,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__DBus,},
|
||||
{SPA_ID_INTERFACE_DBus,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/utils/ringbuffer.h>
|
||||
#include <spa/utils/type.h>
|
||||
|
||||
#define NAME "logger"
|
||||
|
||||
|
|
@ -36,22 +36,10 @@
|
|||
|
||||
#define TRACE_BUFFER (16*1024)
|
||||
|
||||
struct type {
|
||||
uint32_t log;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->log = spa_type_map_get_id(map, SPA_TYPE__Log);
|
||||
}
|
||||
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_log log;
|
||||
|
||||
struct type type;
|
||||
struct spa_type_map *map;
|
||||
|
||||
bool colors;
|
||||
|
||||
struct spa_ringbuffer trace_rb;
|
||||
|
|
@ -170,7 +158,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (interface_id == this->type.log)
|
||||
if (interface_id == SPA_ID_INTERFACE_Log)
|
||||
*interface = &this->log;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -224,16 +212,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->log = impl_log;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_MainLoop)
|
||||
loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(&this->log, "a type-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
if (info && (str = spa_dict_lookup(info, "log.colors")) != NULL)
|
||||
this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1);
|
||||
|
|
@ -256,7 +237,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Log,},
|
||||
{SPA_ID_INTERFACE_Log,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@
|
|||
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/utils/list.h>
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/utils/ringbuffer.h>
|
||||
|
||||
#define NAME "loop"
|
||||
|
|
@ -53,21 +53,8 @@ struct invoke_item {
|
|||
int res;
|
||||
};
|
||||
|
||||
struct type {
|
||||
uint32_t loop;
|
||||
uint32_t loop_control;
|
||||
uint32_t loop_utils;
|
||||
};
|
||||
|
||||
static void loop_signal_event(struct spa_source *source);
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->loop = spa_type_map_get_id(map, SPA_TYPE__Loop);
|
||||
type->loop_control = spa_type_map_get_id(map, SPA_TYPE__LoopControl);
|
||||
type->loop_utils = spa_type_map_get_id(map, SPA_TYPE__LoopUtils);
|
||||
}
|
||||
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_loop loop;
|
||||
|
|
@ -75,8 +62,6 @@ struct impl {
|
|||
struct spa_loop_utils utils;
|
||||
|
||||
struct spa_log *log;
|
||||
struct type type;
|
||||
struct spa_type_map *map;
|
||||
|
||||
struct spa_list source_list;
|
||||
struct spa_list destroy_list;
|
||||
|
|
@ -676,15 +661,19 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
impl = (struct impl *) handle;
|
||||
|
||||
if (interface_id == impl->type.loop)
|
||||
switch (interface_id) {
|
||||
case SPA_ID_INTERFACE_Loop:
|
||||
*interface = &impl->loop;
|
||||
else if (interface_id == impl->type.loop_control)
|
||||
break;
|
||||
case SPA_ID_INTERFACE_LoopControl:
|
||||
*interface = &impl->control;
|
||||
else if (interface_id == impl->type.loop_utils)
|
||||
break;
|
||||
case SPA_ID_INTERFACE_LoopUtils:
|
||||
*interface = &impl->utils;
|
||||
else
|
||||
break;
|
||||
default:
|
||||
return -ENOENT;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -737,16 +726,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
impl->utils = impl_loop_utils;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
impl->map = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_Log)
|
||||
impl->log = support[i].data;
|
||||
}
|
||||
if (impl->map == NULL) {
|
||||
spa_log_error(impl->log, NAME " %p: a type-map is needed", impl);
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&impl->type, impl->map);
|
||||
|
||||
impl->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (impl->epoll_fd == -1)
|
||||
|
|
@ -767,9 +749,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Loop,},
|
||||
{SPA_TYPE__LoopControl,},
|
||||
{SPA_TYPE__LoopUtils,},
|
||||
{SPA_ID_INTERFACE_Loop,},
|
||||
{SPA_ID_INTERFACE_LoopControl,},
|
||||
{SPA_ID_INTERFACE_LoopUtils,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -1,227 +0,0 @@
|
|||
/* Spa
|
||||
* Copyright (C) 2017 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 <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/plugin.h>
|
||||
|
||||
#define NAME "mapper"
|
||||
|
||||
struct type {
|
||||
uint32_t type_map;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->type_map = spa_type_map_get_id(map, SPA_TYPE__TypeMap);
|
||||
}
|
||||
|
||||
struct array {
|
||||
size_t size;
|
||||
size_t maxsize;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_type_map map;
|
||||
|
||||
struct type type;
|
||||
|
||||
struct array types;
|
||||
struct array strings;
|
||||
};
|
||||
|
||||
static inline void * alloc_size(struct array *array, size_t size, size_t extend)
|
||||
{
|
||||
void *res;
|
||||
if (array->size + size > array->maxsize) {
|
||||
array->maxsize = SPA_ROUND_UP_N(array->size + size, extend);
|
||||
array->data = realloc(array->data, array->maxsize);
|
||||
}
|
||||
res = SPA_MEMBER(array->data, array->size, void);
|
||||
array->size += size;
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
impl_type_map_get_id(struct spa_type_map *map, const char *type)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map);
|
||||
uint32_t i, len;
|
||||
void *p;
|
||||
off_t o, *off;
|
||||
|
||||
if (type == NULL)
|
||||
return SPA_ID_INVALID;
|
||||
|
||||
for (i = 0; i < impl->types.size / sizeof(off_t); i++) {
|
||||
o = ((off_t *)impl->types.data)[i];
|
||||
if (strcmp(SPA_MEMBER(impl->strings.data, o, char), type) == 0)
|
||||
return i;
|
||||
}
|
||||
len = strlen(type);
|
||||
p = alloc_size(&impl->strings, len+1, 1024);
|
||||
memcpy(p, type, len + 1);
|
||||
|
||||
off = alloc_size(&impl->types, sizeof(off_t), 128);
|
||||
*off = SPA_PTRDIFF(p, impl->strings.data);
|
||||
i = SPA_PTRDIFF(off, impl->types.data) / sizeof(off_t);
|
||||
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
static const char *
|
||||
impl_type_map_get_type(const struct spa_type_map *map, uint32_t id)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map);
|
||||
|
||||
if (id < impl->types.size / sizeof(off_t)) {
|
||||
off_t o = ((off_t *)impl->types.data)[id];
|
||||
return SPA_MEMBER(impl->strings.data, o, char);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t
|
||||
impl_type_map_get_size(const struct spa_type_map *map)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map);
|
||||
return impl->types.size / sizeof(off_t);
|
||||
}
|
||||
|
||||
static const struct spa_type_map impl_type_map = {
|
||||
SPA_VERSION_TYPE_MAP,
|
||||
NULL,
|
||||
impl_type_map_get_id,
|
||||
impl_type_map_get_type,
|
||||
impl_type_map_get_size,
|
||||
};
|
||||
|
||||
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
|
||||
{
|
||||
struct impl *impl;
|
||||
|
||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(interface != NULL, -EINVAL);
|
||||
|
||||
impl = (struct impl *) handle;
|
||||
|
||||
if (interface_id == impl->type.type_map)
|
||||
*interface = &impl->map;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int impl_clear(struct spa_handle *handle)
|
||||
{
|
||||
struct impl *impl;
|
||||
|
||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||
|
||||
impl = (struct impl *) handle;
|
||||
|
||||
if (impl->types.data)
|
||||
free(impl->types.data);
|
||||
if (impl->strings.data)
|
||||
free(impl->strings.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t
|
||||
impl_get_size(const struct spa_handle_factory *factory,
|
||||
const struct spa_dict *params)
|
||||
{
|
||||
return sizeof(struct impl);
|
||||
}
|
||||
|
||||
static int
|
||||
impl_init(const struct spa_handle_factory *factory,
|
||||
struct spa_handle *handle,
|
||||
const struct spa_dict *info,
|
||||
const struct spa_support *support,
|
||||
uint32_t n_support)
|
||||
{
|
||||
struct impl *impl;
|
||||
|
||||
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||
|
||||
handle->get_interface = impl_get_interface;
|
||||
handle->clear = impl_clear;
|
||||
|
||||
impl = (struct impl *) handle;
|
||||
|
||||
impl->map = impl_type_map;
|
||||
|
||||
init_type(&impl->type, &impl->map);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__TypeMap,},
|
||||
};
|
||||
|
||||
static int
|
||||
impl_enum_interface_info(const struct spa_handle_factory *factory,
|
||||
const struct spa_interface_info **info,
|
||||
uint32_t *index)
|
||||
{
|
||||
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(info != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(index != NULL, -EINVAL);
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
*info = &impl_interfaces[*index];
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
(*index)++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct spa_handle_factory type_map_factory = {
|
||||
SPA_VERSION_HANDLE_FACTORY,
|
||||
NAME,
|
||||
NULL,
|
||||
impl_get_size,
|
||||
impl_init,
|
||||
impl_enum_interface_info,
|
||||
};
|
||||
|
||||
int spa_handle_factory_register(const struct spa_handle_factory *factory);
|
||||
|
||||
static void reg(void) __attribute__ ((constructor));
|
||||
static void reg(void)
|
||||
{
|
||||
spa_handle_factory_register(&type_map_factory);
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
spa_support_sources = ['mapper.c',
|
||||
'logger.c',
|
||||
spa_support_sources = ['logger.c',
|
||||
'loop.c',
|
||||
'plugin.c']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue