Keep the desc block even if the buffer of lb is not ready.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 29 Apr 2013 14:44:49 +0000 (23:44 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 29 Apr 2013 15:13:06 +0000 (00:13 +0900)
Keep the desc blocks even if the buffer of livebox is not created.
The provider will send the created event to the slave.

Then the slave will start to generate the desc file. (script data)

But the provider cannot apply desc to its buffer.
Because there is no created object.

To resolve this issue,
This patch will create a cache.

It will be used for keeping the blocks which are parsed before creating a buffer of livebox (or PD).

Change-Id: I27ee6fda35f93622eef08216da905b9e1ed0b5c7

src/script_handler.c

index 95e09c4..50ec801 100644 (file)
@@ -129,8 +129,12 @@ struct script_info {
 
        struct script_port *port;
        void *port_data;
+
+       Eina_List *cached_blocks;
 };
 
+static inline void consuming_parsed_block(int lineno, struct inst_info *inst, int is_pd, struct block *block);
+
 static inline struct script_port *find_port(const char *magic_id)
 {
        Eina_List *l;
@@ -144,6 +148,18 @@ static inline struct script_port *find_port(const char *magic_id)
        return NULL;
 }
 
+static inline void delete_block(struct block *block)
+{
+       DbgFree(block->file);
+       DbgFree(block->type);
+       DbgFree(block->part);
+       DbgFree(block->data);
+       DbgFree(block->option);
+       DbgFree(block->id);
+       DbgFree(block->target_id);
+       DbgFree(block);
+}
+
 static void render_pre_cb(void *data, Evas *e, void *event_info)
 {
        struct inst_info *inst = data;
@@ -230,6 +246,15 @@ int script_signal_emit(Evas *e, const char *part, const char *signal, double sx,
        return ret;
 }
 
+static inline void flushing_cached_block(struct script_info *info)
+{
+       struct block *block;
+
+       EINA_LIST_FREE(info->cached_blocks, block) {
+               consuming_parsed_block(-1, info->inst, (instance_pd_script(info->inst) == info), block);
+       }
+}
+
 HAPI int script_handler_load(struct script_info *info, int is_pd)
 {
        int ret;
@@ -270,6 +295,7 @@ HAPI int script_handler_load(struct script_info *info, int is_pd)
                        return LB_STATUS_ERROR_FAULT;
                }
                info->loaded = 1;
+               flushing_cached_block(info);
                script_signal_emit(e, util_uri_to_path(instance_id(info->inst)),
                                is_pd ? "pd,show" : "lb,show", 0.0f, 0.0f, 0.0f, 0.0f);
        } else {
@@ -371,6 +397,7 @@ HAPI struct script_info *script_handler_create(struct inst_info *inst, const cha
 
 HAPI int script_handler_destroy(struct script_info *info)
 {
+       struct block *block;
        if (!info || !info->port) {
                ErrPrint("port is not valid\n");
                return LB_STATUS_ERROR_INVALID;
@@ -385,6 +412,10 @@ HAPI int script_handler_destroy(struct script_info *info)
                ErrPrint("Failed to destroy port, but go ahead\n");
 
        fb_destroy(info->fb);
+
+       EINA_LIST_FREE(info->cached_blocks, block) {
+               delete_block(block);
+       }
        DbgFree(info);
        return LB_STATUS_SUCCESS;
 }
@@ -706,43 +737,14 @@ static int update_info(struct inst_info *inst, struct block *block, int is_pd)
        return LB_STATUS_SUCCESS;
 }
 
-HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const char *descfile, int is_pd)
+static inline void consuming_parsed_block(int lineno, struct inst_info *inst, int is_pd, struct block *block)
 {
-       struct inst_info *inst;
-       FILE *fp;
-       int ch;
-       int lineno;
-       enum state {
-               UNKNOWN = 0x10,
-               BLOCK_OPEN = 0x11,
-               FIELD = 0x12,
-               VALUE = 0x13,
-               BLOCK_CLOSE = 0x14,
-
-               VALUE_TYPE = 0x00,
-               VALUE_PART = 0x01,
-               VALUE_DATA = 0x02,
-               VALUE_FILE = 0x03,
-               VALUE_OPTION = 0x04,
-               VALUE_ID = 0x05,
-               VALUE_TARGET = 0x06,
-       };
-       const char *field_name[] = {
-               "type",
-               "part",
-               "data",
-               "file",
-               "option",
-               "id",
-               "target",
-               NULL
-       };
-       enum state state;
-       register int field_idx;
-       register int idx = 0;
-       register int i;
-       struct block *block;
-       struct {
+       struct script_info *info;
+       /*!
+        * To speed up, use the static.
+        * But this will increase the memory slightly.
+        */
+       static struct {
                const char *type;
                int (*handler)(struct inst_info *inst, struct block *block, int is_pd);
        } handlers[] = {
@@ -784,6 +786,74 @@ HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const ch
                },
        };
 
+       info = is_pd ? instance_pd_script(inst) : instance_lb_script(inst);
+       if (!info) {
+               ErrPrint("info is NIL (%d, %s)\n", is_pd, instance_id(inst));
+               goto free_out;
+       }
+
+       if (script_handler_is_loaded(info)) {
+               register int i = 0;
+
+               while (handlers[i].type) {
+                       if (!strcasecmp(handlers[i].type, block->type)) {
+                               handlers[i].handler(inst, block, is_pd);
+                               break;
+                       }
+                       i++;
+               }
+
+               if (!handlers[i].type)
+                       ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
+
+               goto free_out;
+       } else {
+               info->cached_blocks = eina_list_append(info->cached_blocks, block);
+               DbgPrint("%d: Block is cached (%p), %d, %s\n", lineno, block, eina_list_count(info->cached_blocks), instance_id(inst));
+       }
+
+       return;
+
+free_out:
+       delete_block(block);
+}
+
+HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const char *descfile, int is_pd)
+{
+       struct inst_info *inst;
+       FILE *fp;
+       int ch;
+       int lineno;
+       enum state {
+               UNKNOWN = 0x10,
+               BLOCK_OPEN = 0x11,
+               FIELD = 0x12,
+               VALUE = 0x13,
+               BLOCK_CLOSE = 0x14,
+
+               VALUE_TYPE = 0x00,
+               VALUE_PART = 0x01,
+               VALUE_DATA = 0x02,
+               VALUE_FILE = 0x03,
+               VALUE_OPTION = 0x04,
+               VALUE_ID = 0x05,
+               VALUE_TARGET = 0x06,
+       };
+       const char *field_name[] = {
+               "type",
+               "part",
+               "data",
+               "file",
+               "option",
+               "id",
+               "target",
+               NULL
+       };
+       enum state state;
+       register int field_idx;
+       register int idx = 0;
+       struct block *block;
+
        block = NULL;
        inst = package_find_instance_by_id(pkgname, id);
        if (!inst) {
@@ -797,6 +867,8 @@ HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const ch
                return LB_STATUS_ERROR_IO;
        }
 
+       DbgPrint("Parsing %s\n", descfile);
+
        state = UNKNOWN;
        field_idx = 0;
        lineno = 1;
@@ -1127,28 +1199,7 @@ HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const ch
                                }
                        }
 
