* modules, especially intf modules. See config.h for output configuration.
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: messages.c,v 1.5 2002/07/23 00:30:22 sam Exp $
+ * $Id: messages.c,v 1.6 2002/07/31 20:56:53 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
/* Message queue initialization */
vlc_mutex_init( p_this, &p_this->p_vlc->msg_bank.lock );
+ p_this->p_vlc->msg_bank.b_configured = VLC_FALSE;
+ p_this->p_vlc->msg_bank.b_overflow = VLC_FALSE;
+
p_this->p_vlc->msg_bank.i_start = 0;
p_this->p_vlc->msg_bank.i_stop = 0;
vlc_mutex_lock( &p_this->p_vlc->msg_bank.lock );
+ p_this->p_vlc->msg_bank.b_configured = VLC_TRUE;
+
for( i_index = p_this->p_vlc->msg_bank.i_start;
i_index != p_this->p_vlc->msg_bank.i_stop;
i_index = (i_index+1) % VLC_MSG_QSIZE )
*****************************************************************************/
void __msg_Destroy( vlc_object_t *p_this )
{
- /* Destroy lock */
- vlc_mutex_destroy( &p_this->p_vlc->msg_bank.lock );
-
if( p_this->p_vlc->msg_bank.i_sub )
{
- fprintf( stderr, "main error: stale interface subscribers\n" );
+ msg_Err( p_this, "stale interface subscribers" );
}
- /* Free remaining messages */
- FlushMsg( &p_this->p_vlc->msg_bank );
+ /* Flush the queue */
+ if( !p_this->p_vlc->msg_bank.b_configured )
+ {
+ msg_Flush( p_this );
+ }
+ else
+ {
+ FlushMsg( &p_this->p_vlc->msg_bank );
+ }
+
+ /* Destroy lock */
+ vlc_mutex_destroy( &p_this->p_vlc->msg_bank.lock );
}
/*****************************************************************************
static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
const char *psz_format, va_list args )
{
+ msg_bank_t * p_bank = &p_this->p_vlc->msg_bank; /* message bank */
char * psz_str = NULL; /* formatted message string */
- msg_item_t * p_item; /* pointer to message */
+ msg_item_t * p_item = NULL; /* pointer to message */
msg_item_t item; /* message in case of a full queue */
#ifdef WIN32
char * psz_temp;
#endif
/* Put message in queue */
- vlc_mutex_lock( &p_this->p_vlc->msg_bank.lock );
+ vlc_mutex_lock( &p_bank->lock );
/* Check there is room in the queue for our message */
- if( ((p_this->p_vlc->msg_bank.i_stop - p_this->p_vlc->msg_bank.i_start + 1) % VLC_MSG_QSIZE) == 0 )
+ if( p_bank->b_overflow )
+ {
+ FlushMsg( &p_this->p_vlc->msg_bank );
+
+ if( ((p_bank->i_stop - p_bank->i_start + 1) % VLC_MSG_QSIZE) == 0 )
+ {
+ /* Still in overflow mode, print from a dummy item */
+ p_item = &item;
+ }
+ else
+ {
+ /* Pheeew, at last, there is room in the queue! */
+ p_bank->b_overflow = VLC_FALSE;
+ }
+ }
+ else if( ((p_bank->i_stop - p_bank->i_start + 2) % VLC_MSG_QSIZE) == 0 )
{
FlushMsg( &p_this->p_vlc->msg_bank );
- if( ((p_this->p_vlc->msg_bank.i_stop - p_this->p_vlc->msg_bank.i_start + 1) % VLC_MSG_QSIZE) == 0 )
+ if( ((p_bank->i_stop - p_bank->i_start + 2) % VLC_MSG_QSIZE) == 0 )
{
- fprintf( stderr, "main warning: message queue overflow\n" );
+ p_bank->b_overflow = VLC_TRUE;
+
+ /* Put the overflow message in the queue */
+ p_item = p_bank->msg + p_bank->i_stop;
+ p_bank->i_stop = (p_bank->i_stop + 1) % VLC_MSG_QSIZE;
+
+ p_item->i_type = VLC_MSG_ERR;
+ p_item->i_object_id = p_this->i_object_id;
+ p_item->psz_module = strdup( "message" );
+ p_item->psz_msg = strdup( "message queue overflowed" );
+
+ PrintMsg( p_this, p_item );
+
+ /* We print from a dummy item */
p_item = &item;
- goto print_message;
}
}
- /* Put the message in the queue */
- p_item = p_this->p_vlc->msg_bank.msg + p_this->p_vlc->msg_bank.i_stop;
- p_this->p_vlc->msg_bank.i_stop =
- (p_this->p_vlc->msg_bank.i_stop + 1) % VLC_MSG_QSIZE;
+ if( !p_bank->b_overflow )
+ {
+ /* Put the message in the queue */
+ p_item = p_bank->msg + p_bank->i_stop;
+ p_bank->i_stop = (p_bank->i_stop + 1) % VLC_MSG_QSIZE;
+ }
/* Fill message information fields */
-print_message:
p_item->i_type = i_type;
p_item->i_object_id = p_this->i_object_id;
p_item->psz_module = strdup( psz_module );
PrintMsg( p_this, p_item );
- vlc_mutex_unlock( &p_this->p_vlc->msg_bank.lock );
+ if( p_bank->b_overflow )
+ {
+ free( p_item->psz_module );
+ free( p_item->psz_msg );
+ }
+
+ vlc_mutex_unlock( &p_bank->lock );
}
/* following functions are local */
{
int i_index, i_start, i_stop;
+ /* Only flush the queue if it has been properly configured */
+ if( !p_bank->b_configured )
+ {
+ return;
+ }
+
/* Get the maximum message index that can be freed */
i_stop = p_bank->i_stop;
static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
int i_type = p_item->i_type;
+ if( p_this->p_vlc->b_quiet || !p_this->p_vlc->msg_bank.b_configured )
+ {
+ return;
+ }
+
+ if( !p_this->p_vlc->b_verbose &&
+ ( (i_type == VLC_MSG_WARN) || (i_type == VLC_MSG_DBG) ) )
+ {
+ return;
+ }
+
/* Send the message to stderr */
- if( (i_type == VLC_MSG_ERR)
- || ( (i_type == VLC_MSG_INFO) && !p_this->p_vlc->b_quiet )
- || ( (i_type == VLC_MSG_WARN) && p_this->p_vlc->b_verbose
- && !p_this->p_vlc->b_quiet )
- || ( (i_type == VLC_MSG_DBG) && p_this->p_vlc->b_verbose
- && !p_this->p_vlc->b_quiet ) )
+ if( p_this->p_vlc->b_color )
{
- if( p_this->p_vlc->b_color )
- {
- fprintf( stderr, "[" GREEN "%.2x" GRAY ":" GREEN "%.6x" GRAY "] "
- "%s%s: %s%s" GRAY "\n", p_this->p_vlc->i_unique,
- p_item->i_object_id, p_item->psz_module,
- ppsz_type[i_type], ppsz_color[i_type],
- p_item->psz_msg );
- }
- else
- {
- fprintf( stderr, "[%.2x:%.6x] %s%s: %s\n",
- p_this->p_vlc->i_unique, p_item->i_object_id,
- p_item->psz_module, ppsz_type[i_type],
- p_item->psz_msg );
- }
+ fprintf( stderr, "[" GREEN "%.2x" GRAY ":" GREEN "%.6x" GRAY "] "
+ "%s%s: %s%s" GRAY "\n", p_this->p_vlc->i_unique,
+ p_item->i_object_id, p_item->psz_module,
+ ppsz_type[i_type], ppsz_color[i_type],
+ p_item->psz_msg );
+ }
+ else
+ {
+ fprintf( stderr, "[%.2x:%.6x] %s%s: %s\n",
+ p_this->p_vlc->i_unique, p_item->i_object_id,
+ p_item->psz_module, ppsz_type[i_type],
+ p_item->psz_msg );
}
}