X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finterface%2Fintf_msg.c;h=dcb5b92ea29a917bfba461f6f8e36e8e6fc8a726;hb=ffa693e8bdac429c229fa679e64a8bd6cd6af15f;hp=80ba35313bee829ce6d91851fa2e7518b401e97c;hpb=551607d315126846db5538560f52fb2e084a5d6f;p=vlc diff --git a/src/interface/intf_msg.c b/src/interface/intf_msg.c index 80ba35313b..dcb5b92ea2 100644 --- a/src/interface/intf_msg.c +++ b/src/interface/intf_msg.c @@ -11,16 +11,15 @@ * 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. + * 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-1307, USA. + * 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. *****************************************************************************/ /***************************************************************************** @@ -74,6 +73,8 @@ typedef struct #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 @@ -92,7 +93,7 @@ typedef struct intf_msg_s #ifdef DEBUG_LOG /* Log file */ - int i_log_file; /* log file */ + FILE * p_log_file; /* log file */ #endif #if !defined(INTF_MSG_QUEUE) && !defined(DEBUG_LOG) @@ -144,18 +145,12 @@ p_intf_msg_t intf_MsgCreate( void ) p_msg->i_count = 0; /* queue is empty */ #endif + #ifdef DEBUG_LOG /* 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->i_log_file = open( DEBUG_LOG, O_CREAT | O_TRUNC | -#ifndef SYS_BSD - O_SYNC | -#else - O_ASYNC | -#endif /* SYS_BSD */ - O_WRONLY, 0666 ); - + p_msg->p_log_file = fopen( DEBUG_LOG, "w" ); #endif } return( p_msg ); @@ -174,9 +169,9 @@ void intf_MsgDestroy( void ) #ifdef DEBUG_LOG /* Close log file if any */ - if( p_main->p_msg->i_log_file >= 0 ) + if( p_main->p_msg->p_log_file != NULL ) { - close( p_main->p_msg->i_log_file ); + fclose( p_main->p_msg->p_log_file ); } #endif @@ -185,7 +180,7 @@ void intf_MsgDestroy( void ) } /***************************************************************************** - * 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. @@ -200,12 +195,12 @@ void intf_Msg( char *psz_format, ... ) } /***************************************************************************** - * 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; @@ -215,7 +210,26 @@ void intf_ErrMsg( char *psz_format, ...) } /***************************************************************************** - * 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 @@ -235,7 +249,7 @@ void intf_IntfMsg(char *psz_format, ...) } /***************************************************************************** - * _intf_DbgMsg: print a debugging message (ok ?) + * _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, @@ -256,7 +270,7 @@ void _intf_DbgMsg( char *psz_file, char *psz_function, int i_line, #endif /***************************************************************************** - * intf_ErrMsgImm: print a message (ok ?) + * intf_MsgImm: print a message (ok ?) ***************************************************************************** * This function prints a message immediately. If the queue is used, all * waiting messages are also printed. @@ -272,7 +286,7 @@ void intf_MsgImm( char *psz_format, ... ) } /***************************************************************************** - * 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. @@ -288,7 +302,28 @@ void intf_ErrMsgImm(char *psz_format, ...) } /***************************************************************************** - * _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 @@ -309,12 +344,12 @@ void _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line, #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 ) @@ -340,30 +375,31 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a char * psz_str; /* formatted message string */ intf_msg_item_t * p_msg_item; /* pointer to message */ -#ifndef INTF_MSG_QUEUE /*..................................... instant mode ...*/ +#ifndef INTF_MSG_QUEUE /*................................... instant mode ...*/ intf_msg_item_t msg_item; /* message */ p_msg_item = &msg_item; -#endif /*......................................................................*/ +#endif /*....................................................................*/ /* * Convert message to string */ -#ifdef SYS_BEOS +#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 ); -#else - vasprintf( &psz_str, psz_format, ap ); #endif if( psz_str == NULL ) { 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 ...*/ - vlc_mutex_lock( &p_msg->lock ); /* get lock */ +#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 */ @@ -372,20 +408,23 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a FlushLockedMsg( p_msg ); } p_msg_item = p_msg->msg + p_msg->i_count++; /* select message */ -#endif /*................................................ end of queue mode ...*/ +#endif /*.............................................. end of queue mode ...*/ /* * Fill message information fields */ 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 */ +#ifdef INTF_MSG_QUEUE /*......................................... queue mode */ vlc_mutex_unlock( &p_msg->lock ); /* give lock back */ -#else /*......................................................... instant mode */ +#else /*....................................................... instant mode */ PrintMsg( p_msg_item ); /* print message */ free( psz_str ); /* free message data */ -#endif /*......................................................................*/ +#endif /*....................................................................*/ } /***************************************************************************** @@ -401,19 +440,19 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, char * psz_str; /* formatted message string */ intf_msg_item_t * p_msg_item; /* pointer to message */ -#ifndef INTF_MSG_QUEUE /*..................................... instant mode ...*/ +#ifndef INTF_MSG_QUEUE /*................................... instant mode ...*/ intf_msg_item_t msg_item; /* message */ p_msg_item = &msg_item; -#endif /*......................................................................*/ +#endif /*....................................................................*/ /* * Convert message to string */ -#ifdef SYS_BEOS +#ifdef HAVE_VASPRINTF + vasprintf( &psz_str, psz_format, ap ); +#else psz_str = (char*) malloc( INTF_MAX_MSG_SIZE ); vsprintf( psz_str, psz_format, ap ); -#else - vasprintf( &psz_str, psz_format, ap ); #endif if( psz_str == NULL ) { @@ -421,20 +460,19 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, 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 ...*/ - vlc_mutex_lock( &p_msg->lock ); /* get lock */ +#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_msg ); } p_msg_item = p_msg->msg + p_msg->i_count++; /* select message */ -#endif /*................................................ end of queue mode ...*/ +#endif /*.............................................. end of queue mode ...*/ /* * Fill message information fields @@ -446,17 +484,17 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, p_msg_item->i_line = i_line; p_msg_item->date = mdate(); -#ifdef INTF_MSG_QUEUE /*........................................... queue mode */ +#ifdef INTF_MSG_QUEUE /*......................................... queue mode */ vlc_mutex_unlock( &p_msg->lock ); /* give lock back */ -#else /*......................................................... instant mode */ +#else /*....................................................... instant mode */ PrintMsg( p_msg_item ); /* print message */ free( psz_str ); /* free message data */ -#endif /*......................................................................*/ +#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 @@ -479,7 +517,7 @@ static void FlushLockedMsg ( intf_msg_t *p_msg ) #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 @@ -502,6 +540,13 @@ static void PrintMsg( intf_msg_item_t *p_msg ) asprintf( &psz_msg, "%s", p_msg->psz_msg ); break; + 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; @@ -514,7 +559,7 @@ static void PrintMsg( intf_msg_item_t *p_msg ) break; } - /* Check if formatting function suceeded */ + /* Check if formatting function succeeded */ if( psz_msg == NULL ) { fprintf( stderr, "error: can not format message (%s): %s\n", @@ -528,13 +573,14 @@ static void PrintMsg( intf_msg_item_t *p_msg ) switch( p_msg->i_type ) { case INTF_MSG_STD: /* standard messages */ - fprintf( stdout, psz_msg ); + fprintf( stdout, "%s\n", psz_msg ); break; case INTF_MSG_ERR: /* error messages */ + case INTF_MSG_WARN: #ifndef DEBUG_LOG_ONLY 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_ConsolePrint( p_main->p_intf->p_console, psz_msg ); @@ -543,9 +589,10 @@ static void PrintMsg( intf_msg_item_t *p_msg ) #ifdef DEBUG_LOG /* Append all messages to log file */ - if( p_main->p_msg->i_log_file >= 0 ) + if( p_main->p_msg->p_log_file != NULL ) { - write( p_main->p_msg->i_log_file, psz_msg, strlen( psz_msg ) ); + 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 @@ -564,10 +611,11 @@ static void PrintMsg( intf_msg_item_t *p_msg ) { case INTF_MSG_STD: /* standard messages */ case INTF_MSG_DBG: /* debug messages */ - fprintf( stdout, p_msg->psz_msg ); + fprintf( stdout, "%s\n", p_msg->psz_msg ); break; case INTF_MSG_ERR: /* error messages */ - fprintf( stderr, p_msg->psz_msg ); + case INTF_MSG_WARN: + fprintf( stderr, "%s\n", p_msg->psz_msg ); /* warning message */ break; case INTF_MSG_INTF: /* interface messages */ intf_ConsolePrint( p_main->p_intf->p_console, p_msg->psz_msg ); @@ -576,3 +624,4 @@ static void PrintMsg( intf_msg_item_t *p_msg ) } #endif +