base: Make log facility opaque, ref-counted
This commit is contained in:
@@ -93,19 +93,7 @@ typedef void (HEIM_CALLCONV *heim_log_log_func_t)(heim_context,
|
|||||||
void *);
|
void *);
|
||||||
typedef void (HEIM_CALLCONV *heim_log_close_func_t)(void *);
|
typedef void (HEIM_CALLCONV *heim_log_close_func_t)(void *);
|
||||||
|
|
||||||
struct heim_log_facility_internal {
|
typedef struct heim_log_facility_s heim_log_facility;
|
||||||
int min;
|
|
||||||
int max;
|
|
||||||
heim_log_log_func_t log_func;
|
|
||||||
heim_log_close_func_t close_func;
|
|
||||||
void *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct heim_log_facility_s {
|
|
||||||
char *program;
|
|
||||||
int len;
|
|
||||||
struct heim_log_facility_internal *val;
|
|
||||||
} heim_log_facility;
|
|
||||||
|
|
||||||
typedef uintptr_t
|
typedef uintptr_t
|
||||||
(HEIM_LIB_CALL *heim_get_instance_func_t)(const char *);
|
(HEIM_LIB_CALL *heim_get_instance_func_t)(const char *);
|
||||||
|
@@ -41,6 +41,21 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <vis.h>
|
#include <vis.h>
|
||||||
|
|
||||||
|
struct heim_log_facility_internal {
|
||||||
|
int min;
|
||||||
|
int max;
|
||||||
|
heim_log_log_func_t log_func;
|
||||||
|
heim_log_close_func_t close_func;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct heim_log_facility_s {
|
||||||
|
char *program;
|
||||||
|
size_t refs;
|
||||||
|
size_t len;
|
||||||
|
struct heim_log_facility_internal *val;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct heim_pcontext_s *heim_pcontext;
|
typedef struct heim_pcontext_s *heim_pcontext;
|
||||||
typedef struct heim_pconfig *heim_pconfig;
|
typedef struct heim_pconfig *heim_pconfig;
|
||||||
struct heim_svc_req_desc_common_s {
|
struct heim_svc_req_desc_common_s {
|
||||||
@@ -126,6 +141,7 @@ heim_initlog(heim_context context,
|
|||||||
heim_log_facility *f = calloc(1, sizeof(*f));
|
heim_log_facility *f = calloc(1, sizeof(*f));
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return heim_enomem(context);
|
return heim_enomem(context);
|
||||||
|
f->refs = 1;
|
||||||
f->program = strdup(program);
|
f->program = strdup(program);
|
||||||
if (f->program == NULL) {
|
if (f->program == NULL) {
|
||||||
free(f);
|
free(f);
|
||||||
@@ -135,6 +151,14 @@ heim_initlog(heim_context context,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heim_log_facility *
|
||||||
|
heim_log_ref(heim_log_facility *fac)
|
||||||
|
{
|
||||||
|
if (fac)
|
||||||
|
fac->refs++;
|
||||||
|
return fac;
|
||||||
|
}
|
||||||
|
|
||||||
heim_error_code
|
heim_error_code
|
||||||
heim_addlog_func(heim_context context,
|
heim_addlog_func(heim_context context,
|
||||||
heim_log_facility *fac,
|
heim_log_facility *fac,
|
||||||
@@ -432,7 +456,7 @@ heim_closelog(heim_context context, heim_log_facility *fac)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!fac)
|
if (!fac || --(fac->refs))
|
||||||
return;
|
return;
|
||||||
for (i = 0; i < fac->len; i++)
|
for (i = 0; i < fac->len; i++)
|
||||||
(*fac->val[i].close_func)(fac->val[i].data);
|
(*fac->val[i].close_func)(fac->val[i].data);
|
||||||
|
Reference in New Issue
Block a user