summaryrefslogtreecommitdiff
path: root/src/lib/eio
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-13 18:03:05 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-14 10:11:29 -0700
commitcba58203a32d4c586570cf2bb47cbcc048d803d4 (patch)
treef5e671ead38e46c822cb9f069823ea9e65796d1e /src/lib/eio
parent024c6a9fc33c9fc0056f9e6b35dee64fb74cd225 (diff)
eio: move efl.io.manager.xattr.get to use the new Eina_Future.
Diffstat (limited to 'src/lib/eio')
-rw-r--r--src/lib/eio/efl_io_manager.c54
-rw-r--r--src/lib/eio/efl_io_manager.eo2
2 files changed, 29 insertions, 27 deletions
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 6156abe853..b19f7e3476 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -89,22 +89,6 @@ EFL_CALLBACKS_ARRAY_DEFINE(promise_handling,
89 { EFL_EVENT_DEL, _forced_shutdown }); 89 { EFL_EVENT_DEL, _forced_shutdown });
90 90
91static void 91static void
92_file_done_data_cb(void *data, Eio_File *handler, const char *attr_data, unsigned int size)
93{
94 Efl_Promise *p = data;
95 Eina_Binbuf *buf;
96
97 efl_event_callback_array_del(p, promise_handling(), handler);
98
99 buf = eina_binbuf_new();
100 eina_binbuf_append_length(buf, (const unsigned char*) attr_data, size);
101
102 efl_promise_value_set(p, buf, EINA_FREE_CB(eina_binbuf_free));
103
104 efl_del(p);
105}
106
107static void
108_file_error_cb(void *data, Eio_File *handler, int error) 92_file_error_cb(void *data, Eio_File *handler, int error)
109{ 93{
110 Efl_Promise *p = data; 94 Efl_Promise *p = data;
@@ -443,6 +427,23 @@ _future_file_done_cb(void *data, Eio_File *handler)
443} 427}
444 428
445static void 429static void
430_future_file_done_data_cb(void *data, Eio_File *handler EINA_UNUSED, const char *attr_data, unsigned int size)
431{
432 Eina_Promise *p = data;
433 Eina_Value_Blob blob = { EINA_VALUE_BLOB_OPERATIONS_MALLOC, NULL, size };
434 Eina_Value v = EINA_VALUE_EMPTY;
435 char *tmp;
436
437 tmp = malloc(size);
438 memcpy(tmp, attr_data, size);
439 blob.memory = tmp;
440
441 eina_value_setup(&v, EINA_VALUE_TYPE_BLOB);
442 eina_value_set(&v, &blob);
443 eina_promise_resolve(p, v);
444}
445
446static void
446_future_file_error_cb(void *data, 447_future_file_error_cb(void *data,
447 Eio_File *handler EINA_UNUSED, 448 Eio_File *handler EINA_UNUSED,
448 int error) 449 int error)
@@ -491,31 +492,32 @@ _efl_io_manager_xattr_set(Eo *obj,
491 return future; 492 return future;
492} 493}
493 494
494static Efl_Future * 495static Eina_Future *
495_efl_io_manager_xattr_get(Eo *obj, 496_efl_io_manager_xattr_get(Eo *obj,
496 Efl_Io_Manager_Data *pd EINA_UNUSED, 497 Efl_Io_Manager_Data *pd EINA_UNUSED,
497 const char *path, 498 const char *path,
498 const char *attribute) 499 const char *attribute)
499{ 500{
500 Efl_Promise *p; 501 Eina_Promise *p;
502 Eina_Future *future;
501 Eio_File *h; 503 Eio_File *h;
502 504
503 Eo *loop = efl_loop_get(obj); 505 p = eina_promise_new(efl_loop_future_scheduler_get(obj),
504 p = efl_add(EFL_PROMISE_CLASS, loop); 506 _efl_io_manager_future_cancel, NULL);
505 if (!p) return NULL; 507 if (!p) return NULL;
508 future = eina_future_new(p);
506 509
507 h = eio_file_xattr_get(path, attribute, 510 h = eio_file_xattr_get(path, attribute,
508 _file_done_data_cb, 511 _future_file_done_data_cb,
509 _file_error_cb, 512 _future_file_error_cb,
510 p); 513 p);
511 if (!h) goto end; 514 if (!h) goto end;
515 eina_promise_data_set(p, h);
512 516
513 efl_event_callback_array_add(p, promise_handling(), h); 517 return efl_future_Eina_FutureXXX_then(obj, future);
514 return efl_promise_future_get(p);
515 518
516 end: 519 end:
517 efl_del(p); 520 return future;
518 return NULL;
519} 521}
520 522
521static void 523static void
diff --git a/src/lib/eio/efl_io_manager.eo b/src/lib/eio/efl_io_manager.eo
index b1b5d85806..2d4abda082 100644
--- a/src/lib/eio/efl_io_manager.eo
+++ b/src/lib/eio/efl_io_manager.eo
@@ -66,7 +66,7 @@ class Efl.Io.Manager (Efl.Loop_User)
66 return: own(ptr(Eina.Future)); [[Future for asynchronous set operation]] 66 return: own(ptr(Eina.Future)); [[Future for asynchronous set operation]]
67 } 67 }
68 get { 68 get {
69 return: future<Eina.Binbuf>; [[Information]] 69 return: own(ptr(Eina.Future)); [[Information]]
70 } 70 }
71 keys { 71 keys {
72 path: string; [[File path]] 72 path: string; [[File path]]