messages.c 18.1 KB
Newer Older
1
/*****************************************************************************
2 3 4
 * messages.c: messages interface
 * This library provides an interface to the message queue to be used by other
 * modules, especially intf modules. See config.h for output configuration.
5
 *****************************************************************************
Jean-Paul Saman's avatar
Jean-Paul Saman committed
6
 * Copyright (C) 1998-2005 the VideoLAN team
zorglub's avatar
zorglub committed
7
 * $Id$
8
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
9
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
10
 *          Samuel Hocevar <sam@zoy.org>
11 12 13 14 15
 *
 * 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.
16
 *
17 18
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
21
 *
22 23 24
 * 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.
25
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
26

27
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
28
 * Preamble
29
 *****************************************************************************/
30 31 32 33
#include <stdio.h>                                               /* required */
#include <stdarg.h>                                       /* va_list for BSD */
#include <stdlib.h>                                              /* malloc() */
#include <string.h>                                            /* strerror() */
Sam Hocevar's avatar
 
Sam Hocevar committed
34

35
#include <vlc/vlc.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
36

37 38 39 40
#ifdef HAVE_FCNTL_H
#   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
#endif

41
#include <errno.h>                                                  /* errno */
42

Sam Hocevar's avatar
 
Sam Hocevar committed
43
#ifdef HAVE_UNISTD_H
44
#   include <unistd.h>                                   /* close(), write() */
Sam Hocevar's avatar
 
Sam Hocevar committed
45
#endif
Michel Kaempf's avatar
Michel Kaempf committed
46

47
#include "vlc_interface.h"
48

49 50 51 52 53 54 55 56 57 58 59
/*****************************************************************************
 * Local macros
 *****************************************************************************/
#if defined(HAVE_VA_COPY)
#   define vlc_va_copy(dest,src) va_copy(dest,src)
#elif defined(HAVE___VA_COPY)
#   define vlc_va_copy(dest,src) __va_copy(dest,src)
#else
#   define vlc_va_copy(dest,src) (dest)=(src)
#endif

Vincent Seguin's avatar
Vincent Seguin committed
60
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
61
 * Local prototypes
Vincent Seguin's avatar
Vincent Seguin committed
62
 *****************************************************************************/
63
static void QueueMsg ( vlc_object_t *, int, int , const char *,
64
                       const char *, va_list );
65
static void FlushMsg ( msg_queue_t * );
66
static void PrintMsg ( vlc_object_t *, msg_item_t * );
67
static void CreateMsgQueue( vlc_object_t *p_this, int i_queue );
Michel Kaempf's avatar
Michel Kaempf committed
68

sigmunau's avatar
all:  
sigmunau committed
69
/**
70 71
 * Initialize messages queues
 * This function initializes all message queues
sigmunau's avatar
all:  
sigmunau committed
72
 */
73
void __msg_Create( vlc_object_t *p_this )
Michel Kaempf's avatar
Michel Kaempf committed
74
{
75 76
    CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
    CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
77 78

#ifdef UNDER_CE
79
    p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile =
80 81
        CreateFile( L"vlc-log.txt", GENERIC_WRITE,
                    FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
82
                    CREATE_ALWAYS, 0, NULL );
83 84
    SetFilePointer( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
                                     logfile, 0, NULL, FILE_END );
85
#endif
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

}

static void CreateMsgQueue( vlc_object_t *p_this, int i_queue )
{
    msg_queue_t *p_queue = (msg_queue_t *)malloc( sizeof( msg_queue_t ) );

    vlc_mutex_init( p_this, &p_queue->lock );

    p_queue->b_overflow = VLC_FALSE;
    p_queue->i_id = i_queue;
    p_queue->i_start = 0;
    p_queue->i_stop = 0;

    p_queue->i_sub = 0;
    p_queue->pp_sub = NULL;

    INSERT_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
                 p_this->p_libvlc->msg_bank.i_queues,
                 i_queue,
                 p_queue );
