summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-12-07 12:29:22 +0100
committerXavi Artigas <xavierartigas@yahoo.es>2018-12-07 12:42:31 +0100
commit6b22e6e33d1809a7231ad3cd51d9ff531acdbf4f (patch)
treecfccdb63492c0c0b2217aedeebb9f30494a30b6a /src/lib/ecore
parent4aeb3e20c95c53b9a856a9269d691cbc275839a4 (diff)
ecore: use efl_future_then to simplify the code logic and reduce potential bugs.
Summary: Depends on D7380 Reviewers: segfaultxavi, felipealmeida, SanghyeonLee, vitor.sousa, bu5hm4n Reviewed By: bu5hm4n Subscribers: barbieri, #reviewers, #committers Tags: #efl Maniphest Tasks: T7472 Differential Revision: https://phab.enlightenment.org/D7381
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_loop.c39
-rw-r--r--src/lib/ecore/efl_model_composite_boolean.c22
-rw-r--r--src/lib/ecore/efl_model_composite_selection.c129
-rw-r--r--src/lib/ecore/efl_thread.c15
4 files changed, 105 insertions, 100 deletions
diff --git a/src/lib/ecore/efl_loop.c b/src/lib/ecore/efl_loop.c
index 5d24608af3..33b6398fbb 100644
--- a/src/lib/ecore/efl_loop.c
+++ b/src/lib/ecore/efl_loop.c
@@ -365,44 +365,39 @@ _efl_loop_efl_object_destructor(Eo *obj, Efl_Loop_Data *pd)
365 efl_destructor(efl_super(obj, EFL_LOOP_CLASS)); 365 efl_destructor(efl_super(obj, EFL_LOOP_CLASS));
366} 366}
367 367
368static void
369_efl_loop_arguments_cleanup(Eina_Array *arga)
370{
371 Eina_Stringshare *s;
372
373 while ((s = eina_array_pop(arga))) eina_stringshare_del(s);
374 eina_array_free(arga);
375}
376
377static Eina_Value 368static Eina_Value
378_efl_loop_arguments_send(void *data, const Eina_Value v, 369_efl_loop_arguments_send(Eo *o EINA_UNUSED, void *data, const Eina_Value v)
379 const Eina_Future *dead EINA_UNUSED)
380 370
381{ 371{
382 static Eina_Bool initialization = EINA_TRUE; 372 static Eina_Bool initialization = EINA_TRUE;
383 Efl_Loop_Arguments arge; 373 Efl_Loop_Arguments arge;
384 Eina_Array *arga = data; 374 Eina_Array *arga = data;
385 375
386 if (v.type == EINA_VALUE_TYPE_ERROR) goto on_error;
387
388 arge.argv = arga; 376 arge.argv = arga;
389 arge.initialization = initialization; 377 arge.initialization = initialization;
390 initialization = EINA_FALSE; 378 initialization = EINA_FALSE;
391 379
392 efl_event_callback_call(efl_main_loop_get(), 380 efl_event_callback_call(efl_main_loop_get(),
393 EFL_LOOP_EVENT_ARGUMENTS, &arge); 381 EFL_LOOP_EVENT_ARGUMENTS, &arge);
394on_error:
395 _efl_loop_arguments_cleanup(arga);
396 return v; 382 return v;
397} 383}
398 384
385static void
386_efl_loop_arguments_cleanup(Eo *o EINA_UNUSED, void *data, const Eina_Future *dead_future EINA_UNUSED)
387{
388 Eina_Array *arga = data;
389 Eina_Stringshare *s;
390
391 while ((s = eina_array_pop(arga))) eina_stringshare_del(s);
392 eina_array_free(arga);
393}
394
399// It doesn't make sense to send those argument to any other mainloop 395// It doesn't make sense to send those argument to any other mainloop
400// As it also doesn't make sense to allow anyone to override this, so 396// As it also doesn't make sense to allow anyone to override this, so
401// should be internal for sure, not even protected. 397// should be internal for sure, not even protected.
402EAPI void 398EAPI void
403ecore_loop_arguments_send(int argc, const char **argv) 399ecore_loop_arguments_send(int argc, const char **argv)
404{ 400{
405 Eina_Future *job;
406 Eina_Array *arga; 401 Eina_Array *arga;
407 int i = 0; 402 int i = 0;
408 403
@@ -414,18 +409,18 @@ ecore_loop_arguments_send(int argc, const char **argv)
414 efl_task_arg_append(efl_main_loop_get(), argv[i]); 409 efl_task_arg_append(efl_main_loop_get(), argv[i]);
415 } 410 }
416 411
417 job = eina_future_then(efl_loop_job(efl_main_loop_get()), 412 efl_future_then(efl_main_loop_get(), efl_loop_job(efl_main_loop_get()),
418 _efl_loop_arguments_send, arga, NULL); 413 .success = _efl_loop_arguments_send,
419 efl_future_then(efl_main_loop_get(), job); 414 .free = _efl_loop_arguments_cleanup,
415 .data = arga);
420} 416}
421 417
422static Eina_Future * 418static Eina_Future *
423_efl_loop_job(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED) 419_efl_loop_job(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED)
424{ 420{
425 Eina_Future_Scheduler *sched = efl_loop_future_scheduler_get(obj);
426 // NOTE: Eolian should do efl_future_then() to bind future to object. 421 // NOTE: Eolian should do efl_future_then() to bind future to object.
427 return efl_future_then 422 return efl_future_then(obj,
428 (obj, eina_future_resolved(sched, EINA_VALUE_EMPTY)); 423 eina_future_resolved(efl_loop_future_scheduler_get(obj), EINA_VALUE_EMPTY));
429} 424}
430 425
431EOLIAN static void 426EOLIAN static void
diff --git a/src/lib/ecore/efl_model_composite_boolean.c b/src/lib/ecore/efl_model_composite_boolean.c
index 222329eb3b..2db0bc768e 100644
--- a/src/lib/ecore/efl_model_composite_boolean.c
+++ b/src/lib/ecore/efl_model_composite_boolean.c
@@ -181,16 +181,13 @@ struct _Efl_Model_Slice_Request
181}; 181};
182 182
183static Eina_Value 183static Eina_Value
184_efl_model_composite_boolean_then(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED) 184_efl_model_composite_boolean_then(Eo *o EINA_UNUSED, void *data, const Eina_Value v)
185{ 185{
186 Efl_Model_Slice_Request *req = data; 186 Efl_Model_Slice_Request *req = data;
187 unsigned int i, len; 187 unsigned int i, len;
188 Eina_Value r = EINA_VALUE_EMPTY; 188 Eina_Value r = EINA_VALUE_EMPTY;
189 Eo *target = NULL; 189 Eo *target = NULL;
190 190
191 if (eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY)
192 goto on_error;
193
194 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4); 191 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4);
195 192
196 EINA_VALUE_ARRAY_FOREACH(&v, len, i, target) 193 EINA_VALUE_ARRAY_FOREACH(&v, len, i, target)
@@ -206,11 +203,16 @@ _efl_model_composite_boolean_then(void *data, const Eina_Value v, const Eina_Fut
206 eina_value_array_append(&r, composite); 203 eina_value_array_append(&r, composite);
207 } 204 }
208 205
209 on_error: 206 return r;
207}
208
209static void
210_efl_model_composite_boolean_clean(Eo *o EINA_UNUSED, void *data, const Eina_Future *dead_future EINA_UNUSED)
211{
212 Efl_Model_Slice_Request *req = data;
213
210 efl_unref(req->parent); 214 efl_unref(req->parent);
211 free(req); 215 free(req);
212
213 return r;
214} 216}
215 217
216static void 218static void
@@ -295,8 +297,10 @@ _efl_model_composite_boolean_efl_model_children_slice_get(Eo *obj,
295 req->parent = efl_ref(obj); 297 req->parent = efl_ref(obj);
296 req->start = start; 298 req->start = start;
297 299
298 return efl_future_then 300 return efl_future_then(obj, f, .success_type = EINA_VALUE_TYPE_ARRAY,
299 (obj, eina_future_then(f, _efl_model_composite_boolean_then, req, NULL)); 301 .success = _efl_model_composite_boolean_then,
302 .free = _efl_model_composite_boolean_clean,
303 .data = req);
300} 304}
301 305
302#include "efl_model_composite_boolean.eo.c" 306#include "efl_model_composite_boolean.eo.c"
diff --git a/src/lib/ecore/efl_model_composite_selection.c b/src/lib/ecore/efl_model_composite_selection.c
index 25f68c2f5f..ad14b74275 100644
--- a/src/lib/ecore/efl_model_composite_selection.c
+++ b/src/lib/ecore/efl_model_composite_selection.c
@@ -40,10 +40,9 @@ _efl_model_composite_selection_efl_object_constructor(Eo *obj,
40} 40}
41 41
42static Eina_Value 42static Eina_Value
43_commit_change(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED) 43_commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
44{ 44{
45 Efl_Model_Composite_Selection_Data *pd; 45 Efl_Model_Composite_Selection_Data *pd;
46 Efl_Model *child = data;
47 Eina_Value *vc = NULL; 46 Eina_Value *vc = NULL;
48 Eina_Value *selected = NULL; 47 Eina_Value *selected = NULL;
49 Eina_Bool selflag = EINA_FALSE; 48 Eina_Bool selflag = EINA_FALSE;
@@ -85,16 +84,12 @@ _commit_change(void *data, const Eina_Value v, const Eina_Future *dead_future EI
85 return v; 84 return v;
86} 85}
87 86
88static Eina_Value 87static void
89_clear_child(void *data, 88_clear_child(Eo *child,
90 const Eina_Value v, 89 void *data EINA_UNUSED,
91 const Eina_Future *dead_future EINA_UNUSED) 90 const Eina_Future *dead_future EINA_UNUSED)
92{ 91{
93 Efl_Model *child = data;
94
95 efl_del(child); 92 efl_del(child);
96
97 return v;
98} 93}
99 94
100static Efl_Model * 95static Efl_Model *
@@ -131,8 +126,7 @@ _check_child_change(Efl_Model *child, Eina_Bool value)
131 else 126 else
132 { 127 {
133 r = efl_model_property_set(child, "selected", eina_value_bool_new(!!value)); 128 r = efl_model_property_set(child, "selected", eina_value_bool_new(!!value));
134 r = eina_future_then(r, _commit_change, child, NULL); 129 r = efl_future_then(child, r, .success = _commit_change, .free = _clear_child);
135 r = eina_future_then(r, _clear_child, child, NULL);
136 } 130 }
137 131
138 return r; 132 return r;
@@ -151,9 +145,9 @@ _unselect_child(Efl_Model *child)
151} 145}
152 146
153static Eina_Value 147static Eina_Value
154_select_slice_then(void *data EINA_UNUSED, 148_select_slice_then(Eo *obj EINA_UNUSED,
155 const Eina_Value v, 149 void *data EINA_UNUSED,
156 const Eina_Future *dead_future EINA_UNUSED) 150 const Eina_Value v)
157{ 151{
158 Efl_Model *child = NULL; 152 Efl_Model *child = NULL;
159 Eina_Future *r; 153 Eina_Future *r;
@@ -169,9 +163,9 @@ _select_slice_then(void *data EINA_UNUSED,
169} 163}
170 164
171static Eina_Value 165static Eina_Value
172_unselect_slice_then(void *data EINA_UNUSED, 166_unselect_slice_then(Eo *obj EINA_UNUSED,
173 const Eina_Value v, 167 void *data EINA_UNUSED,
174 const Eina_Future *dead_future EINA_UNUSED) 168 const Eina_Value v)
175{ 169{
176 Efl_Model *child = NULL; 170 Efl_Model *child = NULL;
177 Eina_Future *r; 171 Eina_Future *r;
@@ -233,12 +227,13 @@ _efl_model_composite_selection_efl_model_property_set(Eo *obj,
233 if (!success) 227 if (!success)
234 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE); 228 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
235 229
236 return efl_future_then 230 return efl_future_then(obj, efl_model_children_slice_get(obj, l, 1),
237 (obj, eina_future_then(efl_model_children_slice_get(obj, l, 1), 231 .success = _select_slice_then,
238 _select_slice_then, obj, NULL)); 232 .success_type = EINA_VALUE_TYPE_ARRAY);
239 } 233 }
240 234
241 return efl_model_property_set(efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS), property, value); 235 return efl_model_property_set(efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS),
236 property, value);
242} 237}
243 238
244static Eina_Value * 239static Eina_Value *
@@ -277,29 +272,10 @@ _regenerate_error(void *data,
277} 272}
278 273
279static Eina_Value 274static Eina_Value
280_untangle_array(void *data, 275_untangle_array(void *data EINA_UNUSED,
281 const Eina_Value v, 276 const Eina_Value v)
282 const Eina_Future *dead_future EINA_UNUSED)
283{ 277{
284 Efl_Model *child = data;
285 Eina_Value va = EINA_VALUE_EMPTY; 278 Eina_Value va = EINA_VALUE_EMPTY;
286 Eina_Future *f;
287
288 if (v.type == EINA_VALUE_TYPE_ERROR)
289 {
290 // We need to roll back the change, which means in this
291 // case to unselect this child as this is the only case
292 // where we could end up here.
293 Eina_Error *error = calloc(1, sizeof (Eina_Error));
294
295 f = efl_model_property_set(efl_super(child, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS),
296 "selected", eina_value_bool_new(EINA_FALSE));
297 // Once this is done, we need to repropagate the error
298 eina_value_error_get(&v, error);
299 f = eina_future_then(f, _regenerate_error, error, NULL);
300
301 return eina_future_as_value(f);
302 }
303 279
304 // Only return the commit change, not the result of the unselect 280 // Only return the commit change, not the result of the unselect
305 eina_value_array_get(&v, 0, &va); 281 eina_value_array_get(&v, 0, &va);
@@ -317,6 +293,26 @@ _efl_model_composite_selection_children_efl_model_properties_get(const Eo *obj,
317 return props; 293 return props;
318} 294}
319 295
296static Eina_Value
297_untangle_error(void *data, Eina_Error err)
298{
299 Efl_Model *child = data;
300 Eina_Future *f;
301
302 // We need to roll back the change, which means in this
303 // case to unselect this child as this is the only case
304 // where we could end up here.
305 Eina_Error *error = calloc(1, sizeof (Eina_Error));
306
307 f = efl_model_property_set(efl_super(child, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS),
308 "selected", eina_value_bool_new(EINA_FALSE));
309 // Once this is done, we need to repropagate the error
310 *error = err;
311 f = eina_future_then(f, _regenerate_error, error, NULL);
312
313 return eina_future_as_value(f);
314}
315
320static Eina_Future * 316static Eina_Future *
321_efl_model_composite_selection_children_efl_model_property_set(Eo *obj, 317_efl_model_composite_selection_children_efl_model_property_set(Eo *obj,
322 Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED, 318 Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED,
@@ -381,6 +377,7 @@ _efl_model_composite_selection_children_efl_model_property_set(Eo *obj,
381 } 377 }
382 else 378 else
383 { 379 {
380 Eo *parent;
384 Eina_Value *vs; 381 Eina_Value *vs;
385 unsigned long selected = 0; 382 unsigned long selected = 0;
386 Eina_Bool success; 383 Eina_Bool success;
@@ -403,18 +400,23 @@ _efl_model_composite_selection_children_efl_model_property_set(Eo *obj,
403 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE); 400 return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
404 401
405 // There was, need to unselect the previous one along setting the new value 402 // There was, need to unselect the previous one along setting the new value
403 parent = efl_parent_get(obj);
406 chain = eina_future_all(chain, 404 chain = eina_future_all(chain,
407 eina_future_then(efl_model_children_slice_get(efl_parent_get(obj), selected, 1), 405 efl_future_then(parent, efl_model_children_slice_get(parent, selected, 1),
408 _unselect_slice_then, NULL, NULL)); 406 .success = _unselect_slice_then,
409 407 .success_type = EINA_VALUE_TYPE_ARRAY));
410 chain = eina_future_then(chain, _untangle_array, obj, NULL); 408
409 chain = eina_future_then_easy(chain,
410 .success_type = EINA_VALUE_TYPE_ARRAY,
411 .success = _untangle_array,
412 .data = obj,
413 .error = _untangle_error);
411 } 414 }
412 } 415 }
413 416
414 commit_change: 417 commit_change:
415 chain = eina_future_then(chain, _commit_change, obj, NULL); 418 return efl_future_then(obj, chain,
416 419 .success = _commit_change);
417 return efl_future_then(obj, chain);
418} 420}
419 421
420typedef struct _Selection_Children_Request Selection_Children_Request; 422typedef struct _Selection_Children_Request Selection_Children_Request;
@@ -426,18 +428,15 @@ struct _Selection_Children_Request
426}; 428};
427 429
428static Eina_Value 430static Eina_Value
429_slice_get(void *data, 431_slice_get(Eo *o EINA_UNUSED,
430 const Eina_Value v, 432 void *data,
431 const Eina_Future *dead_future EINA_UNUSED) 433 const Eina_Value v)
432{ 434{
433 Selection_Children_Request *req = data; 435 Selection_Children_Request *req = data;
434 unsigned int length, it; 436 unsigned int length, it;
435 Eo *composited = NULL; 437 Eo *composited = NULL;
436 Eina_Value r = EINA_VALUE_EMPTY; 438 Eina_Value r = EINA_VALUE_EMPTY;
437 439
438 if (v.type == EINA_VALUE_TYPE_ERROR)
439 goto error;
440
441 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4); 440 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4);
442 441
443 EINA_VALUE_ARRAY_FOREACH(&v, length, it, composited) 442 EINA_VALUE_ARRAY_FOREACH(&v, length, it, composited)
@@ -450,11 +449,18 @@ _slice_get(void *data,
450 eina_value_array_append(&r, compositing); 449 eina_value_array_append(&r, compositing);
451 } 450 }
452 451
453 error: 452 return r;
453}
454
455static void
456_slice_clean(Eo *o EINA_UNUSED,
457 void *data,
458 const Eina_Future *dead_future EINA_UNUSED)
459{
460 Selection_Children_Request *req = data;
461
454 efl_unref(req->parent); 462 efl_unref(req->parent);
455 free(req); 463 free(req);
456
457 return r;
458} 464}
459 465
460static Eina_Future * 466static Eina_Future *
@@ -473,9 +479,12 @@ _efl_model_composite_selection_efl_model_children_slice_get(Eo *obj,
473 // NOTE: We do jump on purpose EFL_MODEL_COMPOSITE_BOOLEAN_CLASS here 479 // NOTE: We do jump on purpose EFL_MODEL_COMPOSITE_BOOLEAN_CLASS here
474 f = efl_model_children_slice_get(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CLASS), 480 f = efl_model_children_slice_get(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CLASS),
475 start, count); 481 start, count);
476 f = eina_future_then(f, _slice_get, req, NULL);
477 482
478 return efl_future_then(obj, f); 483 return efl_future_then(obj, f,
484 .success_type = EINA_VALUE_TYPE_ARRAY,
485 .success = _slice_get,
486 .free = _slice_clean,
487 .data = req);
479} 488}
480 489
481#include "efl_model_composite_selection.eo.c" 490#include "efl_model_composite_selection.eo.c"
diff --git a/src/lib/ecore/efl_thread.c b/src/lib/ecore/efl_thread.c
index 3a650a7d45..f72aa07231 100644
--- a/src/lib/ecore/efl_thread.c
+++ b/src/lib/ecore/efl_thread.c
@@ -145,19 +145,16 @@ _cb_thread_ctrl_out(void *data, const Efl_Event *event EINA_UNUSED)
145} 145}
146 146
147static Eina_Value 147static Eina_Value
148_efl_loop_arguments_send(void *data, const Eina_Value v, 148_efl_loop_arguments_send(Eo *obj, void *data EINA_UNUSED, const Eina_Value v)
149 const Eina_Future *dead EINA_UNUSED)
150 149
151{ 150{
152 Efl_Loop_Arguments arge; 151 Efl_Loop_Arguments arge;
153 Eo *obj = data;
154 Eina_Array *arga; 152 Eina_Array *arga;
155 Eina_Stringshare *s; 153 Eina_Stringshare *s;
156 unsigned int argc = efl_task_arg_count_get(obj); 154 unsigned int argc = efl_task_arg_count_get(obj);
157 unsigned int i; 155 unsigned int i;
158 156
159 arga = eina_array_new(argc); 157 arga = eina_array_new(argc);
160 if (v.type == EINA_VALUE_TYPE_ERROR) goto on_error;
161 158
162 for (i = 0; i < argc; i++) 159 for (i = 0; i < argc; i++)
163 { 160 {
@@ -169,9 +166,10 @@ _efl_loop_arguments_send(void *data, const Eina_Value v,
169 arge.initialization = EINA_TRUE; 166 arge.initialization = EINA_TRUE;
170 efl_event_callback_call(obj, 167 efl_event_callback_call(obj,
171 EFL_LOOP_EVENT_ARGUMENTS, &arge); 168 EFL_LOOP_EVENT_ARGUMENTS, &arge);
172on_error: 169
173 while ((s = eina_array_pop(arga))) eina_stringshare_del(s); 170 while ((s = eina_array_pop(arga))) eina_stringshare_del(s);
174 eina_array_free(arga); 171 eina_array_free(arga);
172
175 return v; 173 return v;
176} 174}
177 175
@@ -285,8 +283,8 @@ _efl_thread_main(void *data, Eina_Thread t)
285 } 283 }
286 for (i = 0; i < thdat->args.argc; i++) 284 for (i = 0; i < thdat->args.argc; i++)
287 efl_task_arg_append(obj, thdat->args.argv[i]); 285 efl_task_arg_append(obj, thdat->args.argv[i]);
288 job = eina_future_then(efl_loop_job(obj), _efl_loop_arguments_send, obj); 286 efl_future_then(obj, efl_loop_job(obj),
289 efl_future_then(obj, job); 287 .success = _efl_loop_arguments_send);
290 288
291 for (i = 0; i < thdat->args.argc; i++) 289 for (i = 0; i < thdat->args.argc; i++)
292 eina_stringshare_del(thdat->args.argv[i]); 290 eina_stringshare_del(thdat->args.argv[i]);
@@ -780,8 +778,7 @@ _efl_thread_efl_task_run(Eo *obj, Efl_Thread_Data *pd)
780 pd->thdat = thdat; 778 pd->thdat = thdat;
781 pd->run = EINA_TRUE; 779 pd->run = EINA_TRUE;
782 pd->promise = efl_loop_promise_new(obj, _run_cancel_cb, obj); 780 pd->promise = efl_loop_promise_new(obj, _run_cancel_cb, obj);
783 Eina_Future *f = eina_future_new(pd->promise); 781 return efl_future_then(obj, eina_future_new(pd->promise));
784 return efl_future_then(obj, f);
785} 782}
786 783
787EOLIAN static void 784EOLIAN static void