2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <stdlib.h> /* free */
22 #include <sys/types.h>
26 #include <Ecore_Evas.h>
32 #include <livebox-errno.h>
34 #include "slave_life.h"
35 #include "slave_rpc.h"
36 #include "client_life.h"
39 #include "buffer_handler.h"
40 #include "script_handler.h"
46 #define TYPE_COLOR "color"
47 #define TYPE_TEXT "text"
48 #define TYPE_IMAGE "image"
49 #define TYPE_EDJE "script"
50 #define TYPE_SIGNAL "signal"
51 #define TYPE_INFO "info"
52 #define TYPE_DRAG "drag"
53 #define TYPE_ACCESS "access"
55 #define INFO_SIZE "size"
56 #define INFO_CATEGORY "category"
62 Eina_List *script_port_list;
63 enum buffer_type env_buf_type;
65 .script_port_list = NULL,
66 .env_buf_type = BUFFER_TYPE_FILE,
72 const char *(*magic_id)(void);
73 int (*update_color)(void *handle, Evas *e, const char *id, const char *part, const char *rgba);
74 int (*update_text)(void *handle, Evas *e, const char *id, const char *part, const char *text);
75 int (*update_image)(void *handle, Evas *e, const char *id, const char *part, const char *path, const char *option);
76 int (*update_access)(void *handle, Evas *e, const char *id, const char *part, const char *text, const char *option);
77 int (*update_script)(void *handle, Evas *e, const char *src_id, const char *target_id, const char *part, const char *path, const char *option);
78 int (*update_signal)(void *handle, Evas *e, const char *id, const char *part, const char *signal);
79 int (*update_drag)(void *handle, Evas *e, const char *id, const char *part, double x, double y);
80 int (*update_size)(void *handle, Evas *e, const char *id, int w, int h);
81 int (*update_category)(void *handle, Evas *e, const char *id, const char *category);
82 int (*feed_event)(void *handle, Evas *e, int event_type, int x, int y, double timestamp);
84 void *(*create)(const char *file, const char *option);
85 int (*destroy)(void *handle);
87 int (*load)(void *handle, Evas *e, int w, int h);
88 int (*unload)(void *handle, Evas *e);
120 struct inst_info *inst;
130 struct script_port *port;
134 static inline struct script_port *find_port(const char *magic_id)
137 struct script_port *item;
139 EINA_LIST_FOREACH(s_info.script_port_list, l, item) {
140 if (!strcmp(item->magic_id(), magic_id))
147 static void render_pre_cb(void *data, Evas *e, void *event_info)
149 struct inst_info *inst = data;
150 struct script_info *info;
152 if (instance_state(inst) != INST_ACTIVATED) {
153 DbgPrint("Render pre invoked but instance is not activated\n");
157 info = instance_lb_script(inst);
158 if (info && script_handler_evas(info) == e) {
162 info = instance_pd_script(inst);
163 if (info && script_handler_evas(info) == e) {
167 ErrPrint("Failed to do sync\n");
171 static void render_post_cb(void *data, Evas *e, void *event_info)
173 struct inst_info *inst;
174 struct script_info *info;
178 if (instance_state(inst) != INST_ACTIVATED) {
179 DbgPrint("Render post invoked but instance is not activated\n");
183 info = instance_lb_script(inst);
184 if (info && script_handler_evas(info) == e) {
185 fb_sync(script_handler_fb(info));
186 instance_lb_updated_by_instance(inst);
190 info = instance_pd_script(inst);
191 if (info && script_handler_evas(info) == e) {
192 fb_sync(script_handler_fb(info));
193 instance_pd_updated_by_instance(inst, NULL);
197 ErrPrint("Failed to sync\n");
205 int script_signal_emit(Evas *e, const char *part, const char *signal, double sx, double sy, double ex, double ey)
208 struct script_info *info;
211 ee = ecore_evas_ecore_evas_get(e);
213 ErrPrint("Evas has no Ecore_Evas\n");
214 return LB_STATUS_ERROR_INVALID;
217 info = ecore_evas_data_get(ee, "script,info");
219 ErrPrint("ecore_evas doesn't carry info data\n");
220 return LB_STATUS_ERROR_INVALID;
223 if (!signal || strlen(signal) == 0)
226 if (!part || strlen(part) == 0)
229 ret = instance_signal_emit(info->inst, signal, part, sx, sy, ex, ey, (double)info->x / (double)info->w, (double)info->y / (double)info->h, info->down);
233 HAPI int script_handler_load(struct script_info *info, int is_pd)
238 if (!info || !info->port) {
239 ErrPrint("Script handler is not created\n");
240 return LB_STATUS_ERROR_INVALID;
243 if (info->loaded > 0) {
245 return LB_STATUS_SUCCESS;
248 ret = fb_create_buffer(info->fb);
252 info->ee = fb_canvas(info->fb);
254 ErrPrint("Failed to get canvas\n");
255 fb_destroy_buffer(info->fb);
256 return LB_STATUS_ERROR_FAULT;
259 ecore_evas_data_set(info->ee, "script,info", info);
261 e = script_handler_evas(info);
263 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, info->inst);
264 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_POST, render_post_cb, info->inst);
265 if (info->port->load(info->port_data, e, info->w, info->h) < 0) {
266 ErrPrint("Failed to add new script object\n");
267 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, render_post_cb);
268 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb);
269 fb_destroy_buffer(info->fb);
270 return LB_STATUS_ERROR_FAULT;
273 script_signal_emit(e, util_uri_to_path(instance_id(info->inst)),
274 is_pd ? "pd,show" : "lb,show", 0.0f, 0.0f, 0.0f, 0.0f);
276 ErrPrint("Evas: (nil) %dx%d\n", info->w, info->h);
279 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
280 ecore_evas_resize(info->ee, info->w, info->h);
281 ecore_evas_show(info->ee);
282 ecore_evas_activate(info->ee);
285 return LB_STATUS_SUCCESS;
288 HAPI int script_handler_unload(struct script_info *info, int is_pd)
293 if (!info || !info->port)
294 return LB_STATUS_ERROR_INVALID;
297 if (info->loaded > 0)
298 return LB_STATUS_SUCCESS;
300 if (info->loaded < 0) {
302 return LB_STATUS_SUCCESS;
305 e = script_handler_evas(info);
307 script_signal_emit(e, util_uri_to_path(instance_id(info->inst)),
308 is_pd ? "pd,hide" : "lb,hide", 0.0f, 0.0f, 0.0f, 0.0f);
309 if (info->port->unload(info->port_data, e) < 0)
310 ErrPrint("Failed to unload script object. but go ahead\n");
311 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, render_post_cb);
312 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb);
314 ErrPrint("Evas(nil): Unload script\n");
317 ee = fb_canvas(info->fb);
319 ecore_evas_data_set(ee, "script,info", NULL);
321 fb_destroy_buffer(info->fb);
322 return LB_STATUS_SUCCESS;
325 HAPI struct script_info *script_handler_create(struct inst_info *inst, const char *file, const char *option, int w, int h)
327 struct script_info *info;
329 DbgPrint("Create script: %s (%s)\n", file, option);
334 info = calloc(1, sizeof(*info));
336 ErrPrint("Heap: %s\n", strerror(errno));
340 info->fb = fb_create(inst, w, h, s_info.env_buf_type);
342 ErrPrint("Failed to create a FB (%dx%d)\n", w, h);
348 info->port = find_port(package_script(instance_package(inst)));
350 ErrPrint("Failed to find a proper port for [%s]%s\n",
351 instance_package(inst), package_script(instance_package(inst)));
352 fb_destroy(info->fb);
357 DbgPrint("Update info [%dx%d]\n", w, h);
361 info->port_data = info->port->create(file, option);
362 if (!info->port_data) {
363 ErrPrint("Failed to create a port (%s - %s)\n", file, option);
364 fb_destroy(info->fb);
372 HAPI int script_handler_destroy(struct script_info *info)
374 if (!info || !info->port) {
375 ErrPrint("port is not valid\n");
376 return LB_STATUS_ERROR_INVALID;
379 if (info->loaded != 0) {
380 ErrPrint("Script handler is not unloaded\n");
381 return LB_STATUS_ERROR_INVALID;
384 if (info->port->destroy(info->port_data) < 0)
385 ErrPrint("Failed to destroy port, but go ahead\n");
387 fb_destroy(info->fb);
389 return LB_STATUS_SUCCESS;
392 HAPI int script_handler_is_loaded(struct script_info *info)
394 return info ? info->loaded > 0 : 0;
397 HAPI struct fb_info *script_handler_fb(struct script_info *info)
399 return info ? info->fb : NULL;
402 HAPI void *script_handler_evas(struct script_info *info)
410 return ecore_evas_get(info->ee);
413 static int update_script_color(struct inst_info *inst, struct block *block, int is_pd)
415 struct script_info *info;
418 if (!block || !block->part || !block->data) {
419 ErrPrint("Block or part or data is not valid\n");
420 return LB_STATUS_ERROR_INVALID;
423 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
425 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
426 return LB_STATUS_ERROR_FAULT;
430 ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst));
431 return LB_STATUS_ERROR_INVALID;
434 e = script_handler_evas(info);
436 info->port->update_color(info->port_data, e, block->id, block->part, block->data);
438 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
440 return LB_STATUS_SUCCESS;
443 static int update_script_text(struct inst_info *inst, struct block *block, int is_pd)
445 struct script_info *info;
448 if (!block || !block->part || !block->data) {
449 ErrPrint("Block or part or data is not valid\n");
450 return LB_STATUS_ERROR_INVALID;
453 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
455 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
456 return LB_STATUS_ERROR_FAULT;
460 ErrPrint("info->port is NIL\n");
461 return LB_STATUS_ERROR_INVALID;
464 e = script_handler_evas(info);
466 info->port->update_text(info->port_data, e, block->id, block->part, block->data);
468 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
469 return LB_STATUS_SUCCESS;
472 static int update_script_image(struct inst_info *inst, struct block *block, int is_pd)
474 struct script_info *info;
477 if (!block || !block->part) {
478 ErrPrint("Block or part is not valid\n");
479 return LB_STATUS_ERROR_INVALID;
482 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
484 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
485 return LB_STATUS_ERROR_FAULT;
489 ErrPrint("info->port is NIL\n");
490 return LB_STATUS_ERROR_INVALID;
493 e = script_handler_evas(info);
495 info->port->update_image(info->port_data, e, block->id, block->part, block->data, block->option);
497 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
498 return LB_STATUS_SUCCESS;
501 static int update_access(struct inst_info *inst, struct block *block, int is_pd)
503 struct script_info *info;
506 if (!block || !block->part) {
507 ErrPrint("Block or block->part is NIL\n");
508 return LB_STATUS_ERROR_INVALID;
511 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
513 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
514 return LB_STATUS_ERROR_FAULT;
518 ErrPrint("info->port is NIL\n");
519 return LB_STATUS_ERROR_INVALID;
522 e = script_handler_evas(info);
524 info->port->update_access(info->port_data, e, block->id, block->part, block->data, block->option);
526 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
527 return LB_STATUS_SUCCESS;
530 static int update_script_script(struct inst_info *inst, struct block *block, int is_pd)
532 struct script_info *info;
535 if (!block || !block->part) {
536 ErrPrint("Block or part is NIL\n");
537 return LB_STATUS_ERROR_INVALID;
540 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
542 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
543 return LB_STATUS_ERROR_FAULT;
547 ErrPrint("info->port is NIL\n");
548 return LB_STATUS_ERROR_INVALID;
551 e = script_handler_evas(info);
553 info->port->update_script(info->port_data, e, block->id, block->target_id, block->part, block->data, block->option);
555 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s] option[%s]\n",
556 block->id, block->part, block->data, block->option);
557 return LB_STATUS_SUCCESS;
560 static int update_script_signal(struct inst_info *inst, struct block *block, int is_pd)
562 struct script_info *info;
566 ErrPrint("block is NIL\n");
567 return LB_STATUS_ERROR_INVALID;
570 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
572 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
573 return LB_STATUS_ERROR_FAULT;
577 ErrPrint("info->port is NIL\n");
578 return LB_STATUS_ERROR_INVALID;
581 e = script_handler_evas(info);
583 info->port->update_signal(info->port_data, e, block->id, block->part, block->data);
585 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
586 return LB_STATUS_SUCCESS;
589 static int update_script_drag(struct inst_info *inst, struct block *block, int is_pd)
591 struct script_info *info;
595 if (!block || !block->data || !block->part) {
596 ErrPrint("block or block->data or block->part is NIL\n");
597 return LB_STATUS_ERROR_INVALID;
600 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
602 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
603 return LB_STATUS_ERROR_FAULT;
606 if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
607 ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data);
608 return LB_STATUS_ERROR_INVALID;
612 ErrPrint("info->port is NIL\n");
613 return LB_STATUS_ERROR_INVALID;
616 e = script_handler_evas(info);
618 info->port->update_drag(info->port_data, e, block->id, block->part, dx, dy);
620 ErrPrint("Evas(nil) id[%s] part[%s] %lfx%lf\n", block->id, block->part, dx, dy);
621 return LB_STATUS_SUCCESS;
624 HAPI int script_handler_resize(struct script_info *info, int w, int h)
627 //|| (info->w == w && info->h == h)) {
628 ErrPrint("info[%p] resize is ignored\n", info);
629 return LB_STATUS_SUCCESS;
632 fb_resize(script_handler_fb(info), w, h);
634 if (info->port->update_size) {
636 e = script_handler_evas(info);
638 info->port->update_size(info->port_data, e, NULL , w, h);
640 ErrPrint("Evas(nil) resize to %dx%d\n", w, h);
643 if (info->w != w || info->h != h) {
644 if (instance_lb_script(info->inst) == info) {
645 instance_set_lb_info(info->inst, w, h, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
646 } else if (instance_pd_script(info->inst) == info) {
647 instance_set_pd_info(info->inst, w, h);
649 ErrPrint("Script is not known\n");
656 return LB_STATUS_SUCCESS;
659 static int update_info(struct inst_info *inst, struct block *block, int is_pd)
661 struct script_info *info;
663 if (!block || !block->part || !block->data) {
664 ErrPrint("block or block->part or block->data is NIL\n");
665 return LB_STATUS_ERROR_INVALID;
668 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
670 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
671 return LB_STATUS_ERROR_FAULT;
675 ErrPrint("info->port is NIL\n");
676 return LB_STATUS_ERROR_INVALID;
679 if (!strcasecmp(block->part, INFO_SIZE)) {
682 if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
683 ErrPrint("Invalid format for SIZE(%s)\n", block->data);
684 return LB_STATUS_ERROR_INVALID;
688 script_handler_resize(info, w, h);
691 e = script_handler_evas(info);
693 info->port->update_size(info->port_data, e, block->id, w, h);
695 ErrPrint("Evas(nil): id[%s] %dx%d\n", block->id, w, h);
697 } else if (!strcasecmp(block->part, INFO_CATEGORY)) {
699 e = script_handler_evas(info);
701 info->port->update_category(info->port_data, e, block->id, block->data);
703 ErrPrint("Evas(nil): id[%s] data[%s]\n", block->id, block->data);
706 return LB_STATUS_SUCCESS;
709 HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const char *descfile, int is_pd)
711 struct inst_info *inst;
730 const char *field_name[] = {
741 register int field_idx;
742 register int idx = 0;
747 int (*handler)(struct inst_info *inst, struct block *block, int is_pd);
751 .handler = update_script_color,
755 .handler = update_script_text,
759 .handler = update_script_image,
763 .handler = update_script_script,
767 .handler = update_script_signal,
771 .handler = update_script_drag,
775 .handler = update_info,
779 .handler = update_access,
788 inst = package_find_instance_by_id(pkgname, id);
790 ErrPrint("Instance is not exists\n");
791 return LB_STATUS_ERROR_NOT_EXIST;
794 fp = fopen(descfile, "rt");
796 ErrPrint("Error: %s [%s]\n", descfile, strerror(errno));
797 return LB_STATUS_ERROR_IO;
817 if (!isspace(ch) && ch != EOF) {
818 ErrPrint("%d: Syntax error: Desc is not started with '{' or space - (%c = 0x%x)\n", lineno, ch, ch);
820 return LB_STATUS_ERROR_INVALID;
829 ErrPrint("%d: Syntax error: New line must has to be started right after '{'\n", lineno);
833 block = calloc(1, sizeof(*block));
835 ErrPrint("Heap: %s\n", strerror(errno));
837 return LB_STATUS_ERROR_MEMORY;
855 if (field_name[field_idx][idx] != '\0') {
856 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
864 DbgFree(block->type);
873 DbgFree(block->part);
882 DbgFree(block->data);
891 DbgFree(block->file);
898 state = VALUE_OPTION;
900 DbgFree(block->option);
901 block->option = NULL;
902 block->option_len = 0;
916 state = VALUE_TARGET;
917 if (block->target_id) {
918 DbgFree(block->target_id);
919 block->target_id = NULL;
920 block->target_len = 0;
925 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
935 if (field_name[field_idx][idx] != ch) {
941 ungetc(field_name[field_idx][idx], fp);
944 if (field_name[field_idx] == NULL) {
945 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
957 if (idx == block->type_len) {
959 block->type_len += ADDEND;
960 tmp = realloc(block->type, block->type_len);
962 ErrPrint("Heap: %s\n", strerror(errno));
969 block->type[idx] = '\0';
976 block->type[idx] = ch;
981 if (idx == block->part_len) {
983 block->part_len += ADDEND;
984 tmp = realloc(block->part, block->part_len);
986 ErrPrint("Heap: %s\n", strerror(errno));
993 block->part[idx] = '\0';
1000 block->part[idx] = ch;
1005 if (idx == block->data_len) {
1007 block->data_len += ADDEND;
1008 tmp = realloc(block->data, block->data_len);
1010 ErrPrint("Heap: %s\n", strerror(errno));
1017 block->data[idx] = '\0';
1024 block->data[idx] = ch;
1029 if (idx == block->file_len) {
1031 block->file_len += ADDEND;
1032 tmp = realloc(block->file, block->file_len);
1034 ErrPrint("Heap: %s\n", strerror(errno));
1041 block->file[idx] = '\0';
1048 block->file[idx] = ch;
1053 if (idx == block->option_len) {
1055 block->option_len += ADDEND;
1056 tmp = realloc(block->option, block->option_len);
1058 ErrPrint("Heap: %s\n", strerror(errno));
1061 block->option = tmp;
1065 block->option[idx] = '\0';
1072 block->option[idx] = ch;
1076 if (idx == block->id_len) {
1078 block->id_len += ADDEND;
1079 tmp = realloc(block->id, block->id_len);
1081 ErrPrint("Heap: %s\n", strerror(errno));
1088 block->id[idx] = '\0';
1095 block->id[idx] = ch;
1099 if (idx == block->target_len) {
1101 block->target_len += ADDEND;
1102 tmp = realloc(block->target_id, block->target_len);
1104 ErrPrint("Heap: %s\n", strerror(errno));
1107 block->target_id = tmp;
1111 block->target_id[idx] = '\0';
1118 block->target_id[idx] = ch;
1123 block->file = strdup(util_uri_to_path(id));
1125 ErrPrint("Heap: %s\n", strerror(errno));
1131 while (handlers[i].type) {
1132 if (!strcasecmp(handlers[i].type, block->type)) {
1133 handlers[i].handler(inst, block, is_pd);
1139 if (!handlers[i].type)
1140 ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
1142 DbgFree(block->file);
1143 DbgFree(block->type);
1144 DbgFree(block->part);
1145 DbgFree(block->data);
1146 DbgFree(block->option);
1148 DbgFree(block->target_id);
1160 if (state != UNKNOWN) {
1161 ErrPrint("%d: Unknown state\n", lineno);
1166 return LB_STATUS_SUCCESS;
1169 ErrPrint("Parse error at %d file %s\n", lineno, util_basename(descfile));
1171 DbgFree(block->file);
1172 DbgFree(block->type);
1173 DbgFree(block->part);
1174 DbgFree(block->data);
1175 DbgFree(block->option);
1177 DbgFree(block->target_id);
1181 return LB_STATUS_ERROR_INVALID;
1184 HAPI int script_init(void)
1186 struct script_port *item;
1192 if (!strcasecmp(PROVIDER_METHOD, "shm"))
1193 s_info.env_buf_type = BUFFER_TYPE_SHM;
1194 else if (!strcasecmp(PROVIDER_METHOD, "pixmap"))
1195 s_info.env_buf_type = BUFFER_TYPE_PIXMAP;
1197 dir = opendir(SCRIPT_PORT_PATH);
1199 ErrPrint("Error: %s\n", strerror(errno));
1200 return LB_STATUS_ERROR_IO;
1203 while ((ent = readdir(dir))) {
1204 if (ent->d_name[0] == '.')
1207 pathlen = strlen(ent->d_name) + strlen(SCRIPT_PORT_PATH) + 1;
1208 path = malloc(pathlen);
1210 ErrPrint("Heap: %s %d\n", strerror(errno), pathlen);
1212 return LB_STATUS_ERROR_MEMORY;
1215 snprintf(path, pathlen, "%s%s", SCRIPT_PORT_PATH, ent->d_name);
1217 item = malloc(sizeof(*item));
1219 ErrPrint("Heap: %s\n", strerror(errno));
1222 return LB_STATUS_ERROR_MEMORY;
1225 DbgPrint("Open SCRIPT PORT: %s\n", path);
1226 item->handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW | RTLD_DEEPBIND);
1228 if (!item->handle) {
1229 ErrPrint("Error: %s\n", dlerror());
1232 return LB_STATUS_ERROR_FAULT;
1235 item->magic_id = dlsym(item->handle, "script_magic_id");
1236 if (!item->magic_id)
1239 DbgPrint("SCRIPT PORT magic id: %s\n", item->magic_id());
1241 item->update_color = dlsym(item->handle, "script_update_color");
1242 if (!item->update_color)
1245 item->update_text = dlsym(item->handle, "script_update_text");
1246 if (!item->update_text)
1249 item->update_image = dlsym(item->handle, "script_update_image");
1250 if (!item->update_image)
1253 item->update_access = dlsym(item->handle, "script_update_access");
1254 if (!item->update_access)
1257 item->update_script = dlsym(item->handle, "script_update_script");
1258 if (!item->update_script)
1261 item->update_signal = dlsym(item->handle, "script_update_signal");
1262 if (!item->update_signal)
1265 item->update_drag = dlsym(item->handle, "script_update_drag");
1266 if (!item->update_drag)
1269 item->update_size = dlsym(item->handle, "script_update_size");
1270 if (!item->update_size)
1273 item->update_category = dlsym(item->handle, "script_update_category");
1274 if (!item->update_category)
1277 item->create = dlsym(item->handle, "script_create");
1281 item->destroy = dlsym(item->handle, "script_destroy");
1285 item->load = dlsym(item->handle, "script_load");
1289 item->unload = dlsym(item->handle, "script_unload");
1293 item->init = dlsym(item->handle, "script_init");
1297 item->fini = dlsym(item->handle, "script_fini");
1301 item->feed_event = dlsym(item->handle, "script_feed_event");
1302 if (!item->feed_event)
1305 if (item->init() < 0) {
1306 ErrPrint("Failed to initialize script engine\n");
1310 s_info.script_port_list = eina_list_append(s_info.script_port_list, item);
1314 return LB_STATUS_SUCCESS;
1317 ErrPrint("Error: %s\n", dlerror());
1318 dlclose(item->handle);
1321 return LB_STATUS_ERROR_FAULT;
1324 HAPI int script_fini(void)
1326 struct script_port *item;
1328 * \TODO: Release all handles
1330 EINA_LIST_FREE(s_info.script_port_list, item) {
1332 dlclose(item->handle);
1339 HAPI int script_handler_update_pointer(struct script_info *info, int x, int y, int down)
1342 return LB_STATUS_SUCCESS;
1352 return LB_STATUS_SUCCESS;
1355 HAPI int script_handler_feed_event(struct script_info *info, int event, double timestamp)
1360 ErrPrint("info->port is NIL\n");
1361 return LB_STATUS_ERROR_INVALID;
1364 e = script_handler_evas(info);
1366 ErrPrint("Evas is not exists\n");
1367 return LB_STATUS_ERROR_FAULT;
1370 return info->port->feed_event(info->port_data, e, event, info->x, info->y, timestamp);