messages.c 16.9 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
 *****************************************************************************
zorglub's avatar
zorglub committed
6
 * Copyright (C) 1998-2004 VideoLAN
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
41
42
43
44
#ifdef HAVE_FCNTL_H
#   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
#endif

#ifdef HAVE_ERRNO_H
#   include <errno.h>                                               /* errno */
#endif

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

49
#include "vlc_interface.h"
50

51
52
53
54
55
56
57
58
59
60
61
/*****************************************************************************
 * 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
62
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
63
 * Local prototypes
Vincent Seguin's avatar
Vincent Seguin committed
64
 *****************************************************************************/
65
66
67
static void QueueMsg ( vlc_object_t *, int , const char *,
                       const char *, va_list );
static void FlushMsg ( msg_bank_t * );
68
static void PrintMsg ( vlc_object_t *, msg_item_t * );
Michel Kaempf's avatar
Michel Kaempf committed
69

sigmunau's avatar
all:    
sigmunau committed
70
71
72
/**
 * Initialize messages interface
 *
73
 * This functions has to be called before any call to other msg_* functions.
Vincent Seguin's avatar
Vincent Seguin committed
74
 * It set up the locks and the message queue if it is used.
sigmunau's avatar
all:    
sigmunau committed
75
 */
76
void __msg_Create( vlc_object_t *p_this )
Michel Kaempf's avatar
Michel Kaempf committed
77
78
{
    /* Message queue initialization */
79
    vlc_mutex_init( p_this, &p_this->p_libvlc->msg_bank.lock );
80

81
82
    p_this->p_libvlc->msg_bank.b_configured = VLC_FALSE;
    p_this->p_libvlc->msg_bank.b_overflow = VLC_FALSE;
83

84
85
    p_this->p_libvlc->msg_bank.i_start = 0;
    p_this->p_libvlc->msg_bank.i_stop = 0;
Michel Kaempf's avatar
Michel Kaempf committed
86

87
88
    p_this->p_libvlc->msg_bank.i_sub = 0;
    p_this->p_libvlc->msg_bank.pp_sub = NULL;
89
90
91
92
93

#ifdef UNDER_CE
    p_this->p_libvlc->msg_bank.logfile =
        CreateFile( L"vlc-log.txt", GENERIC_WRITE,
                    FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
94
                    CREATE_ALWAYS, 0, NULL );
95
96
    SetFilePointer( p_this->p_libvlc->msg_bank.logfile, 0, NULL, FILE_END );
#endif
Michel Kaempf's avatar
Michel Kaempf committed
97
98
}

sigmunau's avatar
all:    
sigmunau committed
99
100
101
/**
 * Flush the message queue
 */
102
103
104
105
void __msg_Flush( vlc_object_t *p_this )
{
    int i_index;

106
    vlc_mutex_lock( &p_this->p_libvlc->msg_bank.lock );
107

108
    p_this->p_libvlc->msg_bank.b_configured = VLC_TRUE;
109

110
111
    for( i_index = p_this->p_libvlc->msg_bank.i_start;
         i_index != p_this->p_libvlc->msg_bank.i_stop;
112
113
         i_index = (i_index+1) % VLC_MSG_QSIZE )
    {
114
        PrintMsg( p_this, &p_this->p_libvlc->msg_bank.msg[i_index] );
115
116
    }

117
    FlushMsg( &p_this->p_libvlc->msg_bank );
118

119
    vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.lock );
120
121
}

sigmunau's avatar
all:    
sigmunau committed
122
123
124
/**
 * Free resources allocated by msg_Create
 *
125
 * This functions prints all messages remaining in queue, then free all the
126
 * resources allocated by msg_Create.
Michel Kaempf's avatar
Michel Kaempf committed
127
 * No other messages interface functions should be called after this one.
sigmunau's avatar
all:    
sigmunau committed
128
 */
