1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-09-29 04:25:57 -04:00

Feature: Allow asking objects for their error state

This commit is contained in:
Philipp Schafft 2019-09-12 13:17:47 +00:00
parent 3c6c6c62b5
commit 76a9d1c756
2 changed files with 40 additions and 0 deletions

View File

@ -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 */
@ -392,6 +398,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

View File

@ -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() */
@ -512,3 +513,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;
}