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 DbgPrint("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 DbgPrint("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)\n", file, option);
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);
381 DbgPrint("Update info [%dx%d]\n", w, h);
385 info->port_data = info->port->create(file, option);
386 if (!info->port_data) {
387 ErrPrint("Failed to create a port (%s - %s)\n", file, option);
388 fb_destroy(info->fb);
396 HAPI int script_handler_destroy(struct script_info *info)
401 if (!info || !info->port) {
402 ErrPrint("port is not valid\n");
403 return LB_STATUS_ERROR_INVALID;
406 if (info->loaded != 0) {
407 ErrPrint("Script handler is not unloaded\n");
408 return LB_STATUS_ERROR_INVALID;
411 ret = info->port->destroy(info->port_data);
413 ErrPrint("Failed to destroy port, but go ahead: %d\n", ret);
415 fb_destroy(info->fb);
417 EINA_LIST_FREE(info->cached_blocks, block) {
421 return LB_STATUS_SUCCESS;
424 HAPI int script_handler_is_loaded(struct script_info *info)
426 return info ? info->loaded > 0 : 0;
429 HAPI struct fb_info *script_handler_fb(struct script_info *info)
431 return info ? info->fb : NULL;
434 HAPI void *script_handler_evas(struct script_info *info)
442 return ecore_evas_get(info->ee);
445 static int update_script_color(struct inst_info *inst, struct block *block, int is_pd)
447 struct script_info *info;
450 if (!block || !block->part || !block->data) {
451 ErrPrint("Block or part or data is not valid\n");
452 return LB_STATUS_ERROR_INVALID;
455 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
457 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
458 return LB_STATUS_ERROR_FAULT;
462 ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst));
463 return LB_STATUS_ERROR_INVALID;
466 e = script_handler_evas(info);
468 info->port->update_color(info->port_data, e, block->id, block->part, block->data);
470 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
472 return LB_STATUS_SUCCESS;
475 static int update_script_text(struct inst_info *inst, struct block *block, int is_pd)
477 struct script_info *info;
480 if (!block || !block->part || !block->data) {
481 ErrPrint("Block or part or data is not valid\n");
482 return LB_STATUS_ERROR_INVALID;
485 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
487 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
488 return LB_STATUS_ERROR_FAULT;
492 ErrPrint("info->port is NIL\n");
493 return LB_STATUS_ERROR_INVALID;
496 e = script_handler_evas(info);
498 info->port->update_text(info->port_data, e, block->id, block->part, block->data);
500 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
501 return LB_STATUS_SUCCESS;
504 static int update_script_image(struct inst_info *inst, struct block *block, int is_pd)
506 struct script_info *info;
509 if (!block || !block->part) {
510 ErrPrint("Block or part is not valid\n");
511 return LB_STATUS_ERROR_INVALID;
514 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
516 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
517 return LB_STATUS_ERROR_FAULT;
521 ErrPrint("info->port is NIL\n");
522 return LB_STATUS_ERROR_INVALID;
525 e = script_handler_evas(info);
527 info->port->update_image(info->port_data, e, block->id, block->part, block->data, block->option);
529 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
530 return LB_STATUS_SUCCESS;
533 static int update_access(struct inst_info *inst, struct block *block, int is_pd)
535 struct script_info *info;
538 if (!block || !block->part) {
539 ErrPrint("Block or block->part is NIL\n");
540 return LB_STATUS_ERROR_INVALID;
543 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
545 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
546 return LB_STATUS_ERROR_FAULT;
550 ErrPrint("info->port is NIL\n");
551 return LB_STATUS_ERROR_INVALID;
554 e = script_handler_evas(info);
556 info->port->update_access(info->port_data, e, block->id, block->part, block->data, block->option);
558 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
559 return LB_STATUS_SUCCESS;
562 static int update_script_script(struct inst_info *inst, struct block *block, int is_pd)
564 struct script_info *info;
567 if (!block || !block->part) {
568 ErrPrint("Block or part is NIL\n");
569 return LB_STATUS_ERROR_INVALID;
572 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
574 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
575 return LB_STATUS_ERROR_FAULT;
579 ErrPrint("info->port is NIL\n");
580 return LB_STATUS_ERROR_INVALID;
583 e = script_handler_evas(info);
585 info->port->update_script(info->port_data, e, block->id, block->target_id, block->part, block->data, block->option);
587 ErrPrint("Evas: (nil) id[%s] part[%s] data[%s] option[%s]\n",
588 block->id, block->part, block->data, block->option);
589 return LB_STATUS_SUCCESS;
592 static int update_script_signal(struct inst_info *inst, struct block *block, int is_pd)
594 struct script_info *info;
598 ErrPrint("block is NIL\n");
599 return LB_STATUS_ERROR_INVALID;
602 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
604 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
605 return LB_STATUS_ERROR_FAULT;
609 ErrPrint("info->port is NIL\n");
610 return LB_STATUS_ERROR_INVALID;
613 e = script_handler_evas(info);
615 info->port->update_signal(info->port_data, e, block->id, block->part, block->data);
617 ErrPrint("Evas(nil) id[%s] part[%s] data[%s]\n", block->id, block->part, block->data);
618 return LB_STATUS_SUCCESS;
621 static int update_script_drag(struct inst_info *inst, struct block *block, int is_pd)
623 struct script_info *info;
627 if (!block || !block->data || !block->part) {
628 ErrPrint("block or block->data or block->part is NIL\n");
629 return LB_STATUS_ERROR_INVALID;
632 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
634 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
635 return LB_STATUS_ERROR_FAULT;
638 if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
639 ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data);
640 return LB_STATUS_ERROR_INVALID;
644 ErrPrint("info->port is NIL\n");
645 return LB_STATUS_ERROR_INVALID;
648 e = script_handler_evas(info);
650 info->port->update_drag(info->port_data, e, block->id, block->part, dx, dy);
652 ErrPrint("Evas(nil) id[%s] part[%s] %lfx%lf\n", block->id, block->part, dx, dy);
653 return LB_STATUS_SUCCESS;
656 HAPI int script_handler_resize(struct script_info *info, int w, int h)
659 //|| (info->w == w && info->h == h)) {
660 ErrPrint("info[%p] resize is ignored\n", info);
661 return LB_STATUS_SUCCESS;
664 fb_resize(script_handler_fb(info), w, h);
666 if (info->port->update_size) {
668 e = script_handler_evas(info);
670 info->port->update_size(info->port_data, e, NULL , w, h);
672 ErrPrint("Evas(nil) resize to %dx%d\n", w, h);
675 if (instance_lb_script(info->inst) == info) {
676 instance_set_lb_size(info->inst, w, h);
677 } else if (instance_pd_script(info->inst) == info) {
678 instance_set_pd_size(info->inst, w, h);
680 ErrPrint("Script is not known\n");
686 return LB_STATUS_SUCCESS;
689 static int update_info(struct inst_info *inst, struct block *block, int is_pd)
691 struct script_info *info;
693 if (!block || !block->part || !block->data) {
694 ErrPrint("block or block->part or block->data is NIL\n");
695 return LB_STATUS_ERROR_INVALID;
698 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
700 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
701 return LB_STATUS_ERROR_FAULT;
705 ErrPrint("info->port is NIL\n");
706 return LB_STATUS_ERROR_INVALID;
709 if (!strcasecmp(block->part, INFO_SIZE)) {
712 if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
713 ErrPrint("Invalid format for SIZE(%s)\n", block->data);
714 return LB_STATUS_ERROR_INVALID;
718 script_handler_resize(info, w, h);
721 e = script_handler_evas(info);
723 info->port->update_size(info->port_data, e, block->id, w, h);
725 ErrPrint("Evas(nil): id[%s] %dx%d\n", block->id, w, h);
727 } else if (!strcasecmp(block->part, INFO_CATEGORY)) {
729 e = script_handler_evas(info);
731 info->port->update_category(info->port_data, e, block->id, block->data);
733 ErrPrint("Evas(nil): id[%s] data[%s]\n", block->id, block->data);
736 return LB_STATUS_SUCCESS;
739 static inline void consuming_parsed_block(int lineno, struct inst_info *inst, int is_pd, struct block *block)
741 struct script_info *info;
743 * To speed up, use the static.
744 * But this will increase the memory slightly.
748 int (*handler)(struct inst_info *inst, struct block *block, int is_pd);
752 .handler = update_script_color,
756 .handler = update_script_text,
760 .handler = update_script_image,
764 .handler = update_script_script,
768 .handler = update_script_signal,
772 .handler = update_script_drag,
776 .handler = update_info,
780 .handler = update_access,
788 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
790 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
794 if (script_handler_is_loaded(info)) {
797 while (handlers[i].type) {
798 if (!strcasecmp(handlers[i].type, block->type)) {
799 handlers[i].handler(inst, block, is_pd);
805 if (!handlers[i].type)
806 ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
810 info->cached_blocks = eina_list_append(info->cached_blocks, block);
811 DbgPrint("%d: Block is cached (%p), %d, %s\n", lineno, block, eina_list_count(info->cached_blocks), instance_id(inst));
820 HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const char *descfile, int is_pd)
822 struct inst_info *inst;
841 const char *field_name[] = {
852 register int field_idx;
853 register int idx = 0;
857 inst = package_find_instance_by_id(pkgname, id);
859 ErrPrint("Instance is not exists\n");
860 return LB_STATUS_ERROR_NOT_EXIST;
863 fp = fopen(descfile, "rt");
865 ErrPrint("Error: %s [%s]\n", descfile, strerror(errno));
866 return LB_STATUS_ERROR_IO;
869 DbgPrint("Start parsing %s\n", descfile);
888 if (!isspace(ch) && ch != EOF) {
889 ErrPrint("%d: Syntax error: Desc is not started with '{' or space - (%c = 0x%x)\n", lineno, ch, ch);
891 ErrPrint("fclose: %s\n", strerror(errno));
892 return LB_STATUS_ERROR_INVALID;
901 ErrPrint("%d: Syntax error: New line must has to be started right after '{'\n", lineno);
905 block = calloc(1, sizeof(*block));
907 ErrPrint("Heap: %s\n", strerror(errno));
909 ErrPrint("fclose: %s\n", strerror(errno));
910 return LB_STATUS_ERROR_MEMORY;
928 if (field_name[field_idx][idx] != '\0') {
929 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
937 DbgFree(block->type);
946 DbgFree(block->part);
955 DbgFree(block->data);
964 DbgFree(block->file);
971 state = VALUE_OPTION;
973 DbgFree(block->option);
974 block->option = NULL;
975 block->option_len = 0;
989 state = VALUE_TARGET;
990 if (block->target_id) {
991 DbgFree(block->target_id);
992 block->target_id = NULL;
993 block->target_len = 0;
998 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
1008 if (field_name[field_idx][idx] != ch) {
1014 ungetc(field_name[field_idx][idx], fp);
1017 if (field_name[field_idx] == NULL) {
1018 ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
1030 if (idx == block->type_len) {
1032 block->type_len += ADDEND;
1033 tmp = realloc(block->type, block->type_len);
1035 ErrPrint("Heap: %s\n", strerror(errno));
1042 block->type[idx] = '\0';
1049 block->type[idx] = ch;
1054 if (idx == block->part_len) {
1056 block->part_len += ADDEND;
1057 tmp = realloc(block->part, block->part_len);
1059 ErrPrint("Heap: %s\n", strerror(errno));
1066 block->part[idx] = '\0';
1073 block->part[idx] = ch;
1078 if (idx == block->data_len) {
1080 block->data_len += ADDEND;
1081 tmp = realloc(block->data, block->data_len);
1083 ErrPrint("Heap: %s\n", strerror(errno));
1090 block->data[idx] = '\0';
1097 block->data[idx] = ch;
1102 if (idx == block->file_len) {
1104 block->file_len += ADDEND;
1105 tmp = realloc(block->file, block->file_len);
1107 ErrPrint("Heap: %s\n", strerror(errno));
1114 block->file[idx] = '\0';
1121 block->file[idx] = ch;
1126 if (idx == block->option_len) {
1128 block->option_len += ADDEND;
1129 tmp = realloc(block->option, block->option_len);
1131 ErrPrint("Heap: %s\n", strerror(errno));
1134 block->option = tmp;
1138 block->option[idx] = '\0';
1145 block->option[idx] = ch;
1149 if (idx == block->id_len) {
1151 block->id_len += ADDEND;
1152 tmp = realloc(block->id, block->id_len);
1154 ErrPrint("Heap: %s\n", strerror(errno));
1161 block->id[idx] = '\0';
1168 block->id[idx] = ch;
1172 if (idx == block->target_len) {
1174 block->target_len += ADDEND;
1175 tmp = realloc(block->target_id, block->target_len);
1177 ErrPrint("Heap: %s\n", strerror(errno));
1180 block->target_id = tmp;
1184 block->target_id[idx] = '\0';
1191 block->target_id[idx] = ch;
1196 block->file = strdup(util_uri_to_path(id));
1198 ErrPrint("Heap: %s\n", strerror(errno));
1203 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);