summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-02-18 15:33:24 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-02-26 16:25:00 +0100
commite199230615d5cbc317faf85fa43b5383628b6af6 (patch)
tree5a3719682a8dce2a1db25680f655e9e65fd1ad50 /src
parentf98c1393b8b870f9d8c0830f3da23da48a68d812 (diff)
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().
Diffstat (limited to 'src')
-rw-r--r--src/lib/eo/Eo.h5
-rw-r--r--src/lib/eo/eo.c21
-rw-r--r--src/tests/eo/composite_objects/composite_objects_main.c8
3 files changed, 29 insertions, 5 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 9ae740ca1f..06a8ca179b 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);
936 * @brief Make an object a composite object of another. 936 * @brief Make an object a composite object of another.
937 * @param comp_obj the object that will be used to composite parent. 937 * @param comp_obj the object that will be used to composite parent.
938 * @param parent the "parent" object. 938 * @param parent the "parent" object.
939 * @return EINA_TRUE if successfull. EINA_FALSE otherwise.
939 * 940 *
941 * The class of comp_obj must be part of the extensions of the class of the parent.
942 * It is not possible to attach more then 1 composite of the same class.
940 * This functions also sets the parent of comp_obj to parent. 943 * This functions also sets the parent of comp_obj to parent.
941 * 944 *
942 * @see eo_composite_detach() 945 * @see eo_composite_detach()
943 * @see eo_composite_is() 946 * @see eo_composite_is()
944 */ 947 */
945EAPI void eo_composite_attach(Eo *comp_obj, Eo *parent); 948EAPI Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent);
946 949
947/** 950/**
948 * @brief Detach a composite object from another object. 951 * @brief Detach a composite object from another object.
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index fc644642d7..bfee7ebb91 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -1485,16 +1485,31 @@ eo_shutdown(void)
1485 return EINA_TRUE; 1485 return EINA_TRUE;
1486} 1486}
1487 1487
1488EAPI void 1488EAPI Eina_Bool
1489eo_composite_attach(Eo *comp_obj_id, Eo *parent_id) 1489eo_composite_attach(Eo *comp_obj_id, Eo *parent_id)
1490{ 1490{
1491 EO_OBJ_POINTER_RETURN(comp_obj_id, comp_obj); 1491 EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
1492 EO_OBJ_POINTER_RETURN(parent_id, parent); 1492 EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
1493
1494 if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass))) return EINA_FALSE;
1495
1496 {
1497 Eina_List *itr;
1498 Eo *emb_obj_id;
1499 EINA_LIST_FOREACH(parent->composite_objects, itr, emb_obj_id)
1500 {
1501 EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE);
1502 if(emb_obj->klass == comp_obj->klass)
1503 return EINA_FALSE;
1504 }
1505 }
1493 1506
1494 comp_obj->composite = EINA_TRUE; 1507 comp_obj->composite = EINA_TRUE;
1495 parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id); 1508 parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id);
1496 1509
1497 eo_do(comp_obj_id, eo_parent_set(parent_id)); 1510 eo_do(comp_obj_id, eo_parent_set(parent_id));
1511
1512 return EINA_TRUE;
1498} 1513}
1499 1514
1500EAPI void 1515EAPI void
diff --git a/src/tests/eo/composite_objects/composite_objects_main.c b/src/tests/eo/composite_objects/composite_objects_main.c
index 2e5d9ab005..1d5b8c0474 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[])
33 Eo *obj = eo_add(COMP_CLASS, NULL); 33 Eo *obj = eo_add(COMP_CLASS, NULL);
34 eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL)); 34 eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL));
35 35
36 fail_if(!eo_isa(obj, COMP_CLASS));
37 fail_if(!eo_isa(obj, SIMPLE_CLASS));
38
36 int a; 39 int a;
37 eo_do(obj, simple_a_set(1)); 40 eo_do(obj, simple_a_set(1));
38 fail_if(!cb_called); 41 fail_if(!cb_called);
@@ -53,8 +56,11 @@ main(int argc, char *argv[])
53 fail_if(!eo_composite_is(simple)); 56 fail_if(!eo_composite_is(simple));
54 eo_composite_detach(simple, obj); 57 eo_composite_detach(simple, obj);
55 fail_if(eo_composite_is(simple)); 58 fail_if(eo_composite_is(simple));
56 eo_composite_attach(simple, obj); 59 fail_if(!eo_composite_attach(simple, obj));
57 fail_if(!eo_composite_is(simple)); 60 fail_if(!eo_composite_is(simple));
61 fail_if(eo_composite_attach(simple, obj));
62
63 fail_if(eo_composite_attach(obj, simple));
58 64
59 eo_unref(simple); 65 eo_unref(simple);
60 eo_unref(obj); 66 eo_unref(obj);