Eo composite: Fix composite object functions to be eo functions.

For some reason, they were normal functions instead of eo functions,
which makes them harder to bind, less safe, and just wrong.
This commit fixes that.
This commit is contained in:
Tom Hacohen 2014-10-21 12:37:00 +01:00
parent 2ac6c4accf
commit 01a487d881
9 changed files with 113 additions and 120 deletions

View File

@ -23,7 +23,7 @@ _constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
eo_do_super(obj, MY_CLASS, eo_constructor());
Eo *bt = eo_add(ELW_BUTTON_CLASS, obj);
eo_composite_attach(bt, obj);
eo_do(obj, eo_composite_attach(bt));
eo_do(bt, eo_event_callback_forwarder_add(EV_CLICKED, obj));
eo_do(bt, exevas_obj_visibility_set(EINA_TRUE));

View File

@ -872,53 +872,6 @@ EAPI Eina_Bool eo_manual_free(Eo *obj);
*/
EAPI Eina_Bool eo_destructed_is(const Eo *obj);
/**
* @addtogroup Eo_Composite_Objects Composite Objects.
* @{
*/
/**
* @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 Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent);
/**
* @brief Detach a composite object from another object.
* @param comp_obj the object attached to parent.
* @param parent the "parent" object.
* @return EINA_TRUE if successfull. EINA_FALSE otherwise.
*
* This functions also sets the parent of comp_obj to @c NULL.
*
* @see eo_composite_attach()
* @see eo_composite_is()
*/
EAPI Eina_Bool eo_composite_detach(Eo *comp_obj, Eo *parent);
/**
* @brief Check if an object is a composite object.
* @param comp_obj the object to be checked.
* @return @c EINA_TRUE if it is, @c EINA_FALSE otherwise.
*
* @see eo_composite_attach()
* @see eo_composite_detach()
*/
EAPI Eina_Bool eo_composite_is(const Eo *comp_obj);
/**
* @}
*/
/**
* @addtogroup Eo_Class_Class Eo's Class class.
* @{

View File

@ -1855,57 +1855,6 @@ eo_shutdown(void)
return EINA_TRUE;
}
EAPI Eina_Bool
eo_composite_attach(Eo *comp_obj_id, Eo *parent_id)
{
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 Eina_Bool
eo_composite_detach(Eo *comp_obj_id, Eo *parent_id)
{
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
if (!comp_obj->composite)
return EINA_FALSE;
comp_obj->composite = EINA_FALSE;
parent->composite_objects = eina_list_remove(parent->composite_objects, comp_obj_id);
eo_do(comp_obj_id, eo_parent_set(NULL));
return EINA_TRUE;
}
EAPI Eina_Bool
eo_composite_is(const Eo *comp_obj_id)
{
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
return comp_obj->composite;
}
EAPI Eina_Bool
eo_destructed_is(const Eo *obj_id)
{

View File

@ -173,6 +173,48 @@ callbacks of the same priority are called in reverse order of creation. */
/*@ Get an iterator on all childrens */
return: free(own(iterator<Eo *> *), eina_iterator_free) @warn_unused;
}
composite_attach {
/**
* @brief Make an object a composite object of another.
*
* 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_part_is()
* @ingroup Eo_Composite_Objects
*/
params {
@in Eo *comp_obj; /*@ the object that will be used to composite the parent. */
}
return: bool; /*@ EINA_TRUE if successfull. EINA_FALSE otherwise. */
}
composite_detach {
/**
* @brief Detach a composite object from another object.
*
* This functions also sets the parent of comp_obj to @c NULL.
*
* @see eo_composite_attach()
* @see eo_composite_part_is()
* @ingroup Eo_Composite_Objects
*/
params {
@in Eo *comp_obj; /*@ the object that will be removed from the parent. */
}
return: bool; /*@ EINA_TRUE if successfull. EINA_FALSE otherwise. */
}
composite_part_is {
/**
* @brief Check if an object is part of a composite object.
*
* @see eo_composite_attach()
* @see eo_composite_part_is()
* @ingroup Eo_Composite_Objects
*/
return: bool; /*@ EINA_TRUE if it is. EINA_FALSE otherwise. */
}
}
implements {
class.constructor;

View File

@ -104,9 +104,9 @@ _eo_base_parent_set(Eo *obj, Eo_Base_Data *pd, Eo *parent_id)
if (pd->parent == parent_id)
return;
if (eo_composite_is(obj) && pd->parent)
if (eo_do(obj, eo_composite_part_is()) && pd->parent)
{
eo_composite_detach(obj, pd->parent);
eo_do(pd->parent, eo_composite_detach(obj));
}
if (pd->parent)
@ -813,6 +813,57 @@ _eo_base_event_global_freeze_count_get(Eo *klass EINA_UNUSED, void *pd EINA_UNUS
return event_freeze_count;
}
EOLIAN static Eina_Bool
_eo_base_composite_attach(Eo *parent_id, Eo_Base_Data *pd EINA_UNUSED, Eo *comp_obj_id)
{
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;
}
EOLIAN static Eina_Bool
_eo_base_composite_detach(Eo *parent_id, Eo_Base_Data *pd EINA_UNUSED, Eo *comp_obj_id)
{
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
if (!comp_obj->composite)
return EINA_FALSE;
comp_obj->composite = EINA_FALSE;
parent->composite_objects = eina_list_remove(parent->composite_objects, comp_obj_id);
eo_do(comp_obj_id, eo_parent_set(NULL));
return EINA_TRUE;
}
EOLIAN static Eina_Bool
_eo_base_composite_part_is(Eo *comp_obj_id, Eo_Base_Data *pd EINA_UNUSED)
{
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
return comp_obj->composite;
}
/* Eo_Dbg */
EAPI void
eo_dbg_info_free(Eo_Dbg_Info *info)

View File

@ -231,7 +231,7 @@ _eo_del_internal(const char *file, int line, _Eo_Object *obj)
Eo *emb_obj;
EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
{
eo_composite_detach(emb_obj, _eo_id_get(obj));
eo_do(_eo_id_get(obj), eo_composite_detach(emb_obj));
}
}

