Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_error.c
1 #include "ecore_xcb_private.h"
2 #include <xcb/xcb_event.h>
3
4 /* local variables */
5 static void (*_error_func)(void *data) = NULL;
6 static void *_error_data = NULL;
7 static void (*_io_error_func)(void *data) = NULL;
8 static void *_io_error_data = NULL;
9 static int _error_request_code = 0;
10 static int _error_code = 0;
11 static Ecore_X_ID _error_resource_id = 0;
12
13 /**
14  * Set the error handler.
15  * @param func The error handler function
16  * @param data The data to be passed to the handler function
17  *
18  * Set the X error handler function
19  */
20 EAPI void
21 ecore_x_error_handler_set(void        (*func)(void *data),
22                           const void *data)
23 {
24    _error_func = func;
25    _error_data = (void *)data;
26 }
27
28 /**
29  * Set the I/O error handler.
30  * @param func The I/O error handler function
31  * @param data The data to be passed to the handler function
32  *
33  * Set the X I/O error handler function
34  */
35 EAPI void
36 ecore_x_io_error_handler_set(void        (*func)(void *data),
37                              const void *data)
38 {
39    _io_error_func = func;
40    _io_error_data = (void *)data;
41 }
42
43 /**
44  * Get the request code that caused the error.
45  * @return The request code causing the X error
46  *
47  * Return the X request code that caused the last X error
48  */
49 EAPI int
50 ecore_x_error_request_get(void)
51 {
52    return _error_request_code;
53 }
54
55 /**
56  * Get the error code from the error.
57  * @return The error code from the X error
58  *
59  * Return the error code from the last X error
60  */
61 EAPI int
62 ecore_x_error_code_get(void)
63 {
64    return _error_code;
65 }
66
67 /**
68  * Get the resource id that caused the error.
69  * @return The resource id causing the X error
70  *
71  * Return the X resource id that caused the last X error
72  */
73 EAPI Ecore_X_ID
74 ecore_x_error_resource_id_get(void)
75 {
76    return _error_resource_id;
77 }
78
79 int
80 _ecore_xcb_error_handle(xcb_generic_error_t *err)
81 {
82    WRN("Got Error:");
83    WRN("\tEvent: %s", xcb_event_get_request_label(err->major_code));
84    WRN("\tError: %s", xcb_event_get_error_label(err->error_code));
85
86 #ifdef OLD_XCB_VERSION
87    if (err->error_code == XCB_EVENT_ERROR_BAD_VALUE)
88      WRN("\tBad Value: %d", ((xcb_value_error_t *)err)->bad_value);
89    else if (err->error_code == XCB_EVENT_ERROR_BAD_WINDOW)
90      WRN("\tBad Window: %d", ((xcb_window_error_t *)err)->bad_value);
91 #else
92    if (err->error_code == XCB_VALUE)
93      WRN("\tBad Value: %d", ((xcb_value_error_t *)err)->bad_value);
94    else if (err->error_code == XCB_WINDOW)
95      WRN("\tBad Window: %d", ((xcb_window_error_t *)err)->bad_value);
96 #endif
97
98    _error_request_code = err->sequence;
99    _error_code = err->error_code;
100    _error_resource_id = err->resource_id;
101    if (_error_func)
102      _error_func(_error_data);
103
104    return 0;
105 }
106
107 int
108 _ecore_xcb_io_error_handle(xcb_generic_error_t *err)
109 {
110    CRIT("IO Error:");
111    if (err)
112      {
113         CRIT("\tRequest: %d", err->sequence);
114         CRIT("\tCode: %d", err->error_code);
115      }
116    if (_io_error_func)
117      _io_error_func(_io_error_data);
118    else
119      exit(-1);
120
121    return 0;
122 }
123