mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Feature: support passing any object as instance and asking an instance for itself
This commit is contained in:
parent
e92b80ad46
commit
bc46e9c976
@ -52,6 +52,9 @@ igloo_RO_PRIVATE_TYPE(igloo_instance_t,
|
||||
igloo_RO_TYPEDECL_FREE(igloo_initialize__free)
|
||||
);
|
||||
|
||||
/* Internal forwarding */
|
||||
const igloo_ro_type_t **igloo_instance_type = &igloo_ro__type__igloo_instance_t;
|
||||
|
||||
igloo_ro_t igloo_initialize(void)
|
||||
{
|
||||
igloo_instance_t *ret;
|
||||
|
@ -36,6 +36,10 @@ void igloo_resolver_shutdown(void);
|
||||
void igloo_log_initialize(void);
|
||||
void igloo_log_shutdown(void);
|
||||
|
||||
/* Instance type internal forwarding */
|
||||
const igloo_ro_type_t **igloo_instance_type;
|
||||
#define igloo_IS_INSTANCE(x) (igloo_RO_GET_TYPE((x)) == *igloo_instance_type)
|
||||
|
||||
/* Basic interface */
|
||||
#define igloo_interface_base(type) \
|
||||
/* The base object. */ \
|
||||
|
11
src/ro.c
11
src/ro.c
@ -102,10 +102,15 @@ igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name,
|
||||
}
|
||||
|
||||
if (!igloo_RO_IS_NULL(instance)) {
|
||||
if (!igloo_IS_INSTANCE(instance)) {
|
||||
/* In this case we're fine if this returns igloo_RO_NULL. */
|
||||
instance = igloo_ro_get_instance(instance);
|
||||
} else {
|
||||
if (igloo_ro_ref(instance) != igloo_ERROR_NONE) {
|
||||
igloo_ro_unref(base);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
base->instance = instance;
|
||||
}
|
||||
@ -335,7 +340,13 @@ igloo_ro_t igloo_ro_get_instance(igloo_ro_t self)
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
if (igloo_IS_INSTANCE(base)) {
|
||||
ret = (igloo_ro_t)base;
|
||||
} else {
|
||||
ret = base->instance;
|
||||
}
|
||||
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
if (igloo_ro_ref(ret) != igloo_ERROR_NONE) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
Loading…
Reference in New Issue
Block a user