summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-13 15:52:40 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-13 15:53:00 -0700
commitb9ef9af74a4cc401c02468f20a68659b9b2a1235 (patch)
tree09740386a9da902389c689d0b96524bf09dd3d73
parentba34b998eb6920fe0dbccd1037e8344c028754ec (diff)
eio: migrate efl.io.manager.open to use Eina_Future.
Diffstat (limited to '')
-rw-r--r--src/lib/eio/efl_io_manager.c36
-rw-r--r--src/lib/eio/efl_io_manager.eo2
-rw-r--r--src/tests/eio/eio_test_manager.c32
-rw-r--r--src/tests/eio/eio_test_manager_xattr.c2
4 files changed, 42 insertions, 30 deletions
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 75fa2289b0..0b7fb3def9 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -519,43 +519,43 @@ _efl_io_manager_xattr_get(Eo *obj,
519} 519}
520 520
521static void 521static void
522_file_open_cb(void *data, Eio_File *handler, Eina_File *file) 522_future_file_open_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_File *file)
523{ 523{
524 Efl_Promise *p = data; 524 Eina_Promise *p = data;
525 525 Eina_Value v = EINA_VALUE_EMPTY;
526 efl_event_callback_array_del(p, promise_handling(), handler);
527
528 efl_promise_value_set(p, eina_file_dup(file), EINA_FREE_CB(eina_file_close));
529 526
530 efl_del(p); 527 eina_value_setup(&v, EINA_VALUE_TYPE_FILE);
528 eina_value_set(&v, file);
529 eina_promise_resolve(p, v);
530 eina_value_flush(&v);
531} 531}
532 532
533static Efl_Future * 533static Eina_Future *
534_efl_io_manager_open(Eo *obj, 534_efl_io_manager_open(Eo *obj,
535 Efl_Io_Manager_Data *pd EINA_UNUSED, 535 Efl_Io_Manager_Data *pd EINA_UNUSED,
536 const char *path, 536 const char *path,
537 Eina_Bool shared) 537 Eina_Bool shared)
538{ 538{
539 Efl_Promise *p; 539 Eina_Promise *p;
540 Eina_Future *future;
540 Eio_File *h; 541 Eio_File *h;
541 542
542 Eo *loop = efl_loop_get(obj); 543 p = eina_promise_new(efl_loop_future_scheduler_get(obj),
543 p = efl_add(EFL_PROMISE_CLASS, loop); 544 _efl_io_manager_future_cancel, NULL);
544 if (!p) return NULL; 545 if (!p) return NULL;
546 future = eina_future_new(p);
545 547
546 h = eio_file_open(path, shared, 548 h = eio_file_open(path, shared,
547 _file_open_cb, 549 _future_file_open_cb,
548 _file_error_cb, 550 _future_file_error_cb,
549 p); 551 p);
550
551 if (!h) goto end; 552 if (!h) goto end;
553 eina_promise_data_set(p, h);
552 554
553 efl_event_callback_array_add(p, promise_handling(), h); 555 return efl_future_Eina_FutureXXX_then(obj, future);
554 return efl_promise_future_get(p);
555 556
556 end: 557 end:
557 efl_del(p); 558 return future;
558 return NULL;
559} 559}
560 560
561static Eina_Future * 561static Eina_Future *
diff --git a/src/lib/eio/efl_io_manager.eo b/src/lib/eio/efl_io_manager.eo
index a4e8aaddc5..b1b5d85806 100644
--- a/src/lib/eio/efl_io_manager.eo
+++ b/src/lib/eio/efl_io_manager.eo
@@ -83,7 +83,7 @@ class Efl.Io.Manager (Efl.Loop_User)
83 @in path: string; [[Path to file]] 83 @in path: string; [[Path to file]]
84 @in shared: bool; [[$true if the file can be accessed by others, $false otherwise]] 84 @in shared: bool; [[$true if the file can be accessed by others, $false otherwise]]
85 } 85 }
86 return: future<Eina.File>; [[Eina file handle]] 86 return: own(ptr(Eina.Future)); [[Eina file handle]]
87 } 87 }
88 close { 88 close {
89 [[Closes an open Eina.File.]] 89 [[Closes an open Eina.File.]]
diff --git a/src/tests/eio/eio_test_manager.c b/src/tests/eio/eio_test_manager.c
index ebfcc9edf7..e97310276c 100644
--- a/src/tests/eio/eio_test_manager.c
+++ b/src/tests/eio/eio_test_manager.c
@@ -51,16 +51,28 @@ _error_cb(void *data EINA_UNUSED, const Efl_Event *ev)
51 ecore_main_loop_quit(); 51 ecore_main_loop_quit();
52} 52}
53 53
54static void 54static Eina_Value
55_open_done_cb(void *data, const Efl_Event *ev) 55_open_done_cb(void *data,
56 const Eina_Value file,
57 const Eina_Future *dead EINA_UNUSED)
56{ 58{
57 Efl_Future_Event_Success *success = ev->info; 59 if (file.type == EINA_VALUE_TYPE_ERROR)
58 Eina_Bool *opened = (Eina_Bool *)data; 60 {
59 Eina_File* file = eina_file_dup(success->value); 61 Eina_Error err;
60 eina_file_close(file); 62
61 63 eina_value_get(&file, &err);
62 *opened = EINA_TRUE; 64 fprintf(stderr, "Something has gone wrong: %s\n", eina_error_msg_get(err));
65 abort();
66 }
67 if (file.type == EINA_VALUE_TYPE_FILE)
68 {
69 Eina_Bool *opened = (Eina_Bool *)data;
70
71 *opened = EINA_TRUE;
72 }
63 ecore_main_loop_quit(); 73 ecore_main_loop_quit();
74
75 return file;
64} 76}
65 77
66static void 78static void
@@ -221,7 +233,7 @@ START_TEST(efl_io_manager_test_open)
221 Eina_Tmpstr *nested_dirname; 233 Eina_Tmpstr *nested_dirname;
222 Eina_Tmpstr *nested_filename; 234 Eina_Tmpstr *nested_filename;
223 Efl_Io_Manager *job; 235 Efl_Io_Manager *job;
224 Efl_Future *f; 236 Eina_Future *f;
225 Eina_Bool opened_file = EINA_FALSE; 237 Eina_Bool opened_file = EINA_FALSE;
226 int ret; 238 int ret;
227 239
@@ -241,7 +253,7 @@ START_TEST(efl_io_manager_test_open)
241 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get()); 253 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
242 254
243 f = efl_io_manager_open(job, nested_filename, EINA_FALSE); 255 f = efl_io_manager_open(job, nested_filename, EINA_FALSE);
244 efl_future_then(f, &_open_done_cb, &_error_cb, NULL, &opened_file); 256 eina_future_then(f, _open_done_cb, &opened_file);
245 ecore_main_loop_begin(); 257 ecore_main_loop_begin();
246 258
247 fail_if(!opened_file); 259 fail_if(!opened_file);
diff --git a/src/tests/eio/eio_test_manager_xattr.c b/src/tests/eio/eio_test_manager_xattr.c
index 3d41316f20..bb2ddece02 100644
--- a/src/tests/eio/eio_test_manager_xattr.c
+++ b/src/tests/eio/eio_test_manager_xattr.c
@@ -118,7 +118,7 @@ _error_cb(void *data EINA_UNUSED, const Efl_Event *ev)
118} 118}
119 119
120static Eina_Value 120static Eina_Value
121_future_all_cb(const void *data, 121_future_all_cb(void *data,
122 const Eina_Value array, 122 const Eina_Value array,
123 const Eina_Future *dead EINA_UNUSED) 123 const Eina_Future *dead EINA_UNUSED)
124{ 124{