]> rtime.felk.cvut.cz Git - ulut.git/blobdiff - ulut/ul_logreg.h
Added helper macro for log domain registration function building.
[ulut.git] / ulut / ul_logreg.h
index aa0ca6b17f041b97fb8f02eb526641444627f83b..a9a85964975a3d1d9815aed291d45021eab1f8d8 100644 (file)
@@ -22,6 +22,7 @@
  *******************************************************************/
 
 #include <ul_logbase.h>
+#include <ul_utdefs.h>
 
 #ifndef _UL_LOGREG_H
 #define _UL_LOGREG_H
@@ -35,6 +36,23 @@ int ul_log_domain_getlevel(const char *name);
 
 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(); }
 
 #ifdef __cplusplus
 } /* extern "C"*/