mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-11-03 04:17:20 -05:00
Feature: Added instance passing between objects, on a basic level
This commit is contained in:
parent
eb9b0301a0
commit
02837785c3
@ -67,7 +67,7 @@ typedef struct {
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated);
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* This tests a object according to the filter.
|
||||
* Parameters:
|
||||
|
@ -130,7 +130,7 @@ typedef struct {
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
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 * 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_ro_t instance);
|
||||
|
||||
/* Read data from a IO handle.
|
||||
* Parameters:
|
||||
|
@ -164,7 +164,7 @@ int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igl
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char *subformat, const char *name, igloo_ro_t associated);
|
||||
igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char *subformat, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* This creates a filter for log messages.
|
||||
* Parameters:
|
||||
@ -185,7 +185,7 @@ igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char *
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_filter_t * igloo_logmsg_filter(igloo_loglevel_t level_min, igloo_loglevel_t level_max, igloo_logmsg_opt_t options_required, igloo_logmsg_opt_t options_absent, const struct timespec * ts_min, const struct timespec * ts_max, const char *cat, const char *name, igloo_ro_t associated);
|
||||
igloo_filter_t * igloo_logmsg_filter(igloo_loglevel_t level_min, igloo_loglevel_t level_max, igloo_logmsg_opt_t options_required, igloo_logmsg_opt_t options_absent, const struct timespec * ts_min, const struct timespec * ts_max, const char *cat, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ typedef struct {
|
||||
* name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_objecthandler_t * igloo_objecthandler_new(const igloo_objecthandler_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated);
|
||||
igloo_objecthandler_t * igloo_objecthandler_new(const igloo_objecthandler_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* This handles a object according to the filter.
|
||||
* Parameters:
|
||||
|
@ -287,12 +287,12 @@ int igloo_RO_HAS_TYPE_raw(igloo_ro_t object, const igloo_ro_type_t *
|
||||
* the associated refobject is given by associated.
|
||||
*/
|
||||
|
||||
igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated);
|
||||
#define igloo_ro_new_raw(type, name, associated) igloo_RO_TO_TYPE(igloo_ro_new__raw(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated)), type)
|
||||
igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
#define igloo_ro_new_raw(type, name, associated) igloo_RO_TO_TYPE(igloo_ro_new__raw(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), igloo_RO_NULL), type)
|
||||
|
||||
igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, ...);
|
||||
#define igloo_ro_new(type, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), NULL, igloo_RO_NULL, ## __VA_ARGS__), type)
|
||||
#define igloo_ro_new_ext(type, name, associated, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), ## __VA_ARGS__), type)
|
||||
igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, igloo_ro_t instance, ...);
|
||||
#define igloo_ro_new(type, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), NULL, igloo_RO_NULL, igloo_RO_NULL, ## __VA_ARGS__), type)
|
||||
#define igloo_ro_new_ext(type, name, associated, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), igloo_RO_NULL, ## __VA_ARGS__), type)
|
||||
|
||||
/* This increases the reference counter of the object */
|
||||
igloo_error_t igloo_ro_ref(igloo_ro_t self);
|
||||
|
@ -31,7 +31,7 @@ extern "C" {
|
||||
|
||||
#include "io.h"
|
||||
|
||||
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated);
|
||||
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ igloo_RO_PUBLIC_TYPE(igloo_filter_t,
|
||||
igloo_RO_TYPEDECL_FREE(igloo_interface_base_free)
|
||||
);
|
||||
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated)
|
||||
igloo_filter_t * igloo_filter_new(const igloo_filter_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
return igloo_interface_base_new(igloo_filter_t, ifdesc, backend_object, backend_userdata, name, associated);
|
||||
return igloo_interface_base_new(igloo_filter_t, ifdesc, backend_object, backend_userdata, name, associated, instance);
|
||||
}
|
||||
|
||||
igloo_filter_result_t igloo_filter_test(igloo_filter_t *filter, igloo_ro_t object)
|
||||
|
@ -31,7 +31,7 @@ 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 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 instance)
|
||||
{
|
||||
igloo_ro_t self;
|
||||
igloo__interface_base_t *base;
|
||||
@ -42,7 +42,7 @@ igloo_ro_t igloo_interface_base_new_real(const igloo_ro_type_t *type, size_t des
|
||||
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);
|
||||
self = igloo_ro_new__raw(type, name, associated, instance);
|
||||
base = igloo_INTERFACE_CAST(self);
|
||||
|
||||
if (igloo_RO_IS_NULL(self))
|
||||
|
4
src/io.c
4
src/io.c
@ -44,9 +44,9 @@ 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 * 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_ro_t instance)
|
||||
{
|
||||
igloo_io_t *io = igloo_interface_base_new(igloo_io_t, ifdesc, backend_object, backend_userdata, name, associated);
|
||||
igloo_io_t *io = igloo_interface_base_new(igloo_io_t, ifdesc, backend_object, backend_userdata, name, associated, instance);
|
||||
if (!io)
|
||||
return NULL;
|
||||
|
||||
|
@ -270,7 +270,7 @@ static const igloo_objecthandler_ifdesc_t igloo_logmsg_formarter_ifdesc = {
|
||||
.set_backend = __set_backend
|
||||
};
|
||||
|
||||
igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char *subformat, const char *name, igloo_ro_t associated)
|
||||
igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char *subformat, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
igloo_logmsg_formarter_subtype_t *sf = NULL;
|
||||
igloo_objecthandler_t *objecthandler;
|
||||
@ -293,7 +293,7 @@ igloo_objecthandler_t * igloo_logmsg_formarter(igloo_ro_t backend, const char
|
||||
return NULL;
|
||||
}
|
||||
|
||||
objecthandler = igloo_objecthandler_new(&igloo_logmsg_formarter_ifdesc, NULL, sf, name, associated);
|
||||
objecthandler = igloo_objecthandler_new(&igloo_logmsg_formarter_ifdesc, NULL, sf, name, associated, instance);
|
||||
if (!objecthandler) {
|
||||
free(sf);
|
||||
}
|
||||
@ -354,7 +354,7 @@ static const igloo_filter_ifdesc_t igloo_logmsg_filter_ifdesc = {
|
||||
.test = __test
|
||||
};
|
||||
|
||||
igloo_filter_t * igloo_logmsg_filter(igloo_loglevel_t level_min, igloo_loglevel_t level_max, igloo_logmsg_opt_t options_required, igloo_logmsg_opt_t options_absent, const struct timespec * ts_min, const struct timespec * ts_max, const char *cat, const char *name, igloo_ro_t associated)
|
||||
igloo_filter_t * igloo_logmsg_filter(igloo_loglevel_t level_min, igloo_loglevel_t level_max, igloo_logmsg_opt_t options_required, igloo_logmsg_opt_t options_absent, const struct timespec * ts_min, const struct timespec * ts_max, const char *cat, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
igloo_filter_t *filter;
|
||||
igloo_logmsg_filter_mask_t *mask = calloc(1, sizeof(*mask));
|
||||
@ -386,7 +386,7 @@ igloo_filter_t * igloo_logmsg_filter(igloo_loglevel_t level_min, igloo_
|
||||
}
|
||||
}
|
||||
|
||||
filter = igloo_filter_new(&igloo_logmsg_filter_ifdesc, igloo_RO_NULL, mask, name, associated);
|
||||
filter = igloo_filter_new(&igloo_logmsg_filter_ifdesc, igloo_RO_NULL, mask, name, associated, instance);
|
||||
if (!filter) {
|
||||
free(mask);
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ igloo_RO_PUBLIC_TYPE(igloo_objecthandler_t,
|
||||
igloo_RO_TYPEDECL_FREE(__free)
|
||||
);
|
||||
|
||||
igloo_objecthandler_t * igloo_objecthandler_new(const igloo_objecthandler_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated)
|
||||
igloo_objecthandler_t * igloo_objecthandler_new(const igloo_objecthandler_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
igloo_objecthandler_t *handler = igloo_interface_base_new(igloo_objecthandler_t, ifdesc, backend_object, backend_userdata, name, associated);
|
||||
igloo_objecthandler_t *handler = igloo_interface_base_new(igloo_objecthandler_t, ifdesc, backend_object, backend_userdata, name, associated, instance);
|
||||
|
||||
if (!handler)
|
||||
return NULL;
|
||||
|
@ -56,8 +56,8 @@ 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)
|
||||
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 instance);
|
||||
#define igloo_interface_base_new(type, ifdesc, backend_object, backend_userdata, name, associated, instance) 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), (instance)), type)
|
||||
|
||||
size_t igloo_private__vsnprintf_Hstrlen(const char *str, int is_alt, int allow_space);
|
||||
void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||
|
18
src/ro.c
18
src/ro.c
@ -68,8 +68,7 @@ igloo_ro_t igloo_RO_TO_TYPE_raw(igloo_ro_t object, const igloo_ro_type_t *t
|
||||
return igloo_RO_IS_VALID_raw_li(object, type) ? object : igloo_RO_NULL;
|
||||
}
|
||||
|
||||
|
||||
igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated)
|
||||
igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
igloo_ro_base_t *base;
|
||||
|
||||
@ -102,10 +101,19 @@ igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name,
|
||||
base->associated = associated;
|
||||
}
|
||||
|
||||
if (!igloo_RO_IS_NULL(instance)) {
|
||||
if (igloo_ro_ref(instance) != igloo_ERROR_NONE) {
|
||||
igloo_ro_unref(base);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
base->instance = instance;
|
||||
}
|
||||
|
||||
return (igloo_ro_t)base;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, ...)
|
||||
igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, igloo_ro_t instance, ...)
|
||||
{
|
||||
igloo_ro_t ret;
|
||||
int res;
|
||||
@ -117,11 +125,11 @@ igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *na
|
||||
if (!type->type_newcb)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
ret = igloo_ro_new__raw(type, name, associated);
|
||||
ret = igloo_ro_new__raw(type, name, associated, instance);
|
||||
if (igloo_RO_IS_NULL(ret))
|
||||
return igloo_RO_NULL;
|
||||
|
||||
va_start(ap, associated);
|
||||
va_start(ap, instance);
|
||||
res = type->type_newcb(ret, type, ap);
|
||||
va_end(ap);
|
||||
|
||||
|
@ -60,7 +60,7 @@ static const igloo_io_ifdesc_t igloo_stdio_ifdesc = {
|
||||
.get_fd_for_systemcall = __get_fd_for_systemcall
|
||||
};
|
||||
|
||||
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated)
|
||||
igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
FILE *file = fopen(filename, mode);
|
||||
igloo_io_t *io;
|
||||
@ -68,7 +68,7 @@ igloo_io_t * igloo_stdio_new_file(const char *filename, const char *mode, const
|
||||
if (!file)
|
||||
return NULL;
|
||||
|
||||
io = igloo_io_new(&igloo_stdio_ifdesc, igloo_RO_NULL, file, name, associated);
|
||||
io = igloo_io_new(&igloo_stdio_ifdesc, igloo_RO_NULL, file, name, associated, instance);
|
||||
if (!io) {
|
||||
fclose(file);
|
||||
return io;
|
||||
|
@ -28,11 +28,11 @@ static void test_create_unref(void)
|
||||
ctest_test("logmsg created", !igloo_RO_IS_NULL(msg));
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == igloo_ERROR_NONE);
|
||||
|
||||
formater = igloo_logmsg_formarter(igloo_RO_NULL, NULL, NULL, igloo_RO_NULL);
|
||||
formater = igloo_logmsg_formarter(igloo_RO_NULL, NULL, NULL, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("formater created", !igloo_RO_IS_NULL(formater));
|
||||
ctest_test("un-referenced", igloo_ro_unref(formater) == igloo_ERROR_NONE);
|
||||
|
||||
filter = igloo_logmsg_filter(igloo_LOGLEVEL__NONE, igloo_LOGLEVEL__NONE, igloo_LOGMSG_OPT_NONE, igloo_LOGMSG_OPT_NONE, NULL, NULL, NULL, NULL, igloo_RO_NULL);
|
||||
filter = igloo_logmsg_filter(igloo_LOGLEVEL__NONE, igloo_LOGLEVEL__NONE, igloo_LOGMSG_OPT_NONE, igloo_LOGMSG_OPT_NONE, NULL, NULL, NULL, NULL, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("filter created", !igloo_RO_IS_NULL(filter));
|
||||
ctest_test("un-referenced", igloo_ro_unref(filter) == igloo_ERROR_NONE);
|
||||
}
|
||||
@ -96,7 +96,7 @@ static void test_filter(void)
|
||||
igloo_logmsg_t *msg;
|
||||
igloo_ro_base_t *base;
|
||||
|
||||
filter = igloo_logmsg_filter(igloo_LOGLEVEL_ERROR, igloo_LOGLEVEL_WARN, igloo_LOGMSG_OPT_NONE, igloo_LOGMSG_OPT_NONE, NULL, NULL, NULL, NULL, igloo_RO_NULL);
|
||||
filter = igloo_logmsg_filter(igloo_LOGLEVEL_ERROR, igloo_LOGLEVEL_WARN, igloo_LOGMSG_OPT_NONE, igloo_LOGMSG_OPT_NONE, NULL, NULL, NULL, NULL, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("filter created", !igloo_RO_IS_NULL(filter));
|
||||
|
||||
base = igloo_ro_new(igloo_ro_base_t);
|
||||
|
Loading…
Reference in New Issue
Block a user