evas/cserve2: Add valid flag on Image_Data and File_Data
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 23 Aug 2013 06:10:03 +0000 (15:10 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 28 Oct 2013 06:47:14 +0000 (15:47 +0900)
Images and Files can be discovered by the client scanner before they
are valid (aka. loaded or opened). We want clients to ignore all
shared objects that are not ready yet, as they are in an undefined
state (values and memory might be invalid).

src/bin/evas/evas_cserve2_cache.c
src/lib/evas/cserve2/evas_cs2.h
src/lib/evas/cserve2/evas_cs2_client.c

index a1cda8c..88cd2c9 100644 (file)
@@ -618,6 +618,7 @@ _open_request_response(Entry *entry, Slave_Msg_Image_Opened *resp, int *size)
         fd->loader_data = cserve2_shared_string_add(ldata);
      }
 
+   fd->valid = EINA_TRUE;
    return _image_opened_msg_create(fd, size);
 }
 
@@ -831,6 +832,7 @@ _load_request_response(Image_Entry *ientry,
    idata = _image_data_find(ENTRYID(ientry));
    if (!idata) return NULL;
 
+   idata->valid = EINA_TRUE;
    _entry_load_finish(ASENTRY(ientry));
    ASENTRY(ientry)->request = NULL;
 
@@ -1529,6 +1531,7 @@ _image_entry_new(Client *client, int rid,
         idata->opts.degree = opts->degree;
         idata->opts.orientation = opts->orientation;
      }
+   idata->valid = EINA_FALSE;
    idata->file_id = ref->entry->id;
    idata->refcount = 1;
    idata->id = image_id;
@@ -2463,10 +2466,11 @@ cserve2_cache_file_open(Client *client, unsigned int client_file_id,
         ERR("Could not create new file entry!");
         return -1;
      }
-   fd->id = file_id; // FIXME: write last (?)
+   fd->valid = EINA_FALSE;
    fd->refcount = 1;
    fd->path = cserve2_shared_string_add(path);
    fd->key = cserve2_shared_string_add(key);
+   fd->id = file_id;
 
    fentry = calloc(1, sizeof(File_Entry));
    ASENTRY(fentry)->type = CSERVE2_IMAGE_FILE;
index 87633f0..bcba89a 100644 (file)
@@ -332,6 +332,7 @@ struct _File_Data {
    int loop_hint;
    Eina_Bool alpha : 1;
    Eina_Bool invalid : 1;
+   Eina_Bool valid : 1;
 };
 
 #define IMAGE_DATA_ARRAY_TAG ('I' | 'M' << 8 | 'A' << 16 | 'G' << 24)
@@ -343,6 +344,7 @@ struct _Image_Data {
    Eina_Bool alpha_sparse : 1;
    Eina_Bool unused : 1;
    Eina_Bool doload : 1;
+   Eina_Bool valid : 1;
 };
 
 #define FONT_DATA_ARRAY_TAG ('F' | 'O' << 8 | 'N' << 16 | 'T' << 24)
index 7746e1d..b378b79 100644 (file)
@@ -440,6 +440,10 @@ _image_opened_cb(void *data, const void *msg_received, int size)
     * -- jpeg
     */
    //DBG("Received OPENED for RID: %d [open_rid: %d]", answer->rid, ie->open_rid);
+
+   if (ie->server_id && !ie->open_rid)
+     return;
+
    if (answer->rid != ie->open_rid)
      {
         WRN("Message rid (%d) differs from expected rid (open_rid: %d)", answer->rid, ie->open_rid);
@@ -536,6 +540,10 @@ _image_loaded_cb(void *data, const void *msg_received, int size)
    Image_Entry *ie = data;
 
    //DBG("Received LOADED for RID: %d [load_rid: %d]", answer->rid, ie->load_rid);
+
+   if (!ie->load_rid)
+     return;
+
    if (answer->rid != ie->load_rid)
      {
         WRN("Message rid (%d) differs from expected rid (load_rid: %d)", answer->rid, ie->load_rid);
@@ -926,7 +934,7 @@ evas_cserve2_image_load_wait(Image_Entry *ie)
 
 #if USE_SHARED_INDEX
    fd = _shared_image_entry_file_data_find(ie);
-   if (fd)
+   if (fd && fd->valid)
      {
         INF("Bypassing socket wait (open_rid %d)", ie->open_rid);
         ie->w = fd->w;
@@ -935,6 +943,7 @@ evas_cserve2_image_load_wait(Image_Entry *ie)
         ie->animated.loop_hint = fd->loop_hint;
         ie->animated.loop_count = fd->loop_count;
         ie->animated.frame_count = fd->frame_count;
+        ie->server_id = fd->id;
         ie->open_rid = 0;
         return CSERVE2_NONE;
      }
@@ -981,7 +990,7 @@ evas_cserve2_image_load_data_wait(Image_Entry *ie)
 
 #if USE_SHARED_INDEX
    idata = _shared_image_entry_image_data_find(ie);
-   if (idata)
+   if (idata && idata->valid)
      {
         // FIXME: Ugly copy & paste from _loaded_handle
         Data_Entry *dentry = ie->data2;
@@ -2196,7 +2205,7 @@ _shared_image_entry_image_data_find(Image_Entry *ie)
          eina_hash_find(_index.images.entries_by_hkey, ie->cache_key);
    if (idata)
      {
-        ERR("Image found in shared index (by cache_key).");
+        DBG("Image found in shared index (by cache_key).");
         goto found;
      }
 
@@ -2254,6 +2263,12 @@ _shared_image_entry_image_data_find(Image_Entry *ie)
      return NULL;
 
 found:
+   if (!idata->valid)
+     {
+        DBG("Found image but it is not ready yet: %d", idata->id);
+        return NULL;
+     }
+
    shmpath = _shared_string_get(idata->shm_id);
    if (!shmpath)
      {