129
void __msg_Destroy( vlc_object_t *p_this )
Michel Kaempf's avatar
Michel Kaempf committed
130
{
131
    if( p_this->p_libvlc->msg_bank.i_sub )
Vincent Seguin's avatar
Vincent Seguin committed
132
    {
133
        msg_Err( p_this, "stale interface subscribers" );
Vincent Seguin's avatar
Vincent Seguin committed
134
135
    }

136
    /* Flush the queue */
137
    if( !p_this->p_libvlc->msg_bank.b_configured )
138
139
140
141
142
    {
        msg_Flush( p_this );
    }
    else
    {
143
        FlushMsg( &p_this->p_libvlc->msg_bank );
144
145
    }

146
147
148
149
#ifdef UNDER_CE
    CloseHandle( p_this->p_libvlc->msg_bank.logfile );
#endif

150
    /* Destroy lock */
151
    vlc_mutex_destroy( &p_this->p_libvlc->msg_bank.lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
152
153
}

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

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

    /* Add subscription to the list */
165
    INSERT_ELEM( p_bank->pp_sub, p_bank->i_sub, p_bank->i_sub, p_sub );
Sam Hocevar's avatar
   
Sam Hocevar committed
166

167
168
    p_sub->i_start = p_bank->i_start;
    p_sub->pi_stop = &p_bank->i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
169

170
171
    p_sub->p_msg   = p_bank->msg;
    p_sub->p_lock  = &p_bank->lock;
Sam Hocevar's avatar
   
Sam Hocevar committed
172

173
    vlc_mutex_unlock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
174
175
176
177

    return p_sub;
}

sigmunau's avatar
all:    
sigmunau committed
178
179
180
/**
 * Unsubscribe from the message queue.
 */
181
void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
Sam Hocevar's avatar
   
Sam Hocevar committed
182
{
183
    msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
Sam Hocevar's avatar
   
Sam Hocevar committed
184
185
    int i_index;

186
    vlc_mutex_lock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
187

gbazin's avatar
   
gbazin committed
188
    /* Sanity check */
189
    if( !p_bank->i_sub )
gbazin's avatar
   
gbazin committed
190
    {
191
        msg_Err( p_this, "no subscriber in the list" );
gbazin's avatar
   
gbazin committed
192
193
194
        return;
    }

Sam Hocevar's avatar
   
Sam Hocevar committed
195
    /* Look for the appropriate subscription */
196
    for( i_index = 0; i_index < p_bank->i_sub; i_index++ )
Sam Hocevar's avatar
   
Sam Hocevar committed
197
    {
198
        if( p_bank->pp_sub[ i_index ] == p_sub )
Sam Hocevar's avatar
   
Sam Hocevar committed
199
200
201
202
203
        {
            break;
        }
    }

204
    if( p_bank->pp_sub[ i_index ] != p_sub )
Sam Hocevar's avatar
   
Sam Hocevar committed
205
    {
206
        msg_Err( p_this, "subscriber not found" );
207
        vlc_mutex_unlock( &p_bank->lock );
Sam Hocevar's avatar
   
Sam Hocevar committed
208
209
210
211
        return;
    }

    /* Remove this subscription */
212
    REMOVE_ELEM( p_bank->pp_sub, p_bank->i_sub, i_index );
213

214
    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
215
216
}

217
/*****************************************************************************
218
 * __msg_*: print a message
219
 *****************************************************************************
220
 * These functions queue a message for later printing.
221
 *****************************************************************************/
222
void __msg_Generic( vlc_object_t *p_this, int i_type, const char *psz_module,
223
                    const char *psz_format, ... )
Michel Kaempf's avatar
Michel Kaempf committed
224
{
225
    va_list args;
Michel Kaempf's avatar
Michel Kaempf committed
226

227
228
229
    va_start( args, psz_format );
    QueueMsg( p_this, i_type, psz_module, psz_format, args );
    va_end( args );
Michel Kaempf's avatar
Michel Kaempf committed
230
}
231

232
233
234
235
236
237
void __msg_GenericVa( vlc_object_t *p_this, int i_type, const char *psz_module,
                      const char *psz_format, va_list args )
{
    QueueMsg( p_this, i_type, psz_module, psz_format, args );
}

238
239
/* Generic functions used when variadic macros are not available. */
#define DECLARE_MSG_FN( FN_NAME, FN_TYPE ) \
sigmunau's avatar
all:    
sigmunau committed
240
    void FN_NAME( vlc_object_t *p_this, const char *psz_format, ... ) \
241
242
243
244
245
246
    { \
        va_list args; \
        va_start( args, psz_format ); \
        QueueMsg( (vlc_object_t *)p_this, FN_TYPE, "unknown", \
                  psz_format, args ); \
        va_end( args ); \
247
248
    } \
    struct _
sigmunau's avatar
all:    
sigmunau committed
249
250
251
252
253
/**
 * Output an informational message.
 * \note Do not use this for debug messages
 * \see input_AddInfo
 */
254
DECLARE_MSG_FN( __msg_Info, VLC_MSG_INFO );
sigmunau's avatar
all:    
sigmunau committed
255
256
257
/**
 * Output an error message.
 */
258
DECLARE_MSG_FN( __msg_Err,  VLC_MSG_ERR );
sigmunau's avatar
all:    
sigmunau committed
259
260
261
/**
 * Output a waring message
 */
