📄 intf_msg.c
字号:
* _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 * intf_DbgMsgImm(). *****************************************************************************/#ifdef DEBUGvoid _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line, char *psz_format, ...){ va_list ap; va_start( ap, psz_format ); QueueDbgMsg( p_main->p_msg, psz_file, psz_function, i_line, psz_format, ap ); va_end( ap ); intf_FlushMsg();}#endif/***************************************************************************** * 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. *****************************************************************************/#ifdef INTF_MSG_QUEUEvoid intf_FlushMsg( void ){ 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 ***************************************************************************** * 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 * program. If the queue is not used, it prints the message immediately. *****************************************************************************/static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list ap ){ 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 */#ifdef SYS_BEOS 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 ); exit( errno ); }#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 ...*/ /* * Fill message information fields */ p_msg_item->i_type = i_type; p_msg_item->psz_msg = psz_str;#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 DEBUGstatic 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 */ 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 */#ifdef SYS_BEOS 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 ) { 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 ); exit( errno ); }#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 ...*/ /* * Fill message information fields */ 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 ?) ***************************************************************************** * 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_QUEUEstatic void FlushLockedMsg ( intf_msg_t *p_msg ){ int i_index; for( i_index = 0; i_index < p_msg->i_count; i_index++ ) { /* Print message and free message data */ PrintMsg( &p_msg->msg[i_index] ); free( p_msg->msg[i_index].psz_msg ); } p_msg->i_count = 0;}#endif/***************************************************************************** * 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 DEBUGstatic void PrintMsg( intf_msg_item_t *p_msg ){ 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_ERR: asprintf( &psz_msg, "%s", 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; } /* Check if formatting function suceeded */ if( psz_msg == NULL ) { fprintf( stderr, "error: can not format message (%s): %s\n", strerror( errno ), p_msg->psz_msg ); return; } /* * Print messages */ switch( p_msg->i_type ) { case INTF_MSG_STD: /* standard messages */ fprintf( stdout, psz_msg ); break; case INTF_MSG_ERR: /* error messages */#ifndef DEBUG_LOG_ONLY case INTF_MSG_DBG: /* debugging messages */#endif fprintf( stderr, psz_msg ); break; 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 */ if( p_main->p_msg->i_log_file >= 0 ) { write( p_main->p_msg->i_log_file, psz_msg, strlen( psz_msg ) ); }#endif /* Free formatted message */ free( psz_msg );}#elsestatic void PrintMsg( intf_msg_item_t *p_msg ){ /* * 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 ); break; case INTF_MSG_ERR: /* error messages */ fprintf( stderr, p_msg->psz_msg ); break; case INTF_MSG_INTF: /* interface messages */ intf_ConsolePrint( p_main->p_intf->p_console, p_msg->psz_msg ); break; }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -