log.c 4.53 KB
Newer Older
1 2 3
/*****************************************************************************
 * log.c: libvlc new API log functions
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2005 VLC authors and VideoLAN
5
 *
6
 * $Id$
7 8 9
 *
 * Authors: Damien Fouilleul <damienf@videolan.org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13 14 15 16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24
 *****************************************************************************/

25 26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

29
#include <assert.h>
30 31 32 33 34 35 36
#include <vlc/libvlc.h>
#include "libvlc_internal.h"
#include <vlc_common.h>
#include <vlc_interface.h>

/*** Logging core dispatcher ***/

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
void libvlc_log_get_context(const libvlc_log_t *ctx,
                            const char **restrict module,
                            const char **restrict file,
                            unsigned *restrict line)
{
    if (module != NULL)
        *module = ctx->psz_module;
    if (file != NULL)
        *file = NULL;
    if (line != NULL)
        *line = 0;
}

void libvlc_log_get_object(const libvlc_log_t *ctx,
                           const char **restrict name,
                           const char **restrict header,
                           uintptr_t *restrict id)
{
    if (name != NULL)
        *name = (ctx->psz_object_type != NULL)
                ? ctx->psz_object_type : "generic";
    if (header != NULL)
        *header = ctx->psz_header;
    if (id != NULL)
        *id = ctx->i_object_id;
}

64
static void libvlc_logf (void *data, int level, const vlc_log_t *item,
65 66
                         const char *fmt, va_list ap)
{
67
    libvlc_instance_t *inst = data;
68 69 70 71 72 73 74 75 76

    switch (level)
    {
        case VLC_MSG_INFO: level = LIBVLC_NOTICE;  break;
        case VLC_MSG_ERR:  level = LIBVLC_ERROR;   break;
        case VLC_MSG_WARN: level = LIBVLC_WARNING; break;
        case VLC_MSG_DBG:  level = LIBVLC_DEBUG;   break;
    }

77
    inst->log.cb (inst->log.data, level, item, fmt, ap);
78 79
}

80
void libvlc_log_unset (libvlc_instance_t *inst)
81
{
82
    vlc_LogSet (inst->p_libvlc_int, NULL, NULL);
83 84
}

85
void libvlc_log_set (libvlc_instance_t *inst, libvlc_log_cb cb, void *data)
86
{
87 88 89 90
    libvlc_log_unset (inst); /* <- Barrier before modifying the callback */
    inst->log.cb = cb;
    inst->log.data = data;
    vlc_LogSet (inst->p_libvlc_int, libvlc_logf, inst);
91
}
92

93
/*** Helpers for logging to files ***/
94 95
static void libvlc_log_file (void *data, int level, const libvlc_log_t *log,
                             const char *fmt, va_list ap)
96 97 98 99 100 101 102
{
    FILE *stream = data;

    flockfile (stream);
    vfprintf (stream, fmt, ap);
    fputc ('\n', stream);
    funlockfile (stream);
103
    (void) level; (void) log;
104 105
}

106
void libvlc_log_set_file (libvlc_instance_t *inst, FILE *stream)
107
{
108
    libvlc_log_set (inst, libvlc_log_file, stream);
109 110 111
}

/*** Stubs for the old interface ***/
112
unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance )
113
{
114 115
    (void) p_instance;
    return -1;
116 117
}

118
void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level )
119
{
120 121
    (void) p_instance;
    (void) level;
122 123
}

124
libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance )
125
{
126 127
    (void) p_instance;
    return malloc(1);
128 129
}

130
void libvlc_log_close( libvlc_log_t *p_log )
131
{
132
    free(p_log);
133 134
}

135
unsigned libvlc_log_count( const libvlc_log_t *p_log )
136
{
137 138
    (void) p_log;
    return 0;
139 140
}

141
void libvlc_log_clear( libvlc_log_t *p_log )
142
{
143
    (void) p_log;
144 145
}

146
libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log )
147
{
148
    return (p_log != NULL) ? malloc(1) : NULL;
149 150
}

151
void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter )
152
{
153
    free( p_iter );
154 155
}

156
int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter )
157
{
158 159
    (void) p_iter;
    return 0;
160 161 162
}

libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter,
163
                                                libvlc_log_message_t *buffer )
164
{
165
    (void) p_iter; (void) buffer;
166
    return NULL;
167
}