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:
Wim Taymans 2018-08-23 17:47:57 +02:00
parent e6977fa178
commit fca3e1d85d
162 changed files with 5200 additions and 7461 deletions

View file

@ -17,44 +17,27 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef __SPA_TYPE_MAP_H__
#define __SPA_TYPE_MAP_H__
#ifndef __SPA_LOOP_TYPES_H__
#define __SPA_LOOP_TYPES_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/type.h>
#include <spa/support/loop.h>
#include <spa/utils/type-info.h>
#define SPA_TYPE__TypeMap SPA_TYPE_INTERFACE_BASE "TypeMap"
#define SPA_TYPE__Loop SPA_TYPE_INTERFACE_BASE "Loop"
#define SPA_TYPE_LOOP_BASE SPA_TYPE__Loop ":"
/**
* Maps between string types and their type id
*/
struct spa_type_map {
/** the version of this structure. This can be used to expand this
* structure in the future */
#define SPA_VERSION_TYPE_MAP 0
uint32_t version;
/**
* Extra information about the type map
*/
const struct spa_dict *info;
#define SPA_TYPE__LoopControl SPA_TYPE_INTERFACE_BASE "LoopControl"
#define SPA_TYPE__LoopUtils SPA_TYPE_INTERFACE_BASE "LoopUtils"
uint32_t (*get_id) (struct spa_type_map *map, const char *type);
const char *(*get_type) (const struct spa_type_map *map, uint32_t id);
size_t (*get_size) (const struct spa_type_map *map);
};
#define spa_type_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__)
#define spa_type_map_get_type(n,...) (n)->get_type((n),__VA_ARGS__)
#define spa_type_map_get_size(n) (n)->get_size(n)
#define SPA_TYPE_LOOP__MainLoop SPA_TYPE_LOOP_BASE "MainLoop"
#define SPA_TYPE_LOOP__DataLoop SPA_TYPE_LOOP_BASE "DataLoop"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_TYPE_MAP_H__ */
#endif /* __SPA_LOOP_H__ */

View file

@ -25,16 +25,9 @@ extern "C" {
#endif
struct spa_loop;
#define SPA_TYPE__Loop SPA_TYPE_INTERFACE_BASE "Loop"
#define SPA_TYPE_LOOP_BASE SPA_TYPE__Loop ":"
struct spa_loop_control;
#define SPA_TYPE__LoopControl SPA_TYPE_INTERFACE_BASE "LoopControl"
struct spa_loop_utils;
#define SPA_TYPE__LoopUtils SPA_TYPE_INTERFACE_BASE "LoopUtils"
#define SPA_TYPE_LOOP__MainLoop SPA_TYPE_LOOP_BASE "MainLoop"
#define SPA_TYPE_LOOP__DataLoop SPA_TYPE_LOOP_BASE "DataLoop"
struct spa_source;
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
@ -46,8 +39,6 @@ enum spa_io {
SPA_IO_ERR = (1 << 3),
};
struct spa_source;
typedef void (*spa_source_func_t) (struct spa_source *source);
struct spa_source {

View file

@ -66,8 +66,8 @@ struct spa_handle {
* handles.
*/
struct spa_interface_info {
const char *type; /*< the type of the interface, can be
* used to get the interface */
uint32_t type; /*< the type of the interface, can be
* used to get the interface */
};
/**
@ -75,18 +75,18 @@ struct spa_interface_info {
* a factory. It can be extra information or interfaces such as logging.
*/
struct spa_support {
const char *type; /*< the type of the support item */
void *data; /*< specific data for the item */
uint32_t type; /*< the type of the support item */
void *data; /*< specific data for the item */
};
/** Find a support item of the given type */
static inline void *spa_support_find(const struct spa_support *support,
uint32_t n_support,
const char *type)
uint32_t type)
{
uint32_t i;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, type) == 0)
if (support[i].type == type)
return support[i].data;
}
return NULL;

View file

@ -1,87 +0,0 @@
/* Simple Plugin API
* Copyright (C) 2016 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 __SPA_TYPE_MAP_IMPL_H__
#define __SPA_TYPE_MAP_IMPL_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/support/type-map.h>
struct spa_type_map_impl_data {
struct spa_type_map map;
unsigned int n_types;
char *types[1];
};
static inline uint32_t
spa_type_map_impl_get_id (struct spa_type_map *map, const char *type)
{
struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map;
uint32_t i = 0;
for (i = 1; i <= impl->n_types; i++) {
if (strcmp(impl->types[i], type) == 0)
return i;
}
impl->types[i] = (char *) type;
impl->n_types++;
return i;
}
static inline const char *
spa_type_map_impl_get_type (const struct spa_type_map *map, uint32_t id)
{
struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map;
if (id <= impl->n_types)
return impl->types[id];
return NULL;
}
static inline size_t spa_type_map_impl_get_size (const struct spa_type_map *map)
{
struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map;
return impl->n_types;
}
#define SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) \
struct { \
struct spa_type_map map; \
unsigned int n_types; \
char *types[maxtypes]; \
} name
#define SPA_TYPE_MAP_IMPL_INIT \
{ { SPA_VERSION_TYPE_MAP, \
NULL, \
spa_type_map_impl_get_id, \
spa_type_map_impl_get_type, \
spa_type_map_impl_get_size,}, \
0, { NULL, } }
#define SPA_TYPE_MAP_IMPL(name,maxtypes) \
SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) = SPA_TYPE_MAP_IMPL_INIT
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_TYPE_MAP_IMPL_H__ */