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