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 <sys/types.h>
35 #include <livebox-errno.h>
37 #include "slave_life.h"
38 #include "slave_rpc.h"
39 #include "client_life.h"
42 #include "buffer_handler.h"
43 #include "script_handler.h"
48 #define INFO_SIZE "size"
49 #define INFO_CATEGORY "category"
52 static const char *type_list[] = {
65 static const char *field_list[] = {
79 Eina_List *script_port_list;
80 enum buffer_type env_buf_type;
82 .script_port_list = NULL,
83 .env_buf_type = BUFFER_TYPE_FILE,
89 const char *(*magic_id)(void);
90 int (*update_color)(void *handle, const char *id, const char *part, const char *rgba);
91 int (*update_text)(void *handle, const char *id, const char *part, const char *text);
92 int (*update_image)(void *handle, const char *id, const char *part, const char *path, const char *option);
93 int (*update_access)(void *handle, const char *id, const char *part, const char *text, const char *option);
94 int (*operate_access)(void *handle, const char *id, const char *part, const char *operation, const char *option);
95 int (*update_script)(void *handle, const char *src_id, const char *target_id, const char *part, const char *path, const char *option);
96 int (*update_signal)(void *handle, const char *id, const char *part, const char *signal);
97 int (*update_drag)(void *handle, const char *id, const char *part, double x, double y);
98 int (*update_size)(void *handle, const char *id, int w, int h);
99 int (*update_category)(void *handle, const char *id, const char *category);
100 int (*feed_event)(void *handle, int event_type, int x, int y, int down, unsigned int keycode, double timestamp);
102 void *(*create)(void *buffer_info, const char *file, const char *option);
103 int (*destroy)(void *handle);
105 int (*load)(void *handle, int (*render_pre)(void *buffer_info, void *data), int (*render_post)(void *buffer_info, void *data), void *data);
106 int (*unload)(void *handle);
108 int (*init)(double scale, int premultiplied);
136 enum block_type type;
144 /* Should be released */
146 const char *filename;
150 struct buffer_info *buffer_handle;
160 unsigned int keycode;
162 struct script_port *port;
165 Eina_List *cached_blocks;
168 static inline void consuming_parsed_block(struct inst_info *inst, int is_pd, struct block *block);
170 static int load_all_ports(void)
172 struct script_port *item;
178 dir = opendir(SCRIPT_PORT_PATH);
180 ErrPrint("Error: %s\n", strerror(errno));
181 return LB_STATUS_ERROR_IO;
184 while ((ent = readdir(dir))) {
185 if (ent->d_name[0] == '.') {
189 pathlen = strlen(ent->d_name) + strlen(SCRIPT_PORT_PATH) + 1;
190 path = malloc(pathlen);
192 ErrPrint("Heap: %s %d\n", strerror(errno), pathlen);
193 if (closedir(dir) < 0) {
194 ErrPrint("closedir: %s\n", strerror(errno));
196 return LB_STATUS_ERROR_MEMORY;
199 snprintf(path, pathlen, "%s%s", SCRIPT_PORT_PATH, ent->d_name);
201 item = malloc(sizeof(*item));
203 ErrPrint("Heap: %s\n", strerror(errno));
205 if (closedir(dir) < 0) {
206 ErrPrint("closedir: %s\n", strerror(errno));
208 return LB_STATUS_ERROR_MEMORY;
211 DbgPrint("Open SCRIPT PORT: %s\n", path);
212 item->handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW | RTLD_DEEPBIND);
215 ErrPrint("Error: %s\n", dlerror());
217 if (closedir(dir) < 0) {
218 ErrPrint("closedir: %s\n", strerror(errno));
220 return LB_STATUS_ERROR_FAULT;
223 item->magic_id = dlsym(item->handle, "script_magic_id");
224 if (!item->magic_id) {
228 DbgPrint("SCRIPT PORT magic id: %s\n", item->magic_id());
230 item->update_color = dlsym(item->handle, "script_update_color");
231 if (!item->update_color) {
235 item->update_text = dlsym(item->handle, "script_update_text");
236 if (!item->update_text) {
240 item->update_image = dlsym(item->handle, "script_update_image");
241 if (!item->update_image) {
245 item->update_access = dlsym(item->handle, "script_update_access");
246 if (!item->update_access) {
250 item->operate_access = dlsym(item->handle, "script_operate_access");
251 if (!item->operate_access) {
255 item->update_script = dlsym(item->handle, "script_update_script");
256 if (!item->update_script) {
260 item->update_signal = dlsym(item->handle, "script_update_signal");
261 if (!item->update_signal) {
265 item->update_drag = dlsym(item->handle, "script_update_drag");
266 if (!item->update_drag) {
270 item->update_size = dlsym(item->handle, "script_update_size");
271 if (!item->update_size) {
275 item->update_category = dlsym(item->handle, "script_update_category");
276 if (!item->update_category) {
280 item->create = dlsym(item->handle, "script_create");
285 item->destroy = dlsym(item->handle, "script_destroy");
286 if (!item->destroy) {
290 item->load = dlsym(item->handle, "script_load");
295 item->unload = dlsym(item->handle, "script_unload");
300 item->init = dlsym(item->handle, "script_init");
305 item->fini = dlsym(item->handle, "script_fini");
310 item->feed_event = dlsym(item->handle, "script_feed_event");
311 if (!item->feed_event) {
315 if (item->init(SCALE_WIDTH_FACTOR, PREMULTIPLIED_COLOR) < 0) {
316 ErrPrint("Failed to initialize script engine\n");
320 s_info.script_port_list = eina_list_append(s_info.script_port_list, item);
323 if (closedir(dir) < 0) {
324 ErrPrint("closedir: %s\n", strerror(errno));
327 return LB_STATUS_SUCCESS;
330 ErrPrint("Error: %s\n", dlerror());
331 if (dlclose(item->handle) != 0) {
332 ErrPrint("dlclose: %s\n", strerror(errno));
335 if (closedir(dir) < 0) {
336 ErrPrint("closedir: %s\n", strerror(errno));
338 return LB_STATUS_ERROR_FAULT;
341 static inline struct script_port *find_port(const char *magic_id)
344 struct script_port *item;
346 if (!s_info.script_port_list) {
349 ret = load_all_ports();
351 ErrPrint("load_all_ports: %d\n", ret);
355 EINA_LIST_FOREACH(s_info.script_port_list, l, item) {
356 if (!strcmp(item->magic_id(), magic_id)) {
364 static inline void delete_block(struct block *block)
366 DbgFree(block->filebuf);
370 static int render_post_cb(void *_buffer_handle, void *data)
374 struct inst_info *inst;
375 struct buffer_info *buffer_handle = _buffer_handle;
376 struct script_info *info;
378 inst = buffer_handler_instance(buffer_handle);
383 if (instance_state(inst) != INST_ACTIVATED) {
384 ErrPrint("Render post invoked but instance is not activated\n");
386 return LB_STATUS_ERROR_INVALID;
389 info = instance_lb_script(inst);
390 if (info && info == data) {
391 buffer_handler_flush(buffer_handle);
392 instance_lb_updated_by_instance(inst, NULL);
393 PERF_MARK("lb,update");
394 return LB_STATUS_SUCCESS;
397 info = instance_pd_script(inst);
398 if (info && info == data) {
399 buffer_handler_flush(buffer_handle);
400 instance_pd_updated_by_instance(inst, NULL);
401 PERF_MARK("pd,update");
402 return LB_STATUS_SUCCESS;
406 ErrPrint("Failed to sync\n");
408 return LB_STATUS_ERROR_FAULT;
415 EAPI int script_signal_emit(void *buffer_handle, const char *part, const char *signal, double sx, double sy, double ex, double ey)
417 struct script_info *info;
418 struct inst_info *inst;
424 if (!buffer_handle) {
425 ErrPrint("Invalid handle\n");
426 return LB_STATUS_ERROR_INVALID;
429 info = buffer_handler_data(buffer_handle);
431 ErrPrint("Invalid handle\n");
432 return LB_STATUS_ERROR_INVALID;
435 inst = buffer_handler_instance(buffer_handle);
437 return LB_STATUS_ERROR_FAULT;
440 if (!signal || strlen(signal) == 0) {
444 if (!part || strlen(part) == 0) {
448 buffer_handler_get_size(buffer_handle, &w, &h);
450 fx = (double)info->x / (double)w;
451 fy = (double)info->y / (double)h;
453 return instance_signal_emit(inst, signal, part, sx, sy, ex, ey, fx, fy, info->down);
456 static inline void flushing_cached_block(struct script_info *info)
459 struct inst_info *inst;
462 inst = buffer_handler_instance(info->buffer_handle);
464 ErrPrint("Instance is not valid\n");
467 is_pd = instance_pd_script(inst) == info;
469 EINA_LIST_FREE(info->cached_blocks, block) {
470 consuming_parsed_block(inst, is_pd, block);
474 HAPI int script_handler_load(struct script_info *info, int is_pd)
476 struct inst_info *inst;
478 if (!info || !info->port) {
479 ErrPrint("Script handler is not created\n");
480 return LB_STATUS_ERROR_INVALID;
483 if (info->loaded > 0) {
485 return LB_STATUS_SUCCESS;
488 if (info->port->load(info->port_data, NULL, render_post_cb, info) < 0) {
489 ErrPrint("Unable to load the script\n");
490 return LB_STATUS_ERROR_FAULT;
494 flushing_cached_block(info);
496 inst = buffer_handler_instance(info->buffer_handle);
498 script_signal_emit(info->buffer_handle, instance_id(inst),
499 is_pd ? "pd,show" : "lb,show", 0.0f, 0.0f, 0.0f, 0.0f);
501 buffer_handler_flush(info->buffer_handle);
502 return LB_STATUS_SUCCESS;
505 HAPI int script_handler_unload(struct script_info *info, int is_pd)
507 if (!info || !info->port) {
508 return LB_STATUS_ERROR_INVALID;
512 if (info->loaded > 0) {
513 return LB_STATUS_ERROR_BUSY;
516 if (info->loaded < 0) {
518 return LB_STATUS_ERROR_ALREADY;
521 if (info->port->unload(info->port_data) < 0) {
522 ErrPrint("Failed to unload script object. but go ahead\n");
525 return LB_STATUS_SUCCESS;
528 HAPI struct script_info *script_handler_create(struct inst_info *inst, const char *file, const char *option, int w, int h)
530 struct script_info *info;
532 DbgPrint("Create script: %s (%s) %dx%d\n", file, option, w, h);
538 info = calloc(1, sizeof(*info));
540 ErrPrint("Heap: %s\n", strerror(errno));
544 info->buffer_handle = buffer_handler_create(inst, s_info.env_buf_type, w, h, sizeof(int));
545 if (!info->buffer_handle) {
546 /* buffer_handler_create will prints some log */
551 (void)buffer_handler_set_data(info->buffer_handle, info);
553 info->port = find_port(package_script(instance_package(inst)));
555 ErrPrint("Failed to find a proper port for [%s]%s\n",
556 instance_package(inst), package_script(instance_package(inst)));
557 buffer_handler_destroy(info->buffer_handle);
562 info->port_data = info->port->create(info->buffer_handle, file, option);
563 if (!info->port_data) {
564 ErrPrint("Failed to create a port (%s - %s)\n", file, option);
565 buffer_handler_destroy(info->buffer_handle);
573 HAPI int script_handler_destroy(struct script_info *info)
578 if (!info || !info->port) {
579 ErrPrint("port is not valid\n");
580 return LB_STATUS_ERROR_INVALID;
583 if (info->loaded != 0) {
584 ErrPrint("Script handler is not unloaded\n");
585 return LB_STATUS_ERROR_BUSY;
588 ret = info->port->destroy(info->port_data);
590 ErrPrint("Failed to destroy port, but go ahead: %d\n", ret);
593 (void)buffer_handler_destroy(info->buffer_handle);
595 EINA_LIST_FREE(info->cached_blocks, block) {
600 return LB_STATUS_SUCCESS;
603 HAPI int script_handler_is_loaded(struct script_info *info)
605 return info ? info->loaded > 0 : 0;
608 HAPI struct buffer_info *script_handler_buffer_info(struct script_info *info)
614 return info->buffer_handle;
617 static int update_script_color(struct inst_info *inst, struct block *block, int is_pd)
621 struct script_info *info;
624 if (!block || !block->part || !block->data) {
625 ErrPrint("Block or part or data is not valid\n");
627 return LB_STATUS_ERROR_INVALID;
630 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
632 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
634 return LB_STATUS_ERROR_FAULT;
638 ErrPrint("info->port is NIL (%d, %s)\n", is_pd, instance_id(inst));
640 return LB_STATUS_ERROR_INVALID;
643 ret = info->port->update_color(info->port_data, block->id, block->part, block->data);
648 static int update_script_text(struct inst_info *inst, struct block *block, int is_pd)
652 struct script_info *info;
655 if (!block || !block->part || !block->data) {
656 ErrPrint("Block or part or data is not valid\n");
658 return LB_STATUS_ERROR_INVALID;
661 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
663 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
665 return LB_STATUS_ERROR_FAULT;
669 ErrPrint("info->port is NIL\n");
671 return LB_STATUS_ERROR_INVALID;
674 DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data);
675 ret = info->port->update_text(info->port_data, block->id, block->part, block->data);
681 static int update_script_image(struct inst_info *inst, struct block *block, int is_pd)
685 struct script_info *info;
688 if (!block || !block->part) {
689 ErrPrint("Block or part is not valid\n");
691 return LB_STATUS_ERROR_INVALID;
694 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
696 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
698 return LB_STATUS_ERROR_FAULT;
702 ErrPrint("info->port is NIL\n");
704 return LB_STATUS_ERROR_INVALID;
707 DbgPrint("[%s] %s (%s)\n", block->id, block->part, block->data);
708 ret = info->port->update_image(info->port_data, block->id, block->part, block->data, block->option);
713 static int update_access(struct inst_info *inst, struct block *block, int is_pd)
717 struct script_info *info;
720 if (!block || !block->part) {
721 ErrPrint("Block or block->part is NIL\n");
723 return LB_STATUS_ERROR_INVALID;
726 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
728 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
730 return LB_STATUS_ERROR_FAULT;
734 ErrPrint("info->port is NIL\n");
736 return LB_STATUS_ERROR_INVALID;
739 ret = info->port->update_access(info->port_data, block->id, block->part, block->data, block->option);
744 static int operate_access(struct inst_info *inst, struct block *block, int is_pd)
748 struct script_info *info;
751 if (!block || !block->part) {
752 ErrPrint("Block or block->part is NIL\n");
753 PERF_MARK("operate_access");
754 return LB_STATUS_ERROR_INVALID;
757 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
759 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
760 PERF_MARK("operate_access");
761 return LB_STATUS_ERROR_FAULT;
765 ErrPrint("info->port is NIL\n");
766 PERF_MARK("operate_access");
767 return LB_STATUS_ERROR_INVALID;
770 ret = info->port->operate_access(info->port_data, block->id, block->part, block->data, block->option);
771 PERF_MARK("operate_access");
775 static int update_script_script(struct inst_info *inst, struct block *block, int is_pd)
779 struct script_info *info;
782 if (!block || !block->part) {
783 ErrPrint("Block or part is NIL\n");
785 return LB_STATUS_ERROR_INVALID;
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));
792 return LB_STATUS_ERROR_FAULT;
796 ErrPrint("info->port is NIL\n");
798 return LB_STATUS_ERROR_INVALID;
801 ret = info->port->update_script(info->port_data, block->id, block->target, block->part, block->data, block->option);
806 static int update_script_signal(struct inst_info *inst, struct block *block, int is_pd)
810 struct script_info *info;
814 ErrPrint("block is NIL\n");
816 return LB_STATUS_ERROR_INVALID;
819 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
821 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
823 return LB_STATUS_ERROR_FAULT;
827 ErrPrint("info->port is NIL\n");
829 return LB_STATUS_ERROR_INVALID;
832 ret = info->port->update_signal(info->port_data, block->id, block->part, block->data);
837 static int update_script_drag(struct inst_info *inst, struct block *block, int is_pd)
841 struct script_info *info;
845 if (!block || !block->data || !block->part) {
846 ErrPrint("block or block->data or block->part is NIL\n");
848 return LB_STATUS_ERROR_INVALID;
851 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
853 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
855 return LB_STATUS_ERROR_FAULT;
858 if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
859 ErrPrint("Invalid format of data (DRAG data [%s])\n", block->data);
861 return LB_STATUS_ERROR_INVALID;
865 ErrPrint("info->port is NIL\n");
867 return LB_STATUS_ERROR_INVALID;
870 ret = info->port->update_drag(info->port_data, block->id, block->part, dx, dy);
875 static void update_size_for_script(struct script_info *info, struct inst_info *inst, int w, int h)
879 * After update the buffer size,
880 * If it required to be unload and load.
881 * New size of buffer will be allocated
883 buffer_handler_update_size(info->buffer_handle, w, h);
885 if (info->port->update_size) {
886 (void)info->port->update_size(info->port_data, NULL, w, h);
889 if (instance_lb_script(inst) == info) {
890 instance_set_lb_size(inst, w, h);
891 } else if (instance_pd_script(inst) == info) {
892 instance_set_pd_size(inst, w, h);
894 ErrPrint("Unknown script\n");
898 HAPI int script_handler_resize(struct script_info *info, int w, int h)
902 struct inst_info *inst;
905 ErrPrint("info[%p] resize is ignored\n", info);
907 return LB_STATUS_SUCCESS;
910 inst = buffer_handler_instance(info->buffer_handle);
912 ErrPrint("Instance is not valid\n");
914 return LB_STATUS_ERROR_INVALID;
917 update_size_for_script(info, inst, w, h);
920 return LB_STATUS_SUCCESS;
923 HAPI const char *script_handler_buffer_id(struct script_info *info)
925 if (!info || !info->buffer_handle) {
926 ErrPrint("Invalid info\n");
930 return buffer_handler_id(info->buffer_handle);
933 static int update_info(struct inst_info *inst, struct block *block, int is_pd)
937 struct script_info *info;
939 if (!block || !block->part || !block->data) {
940 ErrPrint("block or block->part or block->data is NIL\n");
942 return LB_STATUS_ERROR_INVALID;
945 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
947 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
949 return LB_STATUS_ERROR_FAULT;
953 ErrPrint("info->port is NIL\n");
955 return LB_STATUS_ERROR_INVALID;
958 if (!strcasecmp(block->part, INFO_SIZE)) {
961 if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
962 ErrPrint("Invalid format for SIZE(%s)\n", block->data);
964 return LB_STATUS_ERROR_INVALID;
968 update_size_for_script(info, inst, w, h);
970 (void)info->port->update_size(info->port_data, block->id, w, h);
972 } else if (!strcasecmp(block->part, INFO_CATEGORY)) {
973 (void)info->port->update_category(info->port_data, block->id, block->data);
977 return LB_STATUS_SUCCESS;
980 static inline void consuming_parsed_block(struct inst_info *inst, int is_pd, struct block *block)
982 struct script_info *info;
983 typedef int (*update_function_t)(struct inst_info *inst, struct block *block, int is_pd);
984 update_function_t updators[] = {
991 update_script_script,
992 update_script_signal,
997 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
999 ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
1003 if (script_handler_is_loaded(info)) {
1004 if (block->type >= 0 || block->type < TYPE_MAX) {
1005 (void)updators[block->type](inst, block, is_pd);
1007 ErrPrint("Block type[%d] is not valid\n", block->type);
1010 info->cached_blocks = eina_list_append(info->cached_blocks, block);
1011 DbgPrint("Block is cached (%p), %d, %s\n", block, eina_list_count(info->cached_blocks), instance_id(inst));
1016 delete_block(block);
1019 HAPI int script_init(void)
1021 if (!strcasecmp(PROVIDER_METHOD, "shm")) {
1022 s_info.env_buf_type = BUFFER_TYPE_SHM;
1023 } else if (!strcasecmp(PROVIDER_METHOD, "pixmap")) {
1024 s_info.env_buf_type = BUFFER_TYPE_PIXMAP;
1027 return LB_STATUS_SUCCESS;
1030 HAPI int script_fini(void)
1032 struct script_port *item;
1034 * \TODO: Release all handles
1036 EINA_LIST_FREE(s_info.script_port_list, item) {
1038 if (dlclose(item->handle) != 0) {
1039 ErrPrint("dlclose: %s\n", strerror(errno));
1047 HAPI int script_handler_update_pointer(struct script_info *info, int x, int y, int down)
1050 return LB_STATUS_SUCCESS;
1058 } else if (down == 1) {
1062 return LB_STATUS_SUCCESS;
1065 HAPI int script_handler_update_keycode(struct script_info *info, unsigned int keycode)
1068 return LB_STATUS_SUCCESS;
1071 info->keycode = keycode;
1073 return LB_STATUS_SUCCESS;
1076 HAPI int script_handler_feed_event(struct script_info *info, int event, double timestamp)
1081 ErrPrint("info->port is NIL\n");
1082 return LB_STATUS_ERROR_INVALID;
1085 ret = info->port->feed_event(info->port_data, event, info->x, info->y, info->down, info->keycode, timestamp);
1089 static inline char *load_file(const char *filename)
1091 char *filebuf = NULL;
1095 size_t readsize = 0;
1097 fd = open(filename, O_RDONLY);
1099 ErrPrint("open: %s\n", strerror(errno));
1103 filesize = lseek(fd, 0L, SEEK_END);
1104 if (filesize == (off_t)-1) {
1105 ErrPrint("lseek: %s\n", strerror(errno));
1109 if (lseek(fd, 0L, SEEK_SET) < 0) {
1110 ErrPrint("lseek: %s\n", strerror(errno));
1114 filebuf = malloc(filesize + 1);
1116 ErrPrint("malloc: %s\n", strerror(errno));
1120 while (readsize < filesize) {
1121 ret = read(fd, filebuf + readsize, (size_t)filesize - readsize);
1123 if (errno == EINTR) {
1124 DbgPrint("Read is interrupted\n");
1128 ErrPrint("read: %s\n", strerror(errno));
1138 filebuf[readsize] = '\0';
1143 * Now, we are ready to parse the filebuf.
1147 if (close(fd) < 0) {
1148 ErrPrint("close: %s\n", strerror(errno));
1154 #if defined(_APPLY_SCRIPT_ASYNC_UPDATE)
1156 struct inst_info *inst;
1157 Eina_List *block_list;
1161 static Eina_Bool apply_changes_cb(void *_data)
1163 struct apply_data *data = _data;
1164 struct block *block;
1166 block = eina_list_nth(data->block_list, 0);
1167 data->block_list = eina_list_remove(data->block_list, block);
1168 consuming_parsed_block(data->inst, data->is_pd, block);
1170 if (!data->block_list) {
1172 return ECORE_CALLBACK_CANCEL;
1175 return ECORE_CALLBACK_RENEW;
1180 HAPI int script_handler_parse_desc(struct inst_info *inst, const char *filename, int is_pd)
1191 struct block *block = NULL;
1192 Eina_List *block_list = NULL;
1202 filebuf = load_file(filename);
1204 return LB_STATUS_ERROR_IO;
1210 while (*fileptr && state != ERROR) {
1213 if (*fileptr == '{') {
1214 block = calloc(1, sizeof(*block));
1216 ErrPrint("calloc: %s\n", strerror(errno));
1225 if (isspace(*fileptr)) {
1229 } else if (*fileptr == '=') {
1233 } else if (ptr == NULL) {
1238 while (field_list[field_idx]) {
1239 if (field_list[field_idx][field_len] == *fileptr) {
1245 if (!field_list[field_idx]) {
1246 ErrPrint("Invalid field\n");
1253 if (field_list[field_idx][field_len] != *fileptr) {
1255 while (field_list[field_idx]) {
1256 if (!strncmp(field_list[field_idx], fileptr - field_len, field_len)) {
1263 if (!field_list[field_idx]) {
1265 ErrPrint("field is not valid\n");
1274 switch (field_idx) {
1277 if (isspace(*fileptr)) {
1281 if (*fileptr == '\0') {
1283 ErrPrint("Type is not valid\n");
1292 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1296 if (type_list[type_idx][type_len] != *fileptr) {
1298 while (type_list[type_idx]) {
1299 if (!strncmp(type_list[type_idx], fileptr - type_len, type_len)) {
1306 if (!type_list[type_idx]) {
1308 ErrPrint("type is not valid (%s)\n", fileptr - type_len);
1314 block->type = type_idx;
1326 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1341 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1356 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1361 block->option = ptr;
1371 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1386 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1391 block->target = ptr;
1401 if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) {
1406 block->target = ptr;
1416 if (isspace(*fileptr)) {
1417 } else if (*fileptr == '}') {
1419 block->filename = filename;
1420 block_list = eina_list_append(block_list, block);
1435 if (state != BEGIN) {
1436 ErrPrint("State %d\n", state);
1441 EINA_LIST_FREE(block_list, block) {
1445 PERF_MARK("parser");
1446 return LB_STATUS_ERROR_FAULT;
1449 block = eina_list_data_get(eina_list_last(block_list));
1451 block->filebuf = filebuf;
1453 ErrPrint("Last block is not exists (There is no parsed block)\n");
1457 PERF_MARK("parser");
1459 #if defined(_APPLY_SCRIPT_ASYNC_UPDATE)
1460 struct apply_data *data;
1462 data = malloc(sizeof(*data));
1465 data->is_pd = is_pd;
1466 data->block_list = block_list;
1467 if (!ecore_timer_add(0.001f, apply_changes_cb, data)) {
1468 ErrPrint("Failed to add timer\n");
1470 EINA_LIST_FREE(block_list, block) {
1471 consuming_parsed_block(inst, is_pd, block);
1475 ErrPrint("Heap: %s\n", strerror(errno));
1476 EINA_LIST_FREE(block_list, block) {
1477 consuming_parsed_block(inst, is_pd, block);
1481 ErrPrint("Begin: Set content for EDJE object\n");
1482 EINA_LIST_FREE(block_list, block) {
1483 consuming_parsed_block(inst, is_pd, block);
1485 ErrPrint("End: Set content for EDJE object\n");
1488 * Doesn't need to force to render the contents.
1489 struct script_info *info;
1490 info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
1491 if (info && info->ee) {
1492 ecore_evas_manual_render(info->ee);
1497 return LB_STATUS_SUCCESS;