]> git.sesse.net Git - vlc/blob - include/intf_msg.h
58323fbe91a25e0d825b5e99f454488893daaeef
[vlc] / include / intf_msg.h
1 /*******************************************************************************
2  * intf_msg.h: messages interface
3  * (c)1999 VideoLAN
4  *******************************************************************************
5  * This library provides basic functions for threads to interact with user
6  * interface, such as message output. If INTF_MSG_QUEUE is defined (which is the
7  * defaul), messages are not printed directly by threads, to bypass console 
8  * limitations and slow printf() calls, but sent to a queue and printed later by
9  * interface thread. 
10  * If INTF_MSG_QUEUE is not defined, output is directly performed on stderr.
11  *******************************************************************************
12  * required headers:
13  * "config.h"
14  * "mtime.h"
15  * "vlc_thread.h"
16  *******************************************************************************/
17
18 /*******************************************************************************
19  * interface_message_t                                             
20  *******************************************************************************
21  * Store a single message. Messages have a maximal size of INTF_MSG_MSGSIZE.
22  * If DEBUG is defined, messages have a date field and debug messages are
23  * printed with a date to allow more precise profiling.
24  *******************************************************************************/
25 typedef struct
26 {
27     int     i_type;                                 /* message type, see below */
28     char *  psz_msg;                                     /* the message itself */
29
30 #ifdef DEBUG
31     /* Debugging informations - in DEBUG mode, all messages are dated and debug
32      * messages have calling location informations printed */
33     mtime_t date;                        /* date of the message (all messages) */
34     char *  psz_file;                 /* file in which the function was called */
35     char *  psz_function;       /* function from which the function was called */
36     int     i_line;                   /* line at which the function was called */
37 #endif
38 } interface_msg_message_t;
39
40 /* Message types */
41 #define INTF_MSG_STD    0                                  /* standard message */
42 #define INTF_MSG_ERR    1                                     /* error message */
43 #define INTF_MSG_INTF   2                                 /* interface message */
44 #define INTF_MSG_DBG    3                                     /* debug message */
45
46 /*******************************************************************************
47  * interface_msg_t                                                    
48  *******************************************************************************
49  * Store all data requiered by messages interfaces. It has a singe instance in
50  * program_data.
51  *******************************************************************************/
52 typedef struct
53 {
54 #ifdef INTF_MSG_QUEUE
55     /* Message queue */
56     vlc_mutex_t             lock;                        /* message queue lock */
57     int                     i_count;              /* number of messages stored */
58     interface_msg_message_t msg[INTF_MSG_QSIZE];              /* message queue */
59 #endif
60
61 #ifdef DEBUG_LOG
62     /* Log file */
63     FILE *                  p_log_file;                            /* log file */
64 #endif
65
66 #ifndef INTF_MSG_QUEUE
67 #ifndef DEBUG_LOG
68     /* If neither messages queue, neither log file is used, then the structure
69      * is empty. However, empty structures are not allowed in C. Therefore, a
70      * dummy integer is used to fill it. */
71     int                     i_dummy;                          /* unused filler */
72 #endif
73 #endif
74 } interface_msg_t;
75
76 /*******************************************************************************
77  * intf_DbgMsg macros and functions
78  *******************************************************************************
79  * The intf_DbgMsg* functions are defined as macro to be able to use the 
80  * compiler extensions and print the file, the function and the line number
81  * from which they have been called. They call _intf_DbgMsg*() functions after
82  * having added debugging informations.
83  * Outside DEBUG mode, intf_DbgMsg* functions do nothing.
84  *******************************************************************************/
85 #ifdef DEBUG
86
87 /* DEBUG mode */
88 void    _intf_DbgMsg        ( char *psz_file, char *psz_function, int i_line, 
89                               char *psz_format, ... );
90 void    _intf_DbgMsgImm     ( char *psz_file, char *psz_function, int i_line,
91                               char *psz_format, ... );
92
93 #define intf_DbgMsg( format, args... ) \
94     _intf_DbgMsg( __FILE__, __FUNCTION__, __LINE__, format, ## args )
95 #define intf_DbgMsgImm( format, args... ) \
96     _intf_DbgMsg( __FILE__, __FUNCTION__, __LINE__, format, ## args )
97
98 #else
99
100 /* Non-DEBUG mode */
101 #define intf_DbgMsg( format, args... )      
102 #define intf_DbgMsgImm( format, args...)    
103
104 #endif
105
106 /*******************************************************************************
107  * intf_FlushMsg macro and function
108  *******************************************************************************
109  * intf_FlushMsg is a function which flushs message queue and print all messages
110  * remaining. It is only usefull if INTF_MSG_QUEUE is defined. In this case, it
111  * is really a function. In the other case, it is a macro doing nothing.
112  *******************************************************************************/
113 #ifdef INTF_MSG_QUEUE
114
115 /* Message queue mode */
116 void    intf_FlushMsg       ( void );
117
118 #else
119
120 /* Direct mode */
121 #define intf_FlushMsg()     ;
122
123 #endif
124
125 /*******************************************************************************
126  * Prototypes                                                      
127  *******************************************************************************/
128 int     intf_InitMsg        ( interface_msg_t *p_intf_msg );
129 void    intf_TerminateMsg   ( interface_msg_t *p_intf_msg );
130
131 void    intf_Msg            ( char *psz_format, ... );
132 void    intf_ErrMsg         ( char *psz_format, ... );
133 void    intf_IntfMsg        ( char *psz_format, ... );
134
135 void    intf_MsgImm         ( char *psz_format, ... );
136 void    intf_ErrMsgImm      ( char *psz_format, ... );
137
138