diff options
author | Cedric BAIL <cedric@osg.samsung.com> | 2016-06-16 11:38:47 -0700 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2016-06-22 10:17:06 -0700 |
commit | ec77773aa3bda5df1d3d745b9acfcd5eb0cd193a (patch) | |
tree | 09d74c6ffa651c739a14ce16e9f71a3ec8ba8806 | |
parent | e07d520fa2c4f8b58452728d27a16978591893dd (diff) | |
download | efl-ec77773aa3bda5df1d3d745b9acfcd5eb0cd193a.tar.gz |
ecore: add ability for the main loop to provide other class of object.
-rw-r--r-- | src/lib/ecore/ecore_main.c | 38 | ||||
-rw-r--r-- | src/lib/ecore/ecore_private.h | 2 | ||||
-rw-r--r-- | src/lib/ecore/efl_loop.eo | 17 |
3 files changed, 55 insertions, 2 deletions
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c index 7bab6e6593..d21e35727b 100644 --- a/src/lib/ecore/ecore_main.c +++ b/src/lib/ecore/ecore_main.c @@ -2746,10 +2746,15 @@ _efl_loop_quit(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd EINA_UNUSED) } EOLIAN static Eo_Base * -_efl_loop_eo_base_provider_find(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, const Eo_Base *klass) +_efl_loop_eo_base_provider_find(Eo *obj, Efl_Loop_Data *pd, const Eo_Base *klass) { + Eo_Base *r; + if (klass == EFL_LOOP_CLASS) return obj; + r = eina_hash_find(pd->providers, &klass); + if (r) return r; + return eo_provider_find(eo_super(obj, EFL_LOOP_CLASS), klass); } @@ -2792,12 +2797,24 @@ EO_CALLBACKS_ARRAY_DEFINE(event_catcher_watch, EOLIAN static Eo_Base * _efl_loop_eo_base_constructor(Eo *obj, Efl_Loop_Data *pd) { - eo_constructor(eo_super(obj, EFL_LOOP_CLASS)); + obj = eo_constructor(eo_super(obj, EFL_LOOP_CLASS)); + if (!obj) return NULL; + eo_event_callback_array_add(obj, event_catcher_watch(), pd); + pd->providers = eina_hash_pointer_new((void*) eo_unref); + return obj; } +EOLIAN static void +_efl_loop_eo_base_destructor(Eo *obj, Efl_Loop_Data *pd) +{ + eo_destructor(eo_super(obj, EFL_LOOP_CLASS)); + + eina_hash_free(pd->providers); +} + typedef struct _Efl_Internal_Promise Efl_Internal_Promise; struct _Efl_Internal_Promise { @@ -2964,4 +2981,21 @@ _efl_loop_timeout(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, double time, const voi return NULL; } +static Eina_Bool +_efl_loop_register(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd, const Eo_Class *klass, const Eo_Base *provider) +{ + // The passed object does not provide that said class. + if (!eo_isa(provider, klass)) return EINA_FALSE; + + // Note: I would prefer to use eo_xref here, but I can't figure a nice way to + // call eo_xunref on hash destruction. + return eina_hash_add(pd->providers, &klass, eo_ref(provider)); +} + +static Eina_Bool +_efl_loop_unregister(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd, const Eo_Class *klass, const Eo_Base *provider) +{ + return eina_hash_del(pd->providers, &klass, provider); +} + #include "efl_loop.eo.c" diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h index 172a43c837..91379bad86 100644 --- a/src/lib/ecore/ecore_private.h +++ b/src/lib/ecore/ecore_private.h @@ -82,6 +82,8 @@ typedef struct _Ecore_Factorized_Idle Ecore_Factorized_Idle; typedef struct _Efl_Loop_Data Efl_Loop_Data; struct _Efl_Loop_Data { + Eina_Hash *providers; + int idlers; }; diff --git a/src/lib/ecore/efl_loop.eo b/src/lib/ecore/efl_loop.eo index 2f5459da0a..0091fd41c3 100644 --- a/src/lib/ecore/efl_loop.eo +++ b/src/lib/ecore/efl_loop.eo @@ -45,6 +45,22 @@ class Efl.Loop (Eo.Base) } return: promise<void_ptr>; [[The promise that will be triggered.]] } + register { + [[Will register a manager of a specific class to be answered by eo.provider_find.]] + params { + @in klass: const(Eo.Class); [[The class provided by the registered provider.]] + @in provider: const(Eo.Base); [[The provider for the newly registered class that has to provide that said Eo.Class.]] + } + return: bool; [[true if successfully register, false otherwise.]] + } + unregister { + [[Will unregister a manager of a specific class that was previously registered and answered by eo.provider_find.]] + params { + @in klass: const(Eo.Class); [[The class provided by the provider to unregister for.]] + @in provider: const(Eo.Base); [[The provider for the registered class to unregister.]] + } + return: bool; [[true if successfully unregistered, false otherwise.]] + } args_add { [[Add a new set of arguments to the loop that makes an args event.]] params { @@ -62,6 +78,7 @@ class Efl.Loop (Eo.Base) } implements { Eo.Base.constructor; + Eo.Base.destructor; Eo.Base.provider_find; } } |