summaryrefslogtreecommitdiff
path: root/src/lib/evas/cserve2/evas_cs2_client.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-07-29 15:41:23 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:13 +0900
commit88ef4131a0df0735ebef19306285b4bea608cbab (patch)
treed59961ffc1c7a6253c3e5ac2a2be300d18c94b25 /src/lib/evas/cserve2/evas_cs2_client.c
parent47be3a2b819ed6319a65018195b31b622b547aab (diff)
evas/cserve2: Share paths of index tables with clients
- Send paths to all connected clients - Send paths upon connection from a new client - Client side: - Fast find opened images - Fast find loaded images - Optimize load by skipping socket wait Also, remap indexes when needed (file size changed) When index file grows, the clients are not notified, so they must constantly check that their mapping matches the current array size.
Diffstat (limited to '')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c616
1 files changed, 497 insertions, 119 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index a52d547386..73d0936e66 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -21,6 +21,7 @@ typedef void (*Op_Callback)(void *data, const void *msg, int size);
21 21
22struct _File_Entry { 22struct _File_Entry {
23 unsigned int file_id; 23 unsigned int file_id;
24 unsigned int server_file_id;
24}; 25};
25 26
26struct _Client_Request { 27struct _Client_Request {
@@ -44,7 +45,10 @@ static Eina_List *_requests = NULL;
44 45
45// Shared index table 46// Shared index table
46static Index_Table _index; 47static Index_Table _index;
48static const char *_shared_string_get(int id);
47static int _server_index_list_set(Msg_Base *data, int size); 49static int _server_index_list_set(Msg_Base *data, int size);
50static const File_Data *_shared_image_entry_file_data_find(Image_Entry *ie);
51static const Image_Data *_shared_image_entry_image_data_find(Image_Entry *ie);
48 52
49#ifndef UNIX_PATH_MAX 53#ifndef UNIX_PATH_MAX
50#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path) 54#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
@@ -325,123 +329,6 @@ _next_rid(void)
325 return _rid_count++; 329 return _rid_count++;
326} 330}
327 331
328// Returns the number of correctly opened index arrays
329static int
330_server_index_list_set(Msg_Base *data, int size)
331{
332 Msg_Index_List *msg = (Msg_Index_List *) data;
333 unsigned sz;
334 int ret = 0;
335
336 if (size != sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
337 {
338 CRIT("Invalid message! type: %d, size: %d (expected %d)",
339 msg->base.type, size, (int) sizeof(*msg));
340 return -1;
341 }
342
343 // Reset index table
344 if (_index.files.f)
345 {
346 if (_index.files.header)
347 eina_file_map_free(_index.files.f, (void *) _index.files.header);
348 eina_file_close(_index.files.f);
349 }
350 if (_index.images.f)
351 {
352 if (_index.images.header)
353 eina_file_map_free(_index.images.f, (void *) _index.images.header);
354 eina_file_close(_index.images.f);
355 }
356 if (_index.fonts.f)
357 {
358 if (_index.fonts.header)
359 eina_file_map_free(_index.fonts.f, (void *) _index.fonts.header);
360 eina_file_close(_index.fonts.f);
361 }
362 memset(&_index, 0, sizeof(_index));
363
364 // Open new indexes
365 eina_strlcpy(_index.files.path, msg->files_index_path, 64);
366 eina_strlcpy(_index.images.path, msg->images_index_path, 64);
367 eina_strlcpy(_index.fonts.path, msg->fonts_index_path, 64);
368
369 if (_index.files.path[0])
370 {
371 _index.files.f = eina_file_open(_index.files.path, EINA_TRUE);
372 sz = eina_file_size_get(_index.files.f);
373 if (sz < sizeof(Shared_Array_Header))
374 {
375 ERR("Shared index for files is too small: %u", sz);
376 eina_file_close(_index.files.f);
377 _index.files.f = NULL;
378 }
379 else
380 {
381 _index.files.header = eina_file_map_all(_index.files.f,
382 EINA_FILE_WILLNEED);
383 if (sz < (_index.files.header->count * sizeof(File_Data)
384 + sizeof(Shared_Array_Header)))
385 {
386 ERR("Shared index size does not match array size: %u / %u",
387 sz, _index.files.header->count);
388 eina_file_map_free(_index.files.f,
389 (void *) _index.files.header);
390 eina_file_close(_index.files.f);
391 _index.files.f = NULL;
392 }
393 else
394 {
395 _index.files.entries = (File_Data *) &(_index.files.header[1]);
396 DBG("Mapped files shared index '%s' at %p: %u entries max",
397 _index.files.path, _index.files.header,
398 _index.files.header->count);
399 ret++;
400 }
401 }
402 }
403
404 if (_index.images.path[0])
405 {
406 _index.images.f = eina_file_open(_index.images.path, EINA_TRUE);
407 sz = eina_file_size_get(_index.images.f);
408 if (sz < sizeof(Shared_Array_Header))
409 {
410 ERR("Shared index for images is too small: %u", sz);
411 eina_file_close(_index.images.f);
412 _index.images.f = NULL;
413 }
414 else
415 {
416 _index.images.header = eina_file_map_all(_index.images.f,
417 EINA_FILE_WILLNEED);
418 if (sz < (_index.images.header->count * sizeof(Image_Data)
419 + sizeof(Shared_Array_Header)))
420 {
421 ERR("Shared index size does not match array size: %u / %u",
422 sz, _index.images.header->count);
423 eina_file_map_free(_index.images.f,
424 (void *) _index.images.header);
425 eina_file_close(_index.images.f);
426 _index.images.f = NULL;
427 }
428 else
429 {
430 _index.images.entries = (Image_Data *) &(_index.images.header[1]);
431 DBG("Mapped images shared index '%s' at %p: %u entries max",
432 _index.images.path, _index.images.header,
433 _index.images.header->count);
434 ret++;
435 }
436 }
437 }
438
439 if (_index.fonts.path[0])
440 ERR("Not implemented yet: fonts shared index");
441
442 return ret;
443}
444
445static unsigned int 332static unsigned int
446_server_dispatch(Eina_Bool *failed) 333_server_dispatch(Eina_Bool *failed)
447{ 334{
@@ -546,7 +433,10 @@ _image_opened_cb(void *data, const void *msg_received, int size)
546 */ 433 */
547 //DBG("Received OPENED for RID: %d [open_rid: %d]", answer->rid, ie->open_rid); 434 //DBG("Received OPENED for RID: %d [open_rid: %d]", answer->rid, ie->open_rid);
548 if (answer->rid != ie->open_rid) 435 if (answer->rid != ie->open_rid)
549 WRN("Message rid (%d) differs from expected rid (open_rid: %d)", answer->rid, ie->open_rid); 436 {
437 WRN("Message rid (%d) differs from expected rid (open_rid: %d)", answer->rid, ie->open_rid);
438 return;
439 }
550 ie->open_rid = 0; 440 ie->open_rid = 0;
551 441
552 if (answer->type != CSERVE2_OPENED) 442 if (answer->type != CSERVE2_OPENED)
@@ -639,7 +529,10 @@ _image_loaded_cb(void *data, const void *msg_received, int size)
639 529
640 //DBG("Received LOADED for RID: %d [load_rid: %d]", answer->rid, ie->load_rid); 530 //DBG("Received LOADED for RID: %d [load_rid: %d]", answer->rid, ie->load_rid);
641 if (answer->rid != ie->load_rid) 531 if (answer->rid != ie->load_rid)
642 WRN("Message rid (%d) differs from expected rid (load_rid: %d)", answer->rid, ie->load_rid); 532 {
533 WRN("Message rid (%d) differs from expected rid (load_rid: %d)", answer->rid, ie->load_rid);
534 return;
535 }
643 ie->load_rid = 0; 536 ie->load_rid = 0;
644 537
645 if (!ie->data2) 538 if (!ie->data2)
@@ -1008,9 +901,25 @@ evas_cserve2_image_load(Image_Entry *ie)
1008int 901int
1009evas_cserve2_image_load_wait(Image_Entry *ie) 902evas_cserve2_image_load_wait(Image_Entry *ie)
1010{ 903{
904 const File_Data *fd;
905
1011 if (!ie) 906 if (!ie)
1012 return CSERVE2_GENERIC; 907 return CSERVE2_GENERIC;
1013 908
909 fd = _shared_image_entry_file_data_find(ie);
910 if (fd)
911 {
912 INF("Bypassing socket wait (open_rid %d)", ie->open_rid);
913 ie->w = fd->w;
914 ie->h = fd->h;
915 ie->flags.alpha = fd->alpha;
916 ie->animated.loop_hint = fd->loop_hint;
917 ie->animated.loop_count = fd->loop_count;
918 ie->animated.frame_count = fd->frame_count;
919 ie->open_rid = 0;
920 return CSERVE2_NONE;
921 }
922
1014 if (ie->open_rid) 923 if (ie->open_rid)
1015 { 924 {
1016 if (!_server_dispatch_until(ie->open_rid)) 925 if (!_server_dispatch_until(ie->open_rid))
@@ -1045,9 +954,51 @@ evas_cserve2_image_data_load(Image_Entry *ie)
1045int 954int
1046evas_cserve2_image_load_data_wait(Image_Entry *ie) 955evas_cserve2_image_load_data_wait(Image_Entry *ie)
1047{ 956{
957 const Image_Data *idata;
958
1048 if (!ie) 959 if (!ie)
1049 return CSERVE2_GENERIC; 960 return CSERVE2_GENERIC;
1050 961
962 idata = _shared_image_entry_image_data_find(ie);
963 if (idata)
964 {
965 // FIXME: Ugly copy & paste from _loaded_handle
966 Data_Entry *dentry = ie->data2;
967 RGBA_Image *im = (RGBA_Image *)ie;
968 const char *shmpath;
969
970 shmpath = _shared_string_get(idata->shm_id);
971 if (!shmpath) goto load_wait;
972 INF("Bypassing image load socket wait. Image found: %d in %s",
973 idata->id, shmpath);
974
975 dentry->shm.mmap_offset = 0;
976 dentry->shm.use_offset = 0;
977 dentry->shm.f = eina_file_open(shmpath, EINA_TRUE);
978 dentry->shm.mmap_size = eina_file_size_get(dentry->shm.f);
979 dentry->shm.image_size = dentry->shm.mmap_size;
980
981 dentry->shm.data = eina_file_map_new(dentry->shm.f, EINA_FILE_WILLNEED,
982 dentry->shm.mmap_offset,
983 dentry->shm.mmap_size);
984 if (!dentry->shm.data)
985 {
986 DBG("could not mmap the shm file: %d %m", errno);
987 eina_file_close(dentry->shm.f);
988 dentry->shm.f = NULL;
989 goto load_wait;
990 }
991
992 im->image.data = dentry->shm.data;
993 ie->flags.alpha_sparse = idata->alpha_sparse;
994 ie->flags.loaded = EINA_TRUE;
995 im->image.no_free = 1;
996
997 ie->load_rid = 0;
998 return CSERVE2_NONE;
999 }
1000
1001load_wait:
1051 if (ie->load_rid) 1002 if (ie->load_rid)
1052 { 1003 {
1053 if (!_server_dispatch_until(ie->load_rid)) 1004 if (!_server_dispatch_until(ie->load_rid))
@@ -1652,4 +1603,431 @@ evas_cserve2_font_glyph_bitmap_get(Font_Entry *fe, unsigned int idx, Font_Hint_F
1652 return &(out->base); 1603 return &(out->base);
1653} 1604}
1654 1605
1606
1607
1608// Fast access to shared index tables
1609
1610
1611// Returns the number of correctly opened index arrays
1612static int
1613_server_index_list_set(Msg_Base *data, int size)
1614{
1615 Msg_Index_List *msg = (Msg_Index_List *) data;
1616 unsigned sz;
1617 int ret = 0;
1618
1619 // TODO #1: Check populate rule.
1620 // TODO #2: Protect memory for read-only access.
1621 // TODO #3: Optimize file reopen/remap (esp. strings table)
1622
1623 if (size != sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
1624 {
1625 CRIT("Invalid message! type: %d, size: %d (expected %d)",
1626 msg->base.type, size, (int) sizeof(*msg));
1627 return -1;
1628 }
1629
1630 // Reset index table
1631 if (_index.strings.index_file)
1632 {
1633 if (_index.strings.index_header)
1634 eina_file_map_free(_index.strings.index_file,
1635 (void *) _index.strings.index_header);
1636 eina_file_close(_index.strings.index_file);
1637 }
1638 if (_index.strings.entries_file)
1639 {
1640 if (_index.strings.index_header)
1641 eina_file_map_free(_index.strings.entries_file,
1642 (void *) _index.strings.index_header);
1643 eina_file_close(_index.strings.entries_file);
1644 }
1645 if (_index.files.f)
1646 {
1647 if (_index.files.header)
1648 eina_file_map_free(_index.files.f, (void *) _index.files.header);
1649 eina_file_close(_index.files.f);
1650 }
1651 if (_index.images.f)
1652 {
1653 if (_index.images.header)
1654 eina_file_map_free(_index.images.f, (void *) _index.images.header);
1655 eina_file_close(_index.images.f);
1656 }
1657 if (_index.fonts.f)
1658 {
1659 if (_index.fonts.header)
1660 eina_file_map_free(_index.fonts.f, (void *) _index.fonts.header);
1661 eina_file_close(_index.fonts.f);
1662 }
1663
1664 // Open new indexes
1665 eina_strlcpy(_index.strings.index_path, msg->strings_index_path, 64);
1666 eina_strlcpy(_index.strings.entries_path, msg->strings_entries_path, 64);
1667 eina_strlcpy(_index.files.path, msg->files_index_path, 64);
1668 eina_strlcpy(_index.images.path, msg->images_index_path, 64);
1669 eina_strlcpy(_index.fonts.path, msg->fonts_index_path, 64);
1670
1671 if (_index.strings.index_path[0] && _index.strings.entries_path[0])
1672 {
1673 _index.strings.index_file = eina_file_open(_index.strings.index_path,
1674 EINA_TRUE);
1675 sz = eina_file_size_get(_index.strings.index_file);
1676 _index.strings.index_header = eina_file_map_all(
1677 _index.strings.index_file, EINA_FILE_POPULATE);
1678 if (_index.strings.index_header && sz > sizeof(Shared_Array_Header)
1679 && sz >= (_index.strings.index_header->count * sizeof(Index_Entry)
1680 + sizeof(Shared_Array_Header)))
1681 {
1682 _index.strings.indexes = (Index_Entry *)
1683 &(_index.strings.index_header[1]);
1684 _index.strings.entries_file = eina_file_open(
1685 _index.strings.entries_path, EINA_TRUE);
1686 _index.strings.entries_size = eina_file_size_get(
1687 _index.strings.entries_file);
1688 _index.strings.data = eina_file_map_all(
1689 _index.strings.entries_file, EINA_FILE_RANDOM);
1690 if (!_index.strings.entries_size || !_index.strings.data)
1691 goto strings_map_failed;
1692 DBG("Mapped shared string table with indexes in %s and data in %s",
1693 _index.strings.index_path, _index.strings.entries_path);
1694 }
1695 else
1696 {
1697strings_map_failed:
1698 eina_file_map_free(_index.strings.entries_file,
1699 (void *) _index.strings.data);
1700 eina_file_close(_index.strings.entries_file);
1701 eina_file_map_free(_index.strings.index_file,
1702 (void *) _index.strings.index_header);
1703 eina_file_close(_index.strings.index_file);
1704 memset(&_index.strings, 0, sizeof(_index.strings));
1705 }
1706 }
1707
1708 if (_index.files.path[0])
1709 {
1710 _index.files.f = eina_file_open(_index.files.path, EINA_TRUE);
1711 sz = eina_file_size_get(_index.files.f);
1712 if (sz < sizeof(Shared_Array_Header))
1713 {
1714 ERR("Shared index for files is too small: %u", sz);
1715 eina_file_close(_index.files.f);
1716 _index.files.f = NULL;
1717 }
1718 else
1719 {
1720 _index.files.header = eina_file_map_all(_index.files.f,
1721 EINA_FILE_POPULATE);
1722 if (sz < (_index.files.header->count * sizeof(File_Data)
1723 + sizeof(Shared_Array_Header)))
1724 {
1725 ERR("Shared index size does not match array size: %u / %u",
1726 sz, _index.files.header->count);
1727 eina_file_map_free(_index.files.f,
1728 (void *) _index.files.header);
1729 eina_file_close(_index.files.f);
1730 _index.files.f = NULL;
1731 _index.files.header = NULL;
1732 }
1733 else
1734 {
1735 _index.files.entries.fdata =
1736 (File_Data *) &(_index.files.header[1]);
1737 DBG("Mapped files shared index '%s' at %p: %u entries max",
1738 _index.files.path, _index.files.header,
1739 _index.files.header->count);
1740 ret++;
1741 }
1742 }
1743 }
1744
1745 if (_index.images.path[0])
1746 {
1747 _index.images.f = eina_file_open(_index.images.path, EINA_TRUE);
1748 sz = eina_file_size_get(_index.images.f);
1749 if (sz < sizeof(Shared_Array_Header))
1750 {
1751 ERR("Shared index for images is too small: %u", sz);
1752 eina_file_close(_index.images.f);
1753 _index.images.f = NULL;
1754 }
1755 else
1756 {
1757 int size = eina_file_size_get(_index.images.f);
1758 _index.images.header = eina_file_map_all(_index.images.f,
1759 EINA_FILE_POPULATE);
1760 if (sz < (_index.images.header->count * sizeof(Image_Data)
1761 + sizeof(Shared_Array_Header)))
1762 {
1763 ERR("Shared index size does not match array size: %u / %u",
1764 sz, _index.images.header->count);
1765 eina_file_map_free(_index.images.f,
1766 (void *) _index.images.header);
1767 eina_file_close(_index.images.f);
1768 _index.images.f = NULL;
1769 _index.images.header = NULL;
1770 }
1771 else
1772 {
1773 _index.images.count = (size - sizeof(Shared_Array_Header))
1774 / sizeof(Image_Data);
1775 _index.images.entries.idata =
1776 (Image_Data *) &(_index.images.header[1]);
1777 DBG("Mapped images shared index '%s' at %p: %u entries max",
1778 _index.images.path, _index.images.header,
1779 _index.images.header->count);
1780 ret++;
1781 }
1782 }
1783 }
1784
1785 if (_index.fonts.path[0])
1786 ERR("Not implemented yet: fonts shared index");
1787
1788 return ret;
1789}
1790
1791// FIXME: Copy & paste from evas_cserve2_cache.c
1792static int
1793_shm_object_id_cmp_cb(const void *data1, const void *data2)
1794{
1795 const Shm_Object *obj;
1796 unsigned int key;
1797
1798 if (data1 == data2) return 0;
1799 if (!data1) return 1;
1800 if (!data2) return -1;
1801
1802 obj = data1;
1803 key = *((unsigned int *) data2);
1804 if (obj->id == key) return 0;
1805 if (obj->id < key)
1806 return -1;
1807 else
1808 return +1;
1809}
1810
1811// FIXME: (almost) copy & paste from evas_cserve2_cache.c
1812static const char *
1813_shared_string_get(int id)
1814{
1815 const char *ret;
1816 const Index_Entry *ie = NULL;
1817 int k;
1818
1819 if (id <= 0) return NULL;
1820 if (!_index.strings.data) return NULL;
1821
1822 // Binary search
1823 if (_index.strings.index_header->sortedidx > 0)
1824 {
1825 int low = 0;
1826 int high = _index.strings.index_header->sortedidx;
1827 int prev = -1;
1828 int r;
1829 k = high / 2;
1830 while (prev != k)
1831 {
1832 ie = &(_index.strings.indexes[k]);
1833 r = _shm_object_id_cmp_cb(ie, &id);
1834 if (!r)
1835 goto found;
1836 else if (r > 0)
1837 high = k;
1838 else
1839 low = k;
1840 prev = k;
1841 k = low + (high - low) / 2;
1842 }
1843 }
1844
1845 // Linear search O(n)
1846 k = _index.strings.index_header->sortedidx;
1847 for (; k < _index.strings.index_header->emptyidx; k++)
1848 {
1849 ie = &(_index.strings.indexes[k]);
1850 if (!_shm_object_id_cmp_cb(ie, &id))
1851 goto found;
1852 }
1853
1854 return NULL;
1855
1856found:
1857 if (!ie) return NULL;
1858 if (!ie->refcount) return NULL;
1859 if (ie->length + ie->offset > (int) _index.strings.entries_size)
1860 return NULL;
1861
1862 ret = _index.strings.data + ie->offset;
1863 return ret;
1864}
1865
1866static inline Eina_Bool
1867_shared_image_entry_file_data_match(Image_Entry *ie, const File_Data *fd)
1868{
1869 const char *path, *key, *loader;
1870
1871 if (!fd || !ie) return EINA_FALSE;
1872 if (!ie->file && !ie->key)
1873 return EINA_FALSE;
1874
1875 path = _shared_string_get(fd->path);
1876 key = _shared_string_get(fd->key);
1877 loader = _shared_string_get(fd->loader_data);
1878
1879 if (!path && ie->file)
1880 return EINA_FALSE;
1881 if (ie->file && strcmp(path, ie->file))
1882 return EINA_FALSE;
1883
1884 if (!key && ie->key)
1885 return EINA_FALSE;
1886 if (ie->key && strcmp(key, ie->key))
1887 return EINA_FALSE;
1888
1889 /*
1890 if (!loader && ie->loader_data)
1891 return EINA_FALSE;
1892 if (strcmp(loader, ie->loader_data))
1893 return EINA_FALSE;
1894 */
1895
1896 // Check w,h ?
1897 // Not sure which load opts should be checked here
1898 DBG("Found a match for %s:%s", ie->file, ie->key);
1899 return EINA_TRUE;
1900}
1901
1902static const File_Data *
1903_shared_image_entry_file_data_find(Image_Entry *ie)
1904{
1905 const File_Data *fdata = NULL;
1906 File_Entry *fe;
1907 int k;
1908
1909 DBG("Trying to find if image '%s:%s' is already opened by cserve2",
1910 ie->file, ie->key);
1911
1912 if (!_index.files.entries.fdata)
1913 return NULL;
1914
1915#warning FIXME Use safe count
1916 for (k = 0; k < _index.files.header->count; k++)
1917 {
1918 const File_Data *fd = &(_index.files.entries.fdata[k]);
1919 if (!fd->id) return NULL;
1920 if (!fd->refcount) continue;
1921
1922 if (_shared_image_entry_file_data_match(ie, fd))
1923 {
1924 fdata = fd;
1925 break;
1926 }
1927 }
1928
1929 DBG("Found file data for %s:%s: %d", ie->file, ie->key, fdata->id);
1930 fe = ie->data1;
1931 fe->server_file_id = fdata->id;
1932 return fdata;
1933}
1934
1935static inline Eina_Bool
1936_shared_image_entry_image_data_match(Image_Entry *ie, const Image_Data *id)
1937{
1938 int cmp;
1939 cmp = memcmp(&ie->load_opts, &id->opts, sizeof(ie->load_opts));
1940 if (!cmp)
1941 {
1942 DBG("Found loaded image entry at %d", id->id);
1943 return EINA_TRUE;
1944 }
1945 return EINA_FALSE;
1946}
1947
1948static const Image_Data *
1949_shared_image_entry_image_data_find(Image_Entry *ie)
1950{
1951 const Image_Data *idata = NULL;
1952 File_Entry *fe;
1953 unsigned int file_id = 0;
1954 int k;
1955
1956 DBG("Trying to find if image '%s:%s' is already loaded by cserve2",
1957 ie->file, ie->key);
1958
1959 if (!_index.images.entries.idata || !_index.images.count)
1960 return NULL;
1961
1962 fe = ie->data1;
1963 if (fe && fe->server_file_id)
1964 file_id = fe->server_file_id;
1965 else
1966 {
1967 const File_Data *fdata = _shared_image_entry_file_data_find(ie);
1968 if (!fdata)
1969 {
1970 ERR("File is not opened by cserve2");
1971 return NULL;
1972 }
1973 file_id = fdata->id;
1974 }
1975
1976 // FIXME. Factorize and simplify.
1977 if (_index.images.count != _index.images.header->count)
1978 {
1979 size_t sz;
1980 WRN("Image entries array has been resized from %d to %d. Remapping.",
1981 _index.images.count, _index.images.header->count);
1982 eina_file_map_free(_index.images.f, (void *) _index.images.header);
1983 eina_file_close(_index.images.f);
1984 _index.images.f = eina_file_open(_index.images.path, EINA_TRUE);
1985 sz = eina_file_size_get(_index.images.f);
1986 _index.images.header = eina_file_map_new(_index.images.f, EINA_FILE_RANDOM,
1987 0, sz); //eina_file_map_all(_index.images.f, EINA_FILE_RANDOM);
1988 _index.images.count = _index.images.header->count;
1989 if (_index.images.count * sizeof(Image_Data) + sizeof(Shared_Array_Header) > sz)
1990 CRIT("New mapping might be too small!");
1991 if (!_index.images.header)
1992 {
1993 ERR("Could not remap the array!");
1994 eina_file_close(_index.images.f);
1995 _index.images.f = NULL;
1996 _index.images.entries.idata = NULL;
1997 return NULL;
1998 }
1999 _index.images.entries.idata =
2000 (Image_Data *) &(_index.images.header[1]);
2001 }
2002
2003 DBG("Looking for loaded image with file id %d", file_id);
2004 for (k = 0; k < _index.images.count; k++)
2005 {
2006 const Image_Data *id = &(_index.images.entries.idata[k]);
2007 if (!id->id) return NULL;
2008 if (!id->refcount) continue;
2009 if (id->file_id != file_id) continue;
2010
2011 if (_shared_image_entry_image_data_match(ie, id))
2012 {
2013 idata = id;
2014 break;
2015 }
2016 }
2017
2018 if (!idata)
2019 return NULL;
2020
2021 if (!_shared_string_get(idata->shm_id))
2022 {
2023 ERR("Found image but it is not loaded yet: %d (doload %d shm %s)",
2024 idata->id, idata->doload, _shared_string_get(idata->shm_id));
2025 return NULL;
2026 }
2027
2028 DBG("Found image, loaded, in shm %s", _shared_string_get(idata->shm_id));
2029 return idata;
2030}
2031
2032
1655#endif 2033#endif