262
DECLARE_MSG_FN( __msg_Warn, VLC_MSG_WARN );
sigmunau's avatar
all:    
sigmunau committed
263
264
265
/**
 * Output a debug message
 */
266
DECLARE_MSG_FN( __msg_Dbg,  VLC_MSG_DBG );
Michel Kaempf's avatar
Michel Kaempf committed
267

sigmunau's avatar
all:    
sigmunau committed
268
269
270
/**
 * Add a message to a queue
 *
271
 * This function provides basic functionnalities to other msg_* functions.
272
273
274
 * 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
275
 */
276
static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
277
                      const char *psz_format, va_list _args )
Michel Kaempf's avatar
Michel Kaempf committed
278
{
279
280
    msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank;       /* message bank */
    char *       psz_str = NULL;                 /* formatted message string */
281
    va_list      args;
282
283
    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
284

285
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
286
    int          i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
287
#endif
Vincent Seguin's avatar
Vincent Seguin committed
288

289
290
291
    /*
     * Convert message to string
     */
292
#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined( SYS_BEOS )
293
    vlc_va_copy( args, _args );
294
    vasprintf( &psz_str, psz_format, args );
295
    va_end( args );
Sam Hocevar's avatar
   
Sam Hocevar committed
296
#else
297
    psz_str = (char*) malloc( i_size * sizeof(char) );
298
#endif
Sam Hocevar's avatar
   
Sam Hocevar committed
299

Michel Kaempf's avatar
Michel Kaempf committed
300
301
    if( psz_str == NULL )
    {
302
#ifdef HAVE_ERRNO_H
303
304
        fprintf( stderr, "main warning: can't store message (%s): ",
                 strerror(errno) );
305
306
307
#else
        fprintf( stderr, "main warning: can't store message: " );
#endif
308
        vlc_va_copy( args, _args );
309
        vfprintf( stderr, psz_format, args );
310
        va_end( args );
311
        fprintf( stderr, "\n" );
312
        return;
Michel Kaempf's avatar
Michel Kaempf committed
313
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
314

315
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
316
    vlc_va_copy( args, _args );
317
    vsnprintf( psz_str, i_size, psz_format, args );
318
    va_end( args );
319
    psz_str[ i_size - 1 ] = 0; /* Just in case */
320
#endif
Vincent Seguin's avatar
Vincent Seguin committed
321

Sam Hocevar's avatar
   
Sam Hocevar committed
322
    /* Put message in queue */
323
    vlc_mutex_lock( &p_bank->lock );
Vincent Seguin's avatar
Vincent Seguin committed
324

325
    /* Check there is room in the queue for our message */
326
327
    if( p_bank->b_overflow )
    {
328
        FlushMsg( p_bank );
329
330
331
332
333
334
335
336
337
338
339
340
341

        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 )
Vincent Seguin's avatar
Vincent Seguin committed
342
    {
343
        FlushMsg( p_bank );
Michel Kaempf's avatar
Michel Kaempf committed
344

345
        if( ((p_bank->i_stop - p_bank->i_start + 2) % VLC_MSG_QSIZE) == 0 )
Sam Hocevar's avatar
   
Sam Hocevar committed
346
        {
347
348
349
350
351
352
            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;

353
            p_item->i_type =        VLC_MSG_WARN;
354
355
356
357
            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" );
358
359
360
361

            PrintMsg( p_this, p_item );

            /* We print from a dummy item */
362
            p_item = &item;
Sam Hocevar's avatar
   
Sam Hocevar committed
363
        }
Michel Kaempf's avatar
Michel Kaempf committed
364
365
    }

366
367
368
369
370
371
    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;
    }
Michel Kaempf's avatar
Michel Kaempf committed
372

Sam Hocevar's avatar
   
Sam Hocevar committed
373
    /* Fill message information fields */
374
375
376
377
378
    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;
379
380

    PrintMsg( p_this, p_item );
Michel Kaempf's avatar
Michel Kaempf committed
381

382
383
384
385
386
387
388
    if( p_bank->b_overflow )
    {
        free( p_item->psz_module );
        free( p_item->psz_msg );
    }

    vlc_mutex_unlock( &p_bank->lock );
Michel Kaempf's avatar
Michel Kaempf committed
389
390
}

391
392
/* following functions are local */

393
/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
394
 * FlushMsg
395
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
396
397
 * Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since
 * this function does not check the lock.
398
 *****************************************************************************/
