summaryrefslogtreecommitdiff
path: root/legacy/ethumb
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-12-01 15:37:21 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-12-01 15:37:21 +0000
commit70af55750129bfc4a79fccc7172819b39cdb916a (patch)
treeef3c332460a90c70b87fb92e2116e66665789117 /legacy/ethumb
parente80e88c5cda99e911d6f5afd4a81baa1cdc74337 (diff)
ethumb: provide facility using Ecore_Idler.
SVN revision: 65781
Diffstat (limited to 'legacy/ethumb')
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.c225
-rw-r--r--legacy/ethumb/src/lib/client/Ethumb_Client.h13
2 files changed, 237 insertions, 1 deletions
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.c b/legacy/ethumb/src/lib/client/Ethumb_Client.c
index b9d001cfe3..1d44dea0b4 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.c
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.c
@@ -2340,3 +2340,228 @@ ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generate
2340 2340
2341 return id; 2341 return id;
2342} 2342}
2343
2344struct _Ethumb_Client_Async
2345{
2346 Ethumb_Exists *exists;
2347 Ethumb_Client *client;
2348 Ethumb *dup;
2349
2350 Ethumb_Client_Async_Done_Cb done;
2351 Ethumb_Client_Async_Error_Cb error;
2352 const void *data;
2353
2354 int id;
2355};
2356
2357static Ecore_Idler *idler[2] = { NULL, NULL };
2358static Eina_List *pending = NULL;
2359static Eina_List *idle_tasks[2] = { NULL, NULL };
2360
2361static void
2362_ethumb_client_async_free(Ethumb_Client_Async *async)
2363{
2364 EINA_REFCOUNT_UNREF(async->client)
2365 _ethumb_client_free(async->client);
2366 ethumb_free(async->dup);
2367 free(async);
2368}
2369
2370static void
2371_ethumb_client_thumb_finish(void *data,
2372 Ethumb_Client *client, int id,
2373 const char *file __UNUSED__, const char *key __UNUSED__,
2374 const char *thumb_path, const char *thumb_key,
2375 Eina_Bool success)
2376{
2377 Ethumb_Client_Async *async = data;
2378
2379 assert(async->id == id);
2380
2381 if (success)
2382 {
2383 async->done(client, thumb_path, thumb_key, (void*) async->data);
2384 }
2385 else
2386 {
2387 async->error(client, (void*) async->data);
2388 }
2389
2390 pending = eina_list_remove(pending, async);
2391 _ethumb_client_async_free(async);
2392}
2393
2394static Eina_Bool
2395_ethumb_client_thumb_generate_idler(void *data __UNUSED__)
2396{
2397 Ethumb_Client_Async *async;
2398 Eina_List *l1, *l2;
2399
2400 EINA_LIST_FOREACH_SAFE(idle_tasks[1], l1, l2, async)
2401 {
2402 Ethumb *tmp;
2403
2404 idle_tasks[1] = eina_list_remove_list(idle_tasks[1], l1);
2405
2406 tmp = async->client->ethumb;
2407 async->client->ethumb = async->dup;
2408
2409 async->id = ethumb_client_generate(async->client, _ethumb_client_thumb_finish, async, NULL);
2410 if (async->id == -1)
2411 {
2412 async->error(async->client, (void*) async->data);
2413 async->client->ethumb = tmp;
2414 _ethumb_client_async_free(async);
2415 }
2416 else
2417 {
2418 async->client->ethumb = tmp;
2419 }
2420
2421 pending = eina_list_append(pending, async);
2422
2423 if (ecore_time_get() - ecore_loop_time_get() > ecore_animator_frametime_get() * 0.5)
2424 return EINA_TRUE;
2425 }
2426
2427 idler[1] = NULL;
2428 return EINA_FALSE;
2429}
2430
2431static void
2432_ethumb_client_thumb_exists(Ethumb_Client *client, Ethumb_Exists *request, Eina_Bool exists, void *data)
2433{
2434 Ethumb_Client_Async *async = data;
2435
2436 if (request == NULL)
2437 return ;
2438
2439 assert(async->exists == request);
2440
2441 async->exists = NULL;
2442 pending = eina_list_remove(pending, async);
2443
2444 if (exists)
2445 {
2446 const char *thumb_path;
2447 const char *thumb_key;
2448
2449 ethumb_client_thumb_path_get(client, &thumb_path, &thumb_key);
2450 async->done(client, thumb_path, thumb_key, (void*) async->data);
2451 _ethumb_client_async_free(async);
2452 }
2453 else
2454 {
2455 idle_tasks[1] = eina_list_append(idle_tasks[1], async);
2456
2457 if (!idler[1])
2458 idler[1] = ecore_idler_add(_ethumb_client_thumb_generate_idler, NULL);
2459 }
2460}
2461
2462static Eina_Bool
2463_ethumb_client_thumb_exists_idler(void *data __UNUSED__)
2464{
2465 Ethumb_Client_Async *async;
2466 Eina_List *l1, *l2;
2467
2468 EINA_LIST_FOREACH_SAFE(idle_tasks[0], l1, l2, async)
2469 {
2470 Ethumb *tmp;
2471
2472 idle_tasks[0] = eina_list_remove_list(idle_tasks[0], l1);
2473
2474 tmp = async->client->ethumb;
2475 async->client->ethumb = async->dup;
2476
2477 async->exists = ethumb_client_thumb_exists(async->client, _ethumb_client_thumb_exists, async);
2478 if (!async->exists)
2479 {
2480 async->error(async->client, (void*) async->data);
2481 async->client->ethumb = tmp;
2482 _ethumb_client_async_free(async);
2483 continue ;
2484 }
2485
2486 async->client->ethumb = tmp;
2487
2488 pending = eina_list_append(pending, async);
2489
2490 if (ecore_time_get() - ecore_loop_time_get() > ecore_animator_frametime_get() * 0.5)
2491 return EINA_TRUE;
2492 }
2493
2494 idler[0] = NULL;
2495 return EINA_FALSE;
2496}
2497
2498EAPI Ethumb_Client_Async *
2499ethumb_client_thumb_async_get(Ethumb_Client *client,
2500 Ethumb_Client_Async_Done_Cb done,
2501 Ethumb_Client_Async_Error_Cb error,
2502 const void *data)
2503{
2504 Ethumb_Client_Async *async;
2505
2506 EINA_SAFETY_ON_NULL_RETURN_VAL(client, NULL);
2507
2508 async = malloc(sizeof (Ethumb_Client_Async));
2509 if (!async)
2510 {
2511 error(client, (void*) data);
2512 return NULL;
2513 }
2514
2515 EINA_REFCOUNT_REF(client);
2516 async->client = client;
2517 async->dup = ethumb_dup(client->ethumb);
2518 async->done = done;
2519 async->error = error;
2520 async->data = data;
2521 async->exists = NULL;
2522 async->id = -1;
2523
2524 idle_tasks[0] = eina_list_append(idle_tasks[0], async);
2525
2526 if (!idler[0])
2527 idler[0] = ecore_idler_add(_ethumb_client_thumb_exists_idler, NULL);
2528
2529 return async;
2530}
2531
2532EAPI void
2533ethumb_client_thumb_async_cancel(Ethumb_Client *client, Ethumb_Client_Async *request)
2534{
2535 const char *path;
2536
2537 EINA_SAFETY_ON_NULL_RETURN(client);
2538 EINA_SAFETY_ON_NULL_RETURN(request);
2539
2540 ethumb_file_get(request->dup, &path, NULL);
2541
2542 if (request->exists)
2543 {
2544 ethumb_client_thumb_exists_cancel(request->exists);
2545 request->exists = NULL;
2546
2547 pending = eina_list_remove(pending, request);
2548 }
2549 else if (request->id != -1)
2550 {
2551 Ethumb *tmp = request->client->ethumb;
2552 request->client->ethumb = request->dup;
2553
2554 ethumb_client_generate_cancel(request->client, request->id, NULL, NULL, NULL);
2555
2556 request->client->ethumb = tmp;
2557
2558 pending = eina_list_remove(pending, request);
2559 }
2560 else
2561 {
2562 idle_tasks[0] = eina_list_remove(idle_tasks[0], request);
2563 idle_tasks[1] = eina_list_remove(idle_tasks[1], request);
2564 }
2565
2566 _ethumb_client_async_free(request);
2567}
diff --git a/legacy/ethumb/src/lib/client/Ethumb_Client.h b/legacy/ethumb/src/lib/client/Ethumb_Client.h
index 61037c5a88..42538fa095 100644
--- a/legacy/ethumb/src/lib/client/Ethumb_Client.h
+++ b/legacy/ethumb/src/lib/client/Ethumb_Client.h
@@ -201,7 +201,18 @@ EAPI Eina_Bool ethumb_client_thumb_exists_check(Ethumb_Exists *exists);
201EAPI int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, const void *data, Eina_Free_Cb free_data); 201EAPI int ethumb_client_generate(Ethumb_Client *client, Ethumb_Client_Generate_Cb generated_cb, const void *data, Eina_Free_Cb free_data);
202EAPI 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); 202EAPI 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);
203EAPI void ethumb_client_generate_cancel_all(Ethumb_Client *client); 203EAPI void ethumb_client_generate_cancel_all(Ethumb_Client *client);
204/** 204
205typedef void (*Ethumb_Client_Async_Done_Cb)(Ethumb_Client *ethumbd, const char *thumb_path, const char *thumb_key, void *data);
206typedef void (*Ethumb_Client_Async_Error_Cb)(Ethumb_Client *ethumbd, void *data);
207
208typedef struct _Ethumb_Client_Async Ethumb_Client_Async;
209
210EAPI Ethumb_Client_Async *ethumb_client_thumb_async_get(Ethumb_Client *client,
211 Ethumb_Client_Async_Done_Cb done,
212 Ethumb_Client_Async_Error_Cb error,
213 const void *data);
214EAPI void ethumb_client_thumb_async_cancel(Ethumb_Client *client, Ethumb_Client_Async *request);
215 /**
205 * @} 216 * @}
206 */ 217 */
207 218