From: Cedric BAIL Date: Tue, 29 Jan 2019 19:56:34 +0000 (-0800) Subject: ecore: add infrastructure to make it easy to enforce Efl.Loop_Model children lifecycle. X-Git-Tag: submit/tizen/20190308.115227~139 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1202d52884733a002a98b09affcbe698041b192a;p=platform%2Fupstream%2Fefl.git ecore: add infrastructure to make it easy to enforce Efl.Loop_Model children lifecycle. Reviewed-by: Xavi Artigas Differential Revision: https://phab.enlightenment.org/D7862 --- diff --git a/src/lib/ecore/efl_loop_model.c b/src/lib/ecore/efl_loop_model.c index f04a766..0f212f1 100644 --- a/src/lib/ecore/efl_loop_model.c +++ b/src/lib/ecore/efl_loop_model.c @@ -7,6 +7,7 @@ #include #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 72e094f..362b8bf 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; } }