mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Merge branch 'update-ro' into libigloo
This commit is contained in:
commit
f0384b0b0b
@ -45,15 +45,7 @@ igloo_RO_FORWARD_TYPE(igloo_buffer_t);
|
||||
* userdata, name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
igloo_buffer_t * igloo_buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated);
|
||||
|
||||
/* Depreciated: This creates a new buffer with defaults.
|
||||
* Do NOT use this. Use refobject_new(igloo_buffer_t)
|
||||
*
|
||||
* This is the same as:
|
||||
* igloo_buffer_new(-1, NULL, NULL, REFOBJECT_NULL)
|
||||
*/
|
||||
igloo_buffer_t * igloo_buffer_new_simple(void);
|
||||
igloo_buffer_t * igloo_buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* This function preallocates space for later use.
|
||||
* Parameters:
|
||||
|
@ -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:
|
||||
|
@ -105,7 +105,7 @@ typedef unsigned long int igloo_logmsg_opt_t;
|
||||
* ...
|
||||
* Parameters according to the format string.
|
||||
*/
|
||||
igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated, const char *msgid, const char *cat, const char *func, const char *codefile, const ssize_t codeline, const struct timespec * ts, igloo_loglevel_t level, igloo_logmsg_opt_t options, igloo_list_t *referenced, const char *format, ...);
|
||||
igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated, igloo_ro_t instance, const char *msgid, const char *cat, const char *func, const char *codefile, const ssize_t codeline, const struct timespec * ts, igloo_loglevel_t level, igloo_logmsg_opt_t options, igloo_list_t *referenced, const char *format, ...);
|
||||
|
||||
/* Get the context from a log message object.
|
||||
*
|
||||
@ -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:
|
||||
|
@ -86,7 +86,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_node_by_attribute(igloo_report
|
||||
/* This gets a node by it's type. Otherwise identical to igloo_reportxml_get_node_by_attribute() */
|
||||
igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t *report, igloo_reportxml_node_type_t type, int include_definitions);
|
||||
/* This function parses an XML document and returns the parst report XML document */
|
||||
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc);
|
||||
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc, igloo_ro_t instance);
|
||||
/* This function renders an report XML document as XML structure */
|
||||
xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report);
|
||||
|
||||
@ -98,9 +98,9 @@ xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report)
|
||||
/* This creates a new node of type type.
|
||||
* It's id, definition, and akindof attributes can be given as parameters.
|
||||
*/
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof);
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof, igloo_ro_t instance);
|
||||
/* This parses an XML node and returns the resulting report XML node */
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode);
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode, igloo_ro_t instance);
|
||||
/* Copy an report XML node (and it's children) */
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_copy(igloo_reportxml_node_t *node);
|
||||
/* Renders an report XML node as XML node */
|
||||
|
@ -88,7 +88,7 @@ typedef unsigned long int igloo_ro_cf_t;
|
||||
* name, associated
|
||||
* See igloo_ro_new().
|
||||
*/
|
||||
typedef igloo_ro_t (*igloo_ro_clone_t)(igloo_ro_t self, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated);
|
||||
typedef igloo_ro_t (*igloo_ro_clone_t)(igloo_ro_t self, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* Type used for callback called when the object needs to be converted to another type.
|
||||
*
|
||||
@ -111,7 +111,7 @@ typedef igloo_ro_t (*igloo_ro_clone_t)(igloo_ro_t self, igloo_ro_cf_t required,
|
||||
* name, associated
|
||||
* See igloo_ro_new().
|
||||
*/
|
||||
typedef igloo_ro_t (*igloo_ro_convert_t)(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated);
|
||||
typedef igloo_ro_t (*igloo_ro_convert_t)(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* Type used for callback called when a specific interface to the object is requested.
|
||||
*
|
||||
@ -129,7 +129,7 @@ typedef igloo_ro_t (*igloo_ro_convert_t)(igloo_ro_t self, const igloo_ro_type_t
|
||||
* name, associated
|
||||
* See igloo_ro_new().
|
||||
*/
|
||||
typedef igloo_ro_t (*igloo_ro_get_interface_t)(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated);
|
||||
typedef igloo_ro_t (*igloo_ro_get_interface_t)(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated, igloo_ro_t instance);
|
||||
|
||||
/* Type used to store flags for stringify operation.
|
||||
*/
|
||||
@ -194,6 +194,10 @@ typedef enum {
|
||||
*/
|
||||
typedef igloo_ro_cr_t (*igloo_ro_compare_t)(igloo_ro_t a, igloo_ro_t b);
|
||||
|
||||
/* Type used for callback called when error value is requested from an object.
|
||||
*/
|
||||
typedef igloo_error_t (*igloo_ro_get_error_t)(igloo_ro_t self, igloo_error_t *result);
|
||||
|
||||
/* Meta type used to defined types.
|
||||
* DO NOT use any of the members in here directly!
|
||||
*/
|
||||
@ -232,6 +236,8 @@ struct igloo_ro_type_tag {
|
||||
igloo_ro_stringify_t type_stringifycb;
|
||||
/* Callback to be called by igloo_ro_compare() */
|
||||
igloo_ro_compare_t type_comparecb;
|
||||
/* Callback to be called by igloo_ro_get_error() */
|
||||
igloo_ro_get_error_t type_get_errorcb;
|
||||
};
|
||||
struct igloo_ro_base_tag {
|
||||
/* Type of the object */
|
||||
@ -281,30 +287,33 @@ 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, instance) igloo_RO_TO_TYPE(igloo_ro_new__raw(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), (instance)), 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, instance, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), (instance), ## __VA_ARGS__), type)
|
||||
|
||||
/* This increases the reference counter of the object */
|
||||
int igloo_ro_ref(igloo_ro_t self);
|
||||
igloo_error_t igloo_ro_ref(igloo_ro_t self);
|
||||
/* This decreases the reference counter of the object.
|
||||
* If the object's reference counter reaches zero the object is freed.
|
||||
*/
|
||||
int igloo_ro_unref(igloo_ro_t self);
|
||||
igloo_error_t igloo_ro_unref(igloo_ro_t self);
|
||||
|
||||
/* This is the same as igloo_ro_ref() and igloo_ro_unref() but increases/decreases the weak reference counter. */
|
||||
int igloo_ro_weak_ref(igloo_ro_t self);
|
||||
int igloo_ro_weak_unref(igloo_ro_t self);
|
||||
igloo_error_t igloo_ro_weak_ref(igloo_ro_t self);
|
||||
igloo_error_t igloo_ro_weak_unref(igloo_ro_t self);
|
||||
|
||||
/* This gets the object's name */
|
||||
const char * igloo_ro_get_name(igloo_ro_t self);
|
||||
|
||||
/* This gets the object's associated object. */
|
||||
igloo_ro_t igloo_ro_get_associated(igloo_ro_t self);
|
||||
int igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated);
|
||||
igloo_error_t igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated);
|
||||
|
||||
/* This gets the object's instance object. */
|
||||
igloo_ro_t igloo_ro_get_instance(igloo_ro_t self);
|
||||
|
||||
/* Clone the given object returning a copy of it.
|
||||
*
|
||||
@ -345,7 +354,9 @@ igloo_ro_t igloo_ro_clone(igloo_ro_t self, igloo_ro_cf_t required, igloo_ro
|
||||
* name, associated
|
||||
* See igloo_ro_new().
|
||||
*/
|
||||
igloo_ro_t igloo_ro_convert(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated);
|
||||
igloo_ro_t igloo_ro_convert_ext(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated);
|
||||
igloo_ro_t igloo_ro_convert_simple(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed);
|
||||
#define igloo_ro_convert(self, type) igloo_RO_TO_TYPE(igloo_ro_convert_simple((self), igloo_RO_GET_TYPE_BY_SYMBOL(type), igloo_RO_CF_NONE, igloo_RO_CF_NONE), type)
|
||||
|
||||
/* Request a specific interface from the object.
|
||||
*
|
||||
@ -364,7 +375,8 @@ igloo_ro_t igloo_ro_convert(igloo_ro_t self, const igloo_ro_type_t *type, i
|
||||
* Returns:
|
||||
* An object that represents the given interface or igloo_RO_NULL.
|
||||
*/
|
||||
igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated);
|
||||
igloo_ro_t igloo_ro_get_interface_ext(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated);
|
||||
#define igloo_ro_get_interface(self, type) igloo_RO_TO_TYPE(igloo_ro_get_interface_ext((self), igloo_RO_GET_TYPE_BY_SYMBOL(type), NULL, igloo_RO_NULL), type)
|
||||
|
||||
/* Convert a object to a string.
|
||||
* This is used for debugging and presenting to the user.
|
||||
@ -392,6 +404,19 @@ char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags);
|
||||
*/
|
||||
igloo_ro_cr_t igloo_ro_compare(igloo_ro_t a, igloo_ro_t b);
|
||||
|
||||
/* Get error value from a object.
|
||||
*
|
||||
* Parameters:
|
||||
* self
|
||||
* The Object to request error value from.
|
||||
* result
|
||||
* Pointer to the location the error value should be stored.
|
||||
* The value is only written if igloo_ERROR_NONE is returned.
|
||||
* Returns:
|
||||
* The result of the query.
|
||||
*/
|
||||
igloo_error_t igloo_ro_get_error(igloo_ro_t self, igloo_error_t *result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ static void __free(igloo_ro_t self)
|
||||
free(buffer->buffer);
|
||||
}
|
||||
|
||||
igloo_buffer_t * igloo_buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated)
|
||||
igloo_buffer_t * igloo_buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated, igloo_ro_t instance)
|
||||
{
|
||||
igloo_buffer_t *buffer = igloo_ro_new_ext(igloo_buffer_t, name, associated);
|
||||
igloo_buffer_t *buffer = igloo_ro_new_ext(igloo_buffer_t, name, associated, instance);
|
||||
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
@ -59,11 +59,6 @@ igloo_buffer_t * igloo_buffer_new(ssize_t preallocation, const char *name, iglo
|
||||
return buffer;
|
||||
}
|
||||
|
||||
igloo_buffer_t * igloo_buffer_new_simple(void)
|
||||
{
|
||||
return igloo_ro_new(igloo_buffer_t);
|
||||
}
|
||||
|
||||
void igloo_buffer_preallocate(igloo_buffer_t *buffer, size_t request)
|
||||
{
|
||||
void *n;
|
||||
|
@ -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)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <igloo/ro.h>
|
||||
#include <igloo/io.h>
|
||||
#include <igloo/error.h>
|
||||
#include "private.h"
|
||||
|
||||
void igloo_interface_base_free(igloo_ro_t self)
|
||||
@ -30,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;
|
||||
@ -41,14 +42,14 @@ 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))
|
||||
return igloo_RO_NULL;
|
||||
|
||||
if (!igloo_RO_IS_NULL(backend_object)) {
|
||||
if (igloo_ro_ref(backend_object) != 0) {
|
||||
if (igloo_ro_ref(backend_object) != igloo_ERROR_NONE) {
|
||||
igloo_ro_unref(self);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
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;
|
||||
|
||||
|
@ -28,6 +28,7 @@ typedef struct igloo_instance_tag igloo_instance_t;
|
||||
#define igloo_RO_PRIVATETYPES igloo_RO_TYPE(igloo_instance_t)
|
||||
|
||||
#include "../include/igloo/ro.h"
|
||||
#include "../include/igloo/error.h"
|
||||
#include "private.h"
|
||||
|
||||
struct igloo_instance_tag {
|
||||
@ -35,9 +36,18 @@ struct igloo_instance_tag {
|
||||
};
|
||||
|
||||
static size_t igloo_initialize__refc;
|
||||
static igloo_ro_t default_instance = igloo_RO_NULL;
|
||||
|
||||
|
||||
static void igloo_initialize__free(igloo_ro_t self)
|
||||
{
|
||||
|
||||
if (igloo_RO_IS_SAME(default_instance, self)) {
|
||||
/* This is hacky, but needed to avoid free-before-unlock. */
|
||||
igloo_RO__GETBASE(default_instance)->wrefc--;
|
||||
default_instance = igloo_RO_NULL;
|
||||
}
|
||||
|
||||
igloo_initialize__refc--;
|
||||
if (igloo_initialize__refc)
|
||||
return;
|
||||
@ -52,6 +62,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;
|
||||
@ -66,11 +79,28 @@ igloo_ro_t igloo_initialize(void)
|
||||
|
||||
snprintf(name, sizeof(name), "<libigloo instance %zu>", igloo_initialize__refc);
|
||||
|
||||
ret = igloo_ro_new_raw(igloo_instance_t, name, igloo_RO_NULL);
|
||||
ret = igloo_ro_new_raw(igloo_instance_t, name, igloo_RO_NULL, igloo_RO_NULL);
|
||||
if (!ret)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_initialize__refc++;
|
||||
|
||||
if (igloo_RO_IS_NULL(default_instance)) {
|
||||
if (igloo_ro_weak_ref(ret) == igloo_ERROR_NONE) {
|
||||
default_instance = (igloo_ro_t)ret;
|
||||
}
|
||||
}
|
||||
|
||||
return (igloo_ro_t)ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_get_default_instance(void)
|
||||
{
|
||||
if (igloo_RO_IS_NULL(default_instance))
|
||||
return igloo_RO_NULL;
|
||||
|
||||
if (igloo_ro_ref(default_instance) != igloo_ERROR_NONE)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
return default_instance;
|
||||
}
|
||||
|
11
src/list.c
11
src/list.c
@ -25,6 +25,7 @@
|
||||
|
||||
#include <igloo/list.h>
|
||||
#include <igloo/objecthandler.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
struct igloo_list_tag {
|
||||
igloo_ro_base_t __base;
|
||||
@ -216,7 +217,7 @@ int igloo_list_push(igloo_list_t *list, igloo_ro_t element)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (igloo_ro_ref(element) != 0)
|
||||
if (igloo_ro_ref(element) != igloo_ERROR_NONE)
|
||||
return -1;
|
||||
|
||||
list->elements[list->fill++] = element;
|
||||
@ -263,7 +264,7 @@ int igloo_list_unshift(igloo_list_t *list, igloo_ro_t elemen
|
||||
if (!list->offset)
|
||||
return -1;
|
||||
|
||||
if (igloo_ro_ref(element) != 0)
|
||||
if (igloo_ro_ref(element) != igloo_ERROR_NONE)
|
||||
return -1;
|
||||
|
||||
list->elements[--list->offset] = element;
|
||||
@ -317,7 +318,7 @@ static inline int igloo_list_copy_elements(igloo_list_t *list, igloo_list_t *ele
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (igloo_ro_ref(elements->elements[i]) != 0)
|
||||
if (igloo_ro_ref(elements->elements[i]) != igloo_ERROR_NONE)
|
||||
return -1;
|
||||
|
||||
list->elements[list->fill++] = elements->elements[i];
|
||||
@ -441,7 +442,7 @@ igloo_list_iterator_t * igloo_list_iterator_start(igloo_list_t *list, void *stor
|
||||
iterator = storage;
|
||||
memset(iterator, 0, sizeof(*iterator));
|
||||
|
||||
if (igloo_ro_ref(list) != 0)
|
||||
if (igloo_ro_ref(list) != igloo_ERROR_NONE)
|
||||
return NULL;
|
||||
|
||||
iterator->list = list;
|
||||
@ -463,7 +464,7 @@ igloo_ro_t igloo_list_iterator_next(igloo_list_iterator_t *iterator
|
||||
if (physical >= iterator->list->fill)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
if (igloo_ro_ref(iterator->list->elements[physical]) != 0)
|
||||
if (igloo_ro_ref(iterator->list->elements[physical]) != igloo_ERROR_NONE)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
iterator->idx++;
|
||||
|
17
src/logmsg.c
17
src/logmsg.c
@ -19,6 +19,7 @@
|
||||
#include <igloo/objecthandler.h>
|
||||
#include <igloo/filter.h>
|
||||
#include <igloo/io.h>
|
||||
#include <igloo/error.h>
|
||||
#include "private.h"
|
||||
|
||||
#define LOG_MAXLINELEN 1024
|
||||
@ -53,7 +54,7 @@ igloo_RO_PUBLIC_TYPE(igloo_logmsg_t,
|
||||
);
|
||||
|
||||
|
||||
igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated,
|
||||
igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated, igloo_ro_t instance,
|
||||
const char *msgid,
|
||||
const char *cat,
|
||||
const char *func, const char *codefile, const ssize_t codeline,
|
||||
@ -62,7 +63,7 @@ igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated,
|
||||
igloo_list_t *referenced,
|
||||
const char *format, ...)
|
||||
{
|
||||
igloo_logmsg_t *logmsg = igloo_ro_new_raw(igloo_logmsg_t, name, associated);
|
||||
igloo_logmsg_t *logmsg = igloo_ro_new_raw(igloo_logmsg_t, name, associated, instance);
|
||||
va_list ap;
|
||||
char string[LOG_MAXLINELEN];
|
||||
|
||||
@ -103,7 +104,7 @@ igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated,
|
||||
|
||||
|
||||
if (referenced) {
|
||||
if (igloo_ro_ref(referenced) != 0)
|
||||
if (igloo_ro_ref(referenced) != igloo_ERROR_NONE)
|
||||
break;
|
||||
|
||||
logmsg->referenced = referenced;
|
||||
@ -160,7 +161,7 @@ int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igl
|
||||
|
||||
if (referenced) {
|
||||
if (msg->referenced) {
|
||||
if (igloo_ro_ref(msg->referenced) != 0)
|
||||
if (igloo_ro_ref(msg->referenced) != igloo_ERROR_NONE)
|
||||
return -1;
|
||||
|
||||
*referenced = msg->referenced;
|
||||
@ -269,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;
|
||||
@ -292,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);
|
||||
}
|
||||
@ -353,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));
|
||||
@ -385,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;
|
||||
@ -134,7 +134,7 @@ int igloo_objecthandler_push_filter(igloo_objecthandler_t *handler, igloo_filter
|
||||
|
||||
igloo_thread_rwlock_wlock(&(handler->rwlock));
|
||||
if (!handler->filter_list && handler->filter_a && handler->filter_b) {
|
||||
handler->filter_list = igloo_ro_new(igloo_list_t);
|
||||
handler->filter_list = igloo_ro_new_ext(igloo_list_t, NULL, igloo_RO_NULL, handler);
|
||||
if (!handler->filter_list) {
|
||||
igloo_thread_rwlock_unlock(&(handler->rwlock));
|
||||
return -1;
|
||||
|
@ -62,7 +62,8 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
|
||||
int block_alt = 0;
|
||||
const char * arg;
|
||||
const void * argp;
|
||||
char buf[80];
|
||||
igloo_ro_t argro;
|
||||
char buf[128];
|
||||
|
||||
for (; *format && size; format++)
|
||||
{
|
||||
@ -126,6 +127,21 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
|
||||
snprintf(buf, sizeof(buf), "%p", argp);
|
||||
arg = buf;
|
||||
}
|
||||
case 'P':
|
||||
if (!arg)
|
||||
{
|
||||
igloo_ro_base_t *base;
|
||||
argro = va_arg(ap, igloo_ro_t);
|
||||
base = igloo_RO__GETBASE(argro);
|
||||
if (base) {
|
||||
snprintf(buf, sizeof(buf), "{%s@%p}", base->type->type_name, base);
|
||||
arg = buf;
|
||||
} else if (block_alt) {
|
||||
arg = "-";
|
||||
} else {
|
||||
arg = "{igloo_RO_NULL}";
|
||||
}
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
|
@ -36,6 +36,11 @@ 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)
|
||||
#define igloo_IS_INSTANCE_TYPE(x) ((x) == *igloo_instance_type)
|
||||
|
||||
/* Basic interface */
|
||||
#define igloo_interface_base(type) \
|
||||
/* The base object. */ \
|
||||
@ -56,11 +61,13 @@ 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);
|
||||
void igloo_private__snprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
igloo_ro_t igloo_get_default_instance(void);
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <igloo/reportxml.h>
|
||||
#include <igloo/thread.h>
|
||||
#include <igloo/avl.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
#define XMLSTR(str) ((xmlChar *)(str))
|
||||
|
||||
@ -256,7 +257,7 @@ static void __report_free(igloo_ro_t self)
|
||||
static int __report_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
|
||||
{
|
||||
igloo_reportxml_t *ret = igloo_RO_TO_TYPE(self, igloo_reportxml_t);
|
||||
igloo_reportxml_node_t *root = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL);
|
||||
igloo_reportxml_node_t *root = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL, self);
|
||||
|
||||
if (!root)
|
||||
return -1;
|
||||
@ -273,7 +274,7 @@ static igloo_reportxml_t * reportxml_new_with_root(igloo_reportxml_node_t *ro
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
ret = igloo_ro_new_raw(igloo_reportxml_t, NULL, igloo_RO_NULL);
|
||||
ret = igloo_ro_new_raw(igloo_reportxml_t, NULL, igloo_RO_NULL, root);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
@ -287,7 +288,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_root_node(igloo_reportxml_t *r
|
||||
if (!report)
|
||||
return NULL;
|
||||
|
||||
if (igloo_ro_ref(report->root) != 0)
|
||||
if (igloo_ro_ref(report->root) != igloo_ERROR_NONE)
|
||||
return NULL;
|
||||
|
||||
return report->root;
|
||||
@ -309,7 +310,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t
|
||||
return igloo_reportxml_node_get_child_by_type(report->root, type, include_definitions);
|
||||
}
|
||||
|
||||
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc)
|
||||
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc, igloo_ro_t instance)
|
||||
{
|
||||
igloo_reportxml_node_t *root;
|
||||
igloo_reportxml_t *ret;
|
||||
@ -322,7 +323,7 @@ igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc)
|
||||
if (!xmlroot)
|
||||
return NULL;
|
||||
|
||||
root = igloo_reportxml_node_parse_xmlnode(xmlroot);
|
||||
root = igloo_reportxml_node_parse_xmlnode(xmlroot, instance);
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
@ -383,7 +384,7 @@ static void __report_node_free(igloo_ro_t self)
|
||||
free(node->xml_childs);
|
||||
}
|
||||
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof)
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof, igloo_ro_t instance)
|
||||
{
|
||||
igloo_reportxml_node_t *ret;
|
||||
const struct nodedef *nodedef = __get_nodedef(type);
|
||||
@ -392,7 +393,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type
|
||||
if (!nodedef)
|
||||
return NULL;
|
||||
|
||||
ret = igloo_ro_new_raw(igloo_reportxml_node_t, NULL, igloo_RO_NULL);
|
||||
ret = igloo_ro_new_raw(igloo_reportxml_node_t, NULL, igloo_RO_NULL, instance);
|
||||
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
@ -434,7 +435,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode)
|
||||
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode, igloo_ro_t instance)
|
||||
{
|
||||
igloo_reportxml_node_t *node;
|
||||
|
||||
@ -448,7 +449,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmln
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = igloo_reportxml_node_new(nodedef->type, NULL, NULL, NULL);
|
||||
node = igloo_reportxml_node_new(nodedef->type, NULL, NULL, NULL, instance);
|
||||
if (!node)
|
||||
return NULL;
|
||||
|
||||
@ -506,7 +507,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmln
|
||||
continue;
|
||||
}
|
||||
|
||||
child = igloo_reportxml_node_parse_xmlnode(cur);
|
||||
child = igloo_reportxml_node_parse_xmlnode(cur, instance);
|
||||
if (!child) {
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
@ -543,7 +544,7 @@ static igloo_reportxml_node_t * __reportxml_node_copy_with_db(igloo_reportx
|
||||
if (xml_child_count < 0)
|
||||
return NULL;
|
||||
|
||||
ret = igloo_reportxml_node_parse_xmlnode(node->xmlnode);
|
||||
ret = igloo_reportxml_node_parse_xmlnode(node->xmlnode, node);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
@ -777,7 +778,7 @@ int igloo_reportxml_node_add_child(igloo_reportxml_node_t *n
|
||||
|
||||
node->childs = n;
|
||||
|
||||
if (igloo_ro_ref(child) != 0)
|
||||
if (igloo_ro_ref(child) != igloo_ERROR_NONE)
|
||||
return -1;
|
||||
|
||||
node->childs[node->childs_len++] = child;
|
||||
@ -801,7 +802,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child(igloo_reportxml_nod
|
||||
if (idx >= node->childs_len)
|
||||
return NULL;
|
||||
|
||||
if (igloo_ro_ref(node->childs[idx]) != 0)
|
||||
if (igloo_ro_ref(node->childs[idx]) != igloo_ERROR_NONE)
|
||||
return NULL;
|
||||
|
||||
return node->childs[idx];
|
||||
@ -821,7 +822,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_attribute(igloo_
|
||||
if (strcmp((const char*)k, value) == 0) {
|
||||
xmlFree(k);
|
||||
|
||||
if (igloo_ro_ref(node) != 0)
|
||||
if (igloo_ro_ref(node) != igloo_ERROR_NONE)
|
||||
return NULL;
|
||||
|
||||
return node;
|
||||
@ -849,7 +850,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_type(igloo_repor
|
||||
return NULL;
|
||||
|
||||
if (node->type == type) {
|
||||
if (igloo_ro_ref(node) != 0)
|
||||
if (igloo_ro_ref(node) != igloo_ERROR_NONE)
|
||||
return NULL;
|
||||
return node;
|
||||
}
|
||||
@ -956,12 +957,17 @@ xmlNodePtr igloo_reportxml_node_get_xml_child(igloo_reportxml_node_
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __database_free_key_fun_type(void * key)
|
||||
{
|
||||
return igloo_ro_unref(key) == igloo_ERROR_NONE ? 0 : -1;
|
||||
}
|
||||
|
||||
static void __database_free(igloo_ro_t self)
|
||||
{
|
||||
igloo_reportxml_database_t *db = igloo_RO_TO_TYPE(self, igloo_reportxml_database_t);
|
||||
|
||||
if (db->definitions)
|
||||
igloo_avl_tree_free(db->definitions, (igloo_avl_free_key_fun_type)igloo_ro_unref);
|
||||
igloo_avl_tree_free(db->definitions, __database_free_key_fun_type);
|
||||
|
||||
igloo_thread_mutex_destroy(&(db->lock));
|
||||
}
|
||||
@ -1127,7 +1133,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
|
||||
if (!depth)
|
||||
return NULL;
|
||||
|
||||
search = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL);
|
||||
search = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL, db);
|
||||
if (!search)
|
||||
return NULL;
|
||||
|
||||
@ -1145,7 +1151,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
|
||||
|
||||
igloo_ro_unref(search);
|
||||
|
||||
if (igloo_ro_ref(found) != 0) {
|
||||
if (igloo_ro_ref(found) != igloo_ERROR_NONE) {
|
||||
igloo_thread_mutex_unlock(&(db->lock));
|
||||
return NULL;
|
||||
}
|
||||
@ -1170,7 +1176,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
|
||||
ret = NULL;
|
||||
}
|
||||
} else {
|
||||
ret = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL);
|
||||
ret = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL, db);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
@ -1281,7 +1287,7 @@ igloo_reportxml_t * igloo_reportxml_database_build_report(igloo_report
|
||||
} else if (count == 0) {
|
||||
/* Empty definition? Not exactly an exciting report... */
|
||||
igloo_ro_unref(definition);
|
||||
return igloo_ro_new(igloo_reportxml_t);
|
||||
return igloo_ro_new_ext(igloo_reportxml_t, NULL, igloo_RO_NULL, db);
|
||||
}
|
||||
|
||||
if (type == igloo_REPORTXML_NODE_TYPE__ERROR) {
|
||||
@ -1307,7 +1313,7 @@ igloo_reportxml_t * igloo_reportxml_database_build_report(igloo_report
|
||||
break;
|
||||
}
|
||||
|
||||
ret = igloo_ro_new(igloo_reportxml_t);
|
||||
ret = igloo_ro_new_ext(igloo_reportxml_t, NULL, igloo_RO_NULL, db);
|
||||
if (!ret) {
|
||||
igloo_ro_unref(definition);
|
||||
return NULL;
|
||||
@ -1323,7 +1329,7 @@ igloo_reportxml_t * igloo_reportxml_database_build_report(igloo_report
|
||||
if (type == igloo_REPORTXML_NODE_TYPE_INCIDENT) {
|
||||
igloo_ro_ref(attach_to = root);
|
||||
} else if (type == igloo_REPORTXML_NODE_TYPE_STATE) {
|
||||
attach_to = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
|
||||
attach_to = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL, db);
|
||||
if (attach_to) {
|
||||
if (igloo_reportxml_node_add_child(root, attach_to) != 0) {
|
||||
igloo_ro_unref(attach_to);
|
||||
|
223
src/ro.c
223
src/ro.c
@ -26,6 +26,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <igloo/ro.h>
|
||||
#include <igloo/error.h>
|
||||
#include "private.h"
|
||||
|
||||
/* This is not static as it is used by igloo_RO_TYPEDECL_NEW_NOOP() */
|
||||
@ -67,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;
|
||||
|
||||
@ -93,7 +93,7 @@ igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name,
|
||||
}
|
||||
|
||||
if (!igloo_RO_IS_NULL(associated)) {
|
||||
if (igloo_ro_ref(associated) != 0) {
|
||||
if (igloo_ro_ref(associated) != igloo_ERROR_NONE) {
|
||||
igloo_ro_unref(base);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
@ -101,10 +101,27 @@ 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_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;
|
||||
} else {
|
||||
if (!igloo_IS_INSTANCE_TYPE(type))
|
||||
base->instance = igloo_get_default_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;
|
||||
@ -116,11 +133,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);
|
||||
|
||||
@ -132,22 +149,22 @@ igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *na
|
||||
return ret;
|
||||
}
|
||||
|
||||
int igloo_ro_ref(igloo_ro_t self)
|
||||
igloo_error_t igloo_ro_ref(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
|
||||
if (!base)
|
||||
return -1;
|
||||
return igloo_ERROR_FAULT;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
if (!base->refc) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return -1;
|
||||
return igloo_ERROR_GENERIC;
|
||||
}
|
||||
base->refc++;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
static inline void igloo_ro__destory(igloo_ro_base_t *base)
|
||||
@ -158,24 +175,24 @@ static inline void igloo_ro__destory(igloo_ro_base_t *base)
|
||||
free(base);
|
||||
}
|
||||
|
||||
int igloo_ro_unref(igloo_ro_t self)
|
||||
igloo_error_t igloo_ro_unref(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
|
||||
if (!base)
|
||||
return -1;
|
||||
return igloo_ERROR_FAULT;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
|
||||
if (!base->refc) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return -1;
|
||||
return igloo_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
if (base->refc > 1) {
|
||||
base->refc--;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
if (base->type->type_freecb)
|
||||
@ -184,6 +201,7 @@ int igloo_ro_unref(igloo_ro_t self)
|
||||
base->refc--;
|
||||
|
||||
igloo_ro_unref(base->associated);
|
||||
igloo_ro_unref(base->instance);
|
||||
|
||||
if (base->name)
|
||||
free(base->name);
|
||||
@ -191,47 +209,48 @@ int igloo_ro_unref(igloo_ro_t self)
|
||||
if (base->wrefc) {
|
||||
/* only clear the object */
|
||||
base->associated = igloo_RO_NULL;
|
||||
base->instance = igloo_RO_NULL;
|
||||
base->name = NULL;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
} else {
|
||||
igloo_ro__destory(base);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
int igloo_ro_weak_ref(igloo_ro_t self)
|
||||
igloo_error_t igloo_ro_weak_ref(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
|
||||
if (!base)
|
||||
return -1;
|
||||
return igloo_ERROR_FAULT;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
base->wrefc++;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
int igloo_ro_weak_unref(igloo_ro_t self)
|
||||
igloo_error_t igloo_ro_weak_unref(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
|
||||
if (!base)
|
||||
return -1;
|
||||
return igloo_ERROR_FAULT;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
base->wrefc--;
|
||||
|
||||
if (base->refc || base->wrefc) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
igloo_ro__destory(base);
|
||||
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
const char * igloo_ro_get_name(igloo_ro_t self)
|
||||
@ -268,7 +287,7 @@ igloo_ro_t igloo_ro_get_associated(igloo_ro_t self)
|
||||
}
|
||||
ret = base->associated;
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
if (igloo_ro_ref(ret) != 0) {
|
||||
if (igloo_ro_ref(ret) != igloo_ERROR_NONE) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
@ -278,22 +297,23 @@ igloo_ro_t igloo_ro_get_associated(igloo_ro_t self)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated)
|
||||
igloo_error_t igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t old;
|
||||
igloo_error_t ret;
|
||||
|
||||
if (!base)
|
||||
return 0;
|
||||
return igloo_ERROR_FAULT;
|
||||
|
||||
/* We can not set ourself to be our associated. */
|
||||
if (base == igloo_RO__GETBASE(associated))
|
||||
return -1;
|
||||
return igloo_ERROR_GENERIC;
|
||||
|
||||
if (!igloo_RO_IS_NULL(associated)) {
|
||||
if (igloo_ro_ref(associated) != 0) {
|
||||
if ((ret = igloo_ro_ref(associated)) != igloo_ERROR_NONE) {
|
||||
/* Could not get a reference on the new associated object. */
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +321,7 @@ int igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated)
|
||||
if (!base->refc) {
|
||||
igloo_ro_unref(associated);
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return -1;
|
||||
return igloo_ERROR_GENERIC;
|
||||
}
|
||||
old = base->associated;
|
||||
base->associated = associated;
|
||||
@ -309,7 +329,38 @@ int igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated)
|
||||
|
||||
igloo_ro_unref(old);
|
||||
|
||||
return 0;
|
||||
return igloo_ERROR_NONE;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_get_instance(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t ret;
|
||||
|
||||
if (!base)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
if (!base->refc) {
|
||||
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));
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
}
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_clone(igloo_ro_t self, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated)
|
||||
@ -332,13 +383,13 @@ igloo_ro_t igloo_ro_clone(igloo_ro_t self, igloo_ro_cf_t required, igloo_ro
|
||||
}
|
||||
|
||||
if (base->type->type_clonecb)
|
||||
ret = base->type->type_clonecb(self, required, allowed, name, associated);
|
||||
ret = base->type->type_clonecb(self, required, allowed, name, associated, base->instance);
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_convert(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated)
|
||||
static igloo_ro_t igloo_ro_convert_ext__no_lock(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t ret = igloo_RO_NULL;
|
||||
@ -346,14 +397,11 @@ igloo_ro_t igloo_ro_convert(igloo_ro_t self, const igloo_ro_type_t *type, i
|
||||
if (!base || !type)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
if (!base->refc) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
if (base->type == type) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return igloo_ro_clone(self, required, allowed, name, associated);
|
||||
}
|
||||
|
||||
@ -363,17 +411,46 @@ igloo_ro_t igloo_ro_convert(igloo_ro_t self, const igloo_ro_type_t *type, i
|
||||
allowed = igloo_RO_CF_DEFAULT;
|
||||
|
||||
if (base->type->type_convertcb)
|
||||
ret = base->type->type_convertcb(self, type, required, allowed, name, associated);
|
||||
ret = base->type->type_convertcb(self, type, required, allowed, name, associated, base->instance);
|
||||
|
||||
if (igloo_RO_IS_NULL(ret))
|
||||
if (type->type_convertcb)
|
||||
ret = type->type_convertcb(self, type, required, allowed, name, associated);
|
||||
ret = type->type_convertcb(self, type, required, allowed, name, associated, base->instance);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_convert_ext(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t ret;
|
||||
|
||||
if (!base || !type)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
ret = igloo_ro_convert_ext__no_lock(self, type, required, allowed, name, associated);
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated)
|
||||
igloo_ro_t igloo_ro_convert_simple(igloo_ro_t self, const igloo_ro_type_t *type, igloo_ro_cf_t required, igloo_ro_cf_t allowed)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t ret;
|
||||
|
||||
if (!base || !type)
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
ret = igloo_ro_convert_ext__no_lock(self, type, required, allowed, base->name, base->associated);
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_ro_t igloo_ro_get_interface_ext(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_ro_t ret = igloo_RO_NULL;
|
||||
@ -386,13 +463,38 @@ igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type,
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
/* create a temp reference
|
||||
* This is required so we can run type_get_interfacecb() in unlocked state.
|
||||
*/
|
||||
base->refc++;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
if (base->type->type_get_interfacecb)
|
||||
ret = base->type->type_get_interfacecb(self, type, name, associated);
|
||||
ret = base->type->type_get_interfacecb(self, type, name, associated, base->instance);
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
/* remove temp reference
|
||||
* If refc == 0 the application has a bug.
|
||||
* TODO: We must tell someone about it.
|
||||
* Anyway, we can not just set refc = -1, that will just break things more.
|
||||
*/
|
||||
if (base->refc)
|
||||
base->refc--;
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static size_t igloo_ro_stringify__calc_object_strlen_short(igloo_ro_t self)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
|
||||
if (!base)
|
||||
return 2;
|
||||
|
||||
return strlen(base->type->type_name) + 2+(64/4) /* pointer rendering */ + 4 /* "{@}\0" */;
|
||||
}
|
||||
|
||||
char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
@ -435,23 +537,14 @@ char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags)
|
||||
ret = base->type->type_stringifycb(self, flags);
|
||||
} else {
|
||||
if (flags & igloo_RO_SY_OBJECT) {
|
||||
if (igloo_RO_IS_NULL(base->associated)) {
|
||||
static const char *format = "{%s@%p, strong, name=%# H, associated=-}";
|
||||
size_t len = strlen(base->type->type_name) + 1*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1;
|
||||
static const char *format = "{%s@%p, strong, name=%# H, associated=%#P, instance=%#P}";
|
||||
size_t len = strlen(base->type->type_name) + 1*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1 +
|
||||
igloo_ro_stringify__calc_object_strlen_short(base->associated) +
|
||||
igloo_ro_stringify__calc_object_strlen_short(base->instance);
|
||||
|
||||
ret = calloc(1, len);
|
||||
if (ret) {
|
||||
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name);
|
||||
}
|
||||
} else {
|
||||
static const char *format = "{%s@%p, strong, name=%# H, associated={%s@%p}}";
|
||||
igloo_ro_base_t *associated = igloo_RO__GETBASE(base->associated);
|
||||
size_t len = strlen(base->type->type_name) + strlen(associated->type->type_name) + 2*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1;
|
||||
|
||||
ret = calloc(1, len);
|
||||
if (ret) {
|
||||
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name, associated->type->type_name, associated);
|
||||
}
|
||||
ret = calloc(1, len);
|
||||
if (ret) {
|
||||
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name, base->associated, base->instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,3 +605,23 @@ igloo_ro_cr_t igloo_ro_compare(igloo_ro_t a, igloo_ro_t b)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
igloo_error_t igloo_ro_get_error(igloo_ro_t self, igloo_error_t *result)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
igloo_error_t ret = igloo_ERROR_GENERIC;
|
||||
igloo_error_t res = igloo_ERROR_GENERIC;
|
||||
|
||||
if (!base || !result)
|
||||
return igloo_ERROR_GENERIC;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
if (base->type->type_get_errorcb)
|
||||
ret = base->type->type_get_errorcb(self, &res);
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
if (ret == igloo_ERROR_NONE)
|
||||
*result = res;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -16,6 +16,15 @@ check_PROGRAMS =
|
||||
libice_ctest_la_SOURCES = %reldir%/ctest_lib.c %reldir%/ctest_lib.h
|
||||
noinst_LTLIBRARIES = libice_ctest.la
|
||||
|
||||
base_source_ro = src/ro.o \
|
||||
src/libigloo.o \
|
||||
src/private.o \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
net/libicenet.la \
|
||||
log/libicelog.la
|
||||
|
||||
|
||||
#
|
||||
# Test programs
|
||||
#
|
||||
@ -26,27 +35,18 @@ check_PROGRAMS += ctest_suite.test
|
||||
|
||||
ctest_refobject_test_SOURCES = %reldir%/ctest_refobject.c
|
||||
ctest_refobject_test_LDADD = libice_ctest.la \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
src/ro.o \
|
||||
src/private.o
|
||||
$(base_source_ro)
|
||||
check_PROGRAMS += ctest_refobject.test
|
||||
|
||||
ctest_buffer_test_SOURCES = %reldir%/ctest_buffer.c
|
||||
ctest_buffer_test_LDADD = libice_ctest.la \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
src/ro.o \
|
||||
src/private.o \
|
||||
$(base_source_ro) \
|
||||
src/buffer.o
|
||||
check_PROGRAMS += ctest_buffer.test
|
||||
|
||||
ctest_list_test_SOURCES = %reldir%/ctest_list.c
|
||||
ctest_list_test_LDADD = libice_ctest.la \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
src/ro.o \
|
||||
src/private.o \
|
||||
$(base_source_ro) \
|
||||
src/objecthandler.o \
|
||||
src/filter.o \
|
||||
src/interface.o \
|
||||
@ -55,19 +55,13 @@ check_PROGRAMS += ctest_list.test
|
||||
|
||||
ctest_reportxml_test_SOURCES = %reldir%/ctest_reportxml.c
|
||||
ctest_reportxml_test_LDADD = libice_ctest.la \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
src/ro.o \
|
||||
src/private.o \
|
||||
$(base_source_ro) \
|
||||
src/reportxml.o
|
||||
check_PROGRAMS += ctest_reportxml.test
|
||||
|
||||
ctest_logmsg_test_SOURCES = %reldir%/ctest_logmsg.c
|
||||
ctest_logmsg_test_LDADD = libice_ctest.la \
|
||||
thread/libicethread.la \
|
||||
avl/libiceavl.la \
|
||||
src/ro.o \
|
||||
src/private.o \
|
||||
$(base_source_ro) \
|
||||
src/io.o \
|
||||
src/list.o \
|
||||
src/interface.o \
|
||||
|
@ -16,18 +16,19 @@
|
||||
|
||||
#include <igloo/ro.h>
|
||||
#include <igloo/buffer.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
static void test_create_ref_unref(void)
|
||||
{
|
||||
igloo_buffer_t *a;
|
||||
|
||||
a = igloo_buffer_new(-1, NULL, igloo_RO_NULL);
|
||||
a = igloo_buffer_new(-1, NULL, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
|
||||
a = igloo_ro_new(igloo_buffer_t);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
|
||||
}
|
||||
|
||||
@ -37,14 +38,14 @@ static void test_name(void)
|
||||
const char *name = "test object name";
|
||||
const char *ret;
|
||||
|
||||
a = igloo_buffer_new(-1, name, igloo_RO_NULL);
|
||||
a = igloo_buffer_new(-1, name, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
|
||||
ret = igloo_ro_get_name(a);
|
||||
ctest_test("get name", ret != NULL);
|
||||
ctest_test("name match", strcmp(name, ret) == 0);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_associated(void)
|
||||
@ -56,11 +57,11 @@ static void test_associated(void)
|
||||
ctest_test("refobject created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
|
||||
b = igloo_buffer_new(-1, NULL, a);
|
||||
b = igloo_buffer_new(-1, NULL, a, igloo_RO_NULL);
|
||||
ctest_test("buffer created with associated", !igloo_RO_IS_NULL(b));
|
||||
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_empty(void)
|
||||
@ -104,7 +105,7 @@ static void test_empty(void)
|
||||
}
|
||||
}
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_string(void)
|
||||
@ -139,7 +140,7 @@ static void test_string(void)
|
||||
}
|
||||
}
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_binary(void)
|
||||
@ -183,7 +184,7 @@ static void test_binary(void)
|
||||
}
|
||||
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test__compare_to_string(igloo_buffer_t *a, const char *testname, const char *pattern)
|
||||
@ -222,7 +223,7 @@ static void test_shift(void)
|
||||
test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3 + 2);
|
||||
ctest_test("shifted data beyond end (42 bytes)", igloo_buffer_shift(a, 42) != 0);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_length(void)
|
||||
@ -247,7 +248,7 @@ static void test_length(void)
|
||||
ctest_test("Set length to match pattern a (again)", igloo_buffer_set_length(a, strlen(match_a)) != 0);
|
||||
test__compare_to_string(a, "string still matches pattern c", match_c);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_printf(void)
|
||||
@ -269,7 +270,7 @@ static void test_printf(void)
|
||||
ctest_test("Set length to match pattern a", igloo_buffer_push_printf(a, "?%+5i?", -num) == 0);
|
||||
test__compare_to_string(a, "string matches pattern c", match_c);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_push_buffer(void)
|
||||
@ -293,8 +294,8 @@ static void test_push_buffer(void)
|
||||
ctest_test("pushed buffer a to b", igloo_buffer_push_buffer(b, a) == 0);
|
||||
test__compare_to_string(b, "string matches pattern a", match_a);
|
||||
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <igloo/ro.h>
|
||||
#include <igloo/list.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
static void test_create_ref_unref(void)
|
||||
{
|
||||
@ -24,7 +25,7 @@ static void test_create_ref_unref(void)
|
||||
a = igloo_ro_new(igloo_list_t);
|
||||
ctest_test("list created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test__create_push_unshift(igloo_list_t **list, igloo_ro_base_t **a, igloo_ro_base_t **b)
|
||||
@ -55,9 +56,9 @@ static void test_list_push_unshift(void)
|
||||
|
||||
test__create_push_unshift(&list, &a, &b);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_push_unshift_pop(void)
|
||||
@ -72,11 +73,11 @@ static void test_list_push_unshift_pop(void)
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("popped element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_push_unshift_pop_pop(void)
|
||||
@ -91,20 +92,20 @@ static void test_list_push_unshift_pop_pop(void)
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("popped element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("popped element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped no element", igloo_RO_IS_NULL(ret));
|
||||
igloo_ro_unref(ret); /* just in case we got an element */
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_push_unshift_shift(void)
|
||||
@ -119,11 +120,11 @@ static void test_list_push_unshift_shift(void)
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_push_unshift_shift_shift(void)
|
||||
@ -138,20 +139,20 @@ static void test_list_push_unshift_shift_shift(void)
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted no element", igloo_RO_IS_NULL(ret));
|
||||
igloo_ro_unref(ret); /* just in case we got an element */
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
|
||||
@ -167,16 +168,16 @@ static void test_list_push_unshift_pop_shift(void)
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("popped element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
static void test_list_push_unshift_shift_pop(void)
|
||||
{
|
||||
@ -190,16 +191,16 @@ static void test_list_push_unshift_shift_pop(void)
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_pop(list);
|
||||
ctest_test("popped element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("popped element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced popped element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_merge(void)
|
||||
@ -230,12 +231,12 @@ static void test_list_merge(void)
|
||||
ret = igloo_list_shift(list_a);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list_a);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list_a);
|
||||
ctest_test("shifted no element", igloo_RO_IS_NULL(ret));
|
||||
@ -244,16 +245,16 @@ static void test_list_merge(void)
|
||||
ret = igloo_list_shift(list_b);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches b", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == b);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ret = igloo_list_shift(list_b);
|
||||
ctest_test("shifted no element", igloo_RO_IS_NULL(ret));
|
||||
igloo_ro_unref(ret); /* just in case we got an element */
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list_a) == 0);
|
||||
ctest_test("un-referenced list b", igloo_ro_unref(list_b) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list_a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list b", igloo_ro_unref(list_b) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_set_type(void)
|
||||
@ -290,7 +291,7 @@ static void test_list_set_type(void)
|
||||
ctest_test("can not pin list to type igloo_list_t", igloo_list_set_type(list, igloo_list_t) == 0);
|
||||
ctest_test("pinned list to type igloo_ro_base_t", igloo_list_set_type(list, igloo_ro_base_t) == 0);
|
||||
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
list = igloo_ro_new(igloo_list_t);
|
||||
ctest_test("list created", !igloo_RO_IS_NULL(list));
|
||||
|
||||
@ -304,15 +305,15 @@ static void test_list_set_type(void)
|
||||
ret = igloo_list_shift(list);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(ret));
|
||||
ctest_test("shifted element matches a", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == a);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced shifted element", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("pinned list to type igloo_ro_base_t", igloo_list_set_type(list, igloo_ro_base_t) != 0);
|
||||
ctest_test("can not pin list to type igloo_list_t", igloo_list_set_type(list, igloo_list_t) == 0);
|
||||
ctest_test("pinned list to type igloo_ro_base_t", igloo_list_set_type(list, igloo_ro_base_t) != 0);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list a", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_iterator(void)
|
||||
@ -332,7 +333,7 @@ static void test_list_iterator(void)
|
||||
igloo_ro_t ret = igloo_list_iterator_next(iterator);
|
||||
ctest_test("shifted element matches corresponding element in list", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == elements[i]);
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,7 +343,7 @@ static void test_list_iterator(void)
|
||||
igloo_ro_t ret = igloo_list_iterator_next(iterator);
|
||||
ctest_test("shifted element matches corresponding element in list", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == elements[i]);
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,7 +353,7 @@ static void test_list_iterator(void)
|
||||
igloo_ro_t ret = igloo_list_iterator_next(iterator);
|
||||
ctest_test("shifted element matches corresponding element in list", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == elements[i]);
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,15 +363,15 @@ static void test_list_iterator(void)
|
||||
igloo_ro_t ret = igloo_list_iterator_next(iterator);
|
||||
ctest_test("shifted element matches corresponding element in list", igloo_RO_TO_TYPE(ret, igloo_ro_base_t) == elements[i]);
|
||||
if (!igloo_RO_IS_NULL(ret)) {
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == 0);
|
||||
ctest_test("un-referenced element returned by iterator", igloo_ro_unref(ret) == igloo_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
igloo_list_iterator_end(iterator);
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(elements[0]) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(elements[1]) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(elements[0]) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(elements[1]) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_foreach(void)
|
||||
@ -386,9 +387,9 @@ static void test_list_foreach(void)
|
||||
i++;
|
||||
});
|
||||
|
||||
ctest_test("un-referenced a", igloo_ro_unref(elements[0]) == 0);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(elements[1]) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced a", igloo_ro_unref(elements[0]) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced b", igloo_ro_unref(elements[1]) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_policy_grow(void) {
|
||||
@ -404,10 +405,10 @@ static void test_list_policy_grow(void) {
|
||||
igloo_ro_base_t *element = igloo_ro_new(igloo_ro_base_t);
|
||||
ctest_test("test object created", !igloo_RO_IS_NULL(element));
|
||||
ctest_test("test object pushed", igloo_list_push(list, element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_policy_fixed(void) {
|
||||
@ -429,12 +430,12 @@ static void test_list_policy_fixed(void) {
|
||||
} else {
|
||||
ctest_test("test object can not be pushed", igloo_list_push(list, element) != 0);
|
||||
}
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
element = igloo_RO_TO_TYPE(igloo_list_shift(list), igloo_ro_base_t);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(element));
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
element = igloo_ro_new(igloo_ro_base_t);
|
||||
@ -444,10 +445,10 @@ static void test_list_policy_fixed(void) {
|
||||
} else {
|
||||
ctest_test("test object can not be pushed", igloo_list_push(list, element) != 0);
|
||||
}
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_policy_fixed_pipe_push(void) {
|
||||
@ -469,19 +470,19 @@ static void test_list_policy_fixed_pipe_push(void) {
|
||||
|
||||
if (i == 1) {
|
||||
second_element = element;
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0);
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
element = igloo_RO_TO_TYPE(igloo_list_shift(list), igloo_ro_base_t);
|
||||
ctest_test("shifted element", !igloo_RO_IS_NULL(element));
|
||||
ctest_test("shifted element matches 2nd test object", igloo_RO_TO_TYPE(element, igloo_ro_base_t) == second_element);
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_policy_fixed_pipe_unshift(void) {
|
||||
@ -503,19 +504,19 @@ static void test_list_policy_fixed_pipe_unshift(void) {
|
||||
|
||||
if (i == 1) {
|
||||
second_element = element;
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0);
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
element = igloo_RO_TO_TYPE(igloo_list_pop(list), igloo_ro_base_t);
|
||||
ctest_test("poped element", !igloo_RO_IS_NULL(element));
|
||||
ctest_test("poped element matches 2nd test object", igloo_RO_TO_TYPE(element, igloo_ro_base_t) == second_element);
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced element", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_policy_fixed_pipe_merge(void) {
|
||||
@ -536,7 +537,7 @@ static void test_list_policy_fixed_pipe_merge(void) {
|
||||
element = igloo_ro_new(igloo_ro_base_t);
|
||||
ctest_test("test object created", !igloo_RO_IS_NULL(element));
|
||||
ctest_test("test object pushed", igloo_list_push(srclist, element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("merged source list into destination list", igloo_list_merge(dstlist, srclist) == 0);
|
||||
@ -546,8 +547,8 @@ static void test_list_policy_fixed_pipe_merge(void) {
|
||||
|
||||
ctest_test("merged source list into destination list", igloo_list_merge(dstlist, srclist) == 0);
|
||||
|
||||
ctest_test("un-referenced srclist", igloo_ro_unref(srclist) == 0);
|
||||
ctest_test("un-referenced dstlist", igloo_ro_unref(dstlist) == 0);
|
||||
ctest_test("un-referenced srclist", igloo_ro_unref(srclist) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced dstlist", igloo_ro_unref(dstlist) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_list_remove(void) {
|
||||
@ -567,10 +568,10 @@ static void test_list_remove(void) {
|
||||
|
||||
if (i == 1) {
|
||||
second_element = element;
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0);
|
||||
ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == 0);
|
||||
ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
ctest_test("2nd element was removed", igloo_list_remove(list, second_element) == 0);
|
||||
@ -583,8 +584,8 @@ static void test_list_remove(void) {
|
||||
|
||||
ctest_test("Number of returned elements is correct", count == 3);
|
||||
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == 0);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == 0);
|
||||
ctest_test("un-referenced 2nd test object", igloo_ro_unref(second_element) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced list", igloo_ro_unref(list) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <igloo/logmsg.h>
|
||||
#include <igloo/filter.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
static void test_create_unref(void)
|
||||
{
|
||||
@ -23,17 +24,17 @@ static void test_create_unref(void)
|
||||
igloo_objecthandler_t *formater;
|
||||
igloo_filter_t *filter;
|
||||
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL__NONE, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL__NONE, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
ctest_test("logmsg created", !igloo_RO_IS_NULL(msg));
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == 0);
|
||||
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) == 0);
|
||||
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) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(filter) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_logmsg(void)
|
||||
@ -48,7 +49,7 @@ static void test_logmsg(void)
|
||||
igloo_list_t *referenced_out;
|
||||
int ret;
|
||||
|
||||
msg = igloo_logmsg_new("name", igloo_RO_NULL, "msgid", "cat", "func", "codefile", 13374242, &tv_in, igloo_LOGLEVEL_INFO, igloo_LOGMSG_OPT_ASKACK, NULL, "test %i %s", 5, "msg");
|
||||
msg = igloo_logmsg_new("name", igloo_RO_NULL, igloo_RO_NULL, "msgid", "cat", "func", "codefile", 13374242, &tv_in, igloo_LOGLEVEL_INFO, igloo_LOGMSG_OPT_ASKACK, NULL, "test %i %s", 5, "msg");
|
||||
ctest_test("logmsg created", !igloo_RO_IS_NULL(msg));
|
||||
|
||||
ctest_test("got context", (ret = igloo_logmsg_get_context(msg, &msgid_out, &cat_out, &func_out, &codefile_out, &codeline_out, &tv_out)) == 0);
|
||||
@ -86,7 +87,7 @@ static void test_logmsg(void)
|
||||
ctest_test("got referenced", 0);
|
||||
}
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_filter(void)
|
||||
@ -95,25 +96,25 @@ 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);
|
||||
ctest_test("base created", base != NULL);
|
||||
ctest_test("droping base", igloo_filter_test(filter, base) == igloo_FILTER_RESULT_DROP);
|
||||
ctest_test("base un-referenced", igloo_ro_unref(base) == 0);
|
||||
ctest_test("base un-referenced", igloo_ro_unref(base) == igloo_ERROR_NONE);
|
||||
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL_INFO, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL_INFO, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
ctest_test("logmsg created", !igloo_RO_IS_NULL(msg));
|
||||
ctest_test("droping logmsg", igloo_filter_test(filter, msg) == igloo_FILTER_RESULT_DROP);
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == igloo_ERROR_NONE);
|
||||
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL_WARN, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
msg = igloo_logmsg_new(NULL, igloo_RO_NULL, igloo_RO_NULL, NULL, NULL, NULL, NULL, -1, NULL, igloo_LOGLEVEL_WARN, igloo_LOGMSG_OPT_NONE, NULL, "test");
|
||||
ctest_test("logmsg created", !igloo_RO_IS_NULL(msg));
|
||||
ctest_test("passing logmsg", igloo_filter_test(filter, msg) == igloo_FILTER_RESULT_PASS);
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(msg) == igloo_ERROR_NONE);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(filter) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(filter) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -33,6 +33,7 @@ typedef struct ctest_test_type_d_t ctest_test_type_d_t;
|
||||
igloo_RO_TYPE(ctest_test_type_d_t)
|
||||
|
||||
#include <igloo/ro.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
struct ctest_test_type_t {
|
||||
igloo_ro_base_t __base;
|
||||
@ -99,9 +100,9 @@ static void test_create_ref_unref(void)
|
||||
a = igloo_ro_new(igloo_ro_base_t);
|
||||
ctest_test("refobject created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
ctest_test("referenced", igloo_ro_ref(a) == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("referenced", igloo_ro_ref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_create_weak_ref_unref(void)
|
||||
@ -112,9 +113,9 @@ static void test_create_weak_ref_unref(void)
|
||||
ctest_test("refobject created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
ctest_test("weak referenced", igloo_ro_weak_ref(a) == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("referencing failed", igloo_ro_ref(a) != 0);
|
||||
ctest_test("un-referencing (2 of 2) failed", igloo_ro_unref(a) != 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("referencing failed", igloo_ro_ref(a) != igloo_ERROR_NONE);
|
||||
ctest_test("un-referencing (2 of 2) failed", igloo_ro_unref(a) != igloo_ERROR_NONE);
|
||||
ctest_test("weak un-referenced", igloo_ro_weak_unref(a) == 0);
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ static void test_typename(void)
|
||||
ctest_test("got typename", typename != NULL);
|
||||
ctest_test("typename matches", strcmp(typename, "igloo_ro_base_t") == 0);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_valid(void)
|
||||
@ -145,7 +146,7 @@ static void test_valid(void)
|
||||
ctest_test("is valid", igloo_RO_IS_VALID(a, igloo_ro_base_t));
|
||||
ctest_test("is valid as diffrent type", !igloo_RO_IS_VALID(a, ctest_test_type_t));
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_sizes(void)
|
||||
@ -154,22 +155,22 @@ static void test_sizes(void)
|
||||
|
||||
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_a_t);
|
||||
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) + 1024", !igloo_RO_IS_NULL(a));
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
|
||||
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_b_t);
|
||||
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) + 131072", !igloo_RO_IS_NULL(a));
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
|
||||
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_c_t);
|
||||
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) - 1", igloo_RO_IS_NULL(a));
|
||||
if (!igloo_RO_IS_NULL(a)) {
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_d_t);
|
||||
ctest_test("refobject created with size=0", igloo_RO_IS_NULL(a));
|
||||
if (!igloo_RO_IS_NULL(a)) {
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,14 +180,14 @@ static void test_name(void)
|
||||
const char *name = "test object name";
|
||||
const char *ret;
|
||||
|
||||
a = igloo_ro_new_ext(igloo_ro_base_t, name, igloo_RO_NULL);
|
||||
a = igloo_ro_new_ext(igloo_ro_base_t, name, igloo_RO_NULL, igloo_RO_NULL);
|
||||
ctest_test("refobject created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
ret = igloo_ro_get_name(a);
|
||||
ctest_test("get name", ret != NULL);
|
||||
ctest_test("name match", strcmp(name, ret) == 0);
|
||||
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static void test_associated(void)
|
||||
@ -196,11 +197,11 @@ static void test_associated(void)
|
||||
a = igloo_ro_new(igloo_ro_base_t);
|
||||
ctest_test("refobject created", !igloo_RO_IS_NULL(a));
|
||||
|
||||
b = igloo_ro_new_ext(igloo_ro_base_t, NULL, a);
|
||||
b = igloo_ro_new_ext(igloo_ro_base_t, NULL, a, igloo_RO_NULL);
|
||||
ctest_test("refobject created with associated", !igloo_RO_IS_NULL(b));
|
||||
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(b) == 0);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(b) == igloo_ERROR_NONE);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
static size_t test_freecb__called;
|
||||
@ -216,17 +217,17 @@ static void test_freecb(void)
|
||||
test_freecb__called = 0;
|
||||
a = igloo_ro_new(ctest_test_type_free_t);
|
||||
ctest_test("refobject created", a != NULL);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("freecb called", test_freecb__called == 1);
|
||||
|
||||
test_freecb__called = 0;
|
||||
a = igloo_ro_new(ctest_test_type_free_t);
|
||||
ctest_test("refobject created", a != NULL);
|
||||
ctest_test("referenced", igloo_ro_ref(a) == 0);
|
||||
ctest_test("referenced", igloo_ro_ref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("freecb uncalled", test_freecb__called == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("freecb uncalled", test_freecb__called == 0);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("freecb called", test_freecb__called == 1);
|
||||
|
||||
test_freecb__called = 0;
|
||||
@ -234,7 +235,7 @@ static void test_freecb(void)
|
||||
ctest_test("refobject created", a != NULL);
|
||||
ctest_test("weak referenced", igloo_ro_weak_ref(a) == 0);
|
||||
ctest_test("freecb uncalled", test_freecb__called == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(a) == igloo_ERROR_NONE);
|
||||
ctest_test("freecb called", test_freecb__called == 1);
|
||||
ctest_test("weak un-referenced", igloo_ro_weak_unref(a) == 0);
|
||||
ctest_test("freecb called once", test_freecb__called == 1);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "ctest_lib.h"
|
||||
|
||||
#include <igloo/reportxml.h>
|
||||
#include <igloo/error.h>
|
||||
|
||||
static void test_create_unref(void)
|
||||
{
|
||||
@ -24,15 +25,15 @@ static void test_create_unref(void)
|
||||
|
||||
report = igloo_ro_new(igloo_reportxml_t);
|
||||
ctest_test("report created", !igloo_RO_IS_NULL(report));
|
||||
ctest_test("un-referenced", igloo_ro_unref(report) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(report) == igloo_ERROR_NONE);
|
||||
|
||||
node = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL);
|
||||
node = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL, igloo_RO_NULL);
|
||||
ctest_test("node created", !igloo_RO_IS_NULL(node));
|
||||
ctest_test("un-referenced", igloo_ro_unref(node) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(node) == igloo_ERROR_NONE);
|
||||
|
||||
database = igloo_ro_new(igloo_reportxml_database_t);
|
||||
ctest_test("database created", !igloo_RO_IS_NULL(database));
|
||||
ctest_test("un-referenced", igloo_ro_unref(database) == 0);
|
||||
ctest_test("un-referenced", igloo_ro_unref(database) == igloo_ERROR_NONE);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
Loading…
Reference in New Issue
Block a user