remove deprecated v1 style function j2k_add_mhmarker; rename j2k_add_mhmarker_v2...
[openjpeg.git] / libopenjpeg / event.c
index 77cec8931b0addeb51adc53ca7f48569ccb91595..a9ef528482fe66c4596c626c7354116b24d0e3d6 100644 (file)
@@ -60,19 +60,15 @@ _itoa(int i, char *a, int r) {
 
 #endif /* !_WIN32 */
 #endif
-/* ----------------------------------------------------------------------- */
-
-opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
-       if(cinfo) {
-               opj_event_mgr_t *previous = cinfo->event_mgr;
-               cinfo->event_mgr = event_mgr;
-               cinfo->client_data = context;
-               return previous;
-       }
 
-       return NULL;
-}
+/* ----------------------------------------------------------------------- */
+/**
+ * Default callback function.
+ * Do nothing.
+ */
+static void opj_default_callback (const char *msg, void *client_data){};
 
+/* ----------------------------------------------------------------------- */
 opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
        opj_msg_callback msg_handler = NULL;
@@ -120,32 +116,37 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ..
        return OPJ_TRUE;
 }
 
-opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...) {
+/* ----------------------------------------------------------------------- */
+opj_bool opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_type, const char *fmt, ...) {
 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
-       opj_msg_callback msg_handler = NULL;
+       opj_msg_callback msg_handler = 00;
+       void * l_data = 00;
 
-       if(event_mgr != NULL) {
+       if(p_event_mgr != 00) {
                switch(event_type) {
                        case EVT_ERROR:
-                               msg_handler = event_mgr->error_handler;
+                               msg_handler = p_event_mgr->error_handler;
+                               l_data = p_event_mgr->m_error_data;
                                break;
                        case EVT_WARNING:
-                               msg_handler = event_mgr->warning_handler;
+                               msg_handler = p_event_mgr->warning_handler;
+                               l_data = p_event_mgr->m_warning_data;
                                break;
                        case EVT_INFO:
-                               msg_handler = event_mgr->info_handler;
+                               msg_handler = p_event_mgr->info_handler;
+                               l_data = p_event_mgr->m_info_data;
                                break;
                        default:
                                break;
                }
-               if(msg_handler == NULL) {
+               if(msg_handler == 00) {
                        return OPJ_FALSE;
                }
        } else {
                return OPJ_FALSE;
        }
 
-       if ((fmt != NULL) && (event_mgr != NULL)) {
+       if ((fmt != 00) && (p_event_mgr != 00)) {
                va_list arg;
                int str_length/*, i, j*/; /* UniPG */
                char message[MSG_SIZE];
@@ -160,8 +161,19 @@ opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char
                va_end(arg);
 
                /* output the message to the user program */
-               msg_handler(message, event_mgr->client_data);
+               msg_handler(message, l_data);
        }
 
        return OPJ_TRUE;
 }
+
+void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
+{
+       p_manager->m_error_data = 00;
+       p_manager->m_warning_data = 00;
+       p_manager->m_info_data = 00;
+       p_manager->error_handler = opj_default_callback;
+       p_manager->info_handler = opj_default_callback;
+       p_manager->warning_handler = opj_default_callback;
+}
+