cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=83be87e4a44b45e8f500a95de0f3a3d511e35ea9

commit 83be87e4a44b45e8f500a95de0f3a3d511e35ea9
Author: Cedric BAIL <[email protected]>
Date:   Tue Jan 29 11:56:34 2019 -0800

    ecore: add infrastructure to make it easy to enforce Efl.Loop_Model 
children lifecycle.
    
    Reviewed-by: Xavi Artigas <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D7862
---
 src/lib/ecore/efl_loop_model.c  | 27 +++++++++++++++++++++++++++
 src/lib/ecore/efl_loop_model.eo | 11 +++++++++++
 2 files changed, 38 insertions(+)

diff --git a/src/lib/ecore/efl_loop_model.c b/src/lib/ecore/efl_loop_model.c
index f04a766acb..0f212f1283 100644
--- a/src/lib/ecore/efl_loop_model.c
+++ b/src/lib/ecore/efl_loop_model.c
@@ -7,6 +7,7 @@
 #include <Ecore.h>
 #include "Eo.h"
 
+#include "ecore_private.h"
 #include "efl_loop_model.eo.h"
 
 typedef struct _Efl_Loop_Model_Watcher_Data Efl_Loop_Model_Watcher_Data;
@@ -106,4 +107,30 @@ _efl_loop_model_efl_model_property_ready_get(Eo *obj, void 
*pd EINA_UNUSED, cons
    return efl_future_then(obj, f);
 }
 
+static void
+_noref_death(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   efl_event_callback_del(event->object, EFL_EVENT_NOREF, _noref_death, NULL);
+   // For safety reason and in case multiple call to volatile has been made
+   // we check that there is still a parent at this point in EFL_EVENT_NOREF
+   efl_del(event->object);
+}
+
+static void
+_efl_loop_model_volatile_make(Eo *obj, void *pd EINA_UNUSED)
+{
+   // Just to make sure we do not double register this callback, we first 
remove
+   // any potentially previous one.
+   efl_event_callback_del(obj, EFL_EVENT_NOREF, _noref_death, NULL);
+   efl_event_callback_add(obj, EFL_EVENT_NOREF, _noref_death, NULL);
+}
+
+static void
+_efl_loop_model_efl_object_invalidate(Eo *obj, void *pd EINA_UNUSED)
+{
+   efl_event_callback_del(obj, EFL_EVENT_NOREF, _noref_death, NULL);
+
+   efl_invalidate(efl_super(obj, EFL_LOOP_MODEL_CLASS));
+}
+
 #include "efl_loop_model.eo.c"
diff --git a/src/lib/ecore/efl_loop_model.eo b/src/lib/ecore/efl_loop_model.eo
index 72e094f221..362b8bff09 100644
--- a/src/lib/ecore/efl_loop_model.eo
+++ b/src/lib/ecore/efl_loop_model.eo
@@ -1,7 +1,18 @@
 abstract @beta Efl.Loop_Model extends Efl.Loop_Consumer implements Efl.Model
 {
    data: null;
+   methods {
+      volatile_make {
+         [[To be called when a Child model is created by 
@Efl.Model.children_slice_get by the one creating the child object.
+
+         This function is used to properly define the lifecycle of the new 
Child Model object
+         and make sure that once it has 0 ref except its parent Model, it will 
be destroyed.
+         This function should only be called once per child. It is useful for 
@Efl.Model who
+         have a lot of children and shouldn't keep more than what is used in 
memory.]]
+      }
+   }
    implements {
+      Efl.Object.invalidate;
       Efl.Model.property_ready_get;
    }
 }

-- 


Reply via email to