Allow frontend to change message output level.

Rename tr_setErrorFunction() to tr_setMessageFunction()
This commit is contained in:
Josh Elsasser
2006-08-20 18:15:25 +00:00
parent 4690f987f9
commit 8bc4cefa2d
3 changed files with 35 additions and 17 deletions
+18 -8
View File
@@ -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 );
+17 -6
View File
@@ -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 );
}
}
-3
View File
@@ -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 )