View File

@ -25,11 +25,11 @@ _constructor(Eo *obj, void *class_data EINA_UNUSED)
eo_do_super(obj, MY_CLASS, eo_constructor());
Eo *simple = eo_add(SIMPLE_CLASS, obj);
eo_composite_attach(simple, obj);
eo_do(obj, eo_composite_attach(simple));
eo_do(simple, eo_event_callback_forwarder_add(EV_A_CHANGED, obj));
fail_if(eo_composite_is(obj));
fail_if(!eo_composite_is(simple));
fail_if(eo_do(obj, eo_composite_part_is()));
fail_if(!eo_do(simple, eo_composite_part_is()));
eo_do(obj, eo_key_data_set("simple-obj", simple, NULL));
}

View File

@ -53,15 +53,15 @@ main(int argc, char *argv[])
eo_do(obj, simple_a_set(2));
fail_if(cb_called);
fail_if(!eo_composite_is(simple));
fail_if(!eo_composite_detach(simple, obj));
fail_if(eo_composite_detach(simple, obj));
fail_if(eo_composite_is(simple));
fail_if(!eo_composite_attach(simple, obj));
fail_if(!eo_composite_is(simple));
fail_if(eo_composite_attach(simple, obj));
fail_if(!eo_do(simple, eo_composite_part_is()));
fail_if(!eo_do(obj, eo_composite_detach(simple)));
fail_if(eo_do(obj, eo_composite_detach(simple)));
fail_if(eo_do(simple, eo_composite_part_is()));
fail_if(!eo_do(obj, eo_composite_attach(simple)));
fail_if(!eo_do(simple, eo_composite_part_is()));
fail_if(eo_do(obj, eo_composite_attach(simple)));
fail_if(eo_composite_attach(obj, simple));
fail_if(eo_do(simple, eo_composite_attach(obj)));
eo_unref(simple);
eo_unref(obj);

View File

@ -275,9 +275,9 @@ START_TEST(eo_composite_tests)
Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
fail_if(!obj2);
eo_composite_attach(obj2, obj);
eo_do(obj, eo_composite_attach(obj2));
eo_do(obj2, eo_parent_set(NULL));
fail_if(eo_composite_is(obj2));
fail_if(eo_do(obj2, eo_composite_part_is()));
eo_unref(obj2);
eo_unref(obj);
@ -681,11 +681,9 @@ START_TEST(eo_magic_checks)
fail_if(eo_data_scope_get((Eo *) buf, SIMPLE_CLASS));
eo_composite_attach((Eo *) buf, obj);
eo_composite_attach(obj, (Eo *) buf);
eo_composite_detach((Eo *) buf, obj);
eo_composite_detach(obj, (Eo *) buf);
eo_composite_is((Eo *) buf);
eo_do(obj, eo_composite_attach((Eo *) buf));
eo_do(obj, eo_composite_detach((Eo *) buf));
eo_do((Eo *) buf, eo_composite_part_is());
eo_do(obj, eo_event_callback_forwarder_add(NULL, (Eo *) buf));
eo_do(obj, eo_event_callback_forwarder_del(NULL, (Eo *) buf));