399
static void FlushMsg ( msg_bank_t *p_bank )
Michel Kaempf's avatar
Michel Kaempf committed
400
{
Sam Hocevar's avatar
   
Sam Hocevar committed
401
    int i_index, i_start, i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
402

403
404
405
406
407
408
    /* Only flush the queue if it has been properly configured */
    if( !p_bank->b_configured )
    {
        return;
    }

Sam Hocevar's avatar
   
Sam Hocevar committed
409
    /* Get the maximum message index that can be freed */
410
    i_stop = p_bank->i_stop;
Sam Hocevar's avatar
   
Sam Hocevar committed
411

Sam Hocevar's avatar
   
Sam Hocevar committed
412
    /* Check until which value we can free messages */
413
    for( i_index = 0; i_index < p_bank->i_sub; i_index++ )
Sam Hocevar's avatar
   
Sam Hocevar committed
414
    {
415
        i_start = p_bank->pp_sub[ i_index ]->i_start;
Sam Hocevar's avatar
   
Sam Hocevar committed
416
417
418
419

        /* 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
420
               && (p_bank->i_stop <= i_start || i_stop <= p_bank->i_stop) )
Sam Hocevar's avatar
   
Sam Hocevar committed
421
           || ( i_stop < i_start
422
               && (i_stop <= p_bank->i_stop && p_bank->i_stop <= i_start) ) )
Sam Hocevar's avatar
   
Sam Hocevar committed
423
424
425
        {
            i_stop = i_start;
        }
Sam Hocevar's avatar
   
Sam Hocevar committed
426
    }
427

Sam Hocevar's avatar
   
Sam Hocevar committed
428
    /* Free message data */
429
    for( i_index = p_bank->i_start;
Sam Hocevar's avatar
   
Sam Hocevar committed
430
         i_index != i_stop;
431
         i_index = (i_index+1) % VLC_MSG_QSIZE )
Michel Kaempf's avatar
Michel Kaempf committed
432
    {
433
434
        free( p_bank->msg[i_index].psz_msg );
        free( p_bank->msg[i_index].psz_module );
435
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
436

Sam Hocevar's avatar
   
Sam Hocevar committed
437
    /* Update the new start value */
438
    p_bank->i_start = i_index;
Sam Hocevar's avatar
   
Sam Hocevar committed
439
}
gbazin's avatar
   
gbazin committed
440

441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*****************************************************************************
 * PrintMsg: output a message item to stderr
 *****************************************************************************
 * 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"

455
456
457
#ifdef UNDER_CE
    int i_dummy;
#endif
458
459
    static const char * ppsz_type[4] = { "", " error", " warning", " debug" };
    static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
460
    char *psz_object = "private";
461
462
    int i_type = p_item->i_type;

463
    switch( i_type )
464
    {
465
        case VLC_MSG_ERR:
466
            if( p_this->p_libvlc->i_verbose < 0 ) return;
467
468
            break;
        case VLC_MSG_INFO:
469
            if( p_this->p_libvlc->i_verbose < 0 ) return;
470
471
            break;
        case VLC_MSG_WARN:
472
            if( p_this->p_libvlc->i_verbose < 1 ) return;
473
474
            break;
        case VLC_MSG_DBG:
475
            if( p_this->p_libvlc->i_verbose < 2 ) return;
476
            break;
477
478
    }

479
480
481
    switch( p_item->i_object_type )
    {
        case VLC_OBJECT_ROOT: psz_object = "root"; break;
482
        case VLC_OBJECT_VLC: psz_object = "vlc"; break;
483
484
485
486
487
488
        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
489
490
        case VLC_OBJECT_PACKETIZER: psz_object = "packetizer"; break;
        case VLC_OBJECT_ENCODER: psz_object = "encoder"; break;
491
492
493
        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
494
495
496
497
498
        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;
499
        case VLC_OBJECT_ACCESS: psz_object = "access"; break;
500
501
    }

502
503
504
505
506
507
508
509
510
#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 );
511
    CE_WRITE( "\r\n" );
512
513
514
    FlushFileBuffers( p_this->p_libvlc->msg_bank.logfile );

#else
515
    /* Send the message to stderr */
516
    if( p_this->p_libvlc->b_color )
517
    {
518
        fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
519
                         p_item->i_object_id, p_item->psz_module, psz_object,
520
521
522
523
524
                         ppsz_type[i_type], ppsz_color[i_type],
                         p_item->psz_msg );
    }
    else
    {
525
        fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
526
                         p_item->psz_module, psz_object, ppsz_type[i_type],
527
                         p_item->psz_msg );
528
    }
529

530
#   if defined(WIN32)
531
    fflush( stderr );
532
#   endif
533
#endif
534
}