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

@ -0,0 +1,86 @@
/* Simple Plugin API
* Copyright (C) 2018 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_MONITOR_TYPES_H__
#define __SPA_MONITOR_TYPES_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/type.h>
#include <spa/monitor/monitor.h>
#include <spa/pod/event-types.h>
#define SPA_TYPE_EVENT__Monitor SPA_TYPE_EVENT_BASE "Monitor"
#define SPA_TYPE_EVENT_MONITOR_BASE SPA_TYPE_EVENT__Monitor ":"
#define SPA_TYPE__MonitorItemFlags SPA_TYPE_FLAGS_BASE "MonitorItemFlags"
#define SPA_TYPE_MONITOR_ITEM_FLAGS_BASE SPA_TYPE__MonitorItemFlags ":"
static const struct spa_type_info spa_type_monitor_item_flags[] = {
{ SPA_MONITOR_ITEM_FLAG_NONE, SPA_TYPE_MONITOR_ITEM_FLAGS_BASE "none", SPA_POD_TYPE_INT, },
{ 0, NULL, },
};
#define SPA_TYPE__MonitorItemState SPA_TYPE_ENUM_BASE "MonitorItemState"
#define SPA_TYPE_MONITOR_ITEM_STATE_BASE SPA_TYPE__MonitorItemState ":"
static const struct spa_type_info spa_type_monitor_item_state[] = {
{ SPA_MONITOR_ITEM_STATE_AVAILABLE, SPA_TYPE_MONITOR_ITEM_STATE_BASE "available", SPA_POD_TYPE_INT, },
{ SPA_MONITOR_ITEM_STATE_DISABLED, SPA_TYPE_MONITOR_ITEM_STATE_BASE "disabled", SPA_POD_TYPE_INT, },
{ SPA_MONITOR_ITEM_STATE_UNAVAILABLE, SPA_TYPE_MONITOR_ITEM_STATE_BASE "unavailable", SPA_POD_TYPE_INT, },
{ 0, NULL, },
};
#define SPA_TYPE__MonitorItem SPA_TYPE_POD_OBJECT_BASE "MonitorItem"
#define SPA_TYPE_MONITOR_ITEM_BASE SPA_TYPE__MonitorItem ":"
static const struct spa_type_info spa_type_monitor_item_ids[] = {
{ SPA_MONITOR_ITEM_id, SPA_TYPE_MONITOR_ITEM_BASE "id", SPA_POD_TYPE_STRING, },
{ SPA_MONITOR_ITEM_flags, SPA_TYPE_MONITOR_ITEM_BASE "flags", SPA_POD_TYPE_INT,
spa_type_monitor_item_flags },
{ SPA_MONITOR_ITEM_state, SPA_TYPE_MONITOR_ITEM_BASE "state", SPA_POD_TYPE_INT,
spa_type_monitor_item_state },
{ SPA_MONITOR_ITEM_name, SPA_TYPE_MONITOR_ITEM_BASE "name", SPA_POD_TYPE_STRING, },
{ SPA_MONITOR_ITEM_class, SPA_TYPE_MONITOR_ITEM_BASE "class", SPA_POD_TYPE_STRING, },
{ SPA_MONITOR_ITEM_info, SPA_TYPE_MONITOR_ITEM_BASE "info", SPA_POD_TYPE_POD, },
{ SPA_MONITOR_ITEM_factory, SPA_TYPE_MONITOR_ITEM_BASE "factory", SPA_POD_TYPE_POINTER, },
{ 0, NULL, },
};
#define SPA_TYPE__Monitor SPA_TYPE_INTERFACE_BASE "Monitor"
#define SPA_TYPE_MONITOR_BASE SPA_TYPE__Monitor ":"
static const struct spa_type_info spa_type_monitor[] = {
{ SPA_ID_INTERFACE_Monitor, SPA_TYPE__Monitor, SPA_POD_TYPE_ID, },
{ SPA_ID_EVENT_MONITOR_Added, SPA_TYPE_EVENT_MONITOR_BASE "Added", SPA_POD_TYPE_ID, },
{ SPA_ID_EVENT_MONITOR_Removed, SPA_TYPE_EVENT_MONITOR_BASE "Removed", SPA_POD_TYPE_ID, },
{ SPA_ID_EVENT_MONITOR_Changed, SPA_TYPE_EVENT_MONITOR_BASE "Changed", SPA_POD_TYPE_ID, },
{ SPA_ID_OBJECT_MonitorItem, SPA_TYPE__MonitorItem, SPA_POD_TYPE_OBJECT,
spa_type_monitor_item_ids},
{ 0, NULL, },
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_MONITOR_TYPES_H__ */

