ecore: add infrastructure to make it easy to enforce Efl.Loop_Model children lifecycle.
authorCedric BAIL <cedric.bail@free.fr>
Tue, 29 Jan 2019 19:56:34 +0000 (11:56 -0800)
committerWonki Kim <wonki_.kim@samsung.com>
Fri, 8 Mar 2019 11:49:35 +0000 (20:49 +0900)
Reviewed-by: Xavi Artigas <xavierartigas@yahoo.es>
Differential Revision: https://phab.enlightenment.org/D7862

src/lib/ecore/efl_loop_model.c
src/lib/ecore/efl_loop_model.eo

index f04a766..0f212f1 100644 (file)
@@ -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"
index 72e094f..362b8bf 100644 (file)
@@ -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;
    }
 }