summaryrefslogtreecommitdiff
path: root/legacy/ethumb
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-11-28 23:24:32 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-11-28 23:24:32 +0000
commit12285a5f4f124f3ff5fa73dd4460bd6b2c024df1 (patch)
treebd381b34946590de647249d6e0ae0329cc1f2e25 /legacy/ethumb
parent4726297e7a898c95c6cd02d2b9660d6d7815e124 (diff)
ethumb: cleanup API.
SVN revision: 65660
Diffstat (limited to 'legacy/ethumb')
-rw-r--r--legacy/ethumb/src/lib/Ethumb.c47
-rw-r--r--legacy/ethumb/src/lib/Ethumb.h2
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.c184
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.h2
-rw-r--r--legacy/ethumb/src/lib/ethumb_private.h1
5 files changed, 144 insertions, 92 deletions
diff --git a/legacy/ethumb/src/lib/Ethumb.c b/legacy/ethumb/src/lib/Ethumb.c
index c510fdce83..ecabe9cc02 100644
--- a/legacy/ethumb/src/lib/Ethumb.c
+++ b/legacy/ethumb/src/lib/Ethumb.c
@@ -787,6 +787,7 @@ ethumb_file_set(Ethumb *e, const char *path, const char *key)
787 } 787 }
788 788
789 path = _ethumb_build_absolute_path(path, buf); 789 path = _ethumb_build_absolute_path(path, buf);
790 eina_stringshare_replace(&e->src_hash, NULL);
790 eina_stringshare_replace(&e->src_path, path); 791 eina_stringshare_replace(&e->src_path, path);
791 eina_stringshare_replace(&e->src_key, key); 792 eina_stringshare_replace(&e->src_key, key);
792 793
@@ -949,8 +950,6 @@ static void
949_ethumb_file_generate_path(Ethumb *e) 950_ethumb_file_generate_path(Ethumb *e)
950{ 951{
951 char buf[PATH_MAX]; 952 char buf[PATH_MAX];
952 char *fullname;
953 const char *hash;
954 const char *thumb_dir, *category; 953 const char *thumb_dir, *category;
955 const char *ext; 954 const char *ext;
956 int fdo_format; 955 int fdo_format;
@@ -987,10 +986,15 @@ _ethumb_file_generate_path(Ethumb *e)
987 else 986 else
988 ext = "eet"; 987 ext = "eet";
989 988
990 fullname = ecore_file_realpath(e->src_path); 989 if (!e->src_hash)
991 hash = _ethumb_generate_hash(fullname); 990 {
992 snprintf(buf, sizeof(buf), "%s/%s/%s.%s", thumb_dir, category, hash, ext); 991 char *fullname;
993 free(fullname); 992
993 fullname = ecore_file_realpath(e->src_path);
994 e->src_hash = _ethumb_generate_hash(fullname);
995 free(fullname);
996 }
997 snprintf(buf, sizeof(buf), "%s/%s/%s.%s", thumb_dir, category, e->src_hash, ext);
994 DBG("ethumb=%p, path=%s", e, buf); 998 DBG("ethumb=%p, path=%s", e, buf);
995 eina_stringshare_replace(&e->thumb_path, buf); 999 eina_stringshare_replace(&e->thumb_path, buf);
996 if (e->format == ETHUMB_THUMB_EET) 1000 if (e->format == ETHUMB_THUMB_EET)
@@ -1003,7 +1007,6 @@ _ethumb_file_generate_path(Ethumb *e)
1003 1007
1004 eina_stringshare_del(thumb_dir); 1008 eina_stringshare_del(thumb_dir);
1005 eina_stringshare_del(category); 1009 eina_stringshare_del(category);
1006 eina_stringshare_del(hash);
1007} 1010}
1008 1011
1009EAPI void 1012EAPI void
@@ -1012,6 +1015,7 @@ ethumb_file_free(Ethumb *e)
1012 EINA_SAFETY_ON_NULL_RETURN(e); 1015 EINA_SAFETY_ON_NULL_RETURN(e);
1013 DBG("ethumb=%p", e); 1016 DBG("ethumb=%p", e);
1014 1017
1018 eina_stringshare_replace(&e->src_hash, NULL);
1015 eina_stringshare_replace(&e->src_path, NULL); 1019 eina_stringshare_replace(&e->src_path, NULL);
1016 eina_stringshare_replace(&e->src_key, NULL); 1020 eina_stringshare_replace(&e->src_key, NULL);
1017 eina_stringshare_replace(&e->thumb_path, NULL); 1021 eina_stringshare_replace(&e->thumb_path, NULL);
@@ -1050,6 +1054,32 @@ ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key)
1050 if (key) *key = e->thumb_key; 1054 if (key) *key = e->thumb_key;
1051} 1055}
1052 1056
1057EAPI void
1058ethumb_thumb_hash(Ethumb *e)
1059{
1060 EINA_SAFETY_ON_NULL_RETURN(e);
1061 if (!e->src_hash)
1062 {
1063 char *fullname;
1064
1065 fullname = ecore_file_realpath(e->src_path);
1066 e->src_hash = _ethumb_generate_hash(fullname);
1067 free(fullname);
1068 }
1069}
1070
1071EAPI void
1072ethumb_thumb_hash_copy(Ethumb *dst, const Ethumb *src)
1073{
1074 EINA_SAFETY_ON_NULL_RETURN(dst);
1075 EINA_SAFETY_ON_NULL_RETURN(src);
1076
1077 if (src == dst) return ;
1078
1079 eina_stringshare_del(dst->src_hash);
1080 dst->src_hash = eina_stringshare_ref(src->src_hash);
1081}
1082
1053void 1083void
1054ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h) 1084ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h)
1055{ 1085{
@@ -1602,6 +1632,7 @@ ethumb_dup(const Ethumb *e)
1602 1632
1603 r->thumb_dir = eina_stringshare_ref(e->thumb_dir); 1633 r->thumb_dir = eina_stringshare_ref(e->thumb_dir);
1604 r->category = eina_stringshare_ref(e->category); 1634 r->category = eina_stringshare_ref(e->category);
1635 r->src_hash = eina_stringshare_ref(e->src_hash);
1605 r->src_path = eina_stringshare_ref(e->src_path); 1636 r->src_path = eina_stringshare_ref(e->src_path);
1606 r->src_key = eina_stringshare_ref(e->src_key); 1637 r->src_key = eina_stringshare_ref(e->src_key);
1607 r->thumb_path = eina_stringshare_ref(e->thumb_path); 1638 r->thumb_path = eina_stringshare_ref(e->thumb_path);
@@ -1710,8 +1741,6 @@ ethumb_key_cmp(const void *key1, __UNUSED__ int key1_length,
1710 1741
1711 CMP_PARAM(thumb_dir); 1742 CMP_PARAM(thumb_dir);
1712 CMP_PARAM(category); 1743 CMP_PARAM(category);
1713 CMP_PARAM(thumb_dir);
1714 CMP_PARAM(category);
1715 CMP_PARAM(tw); 1744 CMP_PARAM(tw);
1716 CMP_PARAM(th); 1745 CMP_PARAM(th);
1717 CMP_PARAM(format); 1746 CMP_PARAM(format);
diff --git a/legacy/ethumb/src/lib/Ethumb.h b/legacy/ethumb/src/lib/Ethumb.h
index dc7b133545..96e7d0755a 100644
--- a/legacy/ethumb/src/lib/Ethumb.h
+++ b/legacy/ethumb/src/lib/Ethumb.h
@@ -98,6 +98,8 @@ EAPI const char *ethumb_thumb_category_get(const Ethumb *e) EINA_WARN_UNUSED_RE
98 98
99EAPI void ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) EINA_ARG_NONNULL(1); 99EAPI void ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) EINA_ARG_NONNULL(1);
100EAPI void ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key) EINA_ARG_NONNULL(1); 100EAPI void ethumb_thumb_path_get(Ethumb *e, const char **path, const char **key) EINA_ARG_NONNULL(1);
101EAPI void ethumb_thumb_hash(Ethumb *e) EINA_ARG_NONNULL(1);
102EAPI void ethumb_thumb_hash_copy(Ethumb *dst, const Ethumb *src) EINA_ARG_NONNULL(1, 2);
101 103
102typedef enum _Ethumb_Thumb_FDO_Size 104typedef enum _Ethumb_Thumb_FDO_Size
103{ 105{
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.c b/legacy/ethumb/src/lib/client/Ethumb_Client.c
index a5c01c9397..b9d001cfe3 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.c
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.c
@@ -168,24 +168,23 @@ struct _ethumb_pending_gen
168}; 168};
169 169
170typedef struct _Ethumb_Async_Exists Ethumb_Async_Exists; 170typedef struct _Ethumb_Async_Exists Ethumb_Async_Exists;
171typedef struct _Ethumb_Async_Exists_Cb Ethumb_Async_Exists_Cb;
172 171
173struct _Ethumb_Async_Exists 172struct _Ethumb_Async_Exists
174{ 173{
175 Ethumb *dup; 174 const char *path;
176 Ethumb_Client *source;
177 175
178 Eina_List *callbacks; 176 Ethumb *dup; /* We will work on that one to prevent race and lock */
179 177
178 Eina_List *callbacks;
180 Ecore_Thread *thread; 179 Ecore_Thread *thread;
181 EINA_REFCOUNT;
182
183 Eina_Bool exists : 1;
184 Eina_Bool cancel : 1;
185}; 180};
186 181
187struct _Ethumb_Async_Exists_Cb 182struct _Ethumb_Exists
188{ 183{
184 Ethumb_Async_Exists *parent;
185 Ethumb_Client *client;
186 Ethumb *dup; /* We don't want to loose parameters so keep them around */
187
189 Ethumb_Client_Thumb_Exists_Cb exists_cb; 188 Ethumb_Client_Thumb_Exists_Cb exists_cb;
190 const void *data; 189 const void *data;
191}; 190};
@@ -347,22 +346,16 @@ _ethumb_async_delete(void *data)
347{ 346{
348 Ethumb_Async_Exists *async = data; 347 Ethumb_Async_Exists *async = data;
349 348
350 ethumb_free(async->dup); 349 assert(async->callbacks == NULL);
350 assert(async->thread == NULL);
351 351
352 EINA_REFCOUNT_UNREF(async->source) 352 ethumb_free(async->dup);
353 _ethumb_client_free(async->source); 353 eina_stringshare_del(async->path);
354 354
355 free(async); 355 free(async);
356} 356}
357 357
358static void 358static void
359_ethumb_async_cancel(Ethumb_Async_Exists *async)
360{
361 async->cancel = EINA_TRUE;
362 ecore_thread_cancel(async->thread);
363}
364
365static void
366_ethumb_client_name_owner_changed(void *data, DBusMessage *msg) 359_ethumb_client_name_owner_changed(void *data, DBusMessage *msg)
367{ 360{
368 DBusError err; 361 DBusError err;
@@ -599,28 +592,37 @@ _ethumb_client_exists_heavy(void *data, Ecore_Thread *thread __UNUSED__)
599{ 592{
600 Ethumb_Async_Exists *async = data; 593 Ethumb_Async_Exists *async = data;
601 594
602 async->exists = ethumb_exists(async->dup); 595 ethumb_thumb_hash(async->dup);
603} 596}
604 597
605static void 598static void
606_ethumb_client_exists_end(void *data, Ecore_Thread *thread __UNUSED__) 599_ethumb_client_exists_end(void *data, Ecore_Thread *thread __UNUSED__)
607{ 600{
608 Ethumb_Async_Exists *async = data; 601 Ethumb_Async_Exists *async = data;
609 Ethumb_Async_Exists_Cb *cb; 602 Ethumb_Exists *cb;
610 Ethumb *tmp = async->source->ethumb;
611
612 async->source->ethumb = async->dup;
613 603
614 EINA_LIST_FREE(async->callbacks, cb) 604 EINA_LIST_FREE(async->callbacks, cb)
615 { 605 {
616 cb->exists_cb(async->source, (Ethumb_Exists*) async, async->exists, (void*) cb->data); 606 Ethumb *tmp;
617 free(cb); 607
608 ethumb_thumb_hash_copy(cb->dup, async->dup);
609 tmp = cb->client->ethumb;
610 cb->client->ethumb = cb->dup;
611
612 cb->exists_cb(cb->client, cb,
613 ethumb_exists(cb->client->ethumb),
614 (void*) cb->data);
615
616 cb->client->ethumb = tmp;
617 EINA_REFCOUNT_UNREF(cb->client)
618 _ethumb_client_free(cb->client);
619 ethumb_free(cb->dup);
620 free(cb);
618 } 621 }
619 622
620 async->source->ethumb = tmp;
621 async->thread = NULL; 623 async->thread = NULL;
622 624
623 eina_hash_del(_exists_request, async->dup, async); 625 eina_hash_del(_exists_request, async->path, async);
624} 626}
625 627
626/** 628/**
@@ -666,11 +668,7 @@ ethumb_client_init(void)
666 ethumb_init(); 668 ethumb_init();
667 e_dbus_init(); 669 e_dbus_init();
668 670
669 _exists_request = eina_hash_new(ethumb_length, 671 _exists_request = eina_hash_stringshared_new(_ethumb_async_delete);
670 ethumb_key_cmp,
671 ethumb_hash,
672 _ethumb_async_delete,
673 3);
674 672
675 return ++_initcount; 673 return ++_initcount;
676} 674}
@@ -699,6 +697,8 @@ ethumb_client_shutdown(void)
699 return _initcount; 697 return _initcount;
700 698
701 /* should find a non racy solution to closing all pending exists request */ 699 /* should find a non racy solution to closing all pending exists request */
700 eina_hash_free(_exists_request);
701 _exists_request = NULL;
702 702
703 e_dbus_shutdown(); 703 e_dbus_shutdown();
704 ethumb_shutdown(); 704 ethumb_shutdown();
@@ -2162,57 +2162,81 @@ ethumb_client_thumb_path_get(Ethumb_Client *client, const char **path, const cha
2162EAPI Ethumb_Exists * 2162EAPI Ethumb_Exists *
2163ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data) 2163ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data)
2164{ 2164{
2165 Ethumb_Async_Exists_Cb *cb; 2165 const char *path = NULL;
2166 Ethumb_Async_Exists *async; 2166 Ethumb_Async_Exists *async = NULL;
2167 Ethumb_Exists *cb = NULL;
2167 Ecore_Thread *t; 2168 Ecore_Thread *t;
2168 2169
2169 EINA_SAFETY_ON_NULL_RETURN_VAL(client, NULL); 2170 EINA_SAFETY_ON_NULL_RETURN_VAL(client, NULL);
2170 2171
2171 cb = malloc(sizeof (Ethumb_Async_Exists_Cb)); 2172 ethumb_file_get(client->ethumb, &path, NULL);
2172 if (!cb) 2173 if (!path) goto on_error;
2174
2175 async = eina_hash_find(_exists_request, path);
2176 if (!async)
2173 { 2177 {
2174 exists_cb(client, NULL, EINA_FALSE, (void*) data); 2178 async = malloc(sizeof (Ethumb_Async_Exists));
2175 return NULL; 2179 if (!async) goto on_error;
2176 }
2177 2180
2178 cb->exists_cb = exists_cb; 2181 async->path = eina_stringshare_ref(path);
2179 cb->data = data; 2182 async->callbacks = NULL;
2183 async->dup = ethumb_dup(client->ethumb);
2184
2185 if (!async->dup) goto on_error;
2186
2187 cb = malloc(sizeof (Ethumb_Exists));
2188 if (!cb) goto on_error;
2189
2190 EINA_REFCOUNT_REF(client);
2191 cb->client = client;
2192 cb->dup = ethumb_dup(client->ethumb);
2193 cb->exists_cb = exists_cb;
2194 cb->data = data;
2195 cb->parent = async;
2180 2196
2181 async = eina_hash_find(_exists_request, client->ethumb);
2182 if (async)
2183 {
2184 EINA_REFCOUNT_REF(async);
2185 async->callbacks = eina_list_append(async->callbacks, cb); 2197 async->callbacks = eina_list_append(async->callbacks, cb);
2186 return (Ethumb_Exists*) async; 2198
2199 /* spawn a thread here */
2200 t = ecore_thread_run(_ethumb_client_exists_heavy,
2201 _ethumb_client_exists_end,
2202 _ethumb_client_exists_end,
2203 async);
2204 if (!t) return NULL;
2205 async->thread = t;
2206
2207 eina_hash_direct_add(_exists_request, async->path, async);
2208
2209 return cb;
2187 } 2210 }
2188 2211
2189 async = malloc(sizeof (Ethumb_Async_Exists)); 2212 cb = malloc(sizeof (Ethumb_Exists));
2190 if (!async) 2213 if (!cb)
2191 { 2214 {
2192 free(cb); 2215 async = NULL;
2193 exists_cb(client, NULL, EINA_FALSE, (void*) data); 2216 goto on_error;
2194 return NULL;
2195 } 2217 }
2196 2218
2197 async->dup = ethumb_dup(client->ethumb); 2219 EINA_REFCOUNT_REF(client);
2198 async->source = client; 2220 cb->client = client;
2199 EINA_REFCOUNT_REF(async->source); 2221 cb->dup = ethumb_dup(client->ethumb);
2200 async->exists = EINA_FALSE; 2222 cb->exists_cb = exists_cb;
2201 async->cancel = EINA_FALSE; 2223 cb->data = data;
2224 cb->parent = async;
2202 2225
2203 async->callbacks = eina_list_append(NULL, cb); 2226 async->callbacks = eina_list_append(async->callbacks, cb);
2204 2227
2205 EINA_REFCOUNT_INIT(async); 2228 return cb;
2206 t = ecore_thread_run(_ethumb_client_exists_heavy,
2207 _ethumb_client_exists_end,
2208 _ethumb_client_exists_end,
2209 async);
2210 if (!t) return NULL;
2211 2229
2212 async->thread = t; 2230 on_error:
2213 eina_hash_direct_add(_exists_request, async->dup, async); 2231 exists_cb(client, NULL, EINA_FALSE, (void*) data);
2214 2232
2215 return (Ethumb_Exists*) async; 2233 if (async)
2234 {
2235 eina_stringshare_del(async->path);
2236 if (async->dup) ethumb_free(async->dup);
2237 free(async);
2238 }
2239 return NULL;
2216} 2240}
2217 2241
2218/** 2242/**
@@ -2221,22 +2245,18 @@ ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb
2221 * @param exists the request to cancel. 2245 * @param exists the request to cancel.
2222 */ 2246 */
2223EAPI void 2247EAPI void
2224ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data) 2248ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists)
2225{ 2249{
2226 Ethumb_Async_Exists_Cb *cb; 2250 Ethumb_Async_Exists *async = exists->parent;
2227 Ethumb_Async_Exists *async = (Ethumb_Async_Exists*) exists;
2228 Eina_List *l;
2229 2251
2230 EINA_LIST_FOREACH(async->callbacks, l, cb) 2252 async->callbacks = eina_list_remove(async->callbacks, exists);
2231 if (cb->exists_cb == exists_cb && cb->data == data) 2253 if (eina_list_count(async->callbacks) <= 0)
2232 { 2254 ecore_thread_cancel(async->thread);
2233 async->callbacks = eina_list_remove_list(async->callbacks, l);
2234 free(cb);
2235 break;
2236 }
2237 2255
2238 EINA_REFCOUNT_UNREF(async) 2256 ethumb_free(exists->dup);
2239 _ethumb_async_cancel(async); 2257 EINA_REFCOUNT_UNREF(exists->client)
2258 _ethumb_client_free(exists->client);
2259 free(exists);
2240} 2260}
2241 2261
2242/** 2262/**
@@ -2248,11 +2268,11 @@ ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists, Ethumb_Client_Thumb_Exi
2248EAPI Eina_Bool 2268EAPI Eina_Bool
2249ethumb_client_thumb_exists_check(Ethumb_Exists *exists) 2269ethumb_client_thumb_exists_check(Ethumb_Exists *exists)
2250{ 2270{
2251 Ethumb_Async_Exists *async = (Ethumb_Async_Exists*) exists; 2271 Ethumb_Async_Exists *async = exists->parent;
2252 2272
2253 if (!async) return EINA_TRUE; 2273 if (!async) return EINA_TRUE;
2254 2274
2255 if (async->callbacks || async->cancel) return EINA_FALSE; 2275 if (async->callbacks) return EINA_FALSE;
2256 2276
2257 return ecore_thread_check(async->thread); 2277 return ecore_thread_check(async->thread);
2258} 2278}
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.h b/legacy/ethumb/src/lib/client/Ethumb_Client.h
index 6087277738..e105693e0a 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.h
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.h
@@ -195,7 +195,7 @@ EAPI void ethumb_client_file_get(Ethumb_Client *client, const char **path, const
195EAPI void ethumb_client_file_free(Ethumb_Client *client); 195EAPI void ethumb_client_file_free(Ethumb_Client *client);
196 196
197EAPI Ethumb_Exists *ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data); 197EAPI Ethumb_Exists *ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data);
198EAPI void ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists, Ethumb_Client_Thumb_Exists_Cb exists_cb, const void *data); 198EAPI void ethumb_client_thumb_exists_cancel(Ethumb_Exists *exists);
199EAPI Eina_Bool ethumb_client_thumb_exists_check(Ethumb_Exists *exists); 199EAPI Eina_Bool ethumb_client_thumb_exists_check(Ethumb_Exists *exists);
200EAPI int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, const void *data, Eina_Free_Cb free_data); 200EAPI int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, const void *data, Eina_Free_Cb free_data);
201EAPI void ethumb_client_generate_cancel(Ethumb_Client *client, int id, Ethumb_Client_Generate_Cancel_Cb cancel_cb, const void *data, Eina_Free_Cb free_data); 201EAPI void ethumb_client_generate_cancel(Ethumb_Client *client, int id, Ethumb_Client_Generate_Cancel_Cb cancel_cb, const void *data, Eina_Free_Cb free_data);
diff --git a/legacy/ethumb/src/lib/ethumb_private.h b/legacy/ethumb/src/lib/ethumb_private.h
index 873b97991d..25f2cd354e 100644
--- a/legacy/ethumb/src/lib/ethumb_private.h
+++ b/legacy/ethumb/src/lib/ethumb_private.h
@@ -24,6 +24,7 @@ struct _Ethumb
24 float crop_x, crop_y; 24 float crop_x, crop_y;
25 int quality; 25 int quality;
26 int compress; 26 int compress;
27 const char *src_hash;
27 const char *src_path; 28 const char *src_path;
28 const char *src_key; 29 const char *src_key;
29 const char *thumb_path; 30 const char *thumb_path;