Eo: Improved the data structure used for func fetching.
[profile/ivi/eobj.git] / lib / eo.c
1 #include <Eina.h>
2
3 #include "Eo.h"
4 #include "eo_private.h"
5
6 #include "config.h"
7
8 typedef size_t Eo_Class_Id;
9
10 /* Used inside the class_get functions of classes, see #EO_DEFINE_CLASS */
11 EAPI Eina_Lock _eo_class_creation_lock;
12 int _eo_log_dom = -1;
13
14 static Eo_Class **_eo_classes;
15 static Eo_Class_Id _eo_classes_last_id;
16 static Eina_Bool _eo_init_count = 0;
17
18 static void _eo_callback_remove_all(Eo *obj);
19 static void _eo_constructor(Eo *obj, const Eo_Class *klass);
20 static void _eo_destructor(Eo *obj, const Eo_Class *klass);
21 static void eo_constructor_error_unset(Eo *obj);
22 static inline void *_eo_data_get(const Eo *obj, const Eo_Class *klass);
23
24 typedef struct _Eo_Callback_Description Eo_Callback_Description;
25
26 typedef struct
27 {
28    Eo_Op op;
29    const Eo_Class **kls_itr;
30 } Eo_Kls_Itr;
31
32 #define EO_EINA_MAGIC 0xa186bc32 /* Nothing magical about this number. */
33 #define EO_EINA_MAGIC_STR "Eo"
34 #define EO_CLASS_EINA_MAGIC 0xa186bb32 /* Nothing magical about this number. */
35 #define EO_CLASS_EINA_MAGIC_STR "Eo Class"
36
37 #define EO_MAGIC_RETURN_VAL(d, magic, ret) \
38    do { \
39         if (!EINA_MAGIC_CHECK(d, magic)) \
40           { \
41              EINA_MAGIC_FAIL(d, magic); \
42              return ret; \
43           } \
44    } while (0)
45
46 #define EO_MAGIC_RETURN(d, magic) \
47    do { \
48         if (!EINA_MAGIC_CHECK(d, magic)) \
49           { \
50              EINA_MAGIC_FAIL(d, magic); \
51              return; \
52           } \
53    } while (0)
54
55 struct _Eo {
56      EINA_MAGIC
57      Eo *parent;
58      const Eo_Class *klass;
59      int refcount;
60 #ifndef NDEBUG
61      Eina_Inlist *xrefs;
62 #endif
63
64      Eina_List *composite_objects;
65
66      Eina_Inlist *callbacks;
67      int walking_list;
68
69      Eo_Kls_Itr mro_itr;
70
71      Eina_Bool delete:1;
72      Eina_Bool construct_error:1;
73 };
74
75 /* Start of Dich */
76 /* Dich search, split to 0xff 0xff 0xffff */
77
78 #define DICH_CHAIN1_MASK (0xffff)
79 #define DICH_CHAIN_LAST_MASK (0xffff)
80 #define DICH_CHAIN1(x) (((x) >> 16) & DICH_CHAIN1_MASK)
81 #define DICH_CHAIN_LAST(x) ((x) & DICH_CHAIN_LAST_MASK)
82
83 #define OP_CLASS_OFFSET 16
84 #define OP_CLASS_OFFSET_GET(x) (((x) >> OP_CLASS_OFFSET) & 0xffff)
85 #define OP_CLASS_GET(op) ({ \
86       Eo_Class_Id tmp = OP_CLASS_OFFSET_GET(op); \
87       ID_CLASS_GET(tmp); \
88       })
89 #define OP_SUB_ID_GET(op) ((op) & 0xffff)
90
91 #define ID_CLASS_GET(id) ({ \
92       (Eo_Class *) ((id <= _eo_classes_last_id) && (id > 0)) ? \
93       (_eo_classes[id - 1]) : NULL; \
94       })
95
96 #define EO_ALIGN_SIZE(size) \
97         ((size) + (sizeof(void *) - ((size) % sizeof(void *))))
98
99 /* Structure of Eo_Op is:
100  * 16bit: class
101  * 16bit: op.
102  */
103
104 typedef struct _Dich_Chain1 Dich_Chain1;
105
106 typedef struct
107 {
108    eo_op_func_type func;
109 } op_type_funcs;
110
111 struct _Dich_Chain1
112 {
113    op_type_funcs *funcs;
114 };
115
116 typedef struct
117 {
118      EINA_INLIST;
119      const Eo_Class *klass;
120 } Eo_Extension_Node;
121
122 typedef struct
123 {
124      const Eo_Class *klass;
125      size_t offset;
126 } Eo_Extension_Data_Offset;
127
128 struct _Eo_Class
129 {
130    EINA_MAGIC
131    Eo_Class_Id class_id;
132    const Eo_Class *parent;
133    const Eo_Class_Description *desc;
134    Dich_Chain1 *chain; /**< The size is class_id */
135    Eina_Inlist *extensions;
136
137    Eo_Extension_Data_Offset *extn_data_off;
138    size_t extn_data_size;
139
140    const Eo_Class **mro;
141
142    size_t data_offset; /* < Offset of the data within object data. */
143
144    Eina_Bool constructed : 1;
145 };
146
147 static inline eo_op_func_type
148 dich_func_get(const Eo_Class *klass, Eo_Op op)
149 {
150    if (!klass->chain) return NULL;
151
152    size_t idx1 = DICH_CHAIN1(op) - 1;
153    if (idx1 >= klass->class_id) return NULL;
154    const Dich_Chain1 *chain1 = &klass->chain[idx1];
155    if (!chain1->funcs) return NULL;
156
157    size_t idxl = DICH_CHAIN_LAST(op);
158    /* num_ops is calculated from the class. */
159    const Eo_Class *op_klass = ID_CLASS_GET(idx1 + 1);
160    if (!op_klass || (idxl >= op_klass->desc->ops.count))
161       return NULL;
162
163    return chain1->funcs[idxl].func;
164 }
165
166 static inline void
167 dich_func_set(Eo_Class *klass, Eo_Op op, eo_op_func_type func)
168 {
169    const Eo_Class *op_klass = OP_CLASS_GET(op);
170    size_t num_ops;
171
172    /* Verify op is valid. */
173    if (op_klass)
174      {
175         /* num_ops is calculated from the class. */
176         num_ops = op_klass->desc->ops.count;
177         if (DICH_CHAIN_LAST(op) >= num_ops)
178           {
179              ERR("OP %x is too big for the domain '%s', expected value < %x.",
180                    op, op_klass->desc->name, op_klass->desc->ops.count);
181              return;
182           }
183      }
184    else
185      {
186         ERR("OP %x is from an illegal class.", op);
187         return;
188      }
189
190    if (!klass->chain)
191      {
192         klass->chain = calloc(klass->class_id, sizeof(*klass->chain));
193      }
194
195    size_t idx1 = DICH_CHAIN1(op) - 1;
196    Dich_Chain1 *chain1 = &klass->chain[idx1];
197    if (!chain1->funcs)
198      {
199         chain1->funcs = calloc(num_ops, sizeof(*(chain1->funcs)));
200      }
201
202    chain1->funcs[DICH_CHAIN_LAST(op)].func = func;
203 }
204
205 static inline void
206 dich_func_clean_all(Eo_Class *klass)
207 {
208    size_t i;
209    Dich_Chain1 *chain1 = klass->chain;
210
211    if (!chain1)
212       return;
213
214    for (i = 0 ; i < klass->class_id ; i++, chain1++)
215      {
216         if (chain1->funcs)
217            free(chain1->funcs);
218      }
219    free(klass->chain);
220    klass->chain = NULL;
221 }
222
223 /* END OF DICH */
224
225 static const Eo_Op_Description noop_desc =
226         EO_OP_DESCRIPTION(EO_NOOP, "", "No operation.");
227
228 static const Eo_Op_Description *
229 _eo_op_id_desc_get(Eo_Op op)
230 {
231    const Eo_Class *klass = OP_CLASS_GET(op);
232    Eo_Op sub_id = OP_SUB_ID_GET(op);
233
234    if (op == EO_NOOP)
235       return &noop_desc;
236
237    if (klass && (sub_id < klass->desc->ops.count))
238       return klass->desc->ops.descs + sub_id;
239
240    return NULL;
241 }
242
243 static const char *
244 _eo_op_id_name_get(Eo_Op op)
245 {
246    const Eo_Op_Description *desc = _eo_op_id_desc_get(op);
247    return (desc) ? desc->name : NULL;
248 }
249
250 static inline void
251 _eo_kls_itr_init(Eo *obj, Eo_Op op, Eo_Kls_Itr *prev_state)
252 {
253    prev_state->op = obj->mro_itr.op;
254    prev_state->kls_itr = obj->mro_itr.kls_itr;
255
256    /* If we are in a constructor/destructor or we changed an op - init. */
257    if ((op == EO_NOOP) || (obj->mro_itr.op != op))
258      {
259         obj->mro_itr.op = op;
260         obj->mro_itr.kls_itr = obj->klass->mro;
261      }
262 }
263
264 static inline void
265 _eo_kls_itr_end(Eo *obj, Eo_Kls_Itr *prev_state)
266 {
267    if (obj->mro_itr.op != prev_state->op)
268      {
269         obj->mro_itr.op = prev_state->op;
270         obj->mro_itr.kls_itr = prev_state->kls_itr;
271      }
272 }
273
274 static inline const Eo_Class *
275 _eo_kls_itr_get(Eo *obj)
276 {
277    return (obj->mro_itr.kls_itr) ? *(obj->mro_itr.kls_itr) : NULL;
278 }
279
280 static inline const Eo_Class *
281 _eo_kls_itr_next(Eo *obj, Eo_Op op)
282 {
283    if (obj->mro_itr.op != op)
284      {
285         Eo_Op node_op = obj->mro_itr.op;
286         ERR("Called with op %d ('%s') while expecting: %d ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
287               op, _eo_op_id_name_get(op),
288               node_op, _eo_op_id_name_get(node_op));
289         return NULL;
290      }
291
292    const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
293    if (*kls_itr)
294      {
295         kls_itr++;
296         obj->mro_itr.kls_itr = kls_itr;
297         return *kls_itr;
298      }
299    else
300      {
301         return NULL;
302      }
303 }
304
305 static inline Eina_Bool
306 _eo_kls_itr_reached_end(const Eo *obj)
307 {
308    const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
309    return !(*kls_itr && *(kls_itr + 1));
310 }
311
312 static Eina_Bool
313 _eo_op_internal(Eo *obj, Eina_Bool constant, Eo_Op op, va_list *p_list)
314 {
315    const Eo_Class *klass;
316    Eina_Bool ret = EINA_FALSE;
317
318    const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
319
320    if (op_desc &&
321          ((constant == EINA_TRUE) && (op_desc->constant == EINA_FALSE)))
322      {
323         ERR("Tried calling non-const or non-existant op '%s' (%d) from a const (query) function.", (op_desc) ? op_desc->name : NULL, op);
324         return EINA_FALSE;
325      }
326
327    Eo_Kls_Itr prev_state;
328    _eo_kls_itr_init(obj, op, &prev_state);
329    klass = _eo_kls_itr_get(obj);
330    while (klass)
331      {
332         eo_op_func_type func = dich_func_get(klass, op);
333
334         if (func)
335           {
336              func(obj, _eo_data_get(obj, klass), p_list);
337              ret = EINA_TRUE;
338              goto end;
339           }
340
341         klass = _eo_kls_itr_next(obj, op);
342      }
343
344    /* Try composite objects */
345      {
346         Eina_List *itr;
347         Eo *emb_obj;
348         EINA_LIST_FOREACH(obj->composite_objects, itr, emb_obj)
349           {
350              if (_eo_op_internal(emb_obj, constant, op, p_list))
351                {
352                   ret = EINA_TRUE;
353                   goto end;
354                }
355           }
356      }
357
358 end:
359    _eo_kls_itr_end(obj, &prev_state);
360    return ret;
361 }
362
363 EAPI Eina_Bool
364 eo_do_internal(Eo *obj, Eina_Bool constant, ...)
365 {
366    Eina_Bool ret = EINA_TRUE;
367    Eo_Op op = EO_NOOP;
368    va_list p_list;
369
370    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
371
372    eo_ref(obj);
373
374    va_start(p_list, constant);
375
376    op = va_arg(p_list, Eo_Op);
377    while (op)
378      {
379         if (!_eo_op_internal(obj, constant, op, &p_list))
380           {
381              const Eo_Class *op_klass = OP_CLASS_GET(op);
382              const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
383              ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
384                    op, _eo_op_id_name_get(op), _dom_name,
385                    obj->klass->desc->name);
386              ret = EINA_FALSE;
387              break;
388           }
389         op = va_arg(p_list, Eo_Op);
390      }
391
392    va_end(p_list);
393
394    eo_unref(obj);
395    return ret;
396 }
397
398 EAPI Eina_Bool
399 eo_do_super_internal(Eo *obj, Eina_Bool constant, Eo_Op op, ...)
400 {
401    const Eo_Class *obj_klass;
402    Eina_Bool ret = EINA_TRUE;
403    va_list p_list;
404    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
405
406    /* Advance the kls itr. */
407    obj_klass = _eo_kls_itr_next(obj, op);
408
409    if (!obj_klass)
410      {
411         return EINA_FALSE;
412      }
413
414    va_start(p_list, op);
415    if (!_eo_op_internal(obj, constant, op, &p_list))
416      {
417         const Eo_Class *op_klass = OP_CLASS_GET(op);
418         const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
419         ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
420               op, _eo_op_id_name_get(op), _dom_name,
421               (obj_klass) ? obj_klass->desc->name : NULL);
422         ret = EINA_FALSE;
423      }
424    va_end(p_list);
425
426    return ret;
427 }
428
429 EAPI const Eo_Class *
430 eo_class_get(const Eo *obj)
431 {
432    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
433
434    return obj->klass;
435 }
436
437 EAPI const char *
438 eo_class_name_get(const Eo_Class *klass)
439 {
440    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
441
442    return klass->desc->name;
443 }
444
445 static void
446 _eo_class_base_op_init(Eo_Class *klass)
447 {
448    const Eo_Class_Description *desc = klass->desc;
449    if (!desc || !desc->ops.base_op_id)
450       return;
451
452    /* FIXME: Depends on values defined above! */
453    *(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
454 }
455
456 static Eina_Bool
457 _eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find)
458 {
459    const Eo_Class **itr;
460    for (itr = klass->mro ; *itr ; itr++)
461      {
462         if (*itr == find)
463           {
464              return EINA_TRUE;
465           }
466      }
467
468    return EINA_FALSE;
469 }
470
471 static Eina_List *
472 _eo_class_mro_add(Eina_List *mro, const Eo_Class *klass)
473 {
474    Eina_List *extn_pos = NULL;
475    Eina_Bool check_consistency = !mro;
476    if (!klass)
477       return mro;
478
479    mro = eina_list_append(mro, klass);
480
481    /* Recursively add extenions. */
482      {
483         Eo_Extension_Node *extn;
484         EINA_INLIST_FOREACH(klass->extensions, extn)
485           {
486              mro = _eo_class_mro_add(mro, extn->klass);
487              /* Not possible: if (!mro) return NULL; */
488
489              if (check_consistency)
490                {
491                   extn_pos = eina_list_append(extn_pos, eina_list_last(mro));
492                }
493           }
494      }
495
496    /* Check if we can create a consistent mro. We only do it for the class
497     * we are working on (i.e no parents). */
498    if (check_consistency)
499      {
500         Eo_Extension_Node *extn;
501
502         Eina_List *itr = extn_pos;
503         EINA_INLIST_FOREACH(klass->extensions, extn)
504           {
505              /* Get the first one after the extension. */
506              Eina_List *extn_list = eina_list_next(eina_list_data_get(itr));
507
508              /* If we found the extension again. */
509              if (eina_list_data_find_list(extn_list, extn->klass))
510                {
511                   eina_list_free(mro);
512                   ERR("Cannot create a consistent method resolution order for class '%s' because of '%s'.", klass->desc->name, extn->klass->desc->name);
513                   return NULL;
514                }
515
516              itr = eina_list_next(itr);
517           }
518      }
519
520
521    mro = _eo_class_mro_add(mro, klass->parent);
522
523    return mro;
524 }
525
526 static Eina_Bool
527 _eo_class_mro_init(Eo_Class *klass)
528 {
529    Eina_List *mro = NULL;
530
531    DBG("Started creating MRO for class '%s'", klass->desc->name);
532    mro = _eo_class_mro_add(mro, klass);
533
534    if (!mro)
535       return EINA_FALSE;
536
537    /* Remove duplicates and make them the right order. */
538      {
539         Eina_List *itr1, *itr2, *itr2n;
540
541         itr1 = eina_list_last(mro);
542         while (itr1)
543           {
544              itr2 = eina_list_prev(itr1);
545
546              while (itr2)
547                {
548                   itr2n = eina_list_prev(itr2);
549
550                   if (eina_list_data_get(itr1) == eina_list_data_get(itr2))
551                     {
552                        mro = eina_list_remove_list(mro, itr2);
553                     }
554
555                   itr2 = itr2n;
556                }
557
558              itr1 = eina_list_prev(itr1);
559           }
560      }
561
562    /* Copy the mro and free the list. */
563      {
564         const Eo_Class *kls_itr;
565         const Eo_Class **mro_itr;
566         klass->mro = calloc(sizeof(*klass->mro), eina_list_count(mro) + 1);
567
568         mro_itr = klass->mro;
569
570         EINA_LIST_FREE(mro, kls_itr)
571           {
572              *(mro_itr++) = kls_itr;
573
574              DBG("Added '%s' to MRO", kls_itr->desc->name);
575           }
576         *(mro_itr) = NULL;
577      }
578
579    DBG("Finished creating MRO for class '%s'", klass->desc->name);
580
581    return EINA_TRUE;
582 }
583
584 static void
585 _eo_class_constructor(Eo_Class *klass)
586 {
587    if (klass->constructed)
588       return;
589
590    klass->constructed = EINA_TRUE;
591
592    if (klass->desc->class_constructor)
593       klass->desc->class_constructor(klass);
594 }
595
596 EAPI void
597 eo_class_funcs_set(Eo_Class *klass, const Eo_Op_Func_Description *func_descs)
598 {
599    EO_MAGIC_RETURN(klass, EO_CLASS_EINA_MAGIC);
600
601    const Eo_Op_Func_Description *itr;
602    itr = func_descs;
603    if (itr)
604      {
605         for ( ; itr->op != 0 ; itr++)
606           {
607              const Eo_Op_Description *op_desc = _eo_op_id_desc_get(itr->op);
608
609              if (EINA_LIKELY(!op_desc || (itr->constant == op_desc->constant)))
610                {
611                   dich_func_set(klass, itr->op, itr->func);
612                }
613              else
614                {
615                   ERR("Set function's constant property (%d) is different than the one in the op description (%d) for op '%s' in class '%s'.", itr->constant, op_desc->constant, op_desc->name, klass->desc->name);
616                }
617           }
618      }
619 }
620
621 static void
622 eo_class_free(Eo_Class *klass)
623 {
624    if (klass->constructed)
625      {
626         if (klass->desc->class_destructor)
627            klass->desc->class_destructor(klass);
628
629         dich_func_clean_all(klass);
630      }
631
632      {
633         Eina_Inlist *itrn;
634         Eo_Extension_Node *extn = NULL;
635         EINA_INLIST_FOREACH_SAFE(klass->extensions, itrn, extn)
636           {
637              free(extn);
638           }
639      }
640
641    if (klass->mro)
642       free(klass->mro);
643
644    if (klass->extn_data_off)
645       free(klass->extn_data_off);
646
647    free(klass);
648 }
649
650 /* DEVCHECK */
651 static Eina_Bool
652 _eo_class_check_op_descs(const Eo_Class *klass)
653 {
654    const Eo_Class_Description *desc = klass->desc;
655    const Eo_Op_Description *itr;
656    size_t i;
657
658    if (desc->ops.count > 0)
659      {
660         if (!desc->ops.base_op_id)
661           {
662              ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
663                    desc->name);
664              return EINA_FALSE;
665           }
666
667         if (!desc->ops.descs)
668           {
669              ERR("Class '%s' has a non-zero ops count, but there are no descs.",
670                    desc->name);
671              return EINA_FALSE;
672           }
673      }
674
675    itr = desc->ops.descs;
676    for (i = 0 ; i < desc->ops.count ; i++, itr++)
677      {
678         if (itr->sub_op != i)
679           {
680              if (itr->name)
681                {
682                   ERR("Wrong order in Ops description for class '%s'. Expected %d and got %d", desc->name, i, itr->sub_op);
683                }
684              else
685                {
686                   ERR("Found too few Ops description for class '%s'. Expected %d descriptions, but found %d.", desc->name, desc->ops.count, i);
687                }
688              return EINA_FALSE;
689           }
690      }
691
692    if (itr && itr->name)
693      {
694         ERR("Found extra Ops description for class '%s'. Expected %d descriptions, but found more.", desc->name, desc->ops.count);
695         return EINA_FALSE;
696      }
697
698    return EINA_TRUE;
699 }
700
701 EAPI const Eo_Class *
702 eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...)
703 {
704    Eo_Class *klass;
705    va_list p_list;
706
707    if (parent && !EINA_MAGIC_CHECK(parent, EO_CLASS_EINA_MAGIC))
708      {
709         EINA_MAGIC_FAIL(parent, EO_CLASS_EINA_MAGIC);
710         return NULL;
711      }
712
713    va_start(p_list, parent);
714
715    EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
716    EINA_SAFETY_ON_NULL_RETURN_VAL(desc->name, NULL);
717
718    /* Check restrictions on Interface types. */
719    if (desc->type == EO_CLASS_TYPE_INTERFACE)
720      {
721         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->constructor, NULL);
722         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->destructor, NULL);
723         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_constructor, NULL);
724         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_destructor, NULL);
725         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->data_size, NULL);
726      }
727
728    klass = calloc(1, sizeof(Eo_Class));
729    klass->parent = parent;
730
731    /* Handle class extensions */
732      {
733         Eo_Class *extn = NULL;
734
735         extn = va_arg(p_list, Eo_Class *);
736         while (extn)
737           {
738              switch (extn->desc->type)
739                {
740                 case EO_CLASS_TYPE_REGULAR:
741                 case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
742                    /* Use it like an interface. */
743                 case EO_CLASS_TYPE_INTERFACE:
744                    break;
745                 case EO_CLASS_TYPE_MIXIN:
746                      {
747                         Eo_Extension_Node *node = calloc(1, sizeof(*node));
748                         node->klass = extn;
749                         klass->extensions =
750                            eina_inlist_append(klass->extensions,
751                                  EINA_INLIST_GET(node));
752                      }
753                    break;
754                }
755
756              extn = va_arg(p_list, Eo_Class *);
757           }
758      }
759
760    klass->desc = desc;
761
762    /* Handle the inheritance */
763    if (klass->parent)
764      {
765         /* Verify the inheritance is allowed. */
766         switch (klass->desc->type)
767           {
768            case EO_CLASS_TYPE_REGULAR:
769            case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
770               if ((klass->parent->desc->type != EO_CLASS_TYPE_REGULAR) &&
771                     (klass->parent->desc->type != EO_CLASS_TYPE_REGULAR_NO_INSTANT))
772                 {
773                    ERR("Regular classes ('%s') aren't allowed to inherit from non-regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
774                    goto cleanup;
775                 }
776               break;
777            case EO_CLASS_TYPE_INTERFACE:
778            case EO_CLASS_TYPE_MIXIN:
779               if ((klass->parent->desc->type != EO_CLASS_TYPE_INTERFACE) &&
780                     (klass->parent->desc->type != EO_CLASS_TYPE_MIXIN))
781                 {
782                    ERR("Non-regular classes ('%s') aren't allowed to inherit from regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
783                    goto cleanup;
784                 }
785               break;
786           }
787
788
789         /* Update the current offset. */
790         /* FIXME: Make sure this alignment is enough. */
791         klass->data_offset = klass->parent->data_offset +
792            EO_ALIGN_SIZE(klass->parent->desc->data_size);
793      }
794
795    if (!_eo_class_check_op_descs(klass))
796      {
797         goto cleanup;
798      }
799
800    if (!_eo_class_mro_init(klass))
801      {
802         goto cleanup;
803      }
804
805    /* create MIXIN offset table. */
806      {
807         const Eo_Class **mro_itr = klass->mro;
808         Eo_Extension_Data_Offset *extn_data_itr;
809         size_t extn_num = 0;
810         size_t extn_data_off = klass->data_offset +
811            EO_ALIGN_SIZE(klass->desc->data_size);
812
813         /* FIXME: Make faster... */
814         while (*mro_itr)
815           {
816              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
817                    ((*mro_itr)->desc->data_size > 0))
818                {
819                   extn_num++;
820                }
821              mro_itr++;
822           }
823
824         klass->extn_data_off = calloc(extn_num + 1,
825               sizeof(*klass->extn_data_off));
826
827         extn_data_itr = klass->extn_data_off;
828         mro_itr = klass->mro;
829         while (*mro_itr)
830           {
831              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
832                    ((*mro_itr)->desc->data_size > 0))
833                {
834                   extn_data_itr->klass = *mro_itr;
835                   extn_data_itr->offset = extn_data_off;
836
837                   extn_data_off += EO_ALIGN_SIZE(extn_data_itr->klass->desc->data_size);
838                   extn_data_itr++;
839                }
840              mro_itr++;
841           }
842
843         klass->extn_data_size = extn_data_off;
844      }
845
846    eina_lock_take(&_eo_class_creation_lock);
847    klass->class_id = ++_eo_classes_last_id;
848      {
849         /* FIXME: Handle errors. */
850         Eo_Class **tmp;
851         tmp = realloc(_eo_classes, _eo_classes_last_id * sizeof(*_eo_classes));
852         _eo_classes = tmp;
853         _eo_classes[klass->class_id - 1] = klass;
854      }
855    eina_lock_release(&_eo_class_creation_lock);
856
857    EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC);
858
859    _eo_class_base_op_init(klass);
860
861    _eo_class_constructor(klass);
862
863    va_end(p_list);
864
865    return klass;
866
867 cleanup:
868    eo_class_free(klass);
869    return NULL;
870 }
871
872 EAPI Eo *
873 eo_add(const Eo_Class *klass, Eo *parent)
874 {
875    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
876
877    if (parent) EO_MAGIC_RETURN_VAL(parent, EO_EINA_MAGIC, NULL);
878
879    if (EINA_UNLIKELY(klass->desc->type != EO_CLASS_TYPE_REGULAR))
880      {
881         ERR("Class '%s' is not instantiate-able. Aborting.", klass->desc->name);
882         return NULL;
883      }
884
885    Eo *obj = calloc(1, EO_ALIGN_SIZE(sizeof(*obj)) +
886          (klass->data_offset + EO_ALIGN_SIZE(klass->desc->data_size)) +
887          klass->extn_data_size);
888    obj->klass = klass;
889    obj->parent = parent;
890
891    obj->refcount++;
892
893    Eo_Kls_Itr prev_state;
894
895    _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
896    eo_constructor_error_unset(obj);
897
898    EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
899    eo_ref(obj);
900    _eo_constructor(obj, klass);
901
902    if (EINA_UNLIKELY(eo_constructor_error_get(obj)))
903      {
904         ERR("Type '%s' - One of the object constructors have failed.", klass->desc->name);
905         goto fail;
906      }
907
908    if (EINA_UNLIKELY(!_eo_kls_itr_reached_end(obj)))
909      {
910         ERR("Type '%s' - Not all of the object constructors have been executed.", klass->desc->name);
911         goto fail;
912      }
913    _eo_kls_itr_end(obj, &prev_state);
914    eo_unref(obj);
915
916    return obj;
917
918 fail:
919    _eo_kls_itr_end(obj, &prev_state);
920    /* Unref twice, once for the ref above, and once for the basic object ref. */
921    eo_unref(obj);
922    eo_unref(obj);
923    return NULL;
924 }
925
926 typedef struct
927 {
928    EINA_INLIST;
929    const Eo *ref_obj;
930    const char *file;
931    int line;
932 } Eo_Xref_Node;
933
934 EAPI Eo *
935 eo_xref_internal(Eo *obj, const Eo *ref_obj, const char *file, int line)
936 {
937    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
938
939    eo_ref(obj);
940
941 #ifndef NDEBUG
942    Eo_Xref_Node *xref = calloc(1, sizeof(*xref));
943    xref->ref_obj = ref_obj;
944    xref->file = file;
945    xref->line = line;
946
947    /* FIXME: Make it sorted. */
948    obj->xrefs = eina_inlist_prepend(obj->xrefs, EINA_INLIST_GET(xref));
949 #else
950    (void) ref_obj;
951    (void) file;
952    (void) line;
953 #endif
954
955    return obj;
956 }
957
958 EAPI void
959 eo_xunref(Eo *obj, const Eo *ref_obj)
960 {
961    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
962 #ifndef NDEBUG
963    Eo_Xref_Node *xref = NULL;
964    EINA_INLIST_FOREACH(obj->xrefs, xref)
965      {
966         if (xref->ref_obj == ref_obj)
967            break;
968      }
969
970    if (xref)
971      {
972         obj->xrefs = eina_inlist_remove(obj->xrefs, EINA_INLIST_GET(xref));
973         free(xref);
974      }
975    else
976      {
977         ERR("ref_obj (%p) does not reference obj (%p). Aborting unref.", ref_obj, obj);
978         return;
979      }
980 #else
981    (void) ref_obj;
982 #endif
983    eo_unref(obj);
984 }
985
986 EAPI Eo *
987 eo_ref(Eo *obj)
988 {
989    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
990
991    obj->refcount++;
992    return obj;
993 }
994
995 static void
996 _eo_del_internal(Eo *obj)
997 {
998    if (obj->delete)
999       return;
1000    /* We need that for the event callbacks that may ref/unref. */
1001    obj->refcount++;
1002
1003    eo_event_callback_call(obj, EO_EV_DEL, NULL);
1004    obj->delete = EINA_TRUE;
1005
1006    obj->refcount--;
1007
1008    const Eo_Class *klass = eo_class_get(obj);
1009    Eo_Kls_Itr prev_state;
1010
1011    _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
1012    eo_constructor_error_unset(obj);
1013    _eo_destructor(obj, klass);
1014    if (eo_constructor_error_get(obj))
1015      {
1016         ERR("Type '%s' - One of the object destructors have failed.", klass->desc->name);
1017      }
1018
1019    if (!_eo_kls_itr_reached_end(obj))
1020      {
1021         ERR("Type '%s' - Not all of the object destructors have been executed.", klass->desc->name);
1022      }
1023    _eo_kls_itr_end(obj, &prev_state);
1024    /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
1025
1026    Eina_List *itr, *itr_n;
1027    Eo *emb_obj;
1028    EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
1029      {
1030         eo_composite_object_detach(obj, emb_obj);
1031      }
1032 }
1033
1034 EAPI void
1035 eo_unref(Eo *obj)
1036 {
1037    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1038
1039    if (--(obj->refcount) == 0)
1040      {
1041         _eo_del_internal(obj);
1042         /* We need that for the event callbacks that may ref/unref. */
1043         obj->refcount++;
1044
1045         eo_event_callback_call(obj, EO_EV_FREE, NULL);
1046
1047         obj->refcount--;
1048
1049 #ifndef NDEBUG
1050    /* If for some reason it's not empty, clear it. */
1051    while (obj->xrefs)
1052      {
1053         WRN("obj->xrefs is not empty, possibly a bug, please report. - An error will be reported for each xref in the stack.");
1054         Eina_Inlist *nitr = obj->xrefs->next;
1055         free(EINA_INLIST_CONTAINER_GET(obj->xrefs, Eo_Xref_Node));
1056         obj->xrefs = nitr;
1057      }
1058 #endif
1059
1060         _eo_callback_remove_all(obj);
1061
1062         free(obj);
1063      }
1064 }
1065
1066 EAPI int
1067 eo_ref_get(const Eo *obj)
1068 {
1069    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, 0);
1070
1071    return obj->refcount;
1072 }
1073
1074 EAPI void
1075 eo_del(Eo *obj)
1076 {
1077    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1078
1079    _eo_del_internal(obj);
1080    eo_unref(obj);
1081 }
1082
1083 EAPI Eo *
1084 eo_parent_get(Eo *obj)
1085 {
1086    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1087
1088    return obj->parent;
1089 }
1090
1091 EAPI void
1092 eo_constructor_error_set(Eo *obj)
1093 {
1094    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1095
1096    obj->construct_error = EINA_TRUE;
1097 }
1098
1099 static void
1100 eo_constructor_error_unset(Eo *obj)
1101 {
1102    obj->construct_error = EINA_FALSE;
1103 }
1104
1105 EAPI Eina_Bool
1106 eo_constructor_error_get(const Eo *obj)
1107 {
1108    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_TRUE);
1109
1110    return obj->construct_error;
1111 }
1112
1113 static inline void
1114 _eo_constructor_default(Eo *obj)
1115 {
1116    eo_constructor_super(obj);
1117 }
1118
1119 static inline void
1120 _eo_destructor_default(Eo *obj)
1121 {
1122    eo_destructor_super(obj);
1123 }
1124
1125 static void
1126 _eo_constructor(Eo *obj, const Eo_Class *klass)
1127 {
1128    if (!klass)
1129       return;
1130
1131    if (klass->desc->constructor)
1132       klass->desc->constructor(obj, _eo_data_get(obj, klass));
1133    else
1134       _eo_constructor_default(obj);
1135 }
1136
1137 static void
1138 _eo_destructor(Eo *obj, const Eo_Class *klass)
1139 {
1140    if (!klass)
1141       return;
1142
1143    if (klass->desc->destructor)
1144       klass->desc->destructor(obj, _eo_data_get(obj, klass));
1145    else
1146       _eo_destructor_default(obj);
1147 }
1148
1149 EAPI void
1150 eo_constructor_super(Eo *obj)
1151 {
1152    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1153
1154    _eo_constructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
1155 }
1156
1157 EAPI void
1158 eo_destructor_super(Eo *obj)
1159 {
1160    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1161
1162    _eo_destructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
1163 }
1164
1165 static inline void *
1166 _eo_data_get(const Eo *obj, const Eo_Class *klass)
1167 {
1168    if (EINA_LIKELY(klass->desc->data_size > 0))
1169      {
1170         if (EINA_UNLIKELY(klass->desc->type == EO_CLASS_TYPE_MIXIN))
1171           {
1172              Eo_Extension_Data_Offset *doff_itr =
1173                 eo_class_get(obj)->extn_data_off;
1174
1175              if (!doff_itr)
1176                 return NULL;
1177
1178              while (doff_itr->klass)
1179                {
1180                   if (doff_itr->klass == klass)
1181                      return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1182                            doff_itr->offset;
1183                   doff_itr++;
1184                }
1185           }
1186         else
1187           {
1188           return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1189              klass->data_offset;
1190           }
1191      }
1192
1193    return NULL;
1194 }
1195
1196 EAPI void *
1197 eo_data_get(const Eo *obj, const Eo_Class *klass)
1198 {
1199    void *ret;
1200    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1201
1202 #ifndef NDEBUG
1203    if (!_eo_class_mro_has(obj->klass, klass))
1204      {
1205         ERR("Tried getting data of class '%s' from object of class '%s', but the former is not a direct inheritance of the latter.", klass->desc->name, obj->klass->desc->name);
1206         return NULL;
1207      }
1208 #endif
1209
1210    ret = _eo_data_get(obj, klass);
1211
1212    if (!ret && (klass->desc->data_size == 0))
1213      {
1214         ERR("Tried getting data of class '%s', but it has none..", klass->desc->name);
1215      }
1216
1217    return ret;
1218 }
1219
1220 EAPI Eina_Bool
1221 eo_init(void)
1222 {
1223    const char *log_dom = "eo";
1224    if (_eo_init_count++ > 0)
1225       return EINA_TRUE;
1226
1227    eina_init();
1228
1229    _eo_classes = NULL;
1230    _eo_classes_last_id = 0;
1231    _eo_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_LIGHTBLUE);
1232    if (_eo_log_dom < 0)
1233      {
1234         EINA_LOG_ERR("Could not register log domain: %s", log_dom);
1235         return EINA_FALSE;
1236      }
1237
1238    if (!eina_lock_new(&_eo_class_creation_lock))
1239      {
1240         EINA_LOG_ERR("Could not init lock.");
1241         return EINA_FALSE;
1242      }
1243
1244    eina_magic_string_static_set(EO_EINA_MAGIC, EO_EINA_MAGIC_STR);
1245    eina_magic_string_static_set(EO_CLASS_EINA_MAGIC,
1246          EO_CLASS_EINA_MAGIC_STR);
1247
1248    return EINA_TRUE;
1249 }
1250
1251 EAPI Eina_Bool
1252 eo_shutdown(void)
1253 {
1254    size_t i;
1255    Eo_Class **cls_itr = _eo_classes;
1256
1257    if (--_eo_init_count > 0)
1258       return EINA_TRUE;
1259
1260    for (i = 0 ; i < _eo_classes_last_id ; i++, cls_itr++)
1261      {
1262         if (*cls_itr)
1263            eo_class_free(*cls_itr);
1264      }
1265
1266    if (_eo_classes)
1267       free(_eo_classes);
1268
1269    eina_lock_free(&_eo_class_creation_lock);
1270
1271    eina_log_domain_unregister(_eo_log_dom);
1272    _eo_log_dom = -1;
1273
1274    eina_shutdown();
1275    return EINA_TRUE;
1276 }
1277
1278 EAPI void
1279 eo_composite_object_attach(Eo *obj, Eo *emb_obj)
1280 {
1281    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1282    EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
1283
1284    eo_xref(emb_obj, obj);
1285    obj->composite_objects = eina_list_prepend(obj->composite_objects, emb_obj);
1286 }
1287
1288 EAPI void
1289 eo_composite_object_detach(Eo *obj, Eo *emb_obj)
1290 {
1291    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1292    EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
1293
1294    obj->composite_objects = eina_list_remove(obj->composite_objects, emb_obj);
1295    eo_xunref(emb_obj, obj);
1296 }
1297
1298 EAPI Eina_Bool
1299 eo_composite_is(Eo *emb_obj)
1300 {
1301    if (!EINA_MAGIC_CHECK(emb_obj, EO_EINA_MAGIC))
1302      {
1303         EINA_MAGIC_FAIL(emb_obj, EO_EINA_MAGIC);
1304         return EINA_FALSE;
1305      }
1306
1307    Eo *obj = eo_parent_get(emb_obj);
1308    Eina_List *itr;
1309    Eo *tmp;
1310
1311    if (!obj)
1312       return EINA_FALSE;
1313
1314    EINA_LIST_FOREACH(obj->composite_objects, itr, tmp)
1315      {
1316         if (tmp == emb_obj)
1317            return EINA_TRUE;
1318      }
1319
1320    return EINA_FALSE;
1321 }
1322
1323 /* Callbacks */
1324 struct _Eo_Callback_Description
1325 {
1326    EINA_INLIST;
1327    const Eo_Event_Description *event;
1328    Eo_Event_Cb func;
1329    void *func_data;
1330    Eo_Callback_Priority priority;
1331    Eina_Bool delete_me : 1;
1332 };
1333
1334 /* Actually remove, doesn't care about walking list, or delete_me */
1335 static void
1336 _eo_callback_remove(Eo *obj, Eo_Callback_Description *cb)
1337 {
1338    obj->callbacks = eina_inlist_remove(obj->callbacks,
1339          EINA_INLIST_GET(cb));
1340    free(cb);
1341 }
1342
1343 /* Actually remove, doesn't care about walking list, or delete_me */
1344 static void
1345 _eo_callback_remove_all(Eo *obj)
1346 {
1347    Eina_Inlist *initr;
1348    Eo_Callback_Description *cb = NULL;
1349    EINA_INLIST_FOREACH_SAFE(obj->callbacks, initr, cb)
1350      {
1351         _eo_callback_remove(obj, cb);
1352      }
1353 }
1354
1355 static void
1356 _eo_callbacks_clear(Eo *obj)
1357 {
1358    Eina_Inlist *itn;
1359    Eo_Callback_Description *cb = NULL;
1360
1361    /* Abort if we are currently walking the list. */
1362    if (obj->walking_list > 0)
1363       return;
1364
1365    EINA_INLIST_FOREACH_SAFE(obj->callbacks, itn, cb)
1366      {
1367         if (cb->delete_me)
1368           {
1369              _eo_callback_remove(obj, cb);
1370           }
1371      }
1372 }
1373
1374 static int
1375 _callback_priority_cmp(const void *_a, const void *_b)
1376 {
1377    const Eo_Callback_Description *a, *b;
1378    a = (const Eo_Callback_Description *) _a;
1379    b = (const Eo_Callback_Description *) _b;
1380    if (a->priority < b->priority)
1381       return -1;
1382    else
1383       return 1;
1384 }
1385
1386 EAPI Eina_Bool
1387 eo_event_callback_priority_add(Eo *obj,
1388       const Eo_Event_Description *desc,
1389       Eo_Callback_Priority priority,
1390       Eo_Event_Cb func,
1391       const void *data)
1392 {
1393    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
1394
1395    Eo_Callback_Description *cb = calloc(1, sizeof(*cb));
1396    cb->event = desc;
1397    cb->func = func;
1398    cb->func_data = (void *) data;
1399    cb->priority = priority;
1400    obj->callbacks = eina_inlist_sorted_insert(obj->callbacks,
1401          EINA_INLIST_GET(cb), _callback_priority_cmp);
1402
1403    eo_event_callback_call(obj, EO_EV_CALLBACK_ADD, desc);
1404
1405    return EINA_TRUE;
1406 }
1407
1408 EAPI void *
1409 eo_event_callback_del_lazy(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func)
1410 {
1411    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1412
1413    void *ret = NULL;
1414    Eo_Callback_Description *cb;
1415    EINA_INLIST_FOREACH(obj->callbacks, cb)
1416      {
1417         if ((cb->event == desc) && (cb->func == func))
1418           {
1419              void *data;
1420
1421              data = cb->func_data;
1422              cb->delete_me = EINA_TRUE;
1423              _eo_callbacks_clear(obj);
1424              ret = data;
1425              goto found;
1426           }
1427      }
1428
1429    return NULL;
1430
1431 found:
1432    eo_event_callback_call(obj, EO_EV_CALLBACK_DEL, desc);
1433    return ret;
1434 }
1435
1436 EAPI void *
1437 eo_event_callback_del(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func, const void *user_data)
1438 {
1439    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1440
1441    void *ret = NULL;
1442    Eo_Callback_Description *cb;
1443    EINA_INLIST_FOREACH(obj->callbacks, cb)
1444      {
1445         if ((cb->event == desc) && (cb->func == func) &&
1446               (cb->func_data == user_data))
1447           {
1448              void *data;
1449
1450              data = cb->func_data;
1451              cb->delete_me = EINA_TRUE;
1452              _eo_callbacks_clear(obj);
1453              ret = data;
1454              goto found;
1455           }
1456      }
1457
1458    return NULL;
1459
1460 found:
1461    eo_event_callback_call(obj, EO_EV_CALLBACK_DEL, desc);
1462    return ret;
1463 }
1464
1465 EAPI Eina_Bool
1466 eo_event_callback_call(Eo *obj, const Eo_Event_Description *desc,
1467       const void *event_info)
1468 {
1469    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
1470
1471    Eina_Bool ret = EINA_TRUE;
1472    Eo_Callback_Description *cb;
1473
1474    eo_ref(obj);
1475    obj->walking_list++;
1476
1477    EINA_INLIST_FOREACH(obj->callbacks, cb)
1478      {
1479         if (!cb->delete_me && (cb->event == desc))
1480           {
1481              /* Abort callback calling if the func says so. */
1482              if (!cb->func((void *) cb->func_data, obj, desc,
1483                       (void *) event_info))
1484                {
1485                   ret = EINA_FALSE;
1486                   break;
1487                }
1488           }
1489         if (obj->delete)
1490           break;
1491      }
1492    obj->walking_list--;
1493    _eo_callbacks_clear(obj);
1494    eo_unref(obj);
1495
1496    return ret;
1497 }
1498
1499 static Eina_Bool
1500 _eo_event_forwarder_callback(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
1501 {
1502    (void) obj;
1503    Eo *new_obj = (Eo *) data;
1504    return eo_event_callback_call(new_obj, desc, event_info);
1505 }
1506
1507 /* FIXME: Change default priority? Maybe call later? */
1508 EAPI Eina_Bool
1509 eo_event_callback_forwarder_add(Eo *obj, const Eo_Event_Description *desc, Eo *new_obj)
1510 {
1511    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
1512    EO_MAGIC_RETURN_VAL(new_obj, EO_EINA_MAGIC, EINA_FALSE);
1513
1514    return eo_event_callback_add(obj, desc, _eo_event_forwarder_callback, new_obj);
1515 }
1516
1517 EAPI Eina_Bool
1518 eo_event_callback_forwarder_del(Eo *obj, const Eo_Event_Description *desc, Eo *new_obj)
1519 {
1520    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
1521    EO_MAGIC_RETURN_VAL(new_obj, EO_EINA_MAGIC, EINA_FALSE);
1522
1523    eo_event_callback_del(obj, desc, _eo_event_forwarder_callback, new_obj);
1524    return EINA_TRUE;
1525 }
1526