summaryrefslogtreecommitdiff
path: root/src/lib/eio
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-28 18:18:38 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-28 18:31:34 -0700
commit0fb9af05068d1272e4a5b85d400a0ecb3dc2450d (patch)
tree3772952ed5a5727242ae6e6bfe6ebafe4568aa6a /src/lib/eio
parentab1080bdd36c1f80a287015dc50f81f3456321ad (diff)
eio: migrate efl.io.manager.ls to use Eina_Future.
Diffstat (limited to 'src/lib/eio')
-rw-r--r--src/lib/eio/efl_io_manager.c90
-rw-r--r--src/lib/eio/efl_io_manager.eo19
2 files changed, 77 insertions, 32 deletions
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 59af2d223b..fb1ab21439 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -58,6 +58,24 @@ _efl_io_manager_future_cancel(void *data, const Eina_Promise *dead_ptr EINA_UNUS
58} 58}
59 59
60static void 60static void
61_future_file_done_cb(void *data, Eio_File *handler)
62{
63 Eina_Promise *p = data;
64
65 eina_promise_resolve(p, eina_value_uint64_init(handler->length));
66}
67
68static void
69_future_file_error_cb(void *data,
70 Eio_File *handler EINA_UNUSED,
71 int error)
72{
73 Eina_Promise *p = data;
74
75 eina_promise_reject(p, error);
76}
77
78static void
61_no_future(void *data, const Efl_Event *ev EINA_UNUSED) 79_no_future(void *data, const Efl_Event *ev EINA_UNUSED)
62{ 80{
63 Eio_File *h = data; 81 Eio_File *h = data;
@@ -154,6 +172,31 @@ _cleanup_info_progress(void *data)
154} 172}
155 173
156static void 174static void
175_future_string_cb(void *data EINA_UNUSED, Eio_File *handler, Eina_Array *gather)
176{
177 EflIoPath paths = ecore_thread_local_data_find(handler->thread, ".paths");
178 void *paths_data = ecore_thread_local_data_find(handler->thread, ".paths_data");
179 Eina_Accessor *access;
180 unsigned int count;
181 Eina_Stringshare *s;
182
183 if (!paths)
184 {
185 eina_array_free(gather);
186 return ;
187 }
188
189 access = eina_array_accessor_new(gather);
190 paths(paths_data, access);
191
192 // Cleanup strings, accessor and array
193 EINA_ACCESSOR_FOREACH(access, count, s)
194 eina_stringshare_del(s);
195 eina_accessor_free(access);
196 eina_array_free(gather);
197}
198
199static void
157_file_string_cb(void *data, Eio_File *handler, Eina_Array *gather) 200_file_string_cb(void *data, Eio_File *handler, Eina_Array *gather)
158{ 201{
159 Efl_Promise *p = data; 202 Efl_Promise *p = data;
@@ -320,31 +363,36 @@ _efl_io_manager_stat_ls(Eo *obj,
320 return NULL; 363 return NULL;
321} 364}
322 365
323static Efl_Future * 366static Eina_Future *
324_efl_io_manager_ls(Eo *obj, 367_efl_io_manager_ls(Eo *obj,
325 Efl_Io_Manager_Data *pd EINA_UNUSED, 368 Efl_Io_Manager_Data *pd EINA_UNUSED,
326 const char *path) 369 const char *path,
370 void *paths_data, EflIoPath paths, Eina_Free_Cb paths_free_cb)
327{ 371{
328 Efl_Promise *p; 372 Eina_Promise *p;
373 Eina_Future *future;
329 Eio_File *h; 374 Eio_File *h;
330 375
331 Eo *loop = efl_loop_get(obj); 376 p = eina_promise_new(efl_loop_future_scheduler_get(obj),
332 p = efl_add(EFL_PROMISE_CLASS, loop); 377 _efl_io_manager_future_cancel, NULL);
333 if (!p) return NULL; 378 if (!p) return NULL;
379 future = eina_future_new(p);
334 380
335 h = _eio_file_ls(path, 381 h = _eio_file_ls(path,
336 _file_string_cb, 382 _future_string_cb,
337 _file_done_cb, 383 _future_file_done_cb,
338 _file_error_cb, 384 _future_file_error_cb,
339 p); 385 p);
340 if (!h) goto end; 386 if (!h) goto end;
341 387
342 efl_event_callback_array_add(p, promise_progress_handling(), h); 388 ecore_thread_local_data_add(h->thread, ".paths", paths, NULL, EINA_TRUE);
343 return efl_promise_future_get(p); 389 ecore_thread_local_data_add(h->thread, ".paths_data", paths_data, paths_free_cb, EINA_TRUE);
390 eina_promise_data_set(p, h);
391
392 return efl_future_Eina_FutureXXX_then(obj, future);
344 393
345 end: 394 end:
346 efl_del(p); 395 return future;
347 return NULL;
348} 396}
349 397
350/* Stat function */ 398/* Stat function */
@@ -454,14 +502,6 @@ _efl_io_manager_xattr_ls(Eo *obj,
454} 502}
455 503
456static void 504static void
457_future_file_done_cb(void *data, Eio_File *handler)
458{
459 Eina_Promise *p = data;
460
461 eina_promise_resolve(p, eina_value_uint64_init(handler->length));
462}
463
464static void
465_future_file_done_data_cb(void *data, Eio_File *handler EINA_UNUSED, const char *attr_data, unsigned int size) 505_future_file_done_data_cb(void *data, Eio_File *handler EINA_UNUSED, const char *attr_data, unsigned int size)
466{ 506{
467 Eina_Promise *p = data; 507 Eina_Promise *p = data;
@@ -478,16 +518,6 @@ _future_file_done_data_cb(void *data, Eio_File *handler EINA_UNUSED, const char
478 eina_promise_resolve(p, v); 518 eina_promise_resolve(p, v);
479} 519}
480 520
481static void
482_future_file_error_cb(void *data,
483 Eio_File *handler EINA_UNUSED,
484 int error)
485{
486 Eina_Promise *p = data;
487
488 eina_promise_reject(p, error);
489}
490
491static Eina_Future * 521static Eina_Future *
492_efl_io_manager_xattr_set(Eo *obj, 522_efl_io_manager_xattr_set(Eo *obj,
493 Efl_Io_Manager_Data *pd EINA_UNUSED, 523 Efl_Io_Manager_Data *pd EINA_UNUSED,
diff --git a/src/lib/eio/efl_io_manager.eo b/src/lib/eio/efl_io_manager.eo
index 8ad5443f01..b8ed9002e2 100644
--- a/src/lib/eio/efl_io_manager.eo
+++ b/src/lib/eio/efl_io_manager.eo
@@ -7,17 +7,32 @@ struct Eio.Data
7 size: uint; [[Size of private data]] 7 size: uint; [[Size of private data]]
8} 8}
9 9
10function EflIoPath {
11 params {
12 @in paths: accessor<string>; [[Accessor to an array of path.]]
13 }
14};
15
16function EflIoDirectInfo {
17 params {
18 @in entries: accessor<Eina.File.Direct.Info>; [[Accessor to an array of info.]]
19 }
20};
21
10class Efl.Io.Manager (Efl.Loop_User) 22class Efl.Io.Manager (Efl.Loop_User)
11{ 23{
12 [[Class representing an asynchronous file operation.]] 24 [[Class representing an asynchronous file operation.]]
13 25
14 methods { 26 methods {
15 ls { 27 ls {
16 [[Lists entries in a given path.]] 28 [[Lists entries in a given path.
29 See \@ref eina_file_ls().
30 ]]
17 params { 31 params {
18 @in path: string; [[Path we want to list entries for]] 32 @in path: string; [[Path we want to list entries for]]
33 paths: EflIoPath; [[Callback called for each packet of files found]]
19 } 34 }
20 return: future<uint64, const(array<string>)>; [[List of entries in path]] 35 return: ptr(Eina.Future) @owned; [[Amount of files found during the listing of the directory]]
21 } 36 }
22 37
23 direct_ls { 38 direct_ls {