messages.c 18.4 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
    vlc_mutex_init( p_this, &(p_this->p_libvlc->msg_bank.lock) );

77
78
    CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
    CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
79
80

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

}

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
109
110
}

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

118
    for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
119
    {
120
121
122
        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 );
123
124
125
    }
}

sigmunau's avatar
all:    
sigmunau committed
126
127
128
/**
 * Free resources allocated by msg_Create
 *
129
130
 * This functions prints all messages remaining in the normal queue,
 * then frees all the allocated ressources
Michel Kaempf's avatar
Michel Kaempf committed
131
 * No other messages interface functions should be called after this one.
sigmunau's avatar
all:    
sigmunau committed
132
 */
133
void __msg_Destroy( vlc_object_t *p_this )
Michel Kaempf's avatar
Michel Kaempf committed
134
{
135
136
    int i;
    for( i =  0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
137
    {
138
139
140
141
142
143
        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 );
144

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

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

165
    vlc_mutex_lock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    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
183
    /* Add subscription to the list */
184
185
186
187
    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
188

189
190
    p_sub->i_start = p_queue->i_start;
    p_sub->pi_stop = &p_queue->i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
191

192
193
    p_sub->p_msg   = p_queue->msg;
    p_sub->p_lock  = &p_queue->lock;
Sam Hocevar's avatar
   
Sam Hocevar committed
194

195
    vlc_mutex_unlock( &p_queue->lock );
196
    vlc_mutex_unlock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
197
198
199
200

    return p_sub;
}

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

209
    vlc_mutex_lock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
210

211
    for( i = 0 ; i< p_bank->i_queues ; i++ )
Sam Hocevar's avatar
   
Sam Hocevar committed
212
    {
213
214
        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
215
        {
216
217
218
219
220
221
222
            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
223
        }
224
        vlc_mutex_unlock( & p_bank->pp_queues[i]->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
225
226
    }

227
    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
228
229
}

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

241
    va_start( args, psz_format );
242
    QueueMsg( p_this, i_queue_id, i_type, psz_module, psz_format, args );
243
    va_end( args );
Michel Kaempf's avatar
Michel Kaempf committed
244
}
245

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

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

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

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

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

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

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

Sam Hocevar's avatar
   
Sam Hocevar committed
336
    /* Put message in queue */
337
    vlc_mutex_lock( &p_bank->lock );
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];
        }
    }

zorglub's avatar
zorglub committed
346
347
348
349
350
    if( p_queue == NULL )
    {
        vlc_mutex_unlock( &p_bank->lock );
        return;
    }
351
352

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

354
    /* Check there is room in the queue for our message */
355
    if( p_queue->b_overflow )
356
    {
357
        FlushMsg( p_queue );
358

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

374
        if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
Sam Hocevar's avatar
   
Sam Hocevar committed
375
        {
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
            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
394
        }
Michel Kaempf's avatar
Michel Kaempf committed
395
396
    }

397
    if( !p_queue->b_overflow )
398
399
    {
        /* Put the message in the queue */
400
401
        p_item = p_queue->msg + p_queue->i_stop;
        p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
402
    }
Michel Kaempf's avatar
Michel Kaempf committed
403

Sam Hocevar's avatar
   
Sam Hocevar committed
404
    /* Fill message information fields */
405
406
407
408
409
    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;
410

411
412
    if( p_queue->i_id == MSG_QUEUE_NORMAL )
        PrintMsg( p_this, p_item );
Michel Kaempf's avatar
Michel Kaempf committed
413

414
    if( p_queue->b_overflow )
415
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
416
417
418
419
        if( p_item->psz_module )
            free( p_item->psz_module );
        if( p_item->psz_msg )
            free( p_item->psz_msg );
420
421
    }

422
    vlc_mutex_unlock ( &p_queue->lock );
423
    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
424
425
}

426
427
/* following functions are local */

428
/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
429
 * FlushMsg
430
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
431
432
 * Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since
 * this function does not check the lock.
433
 *****************************************************************************/
