summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-11-21 16:44:17 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-11-23 11:39:35 -0800
commit38865a688a89f69630f4cf3f49fa23a9f82260e4 (patch)
tree7837767f3d2c53ba5e600ab7c7e3067ab2bf5370 /src
parent88553eb9e8185c5505db21ec00b6f7083b5a9859 (diff)
ecore,efl: add Efl.Model.property_get helper which will suceed once when a property finally has a value.
Reviewed-by: Vitor Sousa da Silva <vitorsousa@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D7323
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Ecore.am2
-rw-r--r--src/lib/ecore/Ecore_Eo.h1
-rw-r--r--src/lib/ecore/efl_model_loop.c109
-rw-r--r--src/lib/ecore/efl_model_loop.eo7
-rw-r--r--src/lib/ecore/meson.build2
-rw-r--r--src/lib/efl/interfaces/efl_model.eo17
6 files changed, 138 insertions, 0 deletions
diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index 661ccbf721..5b7c664687 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -41,6 +41,7 @@ ecore_eolian_files_public = \
41 lib/ecore/efl_bounce_interpolator.eo \ 41 lib/ecore/efl_bounce_interpolator.eo \
42 lib/ecore/efl_spring_interpolator.eo \ 42 lib/ecore/efl_spring_interpolator.eo \
43 lib/ecore/efl_cubic_bezier_interpolator.eo \ 43 lib/ecore/efl_cubic_bezier_interpolator.eo \
44 lib/ecore/efl_model_loop.eo \
44 lib/ecore/efl_model_item.eo \ 45 lib/ecore/efl_model_item.eo \
45 lib/ecore/efl_model_container.eo \ 46 lib/ecore/efl_model_container.eo \
46 lib/ecore/efl_model_container_item.eo \ 47 lib/ecore/efl_model_container_item.eo \
@@ -117,6 +118,7 @@ lib/ecore/efl_io_stderr.c \
117lib/ecore/efl_io_file.c \ 118lib/ecore/efl_io_file.c \
118lib/ecore/efl_io_copier.c \ 119lib/ecore/efl_io_copier.c \
119lib/ecore/efl_io_buffered_stream.c \ 120lib/ecore/efl_io_buffered_stream.c \
121lib/ecore/efl_model_loop.c \
120lib/ecore/efl_model_item.c \ 122lib/ecore/efl_model_item.c \
121lib/ecore/efl_model_container.c \ 123lib/ecore/efl_model_container.c \
122lib/ecore/efl_model_container_item.c \ 124lib/ecore/efl_model_container_item.c \
diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h
index cbdf6ce26b..f73080ae4c 100644
--- a/src/lib/ecore/Ecore_Eo.h
+++ b/src/lib/ecore/Ecore_Eo.h
@@ -123,6 +123,7 @@ EAPI Eo *efl_app_get(void);
123 * @{ 123 * @{
124 */ 124 */
125 125
126#include "efl_model_loop.eo.h"
126#include "efl_model_item.eo.h" 127#include "efl_model_item.eo.h"
127#include "efl_model_container.eo.h" 128#include "efl_model_container.eo.h"
128#include "efl_model_container_item.eo.h" 129#include "efl_model_container_item.eo.h"
diff --git a/src/lib/ecore/efl_model_loop.c b/src/lib/ecore/efl_model_loop.c
new file mode 100644
index 0000000000..a64b3f851b
--- /dev/null
+++ b/src/lib/ecore/efl_model_loop.c
@@ -0,0 +1,109 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eina.h"
6#include "Efl.h"
7#include <Ecore.h>
8#include "Eo.h"
9
10#include "efl_model_loop.eo.h"
11
12typedef struct _Efl_Model_Loop_Watcher_Data Efl_Model_Loop_Watcher_Data;
13
14struct _Efl_Model_Loop_Watcher_Data
15{
16 const char *property;
17 Eina_Promise *p;
18 Eo *obj;
19};
20
21static void _propagate_future(void *data, const Efl_Event *event);
22
23static void
24_efl_model_loop_wathcer_free(Efl_Model_Loop_Watcher_Data *wd)
25{
26 efl_event_callback_del(wd->obj, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
27 _propagate_future, wd);
28 eina_stringshare_del(wd->property);
29 free(wd);
30}
31
32static void
33_propagate_future(void *data, const Efl_Event *event)
34{
35 Efl_Model_Property_Event *ev = event->info;
36 const char *property;
37 unsigned int i;
38 Eina_Array_Iterator it;
39 Efl_Model_Loop_Watcher_Data *wd = data;
40
41 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, it)
42 if (property == wd->property || !strcmp(property, wd->property))
43 {
44 Eina_Value *v = efl_model_property_get(wd->obj, wd->property);
45
46 if (eina_value_type_get(v) == EINA_VALUE_TYPE_ERROR)
47 {
48 Eina_Error err = 0;
49
50 eina_value_get(v, &err);
51
52 if (err == EAGAIN)
53 return ; // Not ready yet
54
55 eina_promise_reject(wd->p, err);
56 }
57 else
58 {
59 eina_promise_resolve(wd->p, eina_value_reference_copy(v));
60 }
61
62 eina_value_free(v);
63 _efl_model_loop_wathcer_free(wd);
64 break ;
65 }
66}
67
68static void
69_event_cancel(void *data, const Eina_Promise *dead_ptr)
70{
71 _efl_model_loop_wathcer_free(data);
72}
73
74static Eina_Future *
75_efl_model_loop_efl_model_property_ready_get(Eo *obj, void *pd EINA_UNUSED, const char *property)
76{
77 Eina_Value *value = efl_model_property_get(obj, property);
78 Eina_Future *f;
79
80 if (eina_value_type_get(value) == EINA_VALUE_TYPE_ERROR)
81 {
82 Eina_Error err = 0;
83
84 eina_value_get(value, &err);
85 eina_value_free(value);
86
87 if (err == EAGAIN)
88 {
89 Efl_Model_Loop_Watcher_Data *wd = calloc(1, sizeof (Efl_Model_Loop_Watcher_Data));
90
91 wd->obj = obj;
92 wd->property = eina_stringshare_add(property);
93 wd->p = eina_promise_new(efl_loop_future_scheduler_get(obj),
94 _event_cancel, wd);
95
96 efl_event_callback_add(obj,
97 EFL_MODEL_EVENT_PROPERTIES_CHANGED,
98 _propagate_future, wd);
99 }
100
101 return eina_future_rejected(efl_loop_future_scheduler_get(obj), err);
102 }
103 f = eina_future_resolved(efl_loop_future_scheduler_get(obj),
104 eina_value_reference_copy(value));
105 eina_value_free(value);
106 return efl_future_Eina_FutureXXX_then(obj, f);
107}
108
109#include "efl_model_loop.eo.c"
diff --git a/src/lib/ecore/efl_model_loop.eo b/src/lib/ecore/efl_model_loop.eo
new file mode 100644
index 0000000000..be4fe6a452
--- /dev/null
+++ b/src/lib/ecore/efl_model_loop.eo
@@ -0,0 +1,7 @@
1class Efl.Model_Loop (Efl.Loop_Consumer, Efl.Model)
2{
3 data: null;
4 implements {
5 Efl.Model.property_ready_get;
6 }
7} \ No newline at end of file
diff --git a/src/lib/ecore/meson.build b/src/lib/ecore/meson.build
index 60525ee659..96ad59b98c 100644
--- a/src/lib/ecore/meson.build
+++ b/src/lib/ecore/meson.build
@@ -67,6 +67,7 @@ pub_eo_files = [
67 'efl_cubic_bezier_interpolator.eo', 67 'efl_cubic_bezier_interpolator.eo',
68 'efl_loop_message_future_handler.eo', 68 'efl_loop_message_future_handler.eo',
69 'efl_loop_message_future.eo', 69 'efl_loop_message_future.eo',
70 'efl_model_loop.eo',
70 'efl_model_item.eo', 71 'efl_model_item.eo',
71 'efl_model_container.eo', 72 'efl_model_container.eo',
72 'efl_model_container_item.eo', 73 'efl_model_container_item.eo',
@@ -144,6 +145,7 @@ ecore_src = [
144 'efl_io_file.c', 145 'efl_io_file.c',
145 'efl_io_copier.c', 146 'efl_io_copier.c',
146 'efl_io_buffered_stream.c', 147 'efl_io_buffered_stream.c',
148 'efl_model_loop.c',
147 'efl_model_item.c', 149 'efl_model_item.c',
148 'efl_model_container.c', 150 'efl_model_container.c',
149 'efl_model_container_item.c', 151 'efl_model_container_item.c',
diff --git a/src/lib/efl/interfaces/efl_model.eo b/src/lib/efl/interfaces/efl_model.eo
index ffe8bf4430..ff06a321a8 100644
--- a/src/lib/efl/interfaces/efl_model.eo
+++ b/src/lib/efl/interfaces/efl_model.eo
@@ -76,6 +76,23 @@ interface Efl.Model ()
76 value: any_value_ptr; [[Property value]] 76 value: any_value_ptr; [[Property value]]
77 } 77 }
78 } 78 }
79 property_ready_get {
80 [[Get a future value when it change to something that is not error:EAGAIN
81
82 property_get can return an error with code EAGAIN when it doesn't have any
83 meaningful value. To make life easier, this future will resolve when
84 the error:EAGAIN disapear. Either into a failed future in case the error
85 code change to something else or a success with the value of property whenever
86 the property finally change.
87
88
89 The future can also be canceled if the model itself get destroyed.
90 ]]
91 params {
92 @in property: string;
93 }
94 return: future<any_value_ptr>;
95 }
79 children_slice_get { 96 children_slice_get {
80 [[Get children slice OR full range. 97 [[Get children slice OR full range.
81 98