]> rtime.felk.cvut.cz Git - ulut.git/blobdiff - ulut/ul_logreg.h
Added ul_logreg_for_each_domain()
[ulut.git] / ulut / ul_logreg.h
index 9a25b83745856a45dd6972ab07f317e0673ed474..0aaa260bcf73271640629369b4c4105f7ba6193d 100644 (file)
@@ -22,6 +22,7 @@
  *******************************************************************/
 
 #include <ul_logbase.h>
+#include <ul_utdefs.h>
 
 #ifndef _UL_LOGREG_H
 #define _UL_LOGREG_H
@@ -37,6 +38,40 @@ int ul_logreg_domain(ul_log_domain_t *domain);
 int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count);
 int ul_log_domain_arg2levels(const char *arg);
 
+#define UL_LOGREG_DOMAINS_INIT_FUNCTION(function_name, array_name) \
+int function_name(void) \
+{ \
+  int ret; \
+  static int domains_registered = 0; \
+  if (domains_registered) \
+    return 0; \
+  ret = ul_logreg_domains_static(array_name, \
+           sizeof(array_name)/sizeof(array_name[0])); \
+  if (ret >= 0) \
+    domains_registered = 1; \
+  return ret; \
+} \
+static void function_name##_on_init(void) UL_ATTR_CONSTRUCTOR; \
+static void function_name##_on_init(void) { function_name(); }
+
+#define UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(function_name, domain_name) \
+int function_name(void) \
+{ \
+  int ret; \
+  static int domain_registered = 0; \
+  if (domain_registered) \
+    return 0; \
+  ret = ul_logreg_domain(&domain_name); \
+  if (ret >= 0) \
+    domain_registered = 1; \
+  return ret; \
+} \
+static void function_name##_on_init(void) UL_ATTR_CONSTRUCTOR; \
+static void function_name##_on_init(void) { function_name(); }
+
+typedef int (ul_logreg_domain_cb_t)(ul_log_domain_t *domain, void *context);
+void ul_logreg_for_each_domain(ul_logreg_domain_cb_t *callback, void *context);
+
 #ifdef __cplusplus
 } /* extern "C"*/
 #endif