From 8bc4cefa2d97a1f616b7fcf35bcbe07550057f4b Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Sun, 20 Aug 2006 18:15:25 +0000 Subject: [PATCH] Allow frontend to change message output level. Rename tr_setErrorFunction() to tr_setMessageFunction() --- libtransmission/transmission.h | 26 ++++++++++++++++++-------- libtransmission/utils.c | 23 +++++++++++++++++------ libtransmission/utils.h | 3 --- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index e3ef91163..76444b7c6 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -61,14 +61,25 @@ typedef struct tr_handle_s tr_handle_t; tr_handle_t * tr_init(); /*********************************************************************** - * tr_setErrorFunction + * tr_setMessageFunction *********************************************************************** - * Sets the function used to display libtransmission errors. A NULL - * function means to use the default, which simple prints the message - * to stderr. The function's prototype should look like this: - * void myErrFunc( const char * errstr ); + * Sets the function used to display libtransmission messages. This + * function must be reentrant, it may be called from different threads. + * A NULL argument means to print messages to stderr. The function's + * prototype should look like this: void myErrFunc( const char * ); **********************************************************************/ -void tr_setErrorFunction( void (*func)( const char * ) ); +void tr_setMessageFunction( void (*func)( const char * ) ); + +/*********************************************************************** + * tr_setMessageLevel + *********************************************************************** + * Set the level of messages to be output + **********************************************************************/ +#define TR_MSG_ERR 1 +#define TR_MSG_INF 2 +#define TR_MSG_DBG 4 +void tr_setMessageLevel( int ); +int tr_getMessageLevel( void ); /*********************************************************************** * tr_getPrefsDirectory @@ -81,8 +92,7 @@ char * tr_getPrefsDirectory(); /*********************************************************************** * tr_setBindPort *********************************************************************** - * Sets a "start" port: everytime we start a torrent, we try to bind - * this port, then the next one and so on until we are successful. + * Sets the port to listen for incoming peer connections **********************************************************************/ void tr_setBindPort( tr_handle_t *, int ); diff --git a/libtransmission/utils.c b/libtransmission/utils.c index cc7ad8569..d77c68bb5 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -24,18 +24,29 @@ #include "transmission.h" -static void (*errorFunc)( const char * ); +static void (*messageFunc)( const char * ); -void tr_setErrorFunction( void (*func)( const char * ) ) +static int verboseLevel = 0; + +void tr_setMessageFunction( void (*func)( const char * ) ) { - errorFunc = func; + messageFunc = func; +} + +void tr_setMessageLevel( int level ) +{ + verboseLevel = level; +} + +int tr_getMessageLevel( void ) +{ + return verboseLevel; } void tr_msg( int level, char * msg, ... ) { char string[256]; va_list args; - static int verboseLevel = 0; if( !verboseLevel ) { @@ -58,13 +69,13 @@ void tr_msg( int level, char * msg, ... ) vsnprintf( string, sizeof( string ), msg, args ); va_end( args ); - if( NULL == errorFunc ) + if( NULL == messageFunc ) { fprintf( stderr, "%s\n", string ); } else { - errorFunc( string ); + messageFunc( string ); } } diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 0d162bf45..68897e173 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -25,9 +25,6 @@ #ifndef TR_UTILS_H #define TR_UTILS_H 1 -#define TR_MSG_ERR 1 -#define TR_MSG_INF 2 -#define TR_MSG_DBG 4 #define tr_err( a... ) tr_msg( TR_MSG_ERR, ## a ) #define tr_inf( a... ) tr_msg( TR_MSG_INF, ## a ) #define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a )