]> git.sesse.net Git - vlc/blob - include/vlc_messages.h
* Strings review in include/
[vlc] / include / vlc_messages.h
1 /*****************************************************************************
2  * messages.h: messages interface
3  * This library provides basic functions for threads to interact with user
4  * interface, such as message output.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
7  * $Id: vlc_messages.h,v 1.11 2004/01/25 18:17:08 zorglub Exp $
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *          Samuel Hocevar <sam@zoy.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 #include <stdarg.h>
28 /**
29  * \defgroup messages Messages
30  * This library provides basic functions for threads to interact with user
31  * interface, such as message output.
32  *
33  * @{
34  */
35
36
37 /**
38  * Store a single message.
39  */
40 typedef struct
41 {
42     int     i_type;                             /**< message type, see below */
43     int     i_object_id;
44     int     i_object_type;
45     char *  psz_module;
46     char *  psz_msg;                                 /**< the message itself */
47
48 #if 0
49     mtime_t date;                                     /* date of the message */
50     char *  psz_file;               /* file in which the function was called */
51     char *  psz_function;     /* function from which the function was called */
52     int     i_line;                 /* line at which the function was called */
53 #endif
54 } msg_item_t;
55
56 /* Message types */
57 /** standard messages */
58 #define VLC_MSG_INFO  0
59 /** error messages */
60 #define VLC_MSG_ERR   1
61 /** warning messages */
62 #define VLC_MSG_WARN  2
63 /** debug messages */
64 #define VLC_MSG_DBG   3
65
66 /**
67  * Store all data requiered by messages interfaces.
68  */
69 struct msg_bank_t
70 {
71     /** Message queue lock */
72     vlc_mutex_t             lock;
73     vlc_bool_t              b_configured;
74     vlc_bool_t              b_overflow;
75
76     /* Message queue */
77     msg_item_t              msg[VLC_MSG_QSIZE];           /**< message queue */
78     int i_start;
79     int i_stop;
80
81     /* Subscribers */
82     int i_sub;
83     msg_subscription_t **pp_sub;
84
85     /* Logfile for WinCE */
86 #ifdef UNDER_CE
87     FILE *logfile;
88 #endif
89 };
90
91 /**
92  * Used by interface plugins which subscribe to the message bank.
93  */
94 struct msg_subscription_t
95 {
96     int   i_start;
97     int*  pi_stop;
98
99     msg_item_t*  p_msg;
100     vlc_mutex_t* p_lock;
101 };
102
103 /*****************************************************************************
104  * Prototypes
105  *****************************************************************************/
106 VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 4, 5 ) );
107 VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, const char *, const char *, va_list args ) );
108 VLC_EXPORT( void, __msg_Info,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
109 VLC_EXPORT( void, __msg_Err,     ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
110 VLC_EXPORT( void, __msg_Warn,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
111 VLC_EXPORT( void, __msg_Dbg,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
112
113 #ifdef HAVE_VARIADIC_MACROS
114
115 #   define msg_Info( p_this, psz_format, args... ) \
116       __msg_Generic( VLC_OBJECT(p_this), VLC_MSG_INFO, MODULE_STRING, \
117                      psz_format, ## args )
118
119 #   define msg_Err( p_this, psz_format, args... ) \
120       __msg_Generic( VLC_OBJECT(p_this), VLC_MSG_ERR, MODULE_STRING, \
121                      psz_format, ## args )
122
123 #   define msg_Warn( p_this, psz_format, args... ) \
124       __msg_Generic( VLC_OBJECT(p_this), VLC_MSG_WARN, MODULE_STRING, \
125                      psz_format, ## args )
126
127 #   define msg_Dbg( p_this, psz_format, args... ) \
128       __msg_Generic( VLC_OBJECT(p_this), VLC_MSG_DBG, MODULE_STRING, \
129                      psz_format, ## args )
130
131 #elif defined(_MSC_VER) /* To avoid warnings and even errors with c++ files */
132
133 inline void msg_Info( void *p_this, const char *psz_format, ... )
134 {
135   va_list ap;
136   va_start( ap, psz_format );
137   __msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_INFO, MODULE_STRING,
138                    psz_format, ap );
139   va_end(ap);
140 }
141 inline void msg_Err( void *p_this, const char *psz_format, ... )
142 {
143   va_list ap;
144   va_start( ap, psz_format );
145   __msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_ERR, MODULE_STRING,
146                    psz_format, ap );
147   va_end(ap);
148 }
149 inline void msg_Warn( void *p_this, const char *psz_format, ... )
150 {
151   va_list ap;
152   va_start( ap, psz_format );
153   __msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_WARN, MODULE_STRING,
154                    psz_format, ap );
155   va_end(ap);
156 }
157 inline void msg_Dbg( void *p_this, const char *psz_format, ... )
158 {
159   va_list ap;
160   va_start( ap, psz_format );
161   __msg_GenericVa( ( vlc_object_t *)p_this, VLC_MSG_DBG, MODULE_STRING,
162                    psz_format, ap );
163   va_end(ap);
164 }
165
166 #else /* _MSC_VER */
167
168 #   define msg_Info __msg_Info
169 #   define msg_Err __msg_Err
170 #   define msg_Warn __msg_Warn
171 #   define msg_Dbg __msg_Dbg
172
173 #endif /* HAVE_VARIADIC_MACROS */
174
175 #define msg_Create(a) __msg_Create(VLC_OBJECT(a))
176 #define msg_Flush(a) __msg_Flush(VLC_OBJECT(a))
177 #define msg_Destroy(a) __msg_Destroy(VLC_OBJECT(a))
178 void __msg_Create  ( vlc_object_t * );
179 void __msg_Flush   ( vlc_object_t * );
180 void __msg_Destroy ( vlc_object_t * );
181
182 #define msg_Subscribe(a) __msg_Subscribe(VLC_OBJECT(a))
183 #define msg_Unsubscribe(a,b) __msg_Unsubscribe(VLC_OBJECT(a),b)
184 VLC_EXPORT( msg_subscription_t*, __msg_Subscribe, ( vlc_object_t * ) );
185 VLC_EXPORT( void, __msg_Unsubscribe, ( vlc_object_t *, msg_subscription_t * ) );
186
187
188 /**
189  * @}
190  */