]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_logreg.h
Added ul_logreg_for_each_domain()
[ulut.git] / ulut / ul_logreg.h
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_logreg.h   - registration of logging domains
5
6   (C) Copyright 2006 by Pavel Pisa - Originator
7
8   The uLan utilities library can be used, copied and modified under
9   next licenses
10     - GPL - GNU General Public License
11     - LGPL - GNU Lesser General Public License
12     - MPL - Mozilla Public License
13     - and other licenses added by project originators
14   Code can be modified and re-distributed under any combination
15   of the above listed licenses. If contributor does not agree with
16   some of the licenses, he/she can delete appropriate line.
17   Warning, if you delete all lines, you are not allowed to
18   distribute source code and/or binaries utilizing code.
19   
20   See files COPYING and README for details.
21
22  *******************************************************************/
23
24 #include <ul_logbase.h>
25 #include <ul_utdefs.h>
26
27 #ifndef _UL_LOGREG_H
28 #define _UL_LOGREG_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 int ul_log_domain_setlevel(const char *name, int setlevel);
35 int ul_log_domain_getlevel(const char *name);
36
37 int ul_logreg_domain(ul_log_domain_t *domain);
38 int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count);
39 int ul_log_domain_arg2levels(const char *arg);
40
41 #define UL_LOGREG_DOMAINS_INIT_FUNCTION(function_name, array_name) \
42 int function_name(void) \
43 { \
44   int ret; \
45   static int domains_registered = 0; \
46   if (domains_registered) \
47     return 0; \
48   ret = ul_logreg_domains_static(array_name, \
49            sizeof(array_name)/sizeof(array_name[0])); \
50   if (ret >= 0) \
51     domains_registered = 1; \
52   return ret; \
53 } \
54 static void function_name##_on_init(void) UL_ATTR_CONSTRUCTOR; \
55 static void function_name##_on_init(void) { function_name(); }
56
57 #define UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(function_name, domain_name) \
58 int function_name(void) \
59 { \
60   int ret; \
61   static int domain_registered = 0; \
62   if (domain_registered) \
63     return 0; \
64   ret = ul_logreg_domain(&domain_name); \
65   if (ret >= 0) \
66     domain_registered = 1; \
67   return ret; \
68 } \
69 static void function_name##_on_init(void) UL_ATTR_CONSTRUCTOR; \
70 static void function_name##_on_init(void) { function_name(); }
71
72 typedef int (ul_logreg_domain_cb_t)(ul_log_domain_t *domain, void *context);
73 void ul_logreg_for_each_domain(ul_logreg_domain_cb_t *callback, void *context);
74
75 #ifdef __cplusplus
76 } /* extern "C"*/
77 #endif
78
79 #endif /*_UL_LOGREG_H*/