From: ppisa Date: Mon, 25 May 2009 17:42:12 +0000 (+0000) Subject: Added helper macro for log domain registration function building. X-Git-Tag: ul_drv-0.8.0-release~17 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/ulut.git/commitdiff_plain/26083f92bdf1509302dcd7034998eaa6a6b0fafb Added helper macro for log domain registration function building. --- diff --git a/ulut/ul_logreg.h b/ulut/ul_logreg.h index 9a25b83..a9a8596 100644 --- a/ulut/ul_logreg.h +++ b/ulut/ul_logreg.h @@ -22,6 +22,7 @@ *******************************************************************/ #include +#include #ifndef _UL_LOGREG_H #define _UL_LOGREG_H @@ -37,6 +38,22 @@ 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"*/ #endif