View file

@ -25,68 +25,23 @@ extern "C" {
#endif
struct spa_monitor;
#define SPA_TYPE__Monitor SPA_TYPE_INTERFACE_BASE "Monitor"
#define SPA_TYPE_MONITOR_BASE SPA_TYPE__Monitor ":"
#include <spa/utils/defs.h>
#include <spa/utils/dict.h>
#include <spa/pod/event.h>
#include <spa/pod/builder.h>
#define SPA_TYPE_EVENT__Monitor SPA_TYPE_EVENT_BASE "Monitor"
#define SPA_TYPE_EVENT_MONITOR_BASE SPA_TYPE_EVENT__Monitor ":"
#define SPA_TYPE_EVENT_MONITOR__Added SPA_TYPE_EVENT_MONITOR_BASE "Added"
#define SPA_TYPE_EVENT_MONITOR__Removed SPA_TYPE_EVENT_MONITOR_BASE "Removed"
#define SPA_TYPE_EVENT_MONITOR__Changed SPA_TYPE_EVENT_MONITOR_BASE "Changed"
#define SPA_TYPE__MonitorItem SPA_TYPE_POD_OBJECT_BASE "MonitorItem"
#define SPA_TYPE_MONITOR_ITEM_BASE SPA_TYPE__MonitorItem ":"
#define SPA_TYPE_MONITOR_ITEM__id SPA_TYPE_MONITOR_ITEM_BASE "id"
#define SPA_TYPE_MONITOR_ITEM__flags SPA_TYPE_MONITOR_ITEM_BASE "flags"
#define SPA_TYPE_MONITOR_ITEM__state SPA_TYPE_MONITOR_ITEM_BASE "state"
#define SPA_TYPE_MONITOR_ITEM__name SPA_TYPE_MONITOR_ITEM_BASE "name"
#define SPA_TYPE_MONITOR_ITEM__class SPA_TYPE_MONITOR_ITEM_BASE "class"
#define SPA_TYPE_MONITOR_ITEM__info SPA_TYPE_MONITOR_ITEM_BASE "info"
#define SPA_TYPE_MONITOR_ITEM__factory SPA_TYPE_MONITOR_ITEM_BASE "factory"
struct spa_type_monitor {
uint32_t Monitor; /*< the monitor object */
uint32_t Added; /*< item added event */
uint32_t Removed; /*< item removed event */
uint32_t Changed; /*< item changed event */
uint32_t MonitorItem; /*< monitor item object */
uint32_t id; /*< item id property */
uint32_t flags; /*< item flags property */
uint32_t state; /*< item state property */
uint32_t name; /*< item name property */
uint32_t klass; /*< item klass property */
uint32_t info; /*< item info property */
uint32_t factory; /*< item factory property */
/** properties for SPA_ID_OBJECT_MonitorItem */
enum spa_monitor_item {
SPA_MONITOR_ITEM_id,
SPA_MONITOR_ITEM_flags,
SPA_MONITOR_ITEM_state,
SPA_MONITOR_ITEM_name,
SPA_MONITOR_ITEM_class,
SPA_MONITOR_ITEM_info,
SPA_MONITOR_ITEM_factory,
};
static inline void spa_type_monitor_map(struct spa_type_map *map, struct spa_type_monitor *type)
{
if (type->Monitor == 0) {
type->Monitor = spa_type_map_get_id(map, SPA_TYPE__Monitor);
type->Added = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Added);
type->Removed = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Removed);
type->Changed = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Changed);
type->MonitorItem = spa_type_map_get_id(map, SPA_TYPE__MonitorItem);
type->id = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__id);
type->flags = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__flags);
type->state = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__state);
type->name = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__name);
type->klass = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__class);
type->info = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__info);
type->factory = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__factory);
}
}
enum spa_monitor_item_flags {
SPA_MONITOR_ITEM_FLAG_NONE = 0,
};