diff options
Diffstat (limited to 'libraries/evas/src/lib/canvas/evas_async_events.c')
-rw-r--r-- | libraries/evas/src/lib/canvas/evas_async_events.c | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/libraries/evas/src/lib/canvas/evas_async_events.c b/libraries/evas/src/lib/canvas/evas_async_events.c deleted file mode 100644 index bd2e3a8..0000000 --- a/libraries/evas/src/lib/canvas/evas_async_events.c +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #ifdef BUILD_ASYNC_EVENTS | ||
6 | |||
7 | # ifndef _MSC_VER | ||
8 | # include <unistd.h> | ||
9 | # endif | ||
10 | # include <fcntl.h> | ||
11 | # include <errno.h> | ||
12 | |||
13 | #endif | ||
14 | |||
15 | #include "evas_common.h" | ||
16 | #include "evas_private.h" | ||
17 | |||
18 | #ifdef BUILD_ASYNC_EVENTS | ||
19 | |||
20 | static int _fd_write = -1; | ||
21 | static int _fd_read = -1; | ||
22 | |||
23 | static int _init_evas_event = 0; | ||
24 | |||
25 | typedef struct _Evas_Event_Async Evas_Event_Async; | ||
26 | |||
27 | struct _Evas_Event_Async | ||
28 | { | ||
29 | const void *target; | ||
30 | void *event_info; | ||
31 | Evas_Async_Events_Put_Cb func; | ||
32 | Evas_Callback_Type type; | ||
33 | }; | ||
34 | |||
35 | int | ||
36 | evas_async_events_init(void) | ||
37 | { | ||
38 | int filedes[2]; | ||
39 | |||
40 | _init_evas_event++; | ||
41 | if (_init_evas_event > 1) return _init_evas_event; | ||
42 | |||
43 | if (pipe(filedes) == -1) | ||
44 | { | ||
45 | _init_evas_event = 0; | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | _fd_read = filedes[0]; | ||
50 | _fd_write = filedes[1]; | ||
51 | |||
52 | fcntl(_fd_read, F_SETFL, O_NONBLOCK); | ||
53 | |||
54 | return _init_evas_event; | ||
55 | } | ||
56 | |||
57 | int | ||
58 | evas_async_events_shutdown(void) | ||
59 | { | ||
60 | _init_evas_event--; | ||
61 | if (_init_evas_event > 0) return _init_evas_event; | ||
62 | |||
63 | close(_fd_read); | ||
64 | close(_fd_write); | ||
65 | _fd_read = -1; | ||
66 | _fd_write = -1; | ||
67 | |||
68 | return _init_evas_event; | ||
69 | } | ||
70 | |||
71 | #endif | ||
72 | |||
73 | EAPI int | ||
74 | evas_async_events_fd_get(void) | ||
75 | { | ||
76 | #ifdef BUILD_ASYNC_EVENTS | ||
77 | return _fd_read; | ||
78 | #else | ||
79 | return -1; | ||
80 | #endif | ||
81 | } | ||
82 | |||
83 | EAPI int | ||
84 | evas_async_events_process(void) | ||
85 | { | ||
86 | #ifdef BUILD_ASYNC_EVENTS | ||
87 | Evas_Event_Async *ev; | ||
88 | int check; | ||
89 | int count = 0; | ||
90 | |||
91 | if (_fd_read == -1) return 0; | ||
92 | |||
93 | do | ||
94 | { | ||
95 | check = read(_fd_read, &ev, sizeof (Evas_Event_Async *)); | ||
96 | |||
97 | if (check == sizeof (Evas_Event_Async *)) | ||
98 | { | ||
99 | if (ev->func) ev->func((void *)ev->target, ev->type, ev->event_info); | ||
100 | free(ev); | ||
101 | count++; | ||
102 | } | ||
103 | } | ||
104 | while (check > 0); | ||
105 | |||
106 | evas_cache_image_wakeup(); | ||
107 | |||
108 | if (check < 0) | ||
109 | { | ||
110 | switch (errno) | ||
111 | { | ||
112 | case EBADF: | ||
113 | case EINVAL: | ||
114 | case EIO: | ||
115 | case EISDIR: | ||
116 | _fd_read = -1; | ||
117 | } | ||
118 | } | ||
119 | |||
120 | return count; | ||
121 | #else | ||
122 | return 0; | ||
123 | #endif | ||
124 | } | ||
125 | |||
126 | EAPI Eina_Bool | ||
127 | evas_async_events_put(const void *target, Evas_Callback_Type type, void *event_info, Evas_Async_Events_Put_Cb func) | ||
128 | { | ||
129 | #ifdef BUILD_ASYNC_EVENTS | ||
130 | Evas_Event_Async *ev; | ||
131 | ssize_t check; | ||
132 | Eina_Bool result = EINA_FALSE; | ||
133 | |||
134 | if (!func) return 0; | ||
135 | if (_fd_write == -1) return 0; | ||
136 | |||
137 | ev = calloc(1, sizeof (Evas_Event_Async)); | ||
138 | if (!ev) return 0; | ||
139 | |||
140 | ev->func = func; | ||
141 | ev->target = target; | ||
142 | ev->type = type; | ||
143 | ev->event_info = event_info; | ||
144 | |||
145 | do | ||
146 | { | ||
147 | check = write(_fd_write, &ev, sizeof (Evas_Event_Async*)); | ||
148 | } | ||
149 | while ((check != sizeof (Evas_Event_Async*)) && | ||
150 | ((errno == EINTR) || (errno == EAGAIN))); | ||
151 | |||
152 | evas_cache_image_wakeup(); | ||
153 | |||
154 | if (check == sizeof (Evas_Event_Async*)) | ||
155 | result = EINA_TRUE; | ||
156 | else | ||
157 | { | ||
158 | switch (errno) | ||
159 | { | ||
160 | case EBADF: | ||
161 | case EINVAL: | ||
162 | case EIO: | ||
163 | case EPIPE: | ||
164 | _fd_write = -1; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | return result; | ||
169 | #else | ||
170 | func((void*) target, type, event_info); | ||
171 | return EINA_TRUE; | ||
172 | #endif | ||
173 | } | ||