summaryrefslogtreecommitdiff
path: root/src/lib/eio
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2017-09-27 16:32:58 -0700
committerCedric BAIL <cedric@osg.samsung.com>2017-09-27 16:32:58 -0700
commit245ea06a6565d0261564652a26a9310420e48740 (patch)
tree20760c2df544358b4217b35081ff0ccafc82b349 /src/lib/eio
parent3a3ae49afde1712f4f972d8f3dc4b2feaa5579c7 (diff)
eio: convert Efl.Io.Manager.stat() to return Eina_Future.
Diffstat (limited to 'src/lib/eio')
-rw-r--r--src/lib/eio/efl_io_manager.c81
-rw-r--r--src/lib/eio/efl_io_manager.eo2
2 files changed, 56 insertions, 27 deletions
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index b19f7e3476..59af2d223b 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -51,6 +51,11 @@ struct _Job_Closure
51}; 51};
52 52
53/* Helper functions */ 53/* Helper functions */
54static void
55_efl_io_manager_future_cancel(void *data, const Eina_Promise *dead_ptr EINA_UNUSED)
56{
57 eio_file_cancel(data);
58}
54 59
55static void 60static void
56_no_future(void *data, const Efl_Event *ev EINA_UNUSED) 61_no_future(void *data, const Efl_Event *ev EINA_UNUSED)
@@ -343,50 +348,80 @@ _efl_io_manager_ls(Eo *obj,
343} 348}
344 349
345/* Stat function */ 350/* Stat function */
351EINA_VALUE_STRUCT_DESC_DEFINE(_eina_stat_desc,
352 NULL,
353 sizeof (Eina_Stat),
354 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, dev),
355 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, ino),
356 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_UINT, Eina_Stat, mode),
357 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_UINT, Eina_Stat, nlink),
358 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_UINT, Eina_Stat, uid),
359 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_UINT, Eina_Stat, gid),
360 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, rdev),
361 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, size),
362 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, blksize),
363 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, blocks),
364 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, atime),
365 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, atimensec),
366 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, mtime),
367 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, mtimensec),
368 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, ctime),
369 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_ULONG, Eina_Stat, ctimensec));
370
346static void 371static void
347_file_stat_done_cb(void *data, Eio_File *handle EINA_UNUSED, const Eina_Stat *stat) 372_file_stat_done_cb(void *data, Eio_File *handle EINA_UNUSED, const Eina_Stat *stat)
348{ 373{
349 Efl_Promise *p = data; 374 Eina_Value_Struct value = { _eina_stat_desc(), NULL };
350 Eina_Stat *c; 375 Eina_Promise *p = data;
376 Eina_Value r = EINA_VALUE_EMPTY;
377 Eina_Stat *cpy = NULL;
351 378
352 c = calloc(1, sizeof (Eina_Stat)); 379 cpy = calloc(1, sizeof (Eina_Stat));
353 if (!c) 380 if (!cpy) goto on_error;
354 {
355 efl_promise_failed_set(p, ENOMEM);
356 goto end;
357 }
358 381
359 memcpy(c, stat, sizeof (Eina_Stat)); 382 memcpy(cpy, stat, sizeof (Eina_Stat));
360 efl_promise_value_set(p, c, free); 383 value.memory = cpy;
361 384
362 end: 385 if (!eina_value_setup(&r, EINA_VALUE_TYPE_STRUCT))
363 efl_del(p); 386 goto on_error;
387 if (!eina_value_pset(&r, &value))
388 goto on_error;
389
390 eina_promise_resolve(p, r);
391
392 return ;
393
394 on_error:
395 free(cpy);
396 eina_value_flush(&r);
397 eina_promise_reject(p, eina_error_get());
364} 398}
365 399
366static Efl_Future * 400static Eina_Future *
367_efl_io_manager_stat(Eo *obj, 401_efl_io_manager_stat(Eo *obj,
368 Efl_Io_Manager_Data *pd EINA_UNUSED, 402 Efl_Io_Manager_Data *pd EINA_UNUSED,
369 const char *path) 403 const char *path)
370{ 404{
371 Efl_Promise *p; 405 Eina_Promise *p;
406 Eina_Future *future;
372 Eio_File *h; 407 Eio_File *h;
373 408
374 Eo *loop = efl_loop_get(obj); 409 p = eina_promise_new(efl_loop_future_scheduler_get(obj),
375 p = efl_add(EFL_PROMISE_CLASS, loop); 410 _efl_io_manager_future_cancel, NULL);
376 if (!p) return NULL; 411 if (!p) return NULL;
412 future = eina_future_new(p);
377 413
378 h = eio_file_direct_stat(path, 414 h = eio_file_direct_stat(path,
379 _file_stat_done_cb, 415 _file_stat_done_cb,
380 _file_error_cb, 416 _file_error_cb,
381 p); 417 p);
382 if (!h) goto end; 418 if (!h) goto end;
419 eina_promise_data_set(p, h);
383 420
384 efl_event_callback_array_add(p, promise_handling(), h); 421 return efl_future_Eina_FutureXXX_then(obj, future);
385 return efl_promise_future_get(p);
386 422
387 end: 423 end:
388 efl_del(p); 424 return future;
389 return NULL;
390} 425}
391 426
392/* eXtended attribute manipulation */ 427/* eXtended attribute manipulation */
@@ -453,12 +488,6 @@ _future_file_error_cb(void *data,
453 eina_promise_reject(p, error); 488 eina_promise_reject(p, error);
454} 489}
455 490
456static void
457_efl_io_manager_future_cancel(void *data, const Eina_Promise *dead_ptr EINA_UNUSED)
458{
459 eio_file_cancel(data);
460}
461
462static Eina_Future * 491static Eina_Future *
463_efl_io_manager_xattr_set(Eo *obj, 492_efl_io_manager_xattr_set(Eo *obj,
464 Efl_Io_Manager_Data *pd EINA_UNUSED, 493 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 9d8f46d589..8ad5443f01 100644
--- a/src/lib/eio/efl_io_manager.eo
+++ b/src/lib/eio/efl_io_manager.eo
@@ -52,7 +52,7 @@ class Efl.Io.Manager (Efl.Loop_User)
52 params { 52 params {
53 @in path: string; [[Path we want to get stat information for]] 53 @in path: string; [[Path we want to get stat information for]]
54 } 54 }
55 return: future<Eina.Stat>; [[Stat information]] 55 return: ptr(Eina.Future); [[Stat information]]
56 } 56 }
57 57
58 // FIXME: Add helper for Eina.Value to Xattr 58 // FIXME: Add helper for Eina.Value to Xattr