diff --git a/include/igloo/filter.h b/include/igloo/filter.h index 56c2542..d282b08 100644 --- a/include/igloo/filter.h +++ b/include/igloo/filter.h @@ -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: diff --git a/include/igloo/io.h b/include/igloo/io.h index 4f6de8c..e815fb9 100644 --- a/include/igloo/io.h +++ b/include/igloo/io.h @@ -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: diff --git a/include/igloo/logmsg.h b/include/igloo/logmsg.h index e537b9e..c643817 100644 --- a/include/igloo/logmsg.h +++ b/include/igloo/logmsg.h @@ -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 } diff --git a/include/igloo/objecthandler.h b/include/igloo/objecthandler.h index f541c42..0e20ba2 100644 --- a/include/igloo/objecthandler.h +++ b/include/igloo/objecthandler.h @@ -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: diff --git a/include/igloo/ro.h b/include/igloo/ro.h index df522b5..7b4cea4 100644 --- a/include/igloo/ro.h +++ b/include/igloo/ro.h @@ -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); diff --git a/include/igloo/stdio.h b/include/igloo/stdio.h index cb00917..64dcf4e 100644 --- a/include/igloo/stdio.h +++ b/include/igloo/stdio.h @@ -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 } diff --git a/src/filter.c b/src/filter.c index 0a4e923..8189e49 100644 --- a/src/filter.c +++ b/src/filter.c @@ -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) diff --git a/src/interface.c b/src/interface.c index 13622d1..099546b 100644 --- a/src/interface.c +++ b/src/interface.c @@ -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)) diff --git a/src/io.c b/src/io.c index 1ae625d..b65aa35 100644 --- a/src/io.c +++ b/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; diff --git a/src/logmsg.c b/src/logmsg.c index b248997..adf418f 100644 --- a/src/logmsg.c +++ b/src/logmsg.c @@ -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); } diff --git a/src/objecthandler.c b/src/objecthandler.c index bee50a2..0ec03bc 100644 --- a/src/objecthandler.c +++ b/src/objecthandler.c @@ -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; diff --git a/src/private.h b/src/private.h index 481a299..2751c23 100644 --- a/src/private.h +++ b/src/private.h @@ -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); diff --git a/src/ro.c b/src/ro.c index ac8726b..b524ed1 100644 --- a/src/ro.c +++ b/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); diff --git a/src/stdio.c b/src/stdio.c index 27f9ced..c62fc0a 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -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; diff --git a/src/tests/ctest_logmsg.c b/src/tests/ctest_logmsg.c index 25fb7b8..02d44be 100644 --- a/src/tests/ctest_logmsg.c +++ b/src/tests/ctest_logmsg.c @@ -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);