Michel Kaempf's avatar
Michel Kaempf committed
107 108
}

sigmunau's avatar
all:  
sigmunau committed
109
/**
110
 * Flush all message queues
sigmunau's avatar
all:  
sigmunau committed
111
 */
112 113
void __msg_Flush( vlc_object_t *p_this )
{
114
    int i;
115

116
    for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
117
    {
118 119 120
        vlc_mutex_lock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
        FlushMsg( p_this->p_libvlc->msg_bank.pp_queues[i] );
        vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
121 122 123
    }
}

sigmunau's avatar
all:  
sigmunau committed
124 125 126
/**
 * Free resources allocated by msg_Create
 *
127 128
 * This functions prints all messages remaining in the normal queue,
 * then frees all the allocated ressources
Michel Kaempf's avatar
Michel Kaempf committed
129
 * No other messages interface functions should be called after this one.
sigmunau's avatar
all:  
sigmunau committed
130
 */
131
void __msg_Destroy( vlc_object_t *p_this )
Michel Kaempf's avatar
Michel Kaempf committed
132
{
133 134
    int i;
    for( i =  0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
135
    {
136 137 138 139 140 141
        msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
        if( p_queue->i_sub )
        {
            msg_Err( p_this, "stale interface subscribers" );
        }
        FlushMsg( p_queue );
142

143
#ifdef UNDER_CE
144 145
        if( i == MSG_STREAM_NORMAL )
            CloseHandle( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
146
#endif
147 148 149
        /* Destroy lock */
        vlc_mutex_destroy( &p_queue->lock );
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
150 151
}

sigmunau's avatar
all:  
sigmunau committed
152 153 154
/**
 * Subscribe to the message queue.
 */
155
msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
Sam Hocevar's avatar
 
Sam Hocevar committed
156
{
157
    msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
158
    msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
159 160
    msg_queue_t *p_queue = NULL;
    int i;
Sam Hocevar's avatar
 
Sam Hocevar committed
161

162
    vlc_mutex_lock( &p_bank->lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    for( i = 0 ; i <p_bank->i_queues ;i++ )
    {
        if( p_bank->pp_queues[i]->i_id == i_queue )
        {
            p_queue = p_bank->pp_queues[i];
        }
    }

    if( p_queue == NULL )
    {
        vlc_mutex_unlock( &p_bank->lock );
        return NULL;
    }

    vlc_mutex_lock( &p_queue->lock );

Sam Hocevar's avatar
 
Sam Hocevar committed
180
    /* Add subscription to the list */
181 182 183 184
    INSERT_ELEM( p_bank->pp_queues[i_queue]->pp_sub,
                 p_bank->pp_queues[i_queue]->i_sub,
                 p_bank->pp_queues[i_queue]->i_sub,
                 p_sub );
Sam Hocevar's avatar
 
Sam Hocevar committed
185

186 187
    p_sub->i_start = p_queue->i_start;
    p_sub->pi_stop = &p_queue->i_stop;
Sam Hocevar's avatar
 
Sam Hocevar committed
188

189 190
    p_sub->p_msg   = p_queue->msg;
    p_sub->p_lock  = &p_queue->lock;
Sam Hocevar's avatar
 
Sam Hocevar committed
191

192
    vlc_mutex_unlock( &p_queue->lock );
193
    vlc_mutex_unlock( &p_bank->lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
194 195 196 197

    return p_sub;
}

sigmunau's avatar
all:  
sigmunau committed
198 199 200
/**
 * Unsubscribe from the message queue.
 */
201
void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
Sam Hocevar's avatar
 
Sam Hocevar committed
202
{
203
    msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
204
    int i,j;
Sam Hocevar's avatar
 
Sam Hocevar committed
205

206
    vlc_mutex_lock( &p_bank->lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
207

208
    for( i = 0 ; i< p_bank->i_queues ; i++ )
Sam Hocevar's avatar
 
Sam Hocevar committed
209
    {
210 211
        vlc_mutex_lock( & p_bank->pp_queues[i]->lock );
        for( j = 0 ; j< p_bank->pp_queues[i]->i_sub ; j++ )
Sam Hocevar's avatar
 
Sam Hocevar committed
212
        {
213 214 215 216 217 218 219
            if( p_bank->pp_queues[i]->pp_sub[j] == p_sub )
            {
                REMOVE_ELEM( p_bank->pp_queues[i]->pp_sub,
                             p_bank->pp_queues[i]->i_sub,
                             j );
                if( p_sub ) free( p_sub );
            }
Sam Hocevar's avatar
 
Sam Hocevar committed
220
        }
221
        vlc_mutex_unlock( & p_bank->pp_queues[i]->lock );
Sam Hocevar's avatar
 
Sam Hocevar committed
222 223
    }

224
    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
225 226
}

227
/*****************************************************************************
228
 * __msg_*: print a message
229
 *****************************************************************************
230
 * These functions queue a message for later printing.
231
 *****************************************************************************/
232 233
void __msg_Generic( vlc_object_t *p_this, int i_queue_id, int i_type,
                    const char *psz_module,
234
                    const char *psz_format, ... )
Michel Kaempf's avatar
Michel Kaempf committed
235
{
236
    va_list args;
Michel Kaempf's avatar
Michel Kaempf committed
237

238
    va_start( args, psz_format );
239
    QueueMsg( p_this, i_queue_id, i_type, psz_module, psz_format, args );
240
    va_end( args );
Michel Kaempf's avatar
Michel Kaempf committed
241
}
242

243 244
void __msg_GenericVa( vlc_object_t *p_this, int i_queue_id,
                      int i_type, const char *psz_module,
245 246
                      const char *psz_format, va_list args )
{
247
    QueueMsg( p_this, i_queue_id, i_type, psz_module, psz_format, args );
248 249
}

250 251
/* Generic functions used when variadic macros are not available. */
#define DECLARE_MSG_FN( FN_NAME, FN_TYPE ) \
sigmunau's avatar
all:  
sigmunau committed
252
    void FN_NAME( vlc_object_t *p_this, const char *psz_format, ... ) \
253 254 255
    { \
        va_list args; \
        va_start( args, psz_format ); \
256
        QueueMsg( (vlc_object_t *)p_this,MSG_QUEUE_NORMAL, FN_TYPE, "unknown", \
257 258
                  psz_format, args ); \
        va_end( args ); \
259 260
    } \
    struct _
sigmunau's avatar
all:  
sigmunau committed
261 262 263 264 265
/**
 * Output an informational message.
 * \note Do not use this for debug messages
 * \see input_AddInfo
 */
266
DECLARE_MSG_FN( __msg_Info, VLC_MSG_INFO );
sigmunau's avatar
all:  
sigmunau committed
267 268 269
/**
 * Output an error message.
 */
270
DECLARE_MSG_FN( __msg_Err,  VLC_MSG_ERR );
sigmunau's avatar
all:  
sigmunau committed
271 272 273
/**
 * Output a waring message
 */
274
DECLARE_MSG_FN( __msg_Warn, VLC_MSG_WARN );
sigmunau's avatar
all:  
sigmunau committed
275 276 277
/**
 * Output a debug message
 */
278
DECLARE_MSG_FN( __msg_Dbg,  VLC_MSG_DBG );
Michel Kaempf's avatar
Michel Kaempf committed
279

sigmunau's avatar
all:  
sigmunau committed
280 281 282
/**
 * Add a message to a queue
 *
283
 * This function provides basic functionnalities to other msg_* functions.
284 285 286
 * It adds 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 issues
 * a warning.
sigmunau's avatar
all:  
sigmunau committed
287
 */
288 289
static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
                      const char *psz_module,
290
                      const char *psz_format, va_list _args )
Michel Kaempf's avatar
Michel Kaempf committed
291
{
292
    msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank;       /* message bank */
293
    msg_queue_t *p_queue = NULL;
294
    char *       psz_str = NULL;                 /* formatted message string */
295
    va_list      args;
296 297
    msg_item_t * p_item = NULL;                        /* pointer to message */
    msg_item_t   item;                    /* message in case of a full queue */
gbazin's avatar
 
gbazin committed
298

299
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
300
    int          i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
301
#endif
302
    int i;
Vincent Seguin's avatar
Vincent Seguin committed
303

304 305 306
    /*
     * Convert message to string
     */
307
#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined( SYS_BEOS )
308
    vlc_va_copy( args, _args );
309
    vasprintf( &psz_str, psz_format, args );
310
    va_end( args );
Sam Hocevar's avatar
 
Sam Hocevar committed
311
#else
312
    psz_str = (char*) malloc( i_size * sizeof(char) );
313
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
314

Michel Kaempf's avatar
Michel Kaempf committed
315 316
    if( psz_str == NULL )
    {
317 318
        fprintf( stderr, "main warning: can't store message (%s): ",
                 strerror(errno) );
319
        vlc_va_copy( args, _args );
320
        vfprintf( stderr, psz_format, args );
321
        va_end( args );
322
        fprintf( stderr, "\n" );
323
        return;
Michel Kaempf's avatar
Michel Kaempf committed
324
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
325

326
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
327
    vlc_va_copy( args, _args );
328
    vsnprintf( psz_str, i_size, psz_format, args );
329
    va_end( args );
330
    psz_str[ i_size - 1 ] = 0; /* Just in case */
331
#endif
Vincent Seguin's avatar
Vincent Seguin committed
332

Sam Hocevar's avatar
 
Sam Hocevar committed
333
    /* Put message in queue */
334
    vlc_mutex_lock( &p_bank->lock );
335 336 337 338 339 340 341 342 343 344 345
    for( i = 0 ; i <p_bank->i_queues ;i++ )
    {
        if( p_bank->pp_queues[i]->i_id == i_queue_id )
        {
            p_queue = p_bank->pp_queues[i];
        }
    }

    if( p_queue == NULL ) return;

    vlc_mutex_lock( &p_queue->lock );
Vincent Seguin's avatar
Vincent Seguin committed
346

347
    /* Check there is room in the queue for our message */
348
    if( p_queue->b_overflow )
349
    {
350
        FlushMsg( p_queue );
351

352
        if( ((p_queue->i_stop - p_queue->i_start + 1) % VLC_MSG_QSIZE) == 0 )
353 354 355 356 357 358 359
        {
            /* Still in overflow mode, print from a dummy item */
            p_item = &item;
        }
        else
        {
            /* Pheeew, at last, there is room in the queue! */
360
            p_queue->b_overflow = VLC_FALSE;
361 362
        }
    }
363
    else if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
Vincent Seguin's avatar
Vincent Seguin committed
364
    {
365
        FlushMsg( p_queue );
Michel Kaempf's avatar
Michel Kaempf committed
366

367
        if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
Sam Hocevar's avatar
 
Sam Hocevar committed
368
        {
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
            p_queue->b_overflow = VLC_TRUE;

            if( p_queue->i_id == MSG_QUEUE_NORMAL )
            {
               /* Put the overflow message in the queue */
                p_item = p_queue->msg + p_queue->i_stop;
                p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;

                p_item->i_type =        VLC_MSG_WARN;
                p_item->i_object_id =   p_this->i_object_id;
                p_item->i_object_type = p_this->i_object_type;
                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;
            }
Sam Hocevar's avatar
 
Sam Hocevar committed
387
        }
Michel Kaempf's avatar
Michel Kaempf committed
388 389
    }

390
    if( !p_queue->b_overflow )
391 392
    {
        /* Put the message in the queue */
393 394
        p_item = p_queue->msg + p_queue->i_stop;
        p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
395
    }
Michel Kaempf's avatar
Michel Kaempf committed
396

Sam Hocevar's avatar
 
Sam Hocevar committed
397
    /* Fill message information fields */
398 399 400 401 402
    p_item->i_type =        i_type;
    p_item->i_object_id =   p_this->i_object_id;
    p_item->i_object_type = p_this->i_object_type;
    p_item->psz_module =    strdup( psz_module );
    p_item->psz_msg =       psz_str;
403

404 405
    if( p_queue->i_id == MSG_QUEUE_NORMAL )
        PrintMsg( p_this, p_item );
Michel Kaempf's avatar
Michel Kaempf committed
406

407
    if( p_queue->b_overflow )
408
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
409 410 411 412
        if( p_item->psz_module )
            free( p_item->psz_module );
        if( p_item->psz_msg )
            free( p_item->psz_msg );
413 414
    }

415
    vlc_mutex_unlock ( &p_queue->lock );
416
    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
417 418
}

419 420
/* following functions are local */

421
/*****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
422
 * FlushMsg
423
 *****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
424 425
 * Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since
 * this function does not check the lock.
426
 *****************************************************************************/
427
static void FlushMsg ( msg_queue_t *p_queue )
Michel Kaempf's avatar
Michel Kaempf committed
428
{
Sam Hocevar's avatar
 
Sam Hocevar committed
429
    int i_index, i_start, i_stop;
Sam Hocevar's avatar
 
Sam Hocevar committed
430

Sam Hocevar's avatar
 
Sam Hocevar committed
431
    /* Get the maximum message index that can be freed */
432
    i_stop = p_queue->i_stop;
Sam Hocevar's avatar
 
Sam Hocevar committed
433

Sam Hocevar's avatar
 
Sam Hocevar committed
434
    /* Check until which value we can free messages */
435
    for( i_index = 0; i_index < p_queue->i_sub; i_index++ )
Sam Hocevar's avatar
 
Sam Hocevar committed
436
    {
437
        i_start = p_queue->pp_sub[ i_index ]->i_start;
Sam Hocevar's avatar
 
Sam Hocevar committed
438 439 440 441

        /* If this subscriber is late, we don't free messages before
         * his i_start value, otherwise he'll miss messages */
        if(   ( i_start < i_stop
442
               && (p_queue->i_stop <= i_start || i_stop <= p_queue->i_stop) )
Sam Hocevar's avatar
 
Sam Hocevar committed
443
           || ( i_stop < i_start
444
               && (i_stop <= p_queue->i_stop && p_queue->i_stop <= i_start) ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
445 446 447
        {
            i_stop = i_start;
        }
Sam Hocevar's avatar
 
Sam Hocevar committed
448
    }
449

Sam Hocevar's avatar
 
Sam Hocevar committed
450
    /* Free message data */
451
    for( i_index = p_queue->i_start;
Sam Hocevar's avatar
 
Sam Hocevar committed
452
         i_index != i_stop;
453
         i_index = (i_index+1) % VLC_MSG_QSIZE )
Michel Kaempf's avatar
Michel Kaempf committed
454
    {
455 456 457 458
        if( p_queue->msg[i_index].psz_msg )
            free( p_queue->msg[i_index].psz_msg );
        if( p_queue->msg[i_index].psz_module )
            free( p_queue->msg[i_index].psz_module );
459
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
460

Sam Hocevar's avatar
 
Sam Hocevar committed
461
    /* Update the new start value */
462
    p_queue->i_start = i_index;
Sam Hocevar's avatar
 
Sam Hocevar committed
463
}
gbazin's avatar
 
gbazin committed
464

465
/*****************************************************************************
466
 * PrintMsg: output a standard message item to stderr
467 468 469 470 471 472 473 474 475 476 477 478
 *****************************************************************************
 * Print a message to stderr, with colour formatting if needed.
 *****************************************************************************/
static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
{
#   define COL(x)  "\033[" #x ";1m"
#   define RED     COL(31)
#   define GREEN   COL(32)
#   define YELLOW  COL(33)
#   define WHITE   COL(37)
#   define GRAY    "\033[0m"

479 480 481
#ifdef UNDER_CE
    int i_dummy;
#endif
482
    static const char * ppsz_type[4] = { "", " error", " warning", " debug" };
zorglub's avatar
zorglub committed
483
    static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
484
    char *psz_object = "private";
485 486
    int i_type = p_item->i_type;

487
    switch( i_type )
488
    {
489
        case VLC_MSG_ERR:
490
            if( p_this->p_libvlc->i_verbose < 0 ) return;
491 492
            break;
        case VLC_MSG_INFO:
493
            if( p_this->p_libvlc->i_verbose < 0 ) return;
494 495
            break;
        case VLC_MSG_WARN:
496
            if( p_this->p_libvlc->i_verbose < 1 ) return;
497 498
            break;
        case VLC_MSG_DBG:
499
            if( p_this->p_libvlc->i_verbose < 2 ) return;
500
            break;
501 502
    }

503 504 505
    switch( p_item->i_object_type )
    {
        case VLC_OBJECT_ROOT: psz_object = "root"; break;
506
        case VLC_OBJECT_VLC: psz_object = "vlc"; break;
507 508 509 510 511 512
        case VLC_OBJECT_MODULE: psz_object = "module"; break;
        case VLC_OBJECT_INTF: psz_object = "interface"; break;
        case VLC_OBJECT_PLAYLIST: psz_object = "playlist"; break;
        case VLC_OBJECT_ITEM: psz_object = "item"; break;
        case VLC_OBJECT_INPUT: psz_object = "input"; break;
        case VLC_OBJECT_DECODER: psz_object = "decoder"; break;
gbazin's avatar
 
gbazin committed
513 514
        case VLC_OBJECT_PACKETIZER: psz_object = "packetizer"; break;
        case VLC_OBJECT_ENCODER: psz_object = "encoder"; break;
515 516 517
        case VLC_OBJECT_VOUT: psz_object = "video output"; break;
        case VLC_OBJECT_AOUT: psz_object = "audio output"; break;
        case VLC_OBJECT_SOUT: psz_object = "stream output"; break;
zorglub's avatar
zorglub committed
518 519 520 521 522
        case VLC_OBJECT_HTTPD: psz_object = "http daemon"; break;
        case VLC_OBJECT_DIALOGS: psz_object = "dialogs provider"; break;
        case VLC_OBJECT_VLM: psz_object = "vlm"; break;
        case VLC_OBJECT_ANNOUNCE: psz_object = "announce handler"; break;
        case VLC_OBJECT_DEMUX: psz_object = "demuxer"; break;
523
        case VLC_OBJECT_ACCESS: psz_object = "access"; break;
524 525
    }

526 527 528 529 530 531 532 533 534
#ifdef UNDER_CE
#   define CE_WRITE(str) WriteFile( p_this->p_libvlc->msg_bank.logfile, \
                                    str, strlen(str), &i_dummy, NULL );
    CE_WRITE( p_item->psz_module );
    CE_WRITE( " " );
    CE_WRITE( psz_object );
    CE_WRITE( ppsz_type[i_type] );
    CE_WRITE( ": " );
    CE_WRITE( p_item->psz_msg );
535
    CE_WRITE( "\r\n" );
536 537 538
    FlushFileBuffers( p_this->p_libvlc->msg_bank.logfile );

#else
539
    /* Send the message to stderr */
540
    if( p_this->p_libvlc->b_color )
541
    {
zorglub's avatar
zorglub committed
542
        fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
543
                         p_item->i_object_id, p_item->psz_module, psz_object,
544
                         ppsz_type[i_type], ppsz_color[i_type],
zorglub's avatar
zorglub committed
545
                         p_item->psz_msg );
546 547 548
    }
    else
    {
549
        fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
550
                         p_item->psz_module, psz_object, ppsz_type[i_type],
551
                         p_item->psz_msg );
552
    }
553

554
#   if defined(WIN32)
555
    fflush( stderr );
556
#   endif
557
#endif
558
}