Initialize Tizen 2.3
[apps/livebox/livebox-edje.git] / src / abi.c
1 #define _GNU_SOURCE
2
3 #include <stdio.h>
4 #include <dlfcn.h>
5
6 #include <dlog.h>
7 #include <livebox-errno.h>
8
9 #include "debug.h"
10 #include "abi.h"
11
12 int script_buffer_load(void *handle)
13 {
14         static int (*load)(void *handle) = NULL;
15         if (!load) {
16                 load = dlsym(RTLD_DEFAULT, "buffer_handler_load");
17                 if (!load) {
18                         ErrPrint("broken ABI: %s\n", dlerror());
19                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
20                 }
21         }
22
23         return load(handle);
24 }
25
26 int script_buffer_unload(void *handle)
27 {
28         static int (*unload)(void *handle) = NULL;
29
30         if (!unload) {
31                 unload = dlsym(RTLD_DEFAULT, "buffer_handler_unload");
32                 if (!unload) {
33                         ErrPrint("broken ABI: %s\n", dlerror());
34                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
35                 }
36         }
37
38         return unload(handle);
39 }
40
41 int script_buffer_is_loaded(const void *handle)
42 {
43         static int (*is_loaded)(const void *handle) = NULL;
44
45         if (!is_loaded) {
46                 is_loaded = dlsym(RTLD_DEFAULT, "buffer_handler_is_loaded");
47                 if (!is_loaded) {
48                         ErrPrint("broken ABI: %s\n", dlerror());
49                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
50                 }
51         }
52
53         return is_loaded(handle);
54 }
55
56 int script_buffer_resize(void *handle, int w, int h)
57 {
58         static int (*resize)(void *handle, int w, int h) = NULL;
59
60         if (!resize) {
61                 resize = dlsym(RTLD_DEFAULT, "buffer_handler_resize");
62                 if (!resize) {
63                         ErrPrint("broken ABI: %s\n", dlerror());
64                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
65                 }
66         }
67
68         return resize(handle, w, h);
69 }
70
71 void script_buffer_update_size(void *handle, int w, int h)
72 {
73         static void (*update_size)(void *handle, int w, int h) = NULL;
74
75         if (!update_size) {
76                 update_size = dlsym(RTLD_DEFAULT, "buffer_handler_update_size");
77                 if (!update_size) {
78                         ErrPrint("broken ABI: %s\n", dlerror());
79                         return;
80                 }
81         }
82
83         return update_size(handle, w, h);       /*! "void" function can be used with "return" statement */
84 }
85
86 const char *script_buffer_id(const void *handle)
87 {
88         static const char *(*buffer_id)(const void *handle) = NULL;
89
90         if (!buffer_id) {
91                 buffer_id = dlsym(RTLD_DEFAULT, "buffer_handler_id");
92                 if (!buffer_id) {
93                         ErrPrint("broken ABI: %s\n", dlerror());
94                         return NULL;
95                 }
96         }
97
98         return buffer_id(handle);
99 }
100
101 enum buffer_type script_buffer_type(const void *handle)
102 {
103         static enum buffer_type (*buffer_type)(const void *handle) = NULL;
104
105         if (!buffer_type) {
106                 buffer_type = dlsym(RTLD_DEFAULT, "buffer_handler_type");
107                 if (!buffer_type) {
108                         ErrPrint("broken ABI: %s\n", dlerror());
109                         return BUFFER_TYPE_ERROR;
110                 }
111         }
112
113         return buffer_type(handle);
114 }
115
116 int script_buffer_pixmap(const void *handle)
117 {
118         static int (*buffer_pixmap)(const void *handle) = NULL;
119
120         if (!buffer_pixmap) {
121                 buffer_pixmap = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap");
122                 if (!buffer_pixmap) {
123                         ErrPrint("broken ABI: %s\n", dlerror());
124                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
125                 }
126         }
127
128         return buffer_pixmap(handle);
129 }
130
131 void *script_buffer_pixmap_acquire_buffer(void *handle)
132 {
133         static void *(*pixmap_acquire_buffer)(void *handle) = NULL;
134
135         if (!pixmap_acquire_buffer) {
136                 pixmap_acquire_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_acquire_buffer");
137                 if (!pixmap_acquire_buffer) {
138                         ErrPrint("broken ABI: %s\n", dlerror());
139                         return NULL;
140                 }
141         }
142
143         return pixmap_acquire_buffer(handle);
144 }
145
146 int script_buffer_pixmap_release_buffer(void *canvas)
147 {
148         static int (*pixmap_release_buffer)(void *canvas) = NULL;
149
150         if (!pixmap_release_buffer) {
151                 pixmap_release_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_release_buffer");
152                 if (!pixmap_release_buffer) {
153                         ErrPrint("broekn ABI: %s\n", dlerror());
154                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
155                 }
156         }
157
158         return pixmap_release_buffer(canvas);
159 }
160
161 void *script_buffer_pixmap_ref(void *handle)
162 {
163         static void *(*pixmap_ref)(void *handle) = NULL;
164
165         if (!pixmap_ref) {
166                 pixmap_ref = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_ref");
167                 if (!pixmap_ref) {
168                         ErrPrint("broken ABI: %s\n", dlerror());
169                         return NULL;
170                 }
171         }
172
173         return pixmap_ref(handle);
174 }
175
176 int script_buffer_pixmap_unref(void *buffer_ptr)
177 {
178         static int (*pixmap_unref)(void *ptr) = NULL;
179
180         if (!pixmap_unref) {
181                 pixmap_unref = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_unref");
182                 if (!pixmap_unref) {
183                         ErrPrint("broken ABI: %s\n", dlerror());
184                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
185                 }
186         }
187
188         return pixmap_unref(buffer_ptr);
189 }
190
191 void *script_buffer_pixmap_find(int pixmap)
192 {
193         static void *(*pixmap_find)(int pixmap) = NULL;
194
195         if (!pixmap_find) {
196                 pixmap_find = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_find");
197                 if (!pixmap_find) {
198                         ErrPrint("broken ABI: %s\n", dlerror());
199                         return NULL;
200                 }
201         }
202
203         return pixmap_find(pixmap);
204 }
205
206 void *script_buffer_pixmap_buffer(void *handle)
207 {
208         static void *(*pixmap_buffer)(void *handle) = NULL;
209
210         if (!pixmap_buffer) {
211                 pixmap_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_buffer");
212                 if (!pixmap_buffer) {
213                         ErrPrint("broken ABI: %s\n", dlerror());
214                         return NULL;
215                 }
216         }
217
218         return pixmap_buffer(handle);
219 }
220
221 void *script_buffer_fb(void *handle)
222 {
223         static void *(*buffer_fb)(void *handle) = NULL;
224
225         if (!buffer_fb) {
226                 buffer_fb = dlsym(RTLD_DEFAULT, "buffer_handler_fb");
227                 if (!buffer_fb) {
228                         ErrPrint("broken ABI: %s\n", dlerror());
229                         return NULL;
230                 }
231         }
232
233         return buffer_fb(handle);
234 }
235
236 int script_buffer_get_size(void *handle, int *w, int *h)
237 {
238         static int (*get_size)(void *handle, int *w, int *h) = NULL;
239
240         if (!get_size) {
241                 get_size = dlsym(RTLD_DEFAULT, "buffer_handler_get_size");
242                 if (!get_size) {
243                         ErrPrint("broken ABI: %s\n", dlerror());
244                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
245                 }
246         }
247
248         return get_size(handle, w, h);
249 }
250
251 void script_buffer_flush(void *handle)
252 {
253         static void (*buffer_flush)(void *handle) = NULL;
254
255         if (!buffer_flush) {
256                 buffer_flush = dlsym(RTLD_DEFAULT, "buffer_handler_flush");
257                 if (!buffer_flush) {
258                         ErrPrint("broken ABI: %s\n", dlerror());
259                         return;
260                 }
261         }
262
263         return buffer_flush(handle);    /* "void" function can be used to return from this function ;) */
264 }
265
266 void *script_buffer_instance(void *handle)
267 {
268         static void *(*buffer_instance)(void *handle) = NULL;
269
270         if (!buffer_instance) {
271                 buffer_instance = dlsym(RTLD_DEFAULT, "buffer_handler_instance");
272                 if (!buffer_instance) {
273                         ErrPrint("broken ABI: %s\n", dlerror());
274                         return NULL;
275                 }
276         }
277
278         return buffer_instance(handle);
279 }
280
281 void *script_buffer_raw_open(enum buffer_type type, void *resource)
282 {
283         static void *(*raw_open)(enum buffer_type type, void *resource) = NULL;
284
285         if (!raw_open) {
286                 raw_open = dlsym(RTLD_DEFAULT, "buffer_handler_raw_open");
287                 if (!raw_open) {
288                         ErrPrint("broken ABI: %s\n", dlerror());
289                         return NULL;
290                 }
291         }
292
293         return raw_open(type, resource);
294 }
295
296 int script_buffer_raw_close(void *buffer)
297 {
298         static int (*raw_close)(void *buffer) = NULL;
299
300         if (!raw_close) {
301                 raw_close = dlsym(RTLD_DEFAULT, "buffer_handler_raw_close");
302                 if (!raw_close) {
303                         ErrPrint("broken ABI: %s\n", dlerror());
304                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
305                 }
306         }
307
308         return raw_close(buffer);
309 }
310
311 void *script_buffer_raw_data(void *buffer)
312 {
313         static void *(*raw_data)(void *buffer) = NULL;
314
315         if (!raw_data) {
316                 raw_data = dlsym(RTLD_DEFAULT, "buffer_handler_raw_data");
317                 if (!raw_data) {
318                         ErrPrint("broken ABI: %s\n", dlerror());
319                         return NULL;
320                 }
321         }
322
323         return raw_data(buffer);
324 }
325
326 int script_buffer_raw_size(void *buffer)
327 {
328         static int (*raw_size)(void *buffer) = NULL;
329
330         if (!raw_size) {
331                 raw_size = dlsym(RTLD_DEFAULT, "buffer_handler_raw_size");
332                 if (!raw_size) {
333                         ErrPrint("broken ABI: %s\n", dlerror());
334                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
335                 }
336         }
337
338         return raw_size(buffer);
339 }
340
341 int script_buffer_lock(void *handle)
342 {
343         static int (*buffer_lock)(void *handle) = NULL; 
344
345         if (!buffer_lock) {
346                 buffer_lock = dlsym(RTLD_DEFAULT, "buffer_handler_lock");
347                 if (!buffer_lock) {
348                         ErrPrint("broken ABI: %s\n", dlerror());
349                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
350                 }
351         }
352
353         return buffer_lock(handle);
354 }
355
356 int script_buffer_unlock(void *handle)
357 {
358         static int (*buffer_unlock)(void *handle) = NULL;
359
360         if (!buffer_unlock) {
361                 buffer_unlock = dlsym(RTLD_DEFAULT, "buffer_handler_unlock");
362                 if (!buffer_unlock) {
363                         ErrPrint("broken ABI: %s\n", dlerror());
364                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
365                 }
366         }
367
368         return buffer_unlock(handle);
369 }
370
371 int script_buffer_signal_emit(void *buffer_handle, const char *part, const char *signal, double x, double y, double ex, double ey)
372 {
373         static int (*signal_emit)(void *buffer_handle, const char *part, const char *signal, double x, double y, double ex, double ey) = NULL;
374
375         if (!signal_emit) {
376                 signal_emit = dlsym(RTLD_DEFAULT, "script_signal_emit");
377                 if (!signal_emit) {
378                         ErrPrint("broken ABI: %s\n", dlerror());
379                         return LB_STATUS_ERROR_NOT_IMPLEMENTED;
380                 }
381         }
382
383         return signal_emit(buffer_handle, part, signal, x, y, ex, ey);
384 }
385
386 /* End of a file */
387