mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
Allow frontend to change message output level.
Rename tr_setErrorFunction() to tr_setMessageFunction()
This commit is contained in:
@@ -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
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user