bc1d575dd02cdb0d57dda6956b7adcb0e14f293c
[openjpeg.git] / src / lib / openjp2 / event.h
1 /*
2  * Copyright (c) 2005, Herve Drolon, FreeImage Team
3  * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France 
4  * Copyright (c) 2012, CS Systemes d'Information, France
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef __EVENT_H
29 #define __EVENT_H
30 /**
31 @file event.h
32 @brief Implementation of a event callback system
33
34 The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user.
35 */
36 /**
37 Message handler object
38 used for 
39 <ul>
40 <li>Error messages
41 <li>Warning messages
42 <li>Debugging messages
43 </ul>
44 */
45 typedef struct opj_event_mgr 
46 {
47         /** Data to call the event manager upon */
48         void *                  m_error_data;
49         /** Data to call the event manager upon */
50         void *                  m_warning_data;
51         /** Data to call the event manager upon */
52         void *                  m_info_data;
53         /** Error message callback if available, NULL otherwise */
54         opj_msg_callback error_handler;
55         /** Warning message callback if available, NULL otherwise */
56         opj_msg_callback warning_handler;
57         /** Debug message callback if available, NULL otherwise */
58         opj_msg_callback info_handler;
59 } opj_event_mgr_t;
60
61
62 #define EVT_ERROR       1       /**< Error event type */
63 #define EVT_WARNING     2       /**< Warning event type */
64 #define EVT_INFO        4       /**< Debug event type */
65
66 /** @defgroup EVENT EVENT - Implementation of a event callback system */
67 /*@{*/
68
69 /** @name Exported functions (see also openjpeg.h) */
70 /*@{*/
71 /* ----------------------------------------------------------------------- */
72
73
74 /* ----------------------------------------------------------------------- */
75
76 /**
77  * Write formatted data to a string and send the string to a user callback.
78  *
79  * @param event_mgr                     Event handler
80  * @param event_type            Event type or callback to use to send the message
81  * @param fmt                           Format-control string (plus optional arguments)
82  *
83  * @return Returns true if successful, returns false otherwise
84  */
85 OPJ_BOOL opj_event_msg(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...);
86 /* ----------------------------------------------------------------------- */
87
88 /**
89  * Set the event manager with the default callback function for the 3 levels.
90  */
91 void opj_set_default_event_handler(opj_event_mgr_t * p_manager);
92
93 /*@}*/
94
95 /*@}*/
96
97 #endif /* __EVENT_H */