interface: add an interface struct

The interface struct has the type,version and methods of the
interface.
Make spa interfaces extend from spa_interface and make a
separate structure for the methods.
Pass a generic void* as the first argument of methods, like
we don in PipeWire.
Bundle the methods + implementation in a versioned inteface
and use that to invoke methods. This way we can do version
checks on the methods.
Make resource and proxy interfaces that we can can call. We
can then make the core interfaces independent on proxy/resource and
hide them in the lower layers.
Add add_listener method to methods of core interfaces, just
like SPA.
This commit is contained in:
Wim Taymans 2019-05-20 16:11:23 +02:00
parent eb6481efb3
commit ff946e3d4b
85 changed files with 3051 additions and 3000 deletions

View file

@ -32,6 +32,13 @@ extern "C" {
#include <stdarg.h>
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
/**
* The CPU features interface
*/
#define SPA_VERSION_CPU 0
struct spa_cpu { struct spa_interface iface; };
/* x86 specific */
#define SPA_CPU_FLAG_MMX (1<<0) /**< standard MMX */
@ -72,35 +79,40 @@ extern "C" {
#define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
/**
* The CPU features interface
* methods
*/
struct spa_cpu {
/** the version of this interface. This can be used to expand this
struct spa_cpu_methods {
/** the version of the methods. This can be used to expand this
structure in the future */
#define SPA_VERSION_CPU 0
#define SPA_VERSION_CPU_METHODS 0
uint32_t version;
/**
* Extra information about the interface
*/
const struct spa_dict *info;
/** get CPU flags */
uint32_t (*get_flags) (struct spa_cpu *cpu);
uint32_t (*get_flags) (void *object);
/** force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags */
int (*force_flags) (struct spa_cpu *cpu, uint32_t flags);
int (*force_flags) (void *object, uint32_t flags);
/** get number of CPU cores */
uint32_t (*get_count) (struct spa_cpu *cpu);
uint32_t (*get_count) (void *object);
/** get maximum required alignment of data */
uint32_t (*get_max_align) (struct spa_cpu *cpu);
uint32_t (*get_max_align) (void *object);
};
#define spa_cpu_get_flags(c) (c)->get_flags((c))
#define spa_cpu_force_flags(c,f) (c)->force_flags((c), (f))
#define spa_cpu_get_count(c) (c)->get_count((c))
#define spa_cpu_get_max_align(c) (c)->get_max_align((c))
#define spa_cpu_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_cpu *_c = o; \
spa_interface_call_res(&_c->iface, \
struct spa_cpu_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_cpu_get_flags(c) spa_cpu_method(c, get_flags, 0)
#define spa_cpu_force_flags(c,f) spa_cpu_method(c, force_flags, 0, f)
#define spa_cpu_get_count(c) spa_cpu_method(c, get_count, 0)
#define spa_cpu_get_max_align(c) spa_cpu_method(c, get_max_align, 0)
#ifdef __cplusplus
} /* extern "C" */