summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-07 12:04:40 +0900
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-07 12:36:48 +0900
commit25444568192d5cd5228311f47ecaf9a5abc9fc8d (patch)
treed8066f2364ed4c3ac3d9b101edc166237ad334a6
parentef1c178a2850bebc78f5a97622463d53e953318d (diff)
eio: Fix eio model children count in initialization of children model
-rw-r--r--src/lib/eio/eio_model.c68
-rw-r--r--src/lib/eio/eio_model_private.h2
2 files changed, 62 insertions, 8 deletions
diff --git a/src/lib/eio/eio_model.c b/src/lib/eio/eio_model.c
index 1dee375..26f7696 100644
--- a/src/lib/eio/eio_model.c
+++ b/src/lib/eio/eio_model.c
@@ -20,8 +20,12 @@
20#define MY_CLASS_NAME "Eio_Model" 20#define MY_CLASS_NAME "Eio_Model"
21 21
22static void _eio_prop_set_error_cb(void *, Eio_File *, int); 22static void _eio_prop_set_error_cb(void *, Eio_File *, int);
23static void _eio_stat_done_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *stat); 23static void _eio_stat_done_cb(void *, Eio_File *, const Eina_Stat *);
24static void _eio_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error); 24static void _eio_error_cb(void *, Eio_File *, int error);
25static void _eio_done_children_load_cb(void *, Eio_File *);
26static void _eio_error_children_load_cb(void *, Eio_File *, int);
27static void _eio_main_children_load_cb(void *, Eio_File *, const Eina_File_Direct_Info *);
28static Eina_Bool _eio_filter_children_load_cb(void *, Eio_File *, const Eina_File_Direct_Info *);
25 29
26static void 30static void
27_eio_stat_do(Eio_Model_Data *priv) 31_eio_stat_do(Eio_Model_Data *priv)
@@ -465,9 +469,32 @@ _eio_model_efl_model_children_count_get(Eo *obj EINA_UNUSED, Eio_Model_Data *pri
465 Eo *loop = efl_provider_find(obj, EFL_LOOP_CLASS); 469 Eo *loop = efl_provider_find(obj, EFL_LOOP_CLASS);
466 Efl_Promise *promise = efl_add(EFL_PROMISE_CLASS, loop); 470 Efl_Promise *promise = efl_add(EFL_PROMISE_CLASS, loop);
467 Efl_Future* future = efl_promise_future_get(promise); 471 Efl_Future* future = efl_promise_future_get(promise);
468 unsigned int *c = calloc(sizeof(unsigned int), 1); 472
469 *c = eina_list_count(priv->children_list); 473 if (!priv->path)
470 efl_promise_value_set(promise, c, free); 474 {
475 efl_promise_failed_set(promise, EFL_MODEL_ERROR_INIT_FAILED);
476 return future;
477 }
478
479 if (!(priv->is_listed))
480 {
481 priv->count_promises = eina_list_prepend(priv->count_promises, promise);
482
483 if (priv->is_listing == EINA_FALSE)
484 {
485 priv->is_listing = EINA_TRUE;
486 eio_file_direct_ls(priv->path, _eio_filter_children_load_cb,
487 _eio_main_children_load_cb, _eio_done_children_load_cb,
488 _eio_error_children_load_cb, priv);
489 }
490 }
491 else
492 {
493 unsigned int *c = calloc(1, sizeof(unsigned int));
494 *c = eina_list_count(priv->children_list);
495 efl_promise_value_set(promise, c, free);
496 }
497
471 return future; 498 return future;
472} 499}
473 500
@@ -549,6 +576,10 @@ static void
549_eio_done_children_load_cb(void *data, Eio_File *handler EINA_UNUSED) 576_eio_done_children_load_cb(void *data, Eio_File *handler EINA_UNUSED)
550{ 577{
551 Eio_Model_Data *priv = data; 578 Eio_Model_Data *priv = data;
579 _Eio_Children_Slice_Promise* p;
580 Efl_Promise *promise;
581 Eina_List* li;
582
552 EINA_SAFETY_ON_NULL_RETURN(priv); 583 EINA_SAFETY_ON_NULL_RETURN(priv);
553 584
554 eio_file_cancel(priv->listing_file); 585 eio_file_cancel(priv->listing_file);
@@ -558,9 +589,16 @@ _eio_done_children_load_cb(void *data, Eio_File *handler EINA_UNUSED)
558 589
559 _eio_model_efl_model_monitor_add(priv); 590 _eio_model_efl_model_monitor_add(priv);
560 591
561 Eina_List* i; 592 EINA_LIST_FOREACH(priv->count_promises, li, promise)
562 _Eio_Children_Slice_Promise* p; 593 {
563 EINA_LIST_FOREACH(priv->children_promises, i, p) 594 unsigned int *c = calloc(1, sizeof(unsigned int));
595 *c = eina_list_count(priv->children_list);
596 efl_promise_value_set(promise, c, free);
597 }
598 eina_list_free(priv->count_promises);
599 priv->count_promises = NULL;
600
601 EINA_LIST_FOREACH(priv->children_promises, li, p)
564 { 602 {
565 Eina_Accessor* accessor = efl_model_list_slice(priv->children_list, p->start, p->count); 603 Eina_Accessor* accessor = efl_model_list_slice(priv->children_list, p->start, p->count);
566 efl_promise_value_set(p->promise, accessor, (Eina_Free_Cb)&eina_accessor_free); 604 efl_promise_value_set(p->promise, accessor, (Eina_Free_Cb)&eina_accessor_free);
@@ -575,12 +613,26 @@ static void
575_eio_error_children_load_cb(void *data, Eio_File *handler EINA_UNUSED, int error) 613_eio_error_children_load_cb(void *data, Eio_File *handler EINA_UNUSED, int error)
576{ 614{
577 Eio_Model_Data *priv = data; 615 Eio_Model_Data *priv = data;
616 _Eio_Children_Slice_Promise* p;
617 Efl_Promise *promise;
578 Eo *child; 618 Eo *child;
579 619
580 WRN("%d: %s.", error, strerror(error)); 620 WRN("%d: %s.", error, strerror(error));
581 621
582 EINA_LIST_FREE(priv->children_list, child) 622 EINA_LIST_FREE(priv->children_list, child)
583 efl_unref(child); 623 efl_unref(child);
624 priv->children_list = NULL;
625
626 EINA_LIST_FREE(priv->count_promises, promise)
627 efl_promise_failed_set(promise, EFL_MODEL_ERROR_UNKNOWN);
628 priv->count_promises = NULL;
629
630 EINA_LIST_FREE(priv->children_promises, p)
631 {
632 efl_promise_failed_set(p->promise, EFL_MODEL_ERROR_UNKNOWN);
633 free(p);
634 }
635 priv->children_promises = NULL;
584} 636}
585 637
586static void 638static void
diff --git a/src/lib/eio/eio_model_private.h b/src/lib/eio/eio_model_private.h
index 3bf179c..762d3e6 100644
--- a/src/lib/eio/eio_model_private.h
+++ b/src/lib/eio/eio_model_private.h
@@ -62,6 +62,7 @@ struct _Eio_Model_Data
62 Eina_List *children_list; 62 Eina_List *children_list;
63 Eina_List *property_promises; 63 Eina_List *property_promises;
64 Eina_List *children_promises; 64 Eina_List *children_promises;
65 Eina_List *count_promises;
65 /**< EIO data */ 66 /**< EIO data */
66 Eio_File *stat_file; 67 Eio_File *stat_file;
67 Eio_File *listing_file; 68 Eio_File *listing_file;
@@ -71,6 +72,7 @@ struct _Eio_Model_Data
71 Eio_Model_Monitor_Data mon; 72 Eio_Model_Monitor_Data mon;
72 int cb_count_child_add; /**< monitor reference counter for child add event */ 73 int cb_count_child_add; /**< monitor reference counter for child add event */
73 int cb_count_child_del; /**< monitor reference counter for child del event*/ 74 int cb_count_child_del; /**< monitor reference counter for child del event*/
75 unsigned int count;
74 Eio_Filter_Direct_Cb filter_cb; 76 Eio_Filter_Direct_Cb filter_cb;
75 void *filter_userdata; 77 void *filter_userdata;
76 Eina_Spinlock filter_lock; /**< filter callback is called from another thread */ 78 Eina_Spinlock filter_lock; /**< filter callback is called from another thread */