X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finterface%2Fintf_msg.c;h=dcb5b92ea29a917bfba461f6f8e36e8e6fc8a726;hb=ffa693e8bdac429c229fa679e64a8bd6cd6af15f;hp=766f727588148236c69a8ca05b8af5394e723fcc;hpb=b8d921651c0cda5470cabdfc5204e30c2dbba805;p=vlc diff --git a/src/interface/intf_msg.c b/src/interface/intf_msg.c index 766f727588..dcb5b92ea2 100644 --- a/src/interface/intf_msg.c +++ b/src/interface/intf_msg.c @@ -1,457 +1,570 @@ -/******************************************************************************* +/***************************************************************************** * intf_msg.c: messages interface - * (c)1998 VideoLAN - ******************************************************************************* * This library provides basic functions for threads to interact with user - * interface, such as message output. If INTF_MSG_QUEUE is defined (which is the - * defaul), messages are not printed directly by threads, to bypass console - * limitations and slow printf() calls, but sent to a queue and printed later by - * interface thread. - * If INTF_MSG_QUEUE is not defined, output is directly performed on stderr. - * Exported symbols are declared in intf_msg.h. - *******************************************************************************/ - -/******************************************************************************* + * interface, such as message output. See config.h for output configuration. + ***************************************************************************** + * Copyright (C) 1998, 1999, 2000 VideoLAN + * + * Authors: + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +/***************************************************************************** * Preamble - *******************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + *****************************************************************************/ +#include "defs.h" + +#include /* errno */ +#include /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */ +#include /* required */ +#include /* va_list for BSD */ +#include /* malloc() */ +#include /* strerror() */ +#include /* close(), write() */ #include "config.h" #include "common.h" +#include "threads.h" #include "mtime.h" -#include "debug.h" - -#include "input.h" -#include "input_vlan.h" - -#include "audio_output.h" +#include "plugins.h" +#include "intf_msg.h" +#include "interface.h" +#include "intf_console.h" + +#include "main.h" + +/***************************************************************************** + * intf_msg_item_t + ***************************************************************************** + * Store a single message. Messages have a maximal size of INTF_MSG_MSGSIZE. + * If DEBUG is defined, messages have a date field and debug messages are + * printed with a date to allow more precise profiling. + *****************************************************************************/ +typedef struct +{ + int i_type; /* message type, see below */ + char * psz_msg; /* the message itself */ -#include "video.h" -#include "video_output.h" +#ifdef DEBUG + /* Debugging informations - in DEBUG mode, debug messages have calling + * location informations printed */ + mtime_t date; /* date of the message */ + char * psz_file; /* file in which the function was called */ + char * psz_function; /* function from which the function was called */ + int i_line; /* line at which the function was called */ +#endif +} intf_msg_item_t; + +/* Message types */ +#define INTF_MSG_STD 0 /* standard message */ +#define INTF_MSG_ERR 1 /* error message */ +#define INTF_MSG_INTF 2 /* interface message */ +#define INTF_MSG_DBG 3 /* debug message */ +#define INTF_MSG_WARN 4 /* warning message*/ + + +/***************************************************************************** + * intf_msg_t + ***************************************************************************** + * Store all data requiered by messages interfaces. It has a single reference + * int p_main. + *****************************************************************************/ +typedef struct intf_msg_s +{ +#ifdef INTF_MSG_QUEUE + /* Message queue */ + vlc_mutex_t lock; /* message queue lock */ + int i_count; /* number of messages stored */ + intf_msg_item_t msg[INTF_MSG_QSIZE]; /* message queue */ +#endif -#include "xconsole.h" -#include "interface.h" -#include "intf_msg.h" +#ifdef DEBUG_LOG + /* Log file */ + FILE * p_log_file; /* log file */ +#endif -#include "pgm_data.h" +#if !defined(INTF_MSG_QUEUE) && !defined(DEBUG_LOG) + /* If neither messages queue, neither log file is used, then the structure + * is empty. However, empty structures are not allowed in C. Therefore, a + * dummy integer is used to fill it. */ + int i_dummy; /* unused filler */ +#endif +} intf_msg_t; -/* +/***************************************************************************** * Local prototypes - */ + *****************************************************************************/ -static void QueueMsg ( interface_msg_t *p_intf_msg, int i_type, +static void QueueMsg ( intf_msg_t *p_msg, int i_type, char *psz_format, va_list ap ); -static void PrintMsg ( interface_msg_message_t *p_msg ); +static void PrintMsg ( intf_msg_item_t *p_msg ); #ifdef DEBUG -static void QueueDbgMsg ( interface_msg_t *p_intf_msg, char *psz_file, - char *psz_function, int i_line, +static void QueueDbgMsg ( intf_msg_t *p_msg, char *psz_file, + char *psz_function, int i_line, char *psz_format, va_list ap ); #endif #ifdef INTF_MSG_QUEUE -static void FlushLockedMsg ( interface_msg_t *p_intf_msg ); +static void FlushLockedMsg ( intf_msg_t *p_msg ); #endif -/******************************************************************************* - * intf_InitMsg: initialize messages interface (ok ?) - ******************************************************************************* + +/***************************************************************************** + * intf_MsgCreate: initialize messages interface (ok ?) + ***************************************************************************** * This functions has to be called before any call to other intf_*Msg functions. - * It set up the locks and the message queue if it is used. On error, - * it returns errno (without printing its own error messages) and free all - * alocated resources. - *******************************************************************************/ -int intf_InitMsg( interface_msg_t *p_intf_msg ) + * It set up the locks and the message queue if it is used. + *****************************************************************************/ +p_intf_msg_t intf_MsgCreate( void ) { + p_intf_msg_t p_msg; + + /* Allocate structure */ + p_msg = malloc( sizeof( intf_msg_t ) ); + if( p_msg == NULL ) + { + errno = ENOMEM; + } + else + { #ifdef INTF_MSG_QUEUE /* Message queue initialization */ - pthread_mutex_init( &p_intf_msg->lock, NULL ); /* intialize lock */ - p_intf_msg->i_count = 0; /* queue is empty */ + vlc_mutex_init( &p_msg->lock ); /* intialize lock */ + p_msg->i_count = 0; /* queue is empty */ #endif + #ifdef DEBUG_LOG - /* Log file initialization */ - p_intf_msg->p_log_file = fopen( DEBUG_LOG, "w+" ); - if ( !p_intf_msg->p_log_file ) - { - return( errno ); - } + /* Log file initialization - on failure, file pointer will be null, + * and no log will be issued, but this is not considered as an + * error */ + p_msg->p_log_file = fopen( DEBUG_LOG, "w" ); #endif - - return( 0 ); + } + return( p_msg ); } -/******************************************************************************* - * intf_TerminateMsg: free resources allocated by intf_InitMsg (ok ?) - ******************************************************************************* - * This functions prints all messages remaining in queue, then free all the +/***************************************************************************** + * intf_MsgDestroy: free resources allocated by intf_InitMsg (ok ?) + ***************************************************************************** + * This functions prints all messages remaining in queue, then free all the * resources allocated by intf_InitMsg. * No other messages interface functions should be called after this one. - *******************************************************************************/ -void intf_TerminateMsg( interface_msg_t *p_intf_msg ) + *****************************************************************************/ +void intf_MsgDestroy( void ) { - intf_FlushMsg(); /* print all remaining messages */ + intf_FlushMsg(); /* print all remaining messages */ #ifdef DEBUG_LOG - /* Close log file */ - fclose( p_intf_msg->p_log_file ); + /* Close log file if any */ + if( p_main->p_msg->p_log_file != NULL ) + { + fclose( p_main->p_msg->p_log_file ); + } #endif + + /* Free structure */ + free( p_main->p_msg ); } -/******************************************************************************* - * intf_Msg: print a message (ok ?) - ******************************************************************************* +/***************************************************************************** + * intf_Msg: print a message (ok ?) + ***************************************************************************** * This function queue a message for later printing, or print it immediately * if the queue isn't used. - *******************************************************************************/ + *****************************************************************************/ void intf_Msg( char *psz_format, ... ) { va_list ap; va_start( ap, psz_format ); - QueueMsg( &p_program_data->intf_msg, INTF_MSG_STD, psz_format, ap ); + QueueMsg( p_main->p_msg, INTF_MSG_STD, psz_format, ap ); va_end( ap ); } - -/******************************************************************************* - * intf_ErrMsg : print an error message (ok ?) - ******************************************************************************* + +/***************************************************************************** + * intf_ErrMsg : print an error message (ok ?) + ***************************************************************************** * This function is the same as intf_Msg, except that it prints its messages * on stderr. - *******************************************************************************/ -void intf_ErrMsg(char *psz_format, ...) + *****************************************************************************/ +void intf_ErrMsg( char *psz_format, ... ) { va_list ap; va_start( ap, psz_format ); - QueueMsg( &p_program_data->intf_msg, INTF_MSG_ERR, psz_format, ap ); + QueueMsg( p_main->p_msg, INTF_MSG_ERR, psz_format, ap ); va_end( ap ); } -/******************************************************************************* - * intf_IntfMsg : print an interface message (ok ?) - ******************************************************************************* +/***************************************************************************** + * intf_WarnMsg : print a warning message + ***************************************************************************** + * This function is the same as intf_Msg, except that it concerns warning + * messages for testing purpose. + *****************************************************************************/ +void intf_WarnMsg( int i_level, char *psz_format, ... ) +{ + va_list ap; + + if( i_level >= p_main->p_intf->i_warning_level ) + { + va_start( ap, psz_format ); + QueueMsg( p_main->p_msg, INTF_MSG_WARN, psz_format, ap ); + va_end( ap ); + } +} + + +/***************************************************************************** + * intf_IntfMsg : print an interface message (ok ?) + ***************************************************************************** * In opposition to all other intf_*Msg function, this function does not print - * it's message on default terminal (stdout or stderr), but send it to + * it's message on default terminal (stdout or stderr), but send it to * interface (in fact to the X11 console). This means that the interface MUST * be initialized and a X11 console openned before this function is used, and * that once the console is closed, this call is vorbidden. - * Practically, only the interface thread itself should call this function, and + * Practically, only the interface thread itself should call this function, and * flush all messages before intf_CloseX11Console() is called. - *******************************************************************************/ + *****************************************************************************/ void intf_IntfMsg(char *psz_format, ...) { va_list ap; va_start( ap, psz_format ); - QueueMsg( &p_program_data->intf_msg, INTF_MSG_INTF, psz_format, ap ); + QueueMsg( p_main->p_msg, INTF_MSG_INTF, psz_format, ap ); va_end( ap ); } -/******************************************************************************* - * _intf_DbgMsg: print a debugging message (ok ?) - ******************************************************************************* - * This function prints a debugging message. Compared to other intf_*Msg +/***************************************************************************** + * _intf_DbgMsg: print a debugging message (ok ?) + ***************************************************************************** + * This function prints a debugging message. Compared to other intf_*Msg * functions, it is only defined if DEBUG is defined and require a file name, * a function name and a line number as additionnal debugging informations. It * also prints a debugging header for each received line. - *******************************************************************************/ + *****************************************************************************/ #ifdef DEBUG -void _intf_DbgMsg( char *psz_file, char *psz_function, int i_line, +void _intf_DbgMsg( char *psz_file, char *psz_function, int i_line, char *psz_format, ...) { va_list ap; va_start( ap, psz_format ); - QueueDbgMsg( &p_program_data->intf_msg, psz_file, psz_function, i_line, + QueueDbgMsg( p_main->p_msg, psz_file, psz_function, i_line, psz_format, ap ); va_end( ap ); } #endif -/******************************************************************************* - * intf_ErrMsgImm: print a message (ok ?) - ******************************************************************************* - * This function prints a message immediately. If the queue is used, all +/***************************************************************************** + * intf_MsgImm: print a message (ok ?) + ***************************************************************************** + * This function prints a message immediately. If the queue is used, all * waiting messages are also printed. - *******************************************************************************/ + *****************************************************************************/ void intf_MsgImm( char *psz_format, ... ) { va_list ap; va_start( ap, psz_format ); - QueueMsg( &p_program_data->intf_msg, INTF_MSG_STD, psz_format, ap ); + QueueMsg( p_main->p_msg, INTF_MSG_STD, psz_format, ap ); va_end( ap ); intf_FlushMsg(); } - -/******************************************************************************* - * intf_ErrMsgImm: print an error message immediately (ok ?) - ******************************************************************************* + +/***************************************************************************** + * intf_ErrMsgImm: print an error message immediately (ok ?) + ***************************************************************************** * This function is the same as intf_MsgImm, except that it prints its message * on stderr. - *******************************************************************************/ + *****************************************************************************/ void intf_ErrMsgImm(char *psz_format, ...) { va_list ap; va_start( ap, psz_format ); - QueueMsg( &p_program_data->intf_msg, INTF_MSG_ERR, psz_format, ap ); + QueueMsg( p_main->p_msg, INTF_MSG_ERR, psz_format, ap ); va_end( ap ); intf_FlushMsg(); } -/******************************************************************************* - * _intf_DbgMsgImm: print a debugging message immediately (ok ?) - ******************************************************************************* +/***************************************************************************** + * intf_WarnMsgImm : print a warning message + ***************************************************************************** + * This function is the same as intf_MsgImm, except that it concerns warning + * messages for testing purpose. + *****************************************************************************/ +void intf_WarnMsgImm( int i_level, char *psz_format, ... ) +{ + va_list ap; + + if( i_level >= p_main->p_intf->i_warning_level ) + { + va_start( ap, psz_format ); + QueueMsg( p_main->p_msg, INTF_MSG_WARN, psz_format, ap ); + va_end( ap ); + } + intf_FlushMsg(); +} + + + +/***************************************************************************** + * _intf_DbgMsgImm: print a debugging message immediately (ok ?) + ***************************************************************************** * This function is the same as intf_DbgMsgImm, except that it prints its - * message immediately. It should only be called through the macro + * message immediately. It should only be called through the macro * intf_DbgMsgImm(). - *******************************************************************************/ + *****************************************************************************/ #ifdef DEBUG -void _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line, +void _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line, char *psz_format, ...) { va_list ap; va_start( ap, psz_format ); - QueueDbgMsg( &p_program_data->intf_msg, psz_file, psz_function, i_line, + QueueDbgMsg( p_main->p_msg, psz_file, psz_function, i_line, psz_format, ap ); va_end( ap ); intf_FlushMsg(); } #endif -/******************************************************************************* - * intf_FlushMsg (ok ?) - ******************************************************************************* +/***************************************************************************** + * intf_FlushMsg (ok ?) + ***************************************************************************** * Print all messages remaining in queue: get lock and call FlushLockedMsg. * This function does nothing if the message queue isn't used. - * This function is only implemented if message queue is used. If not, it is an - * empty macro. - *******************************************************************************/ + * This function is only implemented if message queue is used. If not, it is + * an empty macro. + *****************************************************************************/ #ifdef INTF_MSG_QUEUE void intf_FlushMsg( void ) { - pthread_mutex_lock( &p_program_data->intf_msg.lock ); /* get lock */ - FlushLockedMsg( &p_program_data->intf_msg ); /* flush messages */ - pthread_mutex_unlock( &p_program_data->intf_msg.lock ); /* give lock back */ + vlc_mutex_lock( &p_main->p_msg->lock ); /* get lock */ + FlushLockedMsg( p_main->p_msg ); /* flush messages */ + vlc_mutex_unlock( &p_main->p_msg->lock ); /* give lock back */ } #endif /* following functions are local */ -/******************************************************************************* - * QueueMsg: add a message to a queue (ok ?) - ******************************************************************************* +/***************************************************************************** + * QueueMsg: add a message to a queue + ***************************************************************************** * This function provide basic functionnalities to other intf_*Msg functions. * It add a message to a queue (after having printed all stored messages if it - * is full. If the message can't be converted to string in memory, it exit the + * is full. If the message can't be converted to string in memory, it exit the * program. If the queue is not used, it prints the message immediately. - *******************************************************************************/ -static void QueueMsg(interface_msg_t *p_intf_msg, int i_type, char *psz_format, va_list ap) + *****************************************************************************/ +static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list ap ) { - char * psz_str; /* formatted message string */ -#ifndef INTF_MSG_QUEUE - interface_msg_message_t msg; /* message */ -#endif + char * psz_str; /* formatted message string */ + intf_msg_item_t * p_msg_item; /* pointer to message */ + +#ifndef INTF_MSG_QUEUE /*................................... instant mode ...*/ + intf_msg_item_t msg_item; /* message */ + p_msg_item = &msg_item; +#endif /*....................................................................*/ - /* Convert message to string */ + /* + * Convert message to string + */ +#ifdef HAVE_VASPRINTF vasprintf( &psz_str, psz_format, ap ); +#else + psz_str = (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE ); + vsprintf( psz_str, psz_format, ap ); +#endif if( psz_str == NULL ) { - fprintf(stderr, "intf error: *** can not store message (%s) ***\n", + fprintf(stderr, "warning: can't store following message (%s): ", strerror(errno) ); vfprintf(stderr, psz_format, ap ); + fprintf(stderr, "\n" ); exit( errno ); } -#ifdef INTF_MSG_QUEUE - - /* - * Queue mode: the queue is flushed if it is full, then the message is - * queued. A lock is required on queue to avoid indexes corruption - */ - pthread_mutex_lock( &p_intf_msg->lock ); /* get lock */ - - if( p_intf_msg->i_count == INTF_MSG_QSIZE ) /* flush queue if needed */ - { -#ifdef DEBUG /* in debug mode, queue overflow causes a waring */ - fprintf(stderr, "intf warning: *** message queue overflow ***\n" ); +#ifdef INTF_MSG_QUEUE /*...................................... queue mode ...*/ + vlc_mutex_lock( &p_msg->lock ); /* get lock */ + if( p_msg->i_count == INTF_MSG_QSIZE ) /* flush queue if needed */ + { +#ifdef DEBUG /* in debug mode, queue overflow causes a warning */ + fprintf(stderr, "warning: message queue overflow\n" ); #endif - FlushLockedMsg( p_intf_msg ); + FlushLockedMsg( p_msg ); } - - /* Queue message - if DEBUG if defined, the message is dated */ - p_intf_msg->msg[ p_intf_msg->i_count ].i_type = i_type; - p_intf_msg->msg[ p_intf_msg->i_count++ ].psz_msg = psz_str; -#ifdef DEBUG - p_intf_msg->msg[ p_intf_msg->i_count ].date = mdate(); -#endif - - pthread_mutex_unlock( &p_intf_msg->lock ); /* give lock back */ - -#else + p_msg_item = p_msg->msg + p_msg->i_count++; /* select message */ +#endif /*.............................................. end of queue mode ...*/ - /* - * Instant mode: the message is converted and printed immediately + /* + * Fill message information fields */ - msg.i_type = i_type; - msg.psz_msg = psz_str; - msg.date = mdate(); - PrintMsg( &msg ); /* print message */ - free( psz_str ); /* free message data */ - + p_msg_item->i_type = i_type; + p_msg_item->psz_msg = psz_str; +#ifdef DEBUG + p_msg_item->date = mdate(); #endif + +#ifdef INTF_MSG_QUEUE /*......................................... queue mode */ + vlc_mutex_unlock( &p_msg->lock ); /* give lock back */ +#else /*....................................................... instant mode */ + PrintMsg( p_msg_item ); /* print message */ + free( psz_str ); /* free message data */ +#endif /*....................................................................*/ } -/******************************************************************************* +/***************************************************************************** * QueueDbgMsg: add a message to a queue with debugging informations - ******************************************************************************* + ***************************************************************************** * This function is the same as QueueMsg, except that it is only defined when * DEBUG is define, and require additionnal debugging informations. - *******************************************************************************/ + *****************************************************************************/ #ifdef DEBUG -static void QueueDbgMsg(interface_msg_t *p_intf_msg, char *psz_file, char *psz_function, - int i_line, char *psz_format, va_list ap) +static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, + int i_line, char *psz_format, va_list ap) { - char * psz_str; /* formatted message string */ -#ifndef INTF_MSG_QUEUE - interface_msg_message_t msg; /* message */ -#endif + char * psz_str; /* formatted message string */ + intf_msg_item_t * p_msg_item; /* pointer to message */ + +#ifndef INTF_MSG_QUEUE /*................................... instant mode ...*/ + intf_msg_item_t msg_item; /* message */ + p_msg_item = &msg_item; +#endif /*....................................................................*/ - /* Convert message to string */ - vasprintf( &psz_str, psz_format, ap ); + /* + * Convert message to string + */ +#ifdef HAVE_VASPRINTF + vasprintf( &psz_str, psz_format, ap ); +#else + psz_str = (char*) malloc( INTF_MAX_MSG_SIZE ); + vsprintf( psz_str, psz_format, ap ); +#endif if( psz_str == NULL ) - { /* critical error: not enough memory to store message */ - fprintf(stderr, "intf error: *** can not store message (%s) ***\n", strerror(errno) ); + { + fprintf(stderr, "warning: can't store following message (%s): ", + strerror(errno) ); fprintf(stderr, INTF_MSG_DBG_FORMAT, psz_file, psz_function, i_line ); vfprintf(stderr, psz_format, ap ); + fprintf(stderr, "\n" ); exit( errno ); } -#ifdef INTF_MSG_QUEUE - - /* - * Queue mode: the queue is flushed if it is full, then the message is - * queued. A lock is required on queue to avoid indexes corruption - */ - pthread_mutex_lock( &p_intf_msg->lock ); /* get lock */ - - if( p_intf_msg->i_count == INTF_MSG_QSIZE ) /* flush queue if needed */ - { - fprintf(stderr, "intf warning: *** message queue overflow ***\n" ); - FlushLockedMsg( p_intf_msg ); +#ifdef INTF_MSG_QUEUE /*...................................... queue mode ...*/ + vlc_mutex_lock( &p_msg->lock ); /* get lock */ + if( p_msg->i_count == INTF_MSG_QSIZE ) /* flush queue if needed */ + { + fprintf(stderr, "warning: message queue overflow\n" ); + FlushLockedMsg( p_msg ); } - - /* Queue message */ - p_intf_msg->msg[ p_intf_msg->i_count ].i_type = INTF_MSG_DBG; - p_intf_msg->msg[ p_intf_msg->i_count ].date = mdate(); - p_intf_msg->msg[ p_intf_msg->i_count ].psz_file = psz_file; - p_intf_msg->msg[ p_intf_msg->i_count ].psz_function = psz_function; - p_intf_msg->msg[ p_intf_msg->i_count ].i_line = i_line; - p_intf_msg->msg[ p_intf_msg->i_count++ ].psz_msg = psz_str; + p_msg_item = p_msg->msg + p_msg->i_count++; /* select message */ +#endif /*.............................................. end of queue mode ...*/ - pthread_mutex_unlock( &p_intf_msg->lock ); /* give lock back */ - -#else - - /* - * Instant mode: the message is converted and printed immediately + /* + * Fill message information fields */ - msg.i_type = INTF_MSG_DBG; - msg.psz_file = psz_file; - msg.psz_function = psz_function; - msg.i_line = i_line; -#ifdef DEBUG -// msg.date = mdate(); -#endif - msg.psz_msg = psz_str; - PrintMsg( &msg ); /* print message */ - free( psz_str ); /* free message data */ - -#endif + p_msg_item->i_type = INTF_MSG_DBG; + p_msg_item->psz_msg = psz_str; + p_msg_item->psz_file = psz_file; + p_msg_item->psz_function = psz_function; + p_msg_item->i_line = i_line; + p_msg_item->date = mdate(); + +#ifdef INTF_MSG_QUEUE /*......................................... queue mode */ + vlc_mutex_unlock( &p_msg->lock ); /* give lock back */ +#else /*....................................................... instant mode */ + PrintMsg( p_msg_item ); /* print message */ + free( psz_str ); /* free message data */ +#endif /*....................................................................*/ } #endif -/******************************************************************************* - * FlushLockedMsg (ok ?) - ******************************************************************************* +/***************************************************************************** + * FlushLockedMsg (ok ?) + ***************************************************************************** * Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since * this function does not check the lock. This function is only defined if * INTF_MSG_QUEUE is defined. - *******************************************************************************/ + *****************************************************************************/ #ifdef INTF_MSG_QUEUE -static void FlushLockedMsg ( interface_msg_t *p_intf_msg ) +static void FlushLockedMsg ( intf_msg_t *p_msg ) { int i_index; - for( i_index = 0; i_index < p_intf_msg->i_count; i_index++ ) + for( i_index = 0; i_index < p_msg->i_count; i_index++ ) { /* Print message and free message data */ - PrintMsg( &p_intf_msg->msg[i_index] ); - free( p_intf_msg->msg[i_index].psz_msg ); + PrintMsg( &p_msg->msg[i_index] ); + free( p_msg->msg[i_index].psz_msg ); } - - p_intf_msg->i_count = 0; + + p_msg->i_count = 0; } #endif -/******************************************************************************* - * PrintMsg: print a message (ok ?) - ******************************************************************************* +/***************************************************************************** + * PrintMsg: print a message (ok ?) + ***************************************************************************** * Print a single message. The message data is not freed. This function exists * in two version. The DEBUG version prints a date with each message, and is * able to log messages (if DEBUG_LOG is defined). * The normal one just prints messages to the screen. - *******************************************************************************/ + *****************************************************************************/ #ifdef DEBUG -static void PrintMsg( interface_msg_message_t *p_msg ) +static void PrintMsg( intf_msg_item_t *p_msg ) { - char psz_date[MSTRTIME_MAX_SIZE]; /* formatted time buffer */ - char * psz_msg; /* message buffer */ - - - /* Computes date */ - mstrtime( psz_date, p_msg->date ); + char psz_date[MSTRTIME_MAX_SIZE]; /* formatted time buffer */ + char * psz_msg; /* message buffer */ /* Format message - the message is formatted here because in case the log * file is used, it avoids another format string parsing */ switch( p_msg->i_type ) { - case INTF_MSG_STD: /* regular messages */ + case INTF_MSG_STD: /* regular messages */ case INTF_MSG_ERR: - asprintf( &psz_msg, "(%s) %s", psz_date, p_msg->psz_msg ); + asprintf( &psz_msg, "%s", p_msg->psz_msg ); break; - case INTF_MSG_INTF: /* interface messages */ - case INTF_MSG_DBG: - asprintf( &psz_msg, p_msg->psz_msg ); + case INTF_MSG_WARN: /* Warning message */ + mstrtime( psz_date, p_msg->date ); + asprintf( &psz_msg, "(%s) %s", + psz_date, p_msg->psz_msg ); + + break; + + case INTF_MSG_INTF: /* interface messages */ + asprintf( &psz_msg, "%s", p_msg->psz_msg ); + break; + + case INTF_MSG_DBG: /* debug messages */ + mstrtime( psz_date, p_msg->date ); + asprintf( &psz_msg, "(%s) " INTF_MSG_DBG_FORMAT "%s", + psz_date, p_msg->psz_file, p_msg->psz_function, p_msg->i_line, + p_msg->psz_msg ); break; -#if 0 - case INTF_MSG_DBG: /* debug messages */ - asprintf( &psz_msg, "(%s) " INTF_MSG_DBG_FORMAT "%s", - psz_date, p_msg->psz_file, p_msg->psz_function, p_msg->i_line, - p_msg->psz_msg ); - break; -#endif } - - /* Check if formatting function suceeded */ + + /* Check if formatting function succeeded */ if( psz_msg == NULL ) { - fprintf( stderr, "intf error: *** can not format message (%s): %s ***\n", - strerror( errno ), p_msg->psz_msg ); - return; + fprintf( stderr, "error: can not format message (%s): %s\n", + strerror( errno ), p_msg->psz_msg ); + return; } /* @@ -459,50 +572,56 @@ static void PrintMsg( interface_msg_message_t *p_msg ) */ switch( p_msg->i_type ) { - case INTF_MSG_STD: /* standard messages */ - fprintf( stdout, psz_msg ); + case INTF_MSG_STD: /* standard messages */ + fprintf( stdout, "%s\n", psz_msg ); break; - case INTF_MSG_ERR: /* error messages */ + case INTF_MSG_ERR: /* error messages */ + case INTF_MSG_WARN: #ifndef DEBUG_LOG_ONLY - case INTF_MSG_DBG: /* debugging messages */ + case INTF_MSG_DBG: /* debugging messages */ #endif - fprintf( stderr, psz_msg ); + fprintf( stderr, "%s\n", psz_msg ); break; - case INTF_MSG_INTF: /* interface messages */ - intf_PrintXConsole( &p_program_data->intf_thread.xconsole, psz_msg ); + case INTF_MSG_INTF: /* interface messages */ + intf_ConsolePrint( p_main->p_intf->p_console, psz_msg ); break; } - + #ifdef DEBUG_LOG /* Append all messages to log file */ - fprintf( p_program_data->intf_msg.p_log_file, psz_msg ); + if( p_main->p_msg->p_log_file != NULL ) + { + fwrite( psz_msg, strlen( psz_msg ), 1, p_main->p_msg->p_log_file ); + fwrite( "\n", 1, 1, p_main->p_msg->p_log_file ); + } #endif /* Free formatted message */ - free( psz_msg ); + free( psz_msg ); } #else -static void PrintMsg( interface_msg_message_t *p_msg ) +static void PrintMsg( intf_msg_item_t *p_msg ) { /* - * Print messages on screen + * Print messages on screen */ switch( p_msg->i_type ) { - case INTF_MSG_STD: /* standard messages */ - case INTF_MSG_DBG: /* debug messages */ - fprintf( stdout, p_msg->psz_msg ); + case INTF_MSG_STD: /* standard messages */ + case INTF_MSG_DBG: /* debug messages */ + fprintf( stdout, "%s\n", p_msg->psz_msg ); break; - case INTF_MSG_ERR: /* error messages */ - fprintf( stderr, p_msg->psz_msg ); + case INTF_MSG_ERR: /* error messages */ + case INTF_MSG_WARN: + fprintf( stderr, "%s\n", p_msg->psz_msg ); /* warning message */ break; - case INTF_MSG_INTF: /* interface messages */ - intf_PrintXConsole( &p_program_data->intf_thread.xconsole, - p_msg->psz_msg ); + case INTF_MSG_INTF: /* interface messages */ + intf_ConsolePrint( p_main->p_intf->p_console, p_msg->psz_msg ); break; - } + } } #endif +