Make interface types a string

This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
This commit is contained in:
Wim Taymans 2019-12-19 13:15:10 +01:00
parent 9657486a81
commit f391353c7f
123 changed files with 791 additions and 1251 deletions

View file

@ -42,7 +42,9 @@ extern "C" {
* Devices or Nodes.
*
*/
#define SPA_VERSION_DEVICE 0
#define SPA_TYPE_INTERFACE_Device SPA_TYPE_INFO_INTERFACE_BASE "Device"
#define SPA_VERSION_DEVICE 0
struct spa_device { struct spa_interface iface; };
/**
@ -75,7 +77,7 @@ struct spa_device_object_info {
#define SPA_VERSION_DEVICE_OBJECT_INFO 0
uint32_t version;
uint32_t type; /**< the object type managed by this device */
const char *type; /**< the object type managed by this device */
const char *factory_name; /**< a factory name that implements the object */
#define SPA_DEVICE_OBJECT_CHANGE_MASK_FLAGS (1u<<0)

View file

@ -40,7 +40,9 @@ extern "C" {
/**
* A spa_node is a component that can consume and produce buffers.
*/
#define SPA_VERSION_NODE 0
#define SPA_TYPE_INTERFACE_Node SPA_TYPE_INFO_INTERFACE_BASE "Node"
#define SPA_VERSION_NODE 0
struct spa_node { struct spa_interface iface; };
/**

View file

@ -37,7 +37,9 @@ extern "C" {
/**
* The CPU features interface
*/
#define SPA_VERSION_CPU 0
#define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
#define SPA_VERSION_CPU 0
struct spa_cpu { struct spa_interface iface; };
/* x86 specific */

View file

@ -31,7 +31,9 @@ extern "C" {
#include <spa/support/loop.h>
#define SPA_VERSION_DBUS 0
#define SPA_TYPE_INTERFACE_DBus SPA_TYPE_INFO_INTERFACE_BASE "DBus"
#define SPA_VERSION_DBUS 0
struct spa_dbus { struct spa_interface iface; };
enum spa_dbus_type {

View file

@ -46,10 +46,13 @@ enum spa_log_level {
/**
* The Log interface
*/
#define SPA_TYPE_INTERFACE_Log SPA_TYPE_INFO_INTERFACE_BASE "Log"
#define SPA_VERSION_LOG 0
struct spa_log {
/** the version of this log. This can be used to expand this
* structure in the future */
#define SPA_VERSION_LOG 0
struct spa_interface iface;
/**
* Logging level, everything above this level is not logged

View file

@ -33,12 +33,19 @@ extern "C" {
#include <spa/utils/hook.h>
#include <spa/support/system.h>
#define SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"
#define SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"
#define SPA_VERSION_LOOP 0
struct spa_loop { struct spa_interface iface; };
#define SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"
#define SPA_VERSION_LOOP_CONTROL 0
struct spa_loop_control { struct spa_interface iface; };
#define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
#define SPA_VERSION_LOOP_UTILS 0
struct spa_loop_utils { struct spa_interface iface; };
struct spa_source;
typedef void (*spa_source_func_t) (struct spa_source *source);

View file

@ -50,7 +50,7 @@ struct spa_handle {
* -ENOTSUP when there are no interfaces
* -EINVAL when handle or info is NULL
*/
int (*get_interface) (struct spa_handle *handle, uint32_t type, void **interface);
int (*get_interface) (struct spa_handle *handle, const char *type, void **interface);
/**
* Clean up the memory of \a handle. After this, \a handle should not be used
* anymore.
@ -69,8 +69,8 @@ struct spa_handle {
* handles.
*/
struct spa_interface_info {
uint32_t type; /*< the type of the interface, can be
* used to get the interface */
const char *type; /*< the type of the interface, can be
* used to get the interface */
};
/**
@ -78,18 +78,18 @@ struct spa_interface_info {
* a factory. It can be extra information or interfaces such as logging.
*/
struct spa_support {
uint32_t type; /*< the type of the support item */
void *data; /*< specific data for the item */
const char *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,
uint32_t type)
const char *type)
{
uint32_t i;
for (i = 0; i < n_support; i++) {
if (support[i].type == type)
if (strcmp(support[i].type, type) == 0)
return support[i].data;
}
return NULL;

View file

@ -37,6 +37,9 @@ extern "C" {
/**
* a collection of core system functions
*/
#define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System"
#define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem"
#define SPA_VERSION_SYSTEM 0
struct spa_system { struct spa_interface iface; };

View file

@ -54,7 +54,7 @@ struct spa_callbacks {
#define SPA_CALLBACKS_INIT(_funcs,_data) (struct spa_callbacks){ _funcs, _data, }
struct spa_interface {
uint32_t type;
const char *type;
uint32_t version;
struct spa_callbacks cb;
};

View file

@ -98,21 +98,6 @@ static const struct spa_type_info spa_types[] = {
{ SPA_TYPE_POINTER_Meta, SPA_TYPE_Pointer, SPA_TYPE_INFO_POINTER_BASE "Meta", NULL },
{ SPA_TYPE_POINTER_Dict, SPA_TYPE_Pointer, SPA_TYPE_INFO_POINTER_BASE "Dict", NULL },
{ SPA_TYPE_INTERFACE_START, SPA_TYPE_Pointer, SPA_TYPE_INFO_Interface, NULL },
{ SPA_TYPE_INTERFACE_Handle, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Handle", NULL },
{ SPA_TYPE_INTERFACE_HandleFactory, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "HandleFactory", NULL },
{ SPA_TYPE_INTERFACE_Log, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Log", NULL },
{ SPA_TYPE_INTERFACE_System, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "System", NULL },
{ SPA_TYPE_INTERFACE_Loop, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Loop", NULL },
{ SPA_TYPE_INTERFACE_LoopControl, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "LoopControl", NULL },
{ SPA_TYPE_INTERFACE_LoopUtils, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils", NULL },
{ SPA_TYPE_INTERFACE_DataSystem, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "DataSystem", NULL },
{ SPA_TYPE_INTERFACE_DataLoop, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "DataLoop", NULL },
{ SPA_TYPE_INTERFACE_DBus, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "DBus", NULL },
{ SPA_TYPE_INTERFACE_Node, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Node", NULL },
{ SPA_TYPE_INTERFACE_Device, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Device", NULL },
{ SPA_TYPE_INTERFACE_CPU, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "CPU", NULL },
{ SPA_TYPE_EVENT_START, SPA_TYPE_Object, SPA_TYPE_INFO_Event, NULL },
{ SPA_TYPE_EVENT_Device, SPA_TYPE_Object, SPA_TYPE_INFO_EVENT_BASE "Device", NULL },
{ SPA_TYPE_EVENT_Node, SPA_TYPE_Object, SPA_TYPE_INFO_EVENT_BASE "Node", spa_type_node_event },

View file

@ -63,37 +63,20 @@ enum {
SPA_TYPE_POINTER_Dict,
SPA_TYPE_POINTER_LAST, /**< not part of ABI */
/* Interfaces */
SPA_TYPE_INTERFACE_START = 0x20000,
SPA_TYPE_INTERFACE_Handle, /**< object handle */
SPA_TYPE_INTERFACE_HandleFactory, /**< factory for object handles */
SPA_TYPE_INTERFACE_Log, /**< log interface */
SPA_TYPE_INTERFACE_System, /**< System functions */
SPA_TYPE_INTERFACE_Loop, /**< main loop support */
SPA_TYPE_INTERFACE_LoopControl, /**< control of loops */
SPA_TYPE_INTERFACE_LoopUtils, /**< loop utilities */
SPA_TYPE_INTERFACE_DataSystem, /**< System functions for data loop */
SPA_TYPE_INTERFACE_DataLoop, /**< a data loop */
SPA_TYPE_INTERFACE_DBus, /**< dbus connection */
SPA_TYPE_INTERFACE_Node, /**< nodes for data processing */
SPA_TYPE_INTERFACE_Device, /**< device managing nodes */
SPA_TYPE_INTERFACE_CPU, /**< CPU functions */
SPA_TYPE_INTERFACE_LAST, /**< not part of ABI */
/* Events */
SPA_TYPE_EVENT_START = 0x30000,
SPA_TYPE_EVENT_START = 0x20000,
SPA_TYPE_EVENT_Device,
SPA_TYPE_EVENT_Node,
SPA_TYPE_EVENT_LAST, /**< not part of ABI */
/* Commands */
SPA_TYPE_COMMAND_START = 0x40000,
SPA_TYPE_COMMAND_START = 0x30000,
SPA_TYPE_COMMAND_Device,
SPA_TYPE_COMMAND_Node,
SPA_TYPE_COMMAND_LAST, /**< not part of ABI */
/* Objects */
SPA_TYPE_OBJECT_START = 0x50000,
SPA_TYPE_OBJECT_START = 0x40000,
SPA_TYPE_OBJECT_PropInfo,
SPA_TYPE_OBJECT_Props,
SPA_TYPE_OBJECT_Format,