summaryrefslogtreecommitdiff
path: root/src/abi.c
blob: 98a42c8003adad777e7c5dd3323a956696a59672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#define _GNU_SOURCE

#include <stdio.h>
#include <dlfcn.h>

#include <dlog.h>
#include <livebox-errno.h>

#include "debug.h"
#include "abi.h"

int script_buffer_load(void *handle)
{
	static int (*load)(void *handle) = NULL;
	if (!load) {
		load = dlsym(RTLD_DEFAULT, "buffer_handler_load");
		if (!load) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return load(handle);
}

int script_buffer_unload(void *handle)
{
	static int (*unload)(void *handle) = NULL;

	if (!unload) {
		unload = dlsym(RTLD_DEFAULT, "buffer_handler_unload");
		if (!unload) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return unload(handle);
}

int script_buffer_is_loaded(const void *handle)
{
	static int (*is_loaded)(const void *handle) = NULL;

	if (!is_loaded) {
		is_loaded = dlsym(RTLD_DEFAULT, "buffer_handler_is_loaded");
		if (!is_loaded) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return is_loaded(handle);
}

int script_buffer_resize(void *handle, int w, int h)
{
	static int (*resize)(void *handle, int w, int h) = NULL;

	if (!resize) {
		resize = dlsym(RTLD_DEFAULT, "buffer_handler_resize");
		if (!resize) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return resize(handle, w, h);
}

void script_buffer_update_size(void *handle, int w, int h)
{
	static void (*update_size)(void *handle, int w, int h) = NULL;

	if (!update_size) {
		update_size = dlsym(RTLD_DEFAULT, "buffer_handler_update_size");
		if (!update_size) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return;
		}
	}

	return update_size(handle, w, h);	/*! "void" function can be used with "return" statement */
}

const char *script_buffer_id(const void *handle)
{
	static const char *(*buffer_id)(const void *handle) = NULL;

	if (!buffer_id) {
		buffer_id = dlsym(RTLD_DEFAULT, "buffer_handler_id");
		if (!buffer_id) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return buffer_id(handle);
}

enum buffer_type script_buffer_type(const void *handle)
{
	static enum buffer_type (*buffer_type)(const void *handle) = NULL;

	if (!buffer_type) {
		buffer_type = dlsym(RTLD_DEFAULT, "buffer_handler_type");
		if (!buffer_type) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return BUFFER_TYPE_ERROR;
		}
	}

	return buffer_type(handle);
}

int script_buffer_pixmap(const void *handle)
{
	static int (*buffer_pixmap)(const void *handle) = NULL;

	if (!buffer_pixmap) {
		buffer_pixmap = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap");
		if (!buffer_pixmap) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return buffer_pixmap(handle);
}

void *script_buffer_pixmap_acquire_buffer(void *handle)
{
	static void *(*pixmap_acquire_buffer)(void *handle) = NULL;

	if (!pixmap_acquire_buffer) {
		pixmap_acquire_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_acquire_buffer");
		if (!pixmap_acquire_buffer) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return pixmap_acquire_buffer(handle);
}

int script_buffer_pixmap_release_buffer(void *canvas)
{
	static int (*pixmap_release_buffer)(void *canvas) = NULL;

	if (!pixmap_release_buffer) {
		pixmap_release_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_release_buffer");
		if (!pixmap_release_buffer) {
			ErrPrint("broekn ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return pixmap_release_buffer(canvas);
}

void *script_buffer_pixmap_ref(void *handle)
{
	static void *(*pixmap_ref)(void *handle) = NULL;

	if (!pixmap_ref) {
		pixmap_ref = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_ref");
		if (!pixmap_ref) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return pixmap_ref(handle);
}

int script_buffer_pixmap_unref(void *buffer_ptr)
{
	static int (*pixmap_unref)(void *ptr) = NULL;

	if (!pixmap_unref) {
		pixmap_unref = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_unref");
		if (!pixmap_unref) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return pixmap_unref(buffer_ptr);
}

void *script_buffer_pixmap_find(int pixmap)
{
	static void *(*pixmap_find)(int pixmap) = NULL;

	if (!pixmap_find) {
		pixmap_find = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_find");
		if (!pixmap_find) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return pixmap_find(pixmap);
}

void *script_buffer_pixmap_buffer(void *handle)
{
	static void *(*pixmap_buffer)(void *handle) = NULL;

	if (!pixmap_buffer) {
		pixmap_buffer = dlsym(RTLD_DEFAULT, "buffer_handler_pixmap_buffer");
		if (!pixmap_buffer) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return pixmap_buffer(handle);
}

void *script_buffer_fb(void *handle)
{
	static void *(*buffer_fb)(void *handle) = NULL;

	if (!buffer_fb) {
		buffer_fb = dlsym(RTLD_DEFAULT, "buffer_handler_fb");
		if (!buffer_fb) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return buffer_fb(handle);
}

int script_buffer_get_size(void *handle, int *w, int *h)
{
	static int (*get_size)(void *handle, int *w, int *h) = NULL;

	if (!get_size) {
		get_size = dlsym(RTLD_DEFAULT, "buffer_handler_get_size");
		if (!get_size) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return get_size(handle, w, h);
}

void script_buffer_flush(void *handle)
{
	static void (*buffer_flush)(void *handle) = NULL;

	if (!buffer_flush) {
		buffer_flush = dlsym(RTLD_DEFAULT, "buffer_handler_flush");
		if (!buffer_flush) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return;
		}
	}

	return buffer_flush(handle);	/* "void" function can be used to return from this function ;) */
}

void *script_buffer_instance(void *handle)
{
	static void *(*buffer_instance)(void *handle) = NULL;

	if (!buffer_instance) {
		buffer_instance = dlsym(RTLD_DEFAULT, "buffer_handler_instance");
		if (!buffer_instance) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return buffer_instance(handle);
}

void *script_buffer_raw_open(enum buffer_type type, void *resource)
{
	static void *(*raw_open)(enum buffer_type type, void *resource) = NULL;

	if (!raw_open) {
		raw_open = dlsym(RTLD_DEFAULT, "buffer_handler_raw_open");
		if (!raw_open) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return raw_open(type, resource);
}

int script_buffer_raw_close(void *buffer)
{
	static int (*raw_close)(void *buffer) = NULL;

	if (!raw_close) {
		raw_close = dlsym(RTLD_DEFAULT, "buffer_handler_raw_close");
		if (!raw_close) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return raw_close(buffer);
}

void *script_buffer_raw_data(void *buffer)
{
	static void *(*raw_data)(void *buffer) = NULL;

	if (!raw_data) {
		raw_data = dlsym(RTLD_DEFAULT, "buffer_handler_raw_data");
		if (!raw_data) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return NULL;
		}
	}

	return raw_data(buffer);
}

int script_buffer_raw_size(void *buffer)
{
	static int (*raw_size)(void *buffer) = NULL;

	if (!raw_size) {
		raw_size = dlsym(RTLD_DEFAULT, "buffer_handler_raw_size");
		if (!raw_size) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return raw_size(buffer);
}

int script_buffer_lock(void *handle)
{
	static int (*buffer_lock)(void *handle) = NULL; 

	if (!buffer_lock) {
		buffer_lock = dlsym(RTLD_DEFAULT, "buffer_handler_lock");
		if (!buffer_lock) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return buffer_lock(handle);
}

int script_buffer_unlock(void *handle)
{
	static int (*buffer_unlock)(void *handle) = NULL;

	if (!buffer_unlock) {
		buffer_unlock = dlsym(RTLD_DEFAULT, "buffer_handler_unlock");
		if (!buffer_unlock) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return buffer_unlock(handle);
}

int script_buffer_signal_emit(void *buffer_handle, const char *part, const char *signal, double x, double y, double ex, double ey)
{
	static int (*signal_emit)(void *buffer_handle, const char *part, const char *signal, double x, double y, double ex, double ey) = NULL;

	if (!signal_emit) {
		signal_emit = dlsym(RTLD_DEFAULT, "script_signal_emit");
		if (!signal_emit) {
			ErrPrint("broken ABI: %s\n", dlerror());
			return LB_STATUS_ERROR_NOT_IMPLEMENTED;
		}
	}

	return signal_emit(buffer_handle, part, signal, x, y, ex, ey);
}

/* End of a file */