1 /*****************************************************************************
2 * log.c: libvlc new API log functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
8 * Authors: Damien Fouilleul <damienf@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
30 const libvlc_instance_t *p_instance;
31 msg_subscription_t *p_messages;
34 struct libvlc_log_iterator_t
36 msg_subscription_t *p_messages;
42 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
46 return p_instance->p_libvlc_int->i_verbose;
48 RAISEZERO("Invalid VLC instance!");
51 void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level, libvlc_exception_t *p_e )
55 p_instance->p_libvlc_int->i_verbose = level;
58 RAISEVOID("Invalid VLC instance!");
61 libvlc_log_t *libvlc_log_open( const libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
64 struct libvlc_log_t *p_log =
65 (struct libvlc_log_t *)malloc(sizeof(struct libvlc_log_t));
67 if( !p_log ) RAISENULL( "Out of memory" );
69 p_log->p_instance = p_instance;
70 p_log->p_messages = msg_Subscribe(p_instance->p_libvlc_int, MSG_QUEUE_NORMAL);
72 if( !p_log->p_messages ) RAISENULL( "Out of memory" );
77 void libvlc_log_close( libvlc_log_t *p_log, libvlc_exception_t *p_e )
79 if( p_log && p_log->p_messages )
81 msg_Unsubscribe(p_log->p_instance->p_libvlc_int, p_log->p_messages);
85 RAISEVOID("Invalid log object!");
88 unsigned libvlc_log_count( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
90 if( p_log && p_log->p_messages )
92 int i_start = p_log->p_messages->i_start;
93 int i_stop = *(p_log->p_messages->pi_stop);
95 if( i_stop >= i_start )
96 return i_stop-i_start;
98 return VLC_MSG_QSIZE-(i_start-i_stop);
100 RAISEZERO("Invalid log object!");
103 void libvlc_log_clear( libvlc_log_t *p_log, libvlc_exception_t *p_e )
105 if( p_log && p_log->p_messages )
107 vlc_mutex_lock(p_log->p_messages->p_lock);
108 p_log->p_messages->i_start = *(p_log->p_messages->pi_stop);
109 vlc_mutex_unlock(p_log->p_messages->p_lock);
112 RAISEVOID("Invalid log object!");
115 libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
117 if( p_log && p_log->p_messages )
119 struct libvlc_log_iterator_t *p_iter =
120 (struct libvlc_log_iterator_t *)malloc(sizeof(struct libvlc_log_iterator_t));
122 if( !p_iter ) RAISENULL( "Out of memory" );
124 vlc_mutex_lock(p_log->p_messages->p_lock);
125 p_iter->p_messages = p_log->p_messages;
126 p_iter->i_start = p_log->p_messages->i_start;
127 p_iter->i_pos = p_log->p_messages->i_start;
128 p_iter->i_end = *(p_log->p_messages->pi_stop);
129 vlc_mutex_unlock(p_log->p_messages->p_lock);
133 RAISENULL("Invalid log object!");
136 void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
143 RAISEVOID("Invalid log iterator!");
146 int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
150 return p_iter->i_pos != p_iter->i_end;
152 RAISEZERO("Invalid log iterator!");
155 libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter,
156 struct libvlc_log_message_t *buffer,
157 libvlc_exception_t *p_e )
161 if( buffer && (sizeof(struct libvlc_log_message_t) == buffer->sizeof_msg) )
163 int i_pos = p_iter->i_pos;
164 if( i_pos != p_iter->i_end )
167 vlc_mutex_lock(p_iter->p_messages->p_lock);
168 msg = p_iter->p_messages->p_msg+i_pos;
169 buffer->i_severity = msg->i_type;
170 buffer->psz_type = msg_GetObjectTypeName(msg->i_object_type);
171 buffer->psz_name = msg->psz_module;
172 buffer->psz_header = msg->psz_header;
173 buffer->psz_message = msg->psz_msg;
174 p_iter->i_pos = ++i_pos % VLC_MSG_QSIZE;
175 vlc_mutex_unlock(p_iter->p_messages->p_lock);
179 RAISENULL("No more messages");
181 RAISENULL("Invalid message buffer!");
183 RAISENULL("Invalid log iterator!");