1 /*****************************************************************************
2 * log.c: libvlc new API log functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
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 "../libvlc.h"
27 #include <vlc/libvlc.h>
30 /* This API is terminally broken.
31 * First, it does not implement any kind of notification.
32 * Second, the iterating scheme is hermetic to any kind of thread-safety
33 * owing to its constant pointer constraints.
36 * "If you break your leg, don't run to me for sympathy"
37 * -- some character, Beneath a Steel Sky
43 msg_item_t *items[VLC_MSG_QSIZE];
47 static void handler( msg_cb_data_t *d, msg_item_t *p_item, unsigned i_drop )
49 vlc_spin_lock (&d->lock);
50 if (d->count < VLC_MSG_QSIZE)
52 d->items[d->count++] = p_item;
53 /* FIXME FIXME: yield the message item */
55 vlc_spin_unlock (&d->lock);
61 libvlc_instance_t *p_instance;
62 msg_subscription_t *p_messages;
66 struct libvlc_log_iterator_t
68 const msg_cb_data_t *p_data;
73 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
77 libvlc_priv_t *p_priv = libvlc_priv( p_instance->p_libvlc_int );
78 return p_priv->i_verbose;
80 RAISEZERO("Invalid VLC instance!");
83 void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level, libvlc_exception_t *p_e )
87 libvlc_priv_t *p_priv = libvlc_priv( p_instance->p_libvlc_int );
88 p_priv->i_verbose = level;
91 RAISEVOID("Invalid VLC instance!");
94 libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
96 struct libvlc_log_t *p_log =
97 (struct libvlc_log_t *)malloc(sizeof(struct libvlc_log_t));
99 if( !p_log ) RAISENULL( "Out of memory" );
101 p_log->p_instance = p_instance;
102 p_log->p_messages = msg_Subscribe(p_instance->p_libvlc_int, handler, &p_log->data);
104 if( !p_log->p_messages )
107 RAISENULL( "Out of memory" );
110 libvlc_retain( p_instance );
114 void libvlc_log_close( libvlc_log_t *p_log, libvlc_exception_t *p_e )
118 assert( p_log->p_messages );
119 msg_Unsubscribe(p_log->p_messages);
120 libvlc_release( p_log->p_instance );
124 RAISEVOID("Invalid log object!");
127 unsigned libvlc_log_count( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
133 /* We cannot lock due to pointer constraints.
134 * Even then, this would not be thread safe anyway. */
135 /*vlc_spin_lock (&p_log->data.lock);*/
136 ret = p_log->data.count;
137 /*vlc_spin_unlock (&p_log->data.lock);*/
140 RAISEZERO("Invalid log object!");
143 void libvlc_log_clear( libvlc_log_t *p_log, libvlc_exception_t *p_e )
147 /*vlc_spin_lock (&p_log->data.lock);*/
148 p_log->data.count = 0;
149 /* FIXME: release items */
150 /*vlc_spin_unlock (&p_log->data.lock);*/
153 RAISEVOID("Invalid log object!");
156 libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
160 struct libvlc_log_iterator_t *p_iter =
161 (struct libvlc_log_iterator_t *)malloc(sizeof(struct libvlc_log_iterator_t));
163 if( !p_iter ) RAISENULL( "Out of memory" );
165 /*vlc_spin_lock (&p_log->data.lock);*/
166 p_iter->p_data = &p_log->data;
168 p_iter->i_end = p_log->data.count;
169 /*vlc_spin_unlock (&p_log->data.lock);*/
173 RAISENULL("Invalid log object!");
176 void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
183 RAISEVOID("Invalid log iterator!");
186 int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
190 return p_iter->i_pos != p_iter->i_end;
192 RAISEZERO("Invalid log iterator!");
195 libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter,
196 libvlc_log_message_t *buffer,
197 libvlc_exception_t *p_e )
202 RAISENULL("Invalid log iterator!");
204 RAISENULL("Invalid message buffer!");
206 i_pos = p_iter->i_pos;
207 if( i_pos != p_iter->i_end )
210 /*vlc_spin_lock (&p_iter->p_data->lock);*/
211 msg = p_iter->p_data->items[i_pos];
212 buffer->i_severity = msg->i_type;
213 buffer->psz_type = msg->psz_object_type;
214 buffer->psz_name = msg->psz_module;
215 buffer->psz_header = msg->psz_header;
216 buffer->psz_message = msg->psz_msg;
217 /*vlc_spin_unlock (&p_iter->p_data->lock);*/
222 RAISENULL("No more messages");