jeyzu pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=e199230615d5cbc317faf85fa43b5383628b6af6
commit e199230615d5cbc317faf85fa43b5383628b6af6 Author: Jérémy Zurcher <jer...@asynk.ch> Date: Tue Feb 18 15:33:24 2014 +0100 eo: eo_composite_attach check composite class, disallow duplicates eo_composite_attach fail if the class of the composite is not listed in the parent class extensions, or if there is already a composite of the same class. The later because calls are forwarded to the first responding composite, see _eo_op_internal(). --- src/lib/eo/Eo.h | 5 ++++- src/lib/eo/eo.c | 21 ++++++++++++++++++--- .../eo/composite_objects/composite_objects_main.c | 8 +++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 9ae740c..06a8ca1 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -936,13 +936,16 @@ EAPI Eina_Bool eo_destructed_is(const Eo *obj); * @brief Make an object a composite object of another. * @param comp_obj the object that will be used to composite parent. * @param parent the "parent" object. + * @return EINA_TRUE if successfull. EINA_FALSE otherwise. * + * The class of comp_obj must be part of the extensions of the class of the parent. + * It is not possible to attach more then 1 composite of the same class. * This functions also sets the parent of comp_obj to parent. * * @see eo_composite_detach() * @see eo_composite_is() */ -EAPI void eo_composite_attach(Eo *comp_obj, Eo *parent); +EAPI Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent); /** * @brief Detach a composite object from another object. diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index fc64464..bfee7eb 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -1485,16 +1485,31 @@ eo_shutdown(void) return EINA_TRUE; } -EAPI void +EAPI Eina_Bool eo_composite_attach(Eo *comp_obj_id, Eo *parent_id) { - EO_OBJ_POINTER_RETURN(comp_obj_id, comp_obj); - EO_OBJ_POINTER_RETURN(parent_id, parent); + EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE); + EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE); + + if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass))) return EINA_FALSE; + + { + Eina_List *itr; + Eo *emb_obj_id; + EINA_LIST_FOREACH(parent->composite_objects, itr, emb_obj_id) + { + EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE); + if(emb_obj->klass == comp_obj->klass) + return EINA_FALSE; + } + } comp_obj->composite = EINA_TRUE; parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id); eo_do(comp_obj_id, eo_parent_set(parent_id)); + + return EINA_TRUE; } EAPI void diff --git a/src/tests/eo/composite_objects/composite_objects_main.c b/src/tests/eo/composite_objects/composite_objects_main.c index 2e5d9ab..1d5b8c0 100644 --- a/src/tests/eo/composite_objects/composite_objects_main.c +++ b/src/tests/eo/composite_objects/composite_objects_main.c @@ -33,6 +33,9 @@ main(int argc, char *argv[]) Eo *obj = eo_add(COMP_CLASS, NULL); eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL)); + fail_if(!eo_isa(obj, COMP_CLASS)); + fail_if(!eo_isa(obj, SIMPLE_CLASS)); + int a; eo_do(obj, simple_a_set(1)); fail_if(!cb_called); @@ -53,8 +56,11 @@ main(int argc, char *argv[]) fail_if(!eo_composite_is(simple)); eo_composite_detach(simple, obj); fail_if(eo_composite_is(simple)); - eo_composite_attach(simple, obj); + fail_if(!eo_composite_attach(simple, obj)); fail_if(!eo_composite_is(simple)); + fail_if(eo_composite_attach(simple, obj)); + + fail_if(eo_composite_attach(obj, simple)); eo_unref(simple); eo_unref(obj); --