PipeWire
0.3.33
|
Generic implementation of implementation-independent interfaces. More...
Data Structures | |
struct | spa_callbacks |
Callbacks, contains the structure with functions and the data passed to the functions. More... | |
struct | spa_interface |
Macros | |
#define | SPA_CALLBACK_CHECK(c, m, v) ((c) && ((v) == 0 || (c)->version > (v)-1) && (c)->m) |
Check if a callback c has method m of version v. More... | |
#define | SPA_CALLBACKS_INIT(_funcs, _data) (struct spa_callbacks){ _funcs, _data, } |
Initialize the set of functions funcs as a spa_callbacks, together with _data. More... | |
#define | SPA_INTERFACE_INIT(_type, _version, _funcs, _data) (struct spa_interface){ _type, _version, SPA_CALLBACKS_INIT(_funcs,_data), } |
Initialize a spa_interface. More... | |
#define | spa_callbacks_call(callbacks, type, method, vers, ...) |
Invoke method named method in the callbacks. More... | |
#define | spa_callbacks_call_res(callbacks, type, res, method, vers, ...) |
Invoke method named method in the callbacks. More... | |
#define | spa_interface_call(iface, method_type, method, vers, ...) spa_callbacks_call(&(iface)->cb,method_type,method,vers,##__VA_ARGS__) |
Invoke method named method in the callbacks on the given interface object. More... | |
#define | spa_interface_call_res(iface, method_type, res, method, vers, ...) spa_callbacks_call_res(&(iface)->cb,method_type,res,method,vers,##__VA_ARGS__) |
Invoke method named method in the callbacks on the given interface object. More... | |
Generic implementation of implementation-independent interfaces.
A SPA Interface is a generic struct that, together with a few macros, provides a generic way of invoking methods on objects without knowing the details of the implementation.
The primary interaction with interfaces is through macros that expand into the right method call. For the implementation of an interface, we need two structs and a macro to invoke the bar
method:
The struct foo_methods
and the invocation macro foo_bar()
must be available to the caller. The implementation of struct foo
can be private.
The expansion of foo_bar()
resolves roughly into this code:
The typecast used in foo_bar()
allows struct foo
to be opaque to the caller. The implementation may assign the callback methods at object instantiation, and the caller will transparently invoke the method on the given object. For example, the following code assigns a different bar()
method on Mondays - the caller does not need to know this.
#define SPA_CALLBACK_CHECK | ( | c, | |
m, | |||
v | |||
) | ((c) && ((v) == 0 || (c)->version > (v)-1) && (c)->m) |
Check if a callback c has method m of version v.
#define spa_callbacks_call | ( | callbacks, | |
type, | |||
method, | |||
vers, | |||
... | |||
) |
Invoke method named method in the callbacks.
The method_type defines the type of the method struct.
#define spa_callbacks_call_res | ( | callbacks, | |
type, | |||
res, | |||
method, | |||
vers, | |||
... | |||
) |
Invoke method named method in the callbacks.
The method_type defines the type of the method struct.
The return value is stored in res.
#define SPA_CALLBACKS_INIT | ( | _funcs, | |
_data | |||
) | (struct spa_callbacks){ _funcs, _data, } |
Initialize the set of functions funcs as a spa_callbacks, together with _data.
#define spa_interface_call | ( | iface, | |
method_type, | |||
method, | |||
vers, | |||
... | |||
) | spa_callbacks_call(&(iface)->cb,method_type,method,vers,##__VA_ARGS__) |
Invoke method named method in the callbacks on the given interface object.
The method_type defines the type of the method struct, not the interface itself.
#define spa_interface_call_res | ( | iface, | |
method_type, | |||
res, | |||
method, | |||
vers, | |||
... | |||
) | spa_callbacks_call_res(&(iface)->cb,method_type,res,method,vers,##__VA_ARGS__) |
Invoke method named method in the callbacks on the given interface object.
The method_type defines the type of the method struct, not the interface itself.
The return value is stored in res.
#define SPA_INTERFACE_INIT | ( | _type, | |
_version, | |||
_funcs, | |||
_data | |||
) | (struct spa_interface){ _type, _version, SPA_CALLBACKS_INIT(_funcs,_data), } |
Initialize a spa_interface.