-                       i = 0;
-                       while (handlers[i].type) {
-                               if (!strcasecmp(handlers[i].type, block->type)) {
-                                       handlers[i].handler(inst, block, is_pd);
-                                       break;
-                               }
-                               i++;
-                       }
-
-                       if (!handlers[i].type)
-                               ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
-
-                       DbgFree(block->file);
-                       DbgFree(block->type);
-                       DbgFree(block->part);
-                       DbgFree(block->data);
-                       DbgFree(block->option);
-                       DbgFree(block->id);
-                       DbgFree(block->target_id);
-                       DbgFree(block);
-                       block = NULL;
-
+                       consuming_parsed_block(lineno, inst, is_pd, block);
                        state = UNKNOWN;
                        break;
 
@@ -1167,16 +1218,8 @@ HAPI int script_handler_parse_desc(const char *pkgname, const char *id, const ch
 
 errout:
        ErrPrint("Parse error at %d file %s\n", lineno, util_basename(descfile));
-       if (block) {
-               DbgFree(block->file);
-               DbgFree(block->type);
-               DbgFree(block->part);
-               DbgFree(block->data);
-               DbgFree(block->option);
-               DbgFree(block->id);
-               DbgFree(block->target_id);
-               DbgFree(block);
-       }
+       if (block)
+               delete_block(block);
        fclose(fp);
        return LB_STATUS_ERROR_INVALID;
 }