From: Andre Date: Fri, 5 Jan 2007 19:35:47 +0000 (+0100) Subject: introduce INIT_STDERR_LOCKING macro X-Git-Tag: v0.2.15~107 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=b9f9601828dd1a103ec9315bd430d39b458d2b80;p=paraslash.git introduce INIT_STDERR_LOCKING macro This makes para_{audioc,client,filter,recv,write} use the same log function. --- diff --git a/audioc.c b/audioc.c index 0f4c5c50..1679335d 100644 --- a/audioc.c +++ b/audioc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,21 +30,7 @@ INIT_AUDIOC_ERRLISTS; struct audioc_args_info conf; char *tmpfifo; - -/* - * client log function - */ -void para_log(int ll, const char* fmt,...) -{ - va_list argp; - - /* ignore log message if loglevel is not high enough */ - if (ll < conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(conf.loglevel_arg); static char *concat_args(const int argc, char * const *argv) { diff --git a/client.c b/client.c index 88ea5af2..be76a491 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2006 Andre Noll + * Copyright (C) 1997-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,20 +34,8 @@ static struct private_client_data *pcd; static struct stdin_task sit; static struct stdout_task sot; -/* - * client log function - */ -void para_log(int ll, const char* fmt,...) -{ - va_list argp; - /* ignore log message if loglevel is not high enough */ - if (pcd && ll < pcd->conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(pcd->conf.loglevel_arg); static void client_event_handler(struct task *t) { diff --git a/filter.c b/filter.c index 40fbc844..ee3d9655 100644 --- a/filter.c +++ b/filter.c @@ -49,27 +49,7 @@ static struct stdout_task *sot = &stdout_task_struct; /** gengetopt struct that holds the command line args */ static struct filter_args_info conf; - -/** - * standard log function that always writes to stderr - * - * \param ll loglevel. If the loglevel of the current message - * is less than \a ll, the message is going to be ignored. - * - * \param fmt the format string describing the log message. - * - */ -__printf_2_3 void para_log(int ll, const char* fmt,...) -{ - va_list argp; - - /* ignore log message if loglevel is not high enough */ - if (ll < conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(conf.loglevel_arg); static void filter_event_handler(struct task *t) { diff --git a/para.h b/para.h index 47d54a1f..fc0edf9a 100644 --- a/para.h +++ b/para.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2006 Andre Noll + * Copyright (C) 1997-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -100,6 +100,25 @@ #define PARA_EMERG_LOG(...) #endif +/** + * define a standard log function that always writes to stderr + * + * \param loglevel_barier If the loglevel of the current message + * is less than that, the message is going to be ignored. + * + */ +#define INIT_STDERR_LOGGING(loglevel_barrier) \ + __printf_2_3 void para_log(int ll, const char* fmt,...) \ + { \ + va_list argp; \ + if (ll < loglevel_barrier) \ + return; \ + va_start(argp, fmt); \ + vfprintf(stderr, fmt, argp); \ + va_end(argp); \ + } + + #define COPYRIGHT "Copyright (c) 1997-2006 by Andre Noll" #define LICENSE "This is free software with ABSOLUTELY NO WARRANTY. " \ diff --git a/recv.c b/recv.c index cead11a3..35f6948c 100644 --- a/recv.c +++ b/recv.c @@ -15,6 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +/** \file recv.c the stand-alone receiver */ + #include "para.h" #include "list.h" @@ -29,18 +32,8 @@ struct recv_args_info conf; INIT_RECV_ERRLISTS; -__printf_2_3 void para_log(int ll, const char* fmt,...) -{ - va_list argp; - - /* ignore log message if loglevel is not high enough */ - if (ll < conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(conf.loglevel_arg); static void *parse_config(int argc, char *argv[], int *receiver_num) { int i; diff --git a/write.c b/write.c index ec27f3d3..89831a2e 100644 --- a/write.c +++ b/write.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -113,22 +113,7 @@ static void initial_delay_pre_select(struct sched *s, struct task *t) s->timeout = diff; } -/** - * all log messages are written to stderr - * - * \param ll: loglevel - * \param fmt: format string - */ -void para_log(int ll, const char* fmt,...) -{ - va_list argp; - - if (ll < conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(conf.loglevel_arg) static struct writer_node_group *check_args(void) {