434
static void FlushMsg ( msg_queue_t *p_queue )
Michel Kaempf's avatar
Michel Kaempf committed
435
{
Sam Hocevar's avatar
   
Sam Hocevar committed
436
    int i_index, i_start, i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
437

Sam Hocevar's avatar
   
Sam Hocevar committed
438
    /* Get the maximum message index that can be freed */
439
    i_stop = p_queue->i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
440

Sam Hocevar's avatar
   
Sam Hocevar committed
441
    /* Check until which value we can free messages */
442
    for( i_index = 0; i_index < p_queue->i_sub; i_index++ )
Sam Hocevar's avatar
   
Sam Hocevar committed
443
    {
444
        i_start = p_queue->pp_sub[ i_index ]->i_start;
Sam Hocevar's avatar
   
Sam Hocevar committed
445
446
447
448

        /* 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
449
               && (p_queue->i_stop <= i_start || i_stop <= p_queue->i_stop) )
Sam Hocevar's avatar
   
Sam Hocevar committed
450
           || ( i_stop < i_start
451
               && (i_stop <= p_queue->i_stop && p_queue->i_stop <= i_start) ) )
Sam Hocevar's avatar
   
Sam Hocevar committed
452
453
454
        {
            i_stop = i_start;
        }
Sam Hocevar's avatar
   
Sam Hocevar committed
455
    }
456

Sam Hocevar's avatar
   
Sam Hocevar committed
457
    /* Free message data */
458
    for( i_index = p_queue->i_start;
Sam Hocevar's avatar
   
Sam Hocevar committed
459
         i_index != i_stop;
460
         i_index = (i_index+1) % VLC_MSG_QSIZE )
Michel Kaempf's avatar
Michel Kaempf committed
461
    {
462
463
464
465
        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 );
466
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
467

Sam Hocevar's avatar
   
Sam Hocevar committed
468
    /* Update the new start value */
469
    p_queue->i_start = i_index;
Sam Hocevar's avatar
   
Sam Hocevar committed
470
}
gbazin's avatar
   
gbazin committed
471

472
/*****************************************************************************
473
 * PrintMsg: output a standard message item to stderr
474
475
476
477
478
479
480
481
482
483
484
485
 *****************************************************************************
 * 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"

486
487
488
#ifdef UNDER_CE
    int i_dummy;
#endif
489
    static const char * ppsz_type[4] = { "", " error", " warning", " debug" };
zorglub's avatar
zorglub committed
490
    static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
491
    char *psz_object = "private";
492
493
    int i_type = p_item->i_type;

494
    switch( i_type )
495
    {
496
        case VLC_MSG_ERR:
497
            if( p_this->p_libvlc->i_verbose < 0 ) return;
498
499
            break;
        case VLC_MSG_INFO:
500
            if( p_this->p_libvlc->i_verbose < 0 ) return;
501
502
            break;
        case VLC_MSG_WARN:
503
            if( p_this->p_libvlc->i_verbose < 1 ) return;
504
505
            break;
        case VLC_MSG_DBG:
506
            if( p_this->p_libvlc->i_verbose < 2 ) return;
507
            break;
508
509
    }

510
511
512
    switch( p_item->i_object_type )
    {
        case VLC_OBJECT_ROOT: psz_object = "root"; break;
513
        case VLC_OBJECT_VLC: psz_object = "vlc"; break;
514
515
516
517
518
519
        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
520
521
        case VLC_OBJECT_PACKETIZER: psz_object = "packetizer"; break;
        case VLC_OBJECT_ENCODER: psz_object = "encoder"; break;
522
523
524
        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
525
526
527
528
529
        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;
530
        case VLC_OBJECT_ACCESS: psz_object = "access"; break;
531
532
    }

533
#ifdef UNDER_CE
hartman's avatar
hartman committed
534
#   define CE_WRITE(str) WriteFile( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile, \
535
536
537
538
539
540
541
                                    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 );
542
    CE_WRITE( "\r\n" );
hartman's avatar
hartman committed
543
    FlushFileBuffers( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
544
545

#else
546
    /* Send the message to stderr */
547
    if( p_this->p_libvlc->b_color )
548
    {
zorglub's avatar
zorglub committed
549
        fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
550
                         p_item->i_object_id, p_item->psz_module, psz_object,
551
                         ppsz_type[i_type], ppsz_color[i_type],
zorglub's avatar
zorglub committed
552
                         p_item->psz_msg );
553
554
555
    }
    else
    {
556
        fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
557
                         p_item->psz_module, psz_object, ppsz_type[i_type],
558
                         p_item->psz_msg );
559
    }
560

561
#   if defined(WIN32)
562
    fflush( stderr );
563
#   endif
564
#endif
565
}