]> git.sesse.net Git - vlc/blob - src/control/log.c
Disable crashy FS controller by default
[vlc] / src / control / log.c
1 /*****************************************************************************
2  * log.c: libvlc new API log functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * $Id$
7  *
8  * Authors: Damien Fouilleul <damienf@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "libvlc_internal.h"
26 #include "../libvlc.h"
27 #include <vlc/libvlc.h>
28
29 struct libvlc_log_t
30 {
31     libvlc_instance_t  *p_instance;
32     msg_subscription_t *p_messages;
33 };
34
35 struct libvlc_log_iterator_t
36 {
37     msg_subscription_t *p_messages;
38     int i_start;
39     int i_pos;
40     int i_end;
41 };
42
43 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
44 {
45     if( p_instance )
46     {
47         libvlc_priv_t *p_priv = libvlc_priv( p_instance->p_libvlc_int );
48         return p_priv->i_verbose;
49     }
50     RAISEZERO("Invalid VLC instance!");
51 }
52
53 void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level, libvlc_exception_t *p_e )
54 {
55     if( p_instance )
56     {
57         libvlc_priv_t *p_priv = libvlc_priv( p_instance->p_libvlc_int );
58         p_priv->i_verbose = level;
59     }
60     else
61         RAISEVOID("Invalid VLC instance!");
62 }
63
64 libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
65 {
66     struct libvlc_log_t *p_log =
67         (struct libvlc_log_t *)malloc(sizeof(struct libvlc_log_t));
68
69     if( !p_log ) RAISENULL( "Out of memory" );
70
71     p_log->p_instance = p_instance;
72     p_log->p_messages = msg_Subscribe(p_instance->p_libvlc_int);
73
74     if( !p_log->p_messages )
75     {
76         free( p_log );
77         RAISENULL( "Out of memory" );
78     }
79
80     libvlc_retain( p_instance );
81     return p_log;
82 }
83
84 void libvlc_log_close( libvlc_log_t *p_log, libvlc_exception_t *p_e )
85 {
86     if( p_log && p_log->p_messages )
87     {
88         msg_Unsubscribe(p_log->p_instance->p_libvlc_int, p_log->p_messages);
89         libvlc_release( p_log->p_instance );
90         free(p_log);
91     }
92     else
93         RAISEVOID("Invalid log object!");
94 }
95
96 unsigned libvlc_log_count( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
97 {
98     if( p_log && p_log->p_messages )
99     {
100         int i_start = p_log->p_messages->i_start;
101         int i_stop  = *(p_log->p_messages->pi_stop);
102
103         if( i_stop >= i_start )
104             return i_stop-i_start;
105         else
106             return VLC_MSG_QSIZE-(i_start-i_stop);
107     }
108     RAISEZERO("Invalid log object!");
109 }
110
111 void libvlc_log_clear( libvlc_log_t *p_log, libvlc_exception_t *p_e )
112 {
113     if( p_log && p_log->p_messages )
114     {
115         vlc_mutex_lock(p_log->p_messages->p_lock);
116         p_log->p_messages->i_start = *(p_log->p_messages->pi_stop);
117         vlc_mutex_unlock(p_log->p_messages->p_lock);
118     }
119     else
120         RAISEVOID("Invalid log object!");
121 }
122
123 libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log, libvlc_exception_t *p_e )
124 {
125     if( p_log && p_log->p_messages )
126     {
127         struct libvlc_log_iterator_t *p_iter =
128             (struct libvlc_log_iterator_t *)malloc(sizeof(struct libvlc_log_iterator_t));
129
130         if( !p_iter ) RAISENULL( "Out of memory" );
131
132         vlc_mutex_lock(p_log->p_messages->p_lock);
133         p_iter->p_messages = p_log->p_messages;
134         p_iter->i_start    = p_log->p_messages->i_start;
135         p_iter->i_pos      = p_log->p_messages->i_start;
136         p_iter->i_end      = *(p_log->p_messages->pi_stop);
137         vlc_mutex_unlock(p_log->p_messages->p_lock);
138
139         return p_iter;
140     }
141     RAISENULL("Invalid log object!");
142 }
143
144 void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
145 {
146     if( p_iter )
147     {
148         free(p_iter);
149     }
150     else
151         RAISEVOID("Invalid log iterator!");
152 }
153
154 int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter, libvlc_exception_t *p_e )
155 {
156     if( p_iter )
157     {
158         return p_iter->i_pos != p_iter->i_end;
159     }
160     RAISEZERO("Invalid log iterator!");
161 }
162
163 libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter,
164                                                 libvlc_log_message_t *buffer,
165                                                 libvlc_exception_t *p_e )
166 {
167     int i_pos;
168
169     if( !p_iter )
170         RAISENULL("Invalid log iterator!");
171     if( !buffer )
172         RAISENULL("Invalid message buffer!");
173
174     i_pos = p_iter->i_pos;
175     if( i_pos != p_iter->i_end )
176     {
177         msg_item_t *msg;
178         vlc_mutex_lock(p_iter->p_messages->p_lock);
179         msg = p_iter->p_messages->p_msg+i_pos;
180         buffer->i_severity  = msg->i_type;
181         buffer->psz_type    = msg->psz_object_type;
182         buffer->psz_name    = msg->psz_module;
183         buffer->psz_header  = msg->psz_header;
184         buffer->psz_message = msg->psz_msg;
185         p_iter->i_pos = ++i_pos % VLC_MSG_QSIZE;
186         vlc_mutex_unlock(p_iter->p_messages->p_lock);
187
188         return buffer;
189     }
190     RAISENULL("No more messages");
191 }
192