mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-10-27 05:10:16 -04:00
Feature: Make interface decleration much nicer
This commit is contained in:
parent
f5bc4e77c4
commit
129bdeeef3
@ -42,11 +42,23 @@ extern "C" {
|
||||
*/
|
||||
typedef int (*igloo_interface_free_t)(igloo_INTERFACE_BASIC_ARGS);
|
||||
|
||||
#define igloo_INTERFACE_DESCRIPTION_BASE__VERSION 1
|
||||
|
||||
typedef struct {
|
||||
size_t base_length;
|
||||
int base_version;
|
||||
size_t description_length;
|
||||
igloo_interface_free_t free;
|
||||
} igloo_interface_base_ifdesc_t;
|
||||
|
||||
#define igloo_INTERFACE_DESCRIPTION_BASE(type, ...) \
|
||||
.__base = { \
|
||||
.base_length = sizeof(igloo_interface_base_ifdesc_t), \
|
||||
.base_version = igloo_INTERFACE_DESCRIPTION_BASE__VERSION, \
|
||||
.description_length = sizeof(type) \
|
||||
, ## __VA_ARGS__ \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -30,3 +30,33 @@ void igloo_interface_base_free(igloo_ro_t self)
|
||||
free(iface->backend_userdata);
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_interface_base_new_real(const igloo_ro_type_t *type, size_t description_length, const igloo_interface_base_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
igloo_ro_t self;
|
||||
igloo__interface_base_t *base;
|
||||
|
||||
if (!ifdesc)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
if (ifdesc->base_length != sizeof(igloo_interface_base_ifdesc_t) || ifdesc->base_version != igloo_INTERFACE_DESCRIPTION_BASE__VERSION || ifdesc->description_length != description_length)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
self = igloo_ro_new__raw(type, name, associated);
|
||||
base = igloo_INTERFACE_CAST(self);
|
||||
|
||||
if (igloo_RO_IS_NULL(self))
|
||||
return igloo_RO_NULL;
|
||||
|
||||
if (!igloo_RO_IS_NULL(backend_object)) {
|
||||
if (igloo_ro_ref(backend_object) != 0) {
|
||||
igloo_ro_unref(self);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
base->ifdesc = ifdesc;
|
||||
base->backend_object = backend_object;
|
||||
base->backend_userdata = backend_userdata;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
23
src/io.c
23
src/io.c
@ -32,28 +32,7 @@ igloo_RO_PUBLIC_TYPE(igloo_io_t,
|
||||
|
||||
igloo_io_t * igloo_io_new(const igloo_io_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
igloo_io_t *io;
|
||||
|
||||
if (!ifdesc)
|
||||
return NULL;
|
||||
|
||||
io = igloo_ro_new_raw(igloo_io_t, name, associated);
|
||||
|
||||
if (!io)
|
||||
return NULL;
|
||||
|
||||
if (!igloo_RO_IS_NULL(backend_object)) {
|
||||
if (igloo_ro_ref(backend_object) != 0) {
|
||||
igloo_ro_unref(io);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
io->ifdesc = ifdesc;
|
||||
io->backend_object = backend_object;
|
||||
io->backend_userdata = backend_userdata;
|
||||
|
||||
return io;
|
||||
return igloo_interface_base_new(igloo_io_t, ifdesc, backend_object, backend_userdata, name, associated);
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,4 +52,7 @@ void igloo_interface_base_free(igloo_ro_t self);
|
||||
#define igloo_INTERFACE_CAST(obj) ((igloo__interface_base_t*)igloo_RO__GETBASE(obj))
|
||||
#define igloo_INTERFACE_BASIC_CALL(obj) (obj), &(igloo_INTERFACE_CAST(obj)->backend_object), &(igloo_INTERFACE_CAST(obj)->backend_userdata)
|
||||
|
||||
igloo_ro_t igloo_interface_base_new_real(const igloo_ro_type_t *type, size_t description_length, const igloo_interface_base_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated);
|
||||
#define igloo_interface_base_new(type, ifdesc, backend_object, backend_userdata, name, associated) igloo_RO_TO_TYPE(igloo_interface_base_new_real(igloo_ro__type__ ## type, sizeof(*(ifdesc)), (const igloo_interface_base_ifdesc_t*)(ifdesc), (backend_object), (backend_userdata), (name), (associated)), type)
|
||||
|
||||
#endif
|
||||
|
@ -49,7 +49,9 @@ static int __get_fd_for_systemcall(igloo_INTERFACE_BASIC_ARGS)
|
||||
}
|
||||
|
||||
static const igloo_io_ifdesc_t igloo_stdio_ifdesc = {
|
||||
.__base = {.free = __free},
|
||||
igloo_INTERFACE_DESCRIPTION_BASE(igloo_io_ifdesc_t,
|
||||
.free = __free
|
||||
),
|
||||
.read = __read,
|
||||
.write = __write,
|
||||
.flush = __flush,
|
||||
|
Loading…
Reference in New Issue
Block a user