2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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, int down, 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;
133 Eina_List *cached_blocks;
136 static inline void consuming_parsed_block(int lineno, struct inst_info *inst, int is_pd, struct block *block);
138 static inline struct script_port *find_port(const char *magic_id)
141 struct script_port *item;
143 EINA_LIST_FOREACH(s_info.script_port_list, l, item) {
144 if (!strcmp(item->magic_id(), magic_id))
151 static inline void delete_block(struct block *block)
153 DbgFree(block->file);
154 DbgFree(block->type);
155 DbgFree(block->part);
156 DbgFree(block->data);
157 DbgFree(block->option);
159 DbgFree(block->target_id);
163 static void render_pre_cb(void *data, Evas *e, void *event_info)
165 struct inst_info *inst = data;
166 struct script_info *info;
168 if (instance_state(inst) != INST_ACTIVATED) {
169 ErrPrint("Render pre invoked but instance is not activated\n");
173 info = instance_lb_script(inst);
174 if (info && script_handler_evas(info) == e) {
178 info = instance_pd_script(inst);
179 if (info && script_handler_evas(info) == e) {
183 ErrPrint("Failed to do sync\n");
187 static void render_post_cb(void *data, Evas *e, void *event_info)
189 struct inst_info *inst;
190 struct script_info *info;
194 if (instance_state(inst) != INST_ACTIVATED) {
195 ErrPrint("Render post invoked but instance is not activated\n");
199 info = instance_lb_script(inst);
200 if (info && script_handler_evas(info) == e) {
201 fb_sync(script_handler_fb(info));
202 instance_lb_updated_by_instance(inst);
206 info = instance_pd_script(inst);
207 if (info && script_handler_evas(info) == e) {
208 fb_sync(script_handler_fb(info));
209 instance_pd_updated_by_instance(inst, NULL);
213 ErrPrint("Failed to sync\n");
221 int script_signal_emit(Evas *e, const char *part, const char *signal, double sx, double sy, double ex, double ey)
224 struct script_info *info;
226 ee = ecore_evas_ecore_evas_get(e);
228 ErrPrint("Evas has no Ecore_Evas\n");
229 return LB_STATUS_ERROR_INVALID;
232 info = ecore_evas_data_get(ee, "script,info");
234 ErrPrint("ecore_evas doesn't carry info data\n");
235 return LB_STATUS_ERROR_INVALID;
238 if (!signal || strlen(signal) == 0)
241 if (!part || strlen(part) == 0)
244 return 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);
247 static inline void flushing_cached_block(struct script_info *info)
251 EINA_LIST_FREE(info->cached_blocks, block) {
252 consuming_parsed_block(-1, info->inst, (instance_pd_script(info->inst) == info), block);
256 HAPI int script_handler_load(struct script_info *info, int is_pd)
261 if (!info || !info->port) {
262 ErrPrint("Script handler is not created\n");
263 return LB_STATUS_ERROR_INVALID;
266 if (info->loaded > 0) {
268 return LB_STATUS_SUCCESS;
271 ret = fb_create_buffer(info->fb);
275 info->ee = fb_canvas(info->fb);
277 ErrPrint("Failed to get canvas\n");
278 fb_destroy_buffer(info->fb);
279 return LB_STATUS_ERROR_FAULT;
282 ecore_evas_data_set(info->ee, "script,info", info);
284 e = script_handler_evas(info);
286 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, info->inst);
287 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_POST, render_post_cb, info->inst);
288 if (info->port->load(info->port_data, e, info->w, info->h) < 0) {
289 ErrPrint("Failed to add new script object\n");
290 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, render_post_cb);
291 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb);
292 fb_destroy_buffer(info->fb);
293 return LB_STATUS_ERROR_FAULT;
296 flushing_cached_block(info);
297 script_signal_emit(e, instance_id(info->inst),
298 is_pd ? "pd,show" : "lb,show", 0.0f, 0.0f, 0.0f, 0.0f);
300 ErrPrint("Evas: (nil) %dx%d\n", info->w, info->h);
303 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
304 ecore_evas_resize(info->ee, info->w, info->h);
305 ecore_evas_show(info->ee);
306 ecore_evas_activate(info->ee);
309 return LB_STATUS_SUCCESS;
312 HAPI int script_handler_unload(struct script_info *info, int is_pd)
317 if (!info || !info->port)
318 return LB_STATUS_ERROR_INVALID;
321 if (info->loaded > 0)
322 return LB_STATUS_SUCCESS;
324 if (info->loaded < 0) {
326 return LB_STATUS_SUCCESS;
329 e = script_handler_evas(info);
331 script_signal_emit(e, instance_id(info->inst),
332 is_pd ? "pd,hide" : "lb,hide", 0.0f, 0.0f, 0.0f, 0.0f);
333 if (info->port->unload(info->port_data, e) < 0)
334 ErrPrint("Failed to unload script object. but go ahead\n");
335 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, render_post_cb);
336 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb);
338 ErrPrint("Evas(nil): Unload script\n");
341 ee = fb_canvas(info->fb);
343 ecore_evas_data_set(ee, "script,info", NULL);
345 fb_destroy_buffer(info->fb);
346 return LB_STATUS_SUCCESS;
349 HAPI struct script_info *script_handler_create(struct inst_info *inst, const char *file, const char *option, int w, int h)
351 struct script_info *info;
353 DbgPrint("Create script: %s (%s) %dx%d\n", file, option, w, h);
358 info = calloc(1, sizeof(*info));
360 ErrPrint("Heap: %s\n", strerror(errno));
364 info->fb = fb_create(inst, w, h, s_info.env_buf_type);
366 ErrPrint("Failed to create a FB (%dx%d)\n", w, h);
372 info->port = find_port(package_script(instance_package(inst)));
374 ErrPrint("Failed to find a proper port for [%s]%s\n",
375 instance_package(inst), package_script(instance_package(inst)));
376 fb_destroy(info->fb);
384 info->port_data = info->port->create(file, option);
385 if (!info->port_data) {
386 ErrPrint("Failed to create a port (%s - %s)\n", file, option);
387 fb_destroy(info->fb);
395 HAPI int script_handler_destroy(struct script_info *info)
400 if (!info || !info->port) {
401 ErrPrint("port is not valid\n");
402 return LB_STATUS_ERROR_INVALID;
405 if (info->loaded != 0) {
406 ErrPrint("Script handler is not unloaded\n");
407 return LB_STATUS_ERROR_INVALID;
410 ret = info->port->destroy(info->port_data);
412 ErrPrint("Failed to destroy port, but go ahead: %d\n", ret);
414 fb_destroy(info->fb);
416 EINA_LIST_FREE(info->cached_blocks, block) {
420 return LB_STATUS_SUCCESS;
423 HAPI int script_handler_is_loaded(struct script_info *info)
425 return info ? info->loaded > 0 : 0;
428 HAPI struct fb_info *script_handler_fb(struct script_info *info)
430 return info ? info->fb : NULL;
433 HAPI void *script_handler_evas(struct script_info *info)
441 return ecore_evas_get(info->ee);
444 static int update_script_color(struct inst_info *inst, struct block *block, int is_pd)
446 struct script_info *info;
449 if (!block || !block->part || !block->data) {
450 ErrPrint("Block or part or data is not valid\n");
451 return LB_STATUS_ERROR_INVALID;
454 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
456 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
457 return LB_STATUS_ERROR_FAULT;
461 ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst));
462 return LB_STATUS_ERROR_INVALID;
465 e = script_handler_evas(info);
467 info->port->update_color(info->port_data, e, block->id, block->part, block->data);
469 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
471 return LB_STATUS_SUCCESS;
474 static int update_script_text(struct inst_info *inst, struct block *block, int is_pd)
476 struct script_info *info;
479 if (!block || !block->part || !block->data) {
480 ErrPrint("Block or part or data is not valid\n");
481 return LB_STATUS_ERROR_INVALID;
484 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
486 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
487 return LB_STATUS_ERROR_FAULT;
491 ErrPrint("info->port is NIL\n");
492 return LB_STATUS_ERROR_INVALID;
495 e = script_handler_evas(info);
497 info->port->update_text(info->port_data, e, block->id, block->part, block->data);
499 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
500 return LB_STATUS_SUCCESS;
503 static int update_script_image(struct inst_info *inst, struct block *block, int is_pd)
505 struct script_info *info;
508 if (!block || !block->part) {
509 ErrPrint("Block or part is not valid\n");
510 return LB_STATUS_ERROR_INVALID;
513 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
515 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
516 return LB_STATUS_ERROR_FAULT;
520 ErrPrint("info->port is NIL\n");
521 return LB_STATUS_ERROR_INVALID;
524 e = script_handler_evas(info);
526 info->port->update_image(info->port_data, e, block->id, block->part, block->data, block->option);
528 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
529 return LB_STATUS_SUCCESS;
532 static int update_access(struct inst_info *inst, struct block *block, int is_pd)
534 struct script_info *info;
537 if (!block || !block->part) {
538 ErrPrint("Block or block->part is NIL\n");
539 return LB_STATUS_ERROR_INVALID;
542 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
544 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
545 return LB_STATUS_ERROR_FAULT;
549 ErrPrint("info->port is NIL\n");
550 return LB_STATUS_ERROR_INVALID;
553 e = script_handler_evas(info);
555 info->port->update_access(info->port_data, e, block->id, block->part, block->data, block->option);
557 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
558 return LB_STATUS_SUCCESS;
561 static int update_script_script(struct inst_info *inst, struct block *block, int is_pd)
563 struct script_info *info;
566 if (!block || !block->part) {
567 ErrPrint("Block or part is NIL\n");
568 return LB_STATUS_ERROR_INVALID;
571 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
573 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
574 return LB_STATUS_ERROR_FAULT;
578 ErrPrint("info->port is NIL\n");
579 return LB_STATUS_ERROR_INVALID;
582 e = script_handler_evas(info);
584 info->port->update_script(info->port_data, e, block->id, block->target_id, block->part, block->data, block->option);
586 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s] option[%s]\n",
587 block->id, block->part, block->data, block->option);
588 return LB_STATUS_SUCCESS;
591 static int update_script_signal(struct inst_info *inst, struct block *block, int is_pd)
593 struct script_info *info;
597 ErrPrint("block is NIL\n");
598 return LB_STATUS_ERROR_INVALID;
601 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
603 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
604 return LB_STATUS_ERROR_FAULT;
608 ErrPrint("info->port is NIL\n");
609 return LB_STATUS_ERROR_INVALID;
612 e = script_handler_evas(info);
614 info->port->update_signal(info->port_data, e, block->id, block->part, block->data);
616 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
617 return LB_STATUS_SUCCESS;
620 static int update_script_drag(struct inst_info *inst, struct block *block, int is_pd)
622 struct script_info *info;
626 if (!block || !block->data || !block->part) {
627 ErrPrint("block or block->data or block->part is NIL\n");
628 return LB_STATUS_ERROR_INVALID;
631 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
633 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
634 return LB_STATUS_ERROR_FAULT;
637 if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
638 ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data);
639 return LB_STATUS_ERROR_INVALID;
643 ErrPrint("info->port is NIL\n");
644 return LB_STATUS_ERROR_INVALID;
647 e = script_handler_evas(info);
649 info->port->update_drag(info->port_data, e, block->id, block->part, dx, dy);
651 ErrPrint("Evas(nil) id[%s] part[%s] %lfx%lf\n", block->id, block->part, dx, dy);
652 return LB_STATUS_SUCCESS;
655 HAPI int script_handler_resize(struct script_info *info, int w, int h)
658 //|| (info->w == w && info->h == h)) {
659 ErrPrint("info[%p] resize is ignored\n", info);
660 return LB_STATUS_SUCCESS;
663 fb_resize(script_handler_fb(info), w, h);
665 if (info->port->update_size) {
667 e = script_handler_evas(info);
669 info->port->update_size(info->port_data, e, NULL , w, h);
671 ErrPrint("Evas(nil) resize to %dx%d\n", w, h);
674 if (instance_lb_script(info->inst) == info) {
675 instance_set_lb_size(info->inst, w, h);
676 } else if (instance_pd_script(info->inst) == info) {
677 instance_set_pd_size(info->inst, w, h);
679 ErrPrint("Script is not known\n");
685 return LB_STATUS_SUCCESS;
688 static int update_info(struct inst_info *inst, struct block *block, int is_pd)
690 struct script_info *info;
692 if (!block || !block->part || !block->data) {
693 ErrPrint("block or block->part or block->data is NIL\n");
694 return LB_STATUS_ERROR_INVALID;
697 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
699 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
700 return LB_STATUS_ERROR_FAULT;
704 ErrPrint("info->port is NIL\n");
705 return LB_STATUS_ERROR_INVALID;
708 if (!strcasecmp(block->part, INFO_SIZE)) {
711 if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
712 ErrPrint("Invalid format for SIZE(%s)\n", block->data);
713 return LB_STATUS_ERROR_INVALID;
717 script_handler_resize(info, w, h);
720 e = script_handler_evas(info);
722 info->port->update_size(info->port_data, e, block->id, w, h);
724 ErrPrint("Evas(nil): id[%s] %dx%d\n", block->id, w, h);
726 } else if (!strcasecmp(block->part, INFO_CATEGORY)) {
728 e = script_handler_evas(info);
730 info->port->update_category(info->port_data, e, block->id, block->data);
732 ErrPrint("Evas(nil): id[%s] data[%s]\n", block->id, block->data);
735 return LB_STATUS_SUCCESS;
738 static inline void consuming_parsed_block(int lineno, struct inst_info *inst, int is_pd, struct block *block)
740 struct script_info *info;
742 * To speed up, use the static.
743 * But this will increase the memory slightly.
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,
787 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
789 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
793 if (script_handler_is_loaded(info)) {
796 while (handlers[i].type) {
797 if (!strcasecmp(handlers[i].type, block->type)) {
798 handlers[i].handler(inst, block, is_pd);
804 if (!handlers[i].type)
805 ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
809 info->cached_blocks = eina_list_append(info->cached_blocks, block);
810 DbgPrint("%d: Block is cached (%p), %d, %s\n", lineno, block, eina_list_count(info->cached_blocks), instance_id(inst));
819 HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const char *descfile, int is_pd)
821 struct inst_info *inst;
840 const char *field_name[] = {
851 register int field_idx;
852 register int idx = 0;
856 inst = package_find_instance_by_id(pkgname, id);
858 ErrPrint("Instance is not exists\n");
859 return LB_STATUS_ERROR_NOT_EXIST;
862 fp = fopen(descfile, "rt");
864 ErrPrint("Error: %s [%s]\n", descfile, strerror(errno));
865 return LB_STATUS_ERROR_IO;
868 DbgPrint("Start parsing %s\n", descfile);
887 if (!isspace(ch) && ch != EOF) {
888 ErrPrint("%d: Syntax error: Desc is not started with '{' or space - (%c = 0x%x)\n", lineno, ch, ch);
890 ErrPrint("fclose: %s\n", strerror(errno));
891 return LB_STATUS_ERROR_INVALID;
900 ErrPrint("%d: Syntax error: New line must has to be started right after '{'\n", lineno);
904 block = calloc(1, sizeof(*block));
906 ErrPrint("Heap: %s\n", strerror(errno));
908 ErrPrint("fclose: %s\n", strerror(errno));
909 return LB_STATUS_ERROR_MEMORY;
927 if (field_name[field_idx][idx] != '\0') {
928 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
936 DbgFree(block->type);
945 DbgFree(block->part);
954 DbgFree(block->data);
963 DbgFree(block->file);
970 state = VALUE_OPTION;
972 DbgFree(block->option);
973 block->option = NULL;
974 block->option_len = 0;
988 state = VALUE_TARGET;
989 if (block->target_id) {
990 DbgFree(block->target_id);
991 block->target_id = NULL;
992 block->target_len = 0;
997 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
1007 if (field_name[field_idx][idx] != ch) {
1013 ungetc(field_name[field_idx][idx], fp);
1016 if (field_name[field_idx] == NULL) {
1017 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
1029 if (idx == block->type_len) {
1031 block->type_len += ADDEND;
1032 tmp = realloc(block->type, block->type_len);
1034 ErrPrint("Heap: %s\n", strerror(errno));
1041 block->type[idx] = '\0';
1048 block->type[idx] = ch;
1053 if (idx == block->part_len) {
1055 block->part_len += ADDEND;
1056 tmp = realloc(block->part, block->part_len);
1058 ErrPrint("Heap: %s\n", strerror(errno));
1065 block->part[idx] = '\0';
1072 block->part[idx] = ch;
1077 if (idx == block->data_len) {
1079 block->data_len += ADDEND;
1080 tmp = realloc(block->data, block->data_len);
1082 ErrPrint("Heap: %s\n", strerror(errno));
1089 block->data[idx] = '\0';
1096 block->data[idx] = ch;
1101 if (idx == block->file_len) {
1103 block->file_len += ADDEND;
1104 tmp = realloc(block->file, block->file_len);
1106 ErrPrint("Heap: %s\n", strerror(errno));
1113 block->file[idx] = '\0';
1120 block->file[idx] = ch;
1125 if (idx == block->option_len) {
1127 block->option_len += ADDEND;
1128 tmp = realloc(block->option, block->option_len);
1130 ErrPrint("Heap: %s\n", strerror(errno));
1133 block->option = tmp;
1137 block->option[idx] = '\0';
1144 block->option[idx] = ch;
1148 if (idx == block->id_len) {
1150 block->id_len += ADDEND;
1151 tmp = realloc(block->id, block->id_len);
1153 ErrPrint("Heap: %s\n", strerror(errno));
1160 block->id[idx] = '\0';
1167 block->id[idx] = ch;
1171 if (idx == block->target_len) {
1173 block->target_len += ADDEND;
1174 tmp = realloc(block->target_id, block->target_len);
1176 ErrPrint("Heap: %s\n", strerror(errno));
1179 block->target_id = tmp;
1183 block->target_id[idx] = '\0';
1190 block->target_id[idx] = ch;
1195 block->file = strdup(util_uri_to_path(id));
1197 ErrPrint("Heap: %s\n", strerror(errno));
1202 consuming_parsed_block(lineno, inst, is_pd, block);
1212 if (state != UNKNOWN) {
1213 ErrPrint("%d: Unknown state\n", lineno);
1217 if (fclose(fp) != 0)
1218 ErrPrint("fclose: %s\n", strerror(errno));
1219 return LB_STATUS_SUCCESS;
1222 ErrPrint("Parse error at %d file %s\n", lineno, util_basename(descfile));
1224 delete_block(block);
1225 if (fclose(fp) != 0)
1226 ErrPrint("fclose: %s\n", strerror(errno));
1227 return LB_STATUS_ERROR_INVALID;
1230 HAPI int script_init(void)
1232 struct script_port *item;
1238 if (!strcasecmp(PROVIDER_METHOD, "shm"))
1239 s_info.env_buf_type = BUFFER_TYPE_SHM;
1240 else if (!strcasecmp(PROVIDER_METHOD, "pixmap"))
1241 s_info.env_buf_type = BUFFER_TYPE_PIXMAP;
1243 dir = opendir(SCRIPT_PORT_PATH);
1245 ErrPrint("Error: %s\n", strerror(errno));
1246 return LB_STATUS_ERROR_IO;
1249 while ((ent = readdir(dir))) {
1250 if (ent->d_name[0] == '.')
1253 pathlen = strlen(ent->d_name) + strlen(SCRIPT_PORT_PATH) + 1;
1254 path = malloc(pathlen);
1256 ErrPrint("Heap: %s %d\n", strerror(errno), pathlen);
1257 if (closedir(dir) < 0)
1258 ErrPrint("closedir: %s\n", strerror(errno));
1259 return LB_STATUS_ERROR_MEMORY;
1262 snprintf(path, pathlen, "%s%s", SCRIPT_PORT_PATH, ent->d_name);
1264 item = malloc(sizeof(*item));
1266 ErrPrint("Heap: %s\n", strerror(errno));
1268 if (closedir(dir) < 0)
1269 ErrPrint("closedir: %s\n", strerror(errno));
1270 return LB_STATUS_ERROR_MEMORY;
1273 DbgPrint("Open SCRIPT PORT: %s\n", path);
1274 item->handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW | RTLD_DEEPBIND);
1276 if (!item->handle) {
1277 ErrPrint("Error: %s\n", dlerror());
1279 if (closedir(dir) < 0)
1280 ErrPrint("closedir: %s\n", strerror(errno));
1281 return LB_STATUS_ERROR_FAULT;
1284 item->magic_id = dlsym(item->handle, "script_magic_id");
1285 if (!item->magic_id)
1288 DbgPrint("SCRIPT PORT magic id: %s\n", item->magic_id());
1290 item->update_color = dlsym(item->handle, "script_update_color");
1291 if (!item->update_color)
1294 item->update_text = dlsym(item->handle, "script_update_text");
1295 if (!item->update_text)
1298 item->update_image = dlsym(item->handle, "script_update_image");
1299 if (!item->update_image)
1302 item->update_access = dlsym(item->handle, "script_update_access");
1303 if (!item->update_access)
1306 item->update_script = dlsym(item->handle, "script_update_script");
1307 if (!item->update_script)
1310 item->update_signal = dlsym(item->handle, "script_update_signal");
1311 if (!item->update_signal)
1314 item->update_drag = dlsym(item->handle, "script_update_drag");
1315 if (!item->update_drag)
1318 item->update_size = dlsym(item->handle, "script_update_size");
1319 if (!item->update_size)
1322 item->update_category = dlsym(item->handle, "script_update_category");
1323 if (!item->update_category)
1326 item->create = dlsym(item->handle, "script_create");
1330 item->destroy = dlsym(item->handle, "script_destroy");
1334 item->load = dlsym(item->handle, "script_load");
1338 item->unload = dlsym(item->handle, "script_unload");
1342 item->init = dlsym(item->handle, "script_init");
1346 item->fini = dlsym(item->handle, "script_fini");
1350 item->feed_event = dlsym(item->handle, "script_feed_event");
1351 if (!item->feed_event)
1354 if (item->init() < 0) {
1355 ErrPrint("Failed to initialize script engine\n");
1359 s_info.script_port_list = eina_list_append(s_info.script_port_list, item);
1362 if (closedir(dir) < 0)
1363 ErrPrint("closedir: %s\n", strerror(errno));
1365 return LB_STATUS_SUCCESS;
1368 ErrPrint("Error: %s\n", dlerror());
1369 if (dlclose(item->handle) != 0)
1370 ErrPrint("dlclose: %s\n", strerror(errno));
1372 if (closedir(dir) < 0)
1373 ErrPrint("closedir: %s\n", strerror(errno));
1374 return LB_STATUS_ERROR_FAULT;
1377 HAPI int script_fini(void)
1379 struct script_port *item;
1381 * \TODO: Release all handles
1383 EINA_LIST_FREE(s_info.script_port_list, item) {
1385 if (dlclose(item->handle) != 0)
1386 ErrPrint("dlclose: %s\n", strerror(errno));
1393 HAPI int script_handler_update_pointer(struct script_info *info, int x, int y, int down)
1396 return LB_STATUS_SUCCESS;
1406 return LB_STATUS_SUCCESS;
1409 HAPI int script_handler_feed_event(struct script_info *info, int event, double timestamp)
1414 ErrPrint("info->port is NIL\n");
1415 return LB_STATUS_ERROR_INVALID;
1418 e = script_handler_evas(info);
1420 ErrPrint("Evas is not exists\n");
1421 return LB_STATUS_ERROR_FAULT;
1424 return info->port->feed_event(info->port_data, e, event, info->x, info->y, info->down, timestamp);