Eo: Overhauled the mro-walking mechanism.
[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 int 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
23 typedef struct _Eo_Callback_Description Eo_Callback_Description;
24
25 typedef struct
26 {
27    Eo_Op op;
28    const Eo_Class **kls_itr;
29 } Eo_Kls_Itr;
30
31 #define EO_EINA_MAGIC 0xa186bc32 /* Nothing magical about this number. */
32 #define EO_EINA_MAGIC_STR "Eo"
33 #define EO_CLASS_EINA_MAGIC 0xa186bb32 /* Nothing magical about this number. */
34 #define EO_CLASS_EINA_MAGIC_STR "Eo Class"
35
36 #define EO_MAGIC_RETURN_VAL(d, magic, ret) \
37    do { \
38         if (!EINA_MAGIC_CHECK(d, magic)) \
39           { \
40              EINA_MAGIC_FAIL(d, magic); \
41              return ret; \
42           } \
43    } while (0)
44
45 #define EO_MAGIC_RETURN(d, magic) \
46    do { \
47         if (!EINA_MAGIC_CHECK(d, magic)) \
48           { \
49              EINA_MAGIC_FAIL(d, magic); \
50              return; \
51           } \
52    } while (0)
53
54 struct _Eo {
55      EINA_MAGIC
56      Eo *parent;
57      const Eo_Class *klass;
58      int refcount;
59 #ifndef NDEBUG
60      Eina_Inlist *xrefs;
61 #endif
62
63      Eina_List *composite_objects;
64
65      Eina_Inlist *callbacks;
66      int walking_list;
67
68      Eo_Kls_Itr mro_itr;
69
70      Eina_Bool delete:1;
71      Eina_Bool construct_error:1;
72 };
73
74 /* Start of Dich */
75 /* Dich search, split to 0xff 0xff 0xffff */
76
77 #define DICH_CHAIN1_MASK (0xff)
78 #define DICH_CHAIN2_MASK (0xff)
79 #define DICH_CHAIN_LAST_MASK (0xffff)
80 #define DICH_CHAIN1_SIZE (DICH_CHAIN1_MASK + 1)
81 #define DICH_CHAIN2_SIZE (DICH_CHAIN2_MASK + 1)
82 #define DICH_CHAIN_LAST_SIZE (DICH_CHAIN_LAST_MASK + 1)
83 #define DICH_CHAIN1(x) (((x) >> 24) & DICH_CHAIN1_MASK)
84 #define DICH_CHAIN2(x) (((x) >> 16) & DICH_CHAIN2_MASK)
85 #define DICH_CHAIN_LAST(x) ((x) & DICH_CHAIN_LAST_MASK)
86
87 #define OP_CLASS_OFFSET 16
88 #define OP_CLASS_OFFSET_GET(x) (((x) >> OP_CLASS_OFFSET) & 0xffff)
89 #define OP_CLASS_GET(op) ({ \
90       Eo_Class_Id tmp = OP_CLASS_OFFSET_GET(op); \
91       (Eo_Class *) ((tmp <= _eo_classes_last_id) && (tmp > 0)) ? \
92       (_eo_classes[tmp - 1]) : NULL; \
93       })
94 #define OP_SUB_ID_GET(op) ((op) & 0xffff)
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 typedef struct
112 {
113    op_type_funcs *funcs;
114 } Dich_Chain2;
115
116 struct _Dich_Chain1
117 {
118    Dich_Chain2 *chain;
119 };
120
121 typedef struct
122 {
123      EINA_INLIST;
124      const Eo_Class *klass;
125 } Eo_Extension_Node;
126
127 typedef struct
128 {
129      const Eo_Class *klass;
130      size_t offset;
131 } Eo_Extension_Data_Offset;
132
133 struct _Eo_Class
134 {
135    EINA_MAGIC
136    Eo_Class_Id class_id;
137    const Eo_Class *parent;
138    const Eo_Class_Description *desc;
139    Dich_Chain1 chain[DICH_CHAIN1_SIZE];
140    Eina_Inlist *extensions;
141
142    Eo_Extension_Data_Offset *extn_data_off;
143    size_t extn_data_size;
144
145    const Eo_Class **mro;
146
147    size_t data_offset; /* < Offset of the data within object data. */
148
149    Eina_Bool constructed : 1;
150 };
151
152 static inline eo_op_func_type
153 dich_func_get(const Eo_Class *klass, Eo_Op op)
154 {
155    const Dich_Chain1 *chain1 = &klass->chain[DICH_CHAIN1(op)];
156    if (!chain1) return NULL;
157    if (!chain1->chain) return NULL;
158    Dich_Chain2 *chain2 = &chain1->chain[DICH_CHAIN2(op)];
159    if (!chain2) return NULL;
160    if (!chain2->funcs) return NULL;
161
162    /* num_ops is calculated from the class. */
163    const Eo_Class *op_klass = OP_CLASS_GET(op);
164    if (!op_klass || (DICH_CHAIN_LAST(op) >= op_klass->desc->ops.count))
165       return NULL;
166
167    return chain2->funcs[DICH_CHAIN_LAST(op)].func;
168 }
169
170 static inline void
171 dich_func_set(Eo_Class *klass, Eo_Op op, eo_op_func_type func)
172 {
173    const Eo_Class *op_klass = OP_CLASS_GET(op);
174    size_t num_ops;
175
176    /* Verify op is valid. */
177    if (op_klass)
178      {
179         /* num_ops is calculated from the class. */
180         num_ops = op_klass->desc->ops.count;
181         if (DICH_CHAIN_LAST(op) >= num_ops)
182           {
183              ERR("OP %x is too big for the domain '%s', expected value < %x.",
184                    op, op_klass->desc->name, op_klass->desc->ops.count);
185              return;
186           }
187      }
188    else
189      {
190         ERR("OP %x is from an illegal class.", op);
191         return;
192      }
193
194    Dich_Chain1 *chain1 = &klass->chain[DICH_CHAIN1(op)];
195    if (!chain1->chain)
196      {
197         chain1->chain = calloc(DICH_CHAIN2_SIZE, sizeof(*(chain1->chain)));
198      }
199
200    Dich_Chain2 *chain2 = &chain1->chain[DICH_CHAIN2(op)];
201    if (!chain2->funcs)
202      {
203         chain2->funcs = calloc(num_ops, sizeof(*(chain2->funcs)));
204      }
205
206    chain2->funcs[DICH_CHAIN_LAST(op)].func = func;
207 }
208
209 static inline void
210 dich_func_clean_all(Eo_Class *klass)
211 {
212    int i;
213    Dich_Chain1 *chain1 = klass->chain;
214
215    for (i = 0 ; i < DICH_CHAIN1_SIZE ; i++, chain1++)
216      {
217         int j;
218         Dich_Chain2 *chain2 = chain1->chain;
219
220         if (!chain2)
221            continue;
222
223         for (j = 0 ; j < DICH_CHAIN2_SIZE ; j++, chain2++)
224           {
225              free(chain2->funcs);
226           }
227         free(chain1->chain);
228         chain1->chain = NULL;
229      }
230 }
231
232 /* END OF DICH */
233
234 static const Eo_Op_Description noop_desc =
235         EO_OP_DESCRIPTION(EO_NOOP, "", "No operation.");
236
237 static const Eo_Op_Description *
238 _eo_op_id_desc_get(Eo_Op op)
239 {
240    const Eo_Class *klass = OP_CLASS_GET(op);
241    Eo_Op sub_id = OP_SUB_ID_GET(op);
242
243    if (op == EO_NOOP)
244       return &noop_desc;
245
246    if (klass && (sub_id < klass->desc->ops.count))
247       return klass->desc->ops.descs + sub_id;
248
249    return NULL;
250 }
251
252 static const char *
253 _eo_op_id_name_get(Eo_Op op)
254 {
255    const Eo_Op_Description *desc = _eo_op_id_desc_get(op);
256    return (desc) ? desc->name : NULL;
257 }
258
259 static inline void
260 _eo_kls_itr_init(Eo *obj, Eo_Op op, Eo_Kls_Itr *prev_state)
261 {
262    prev_state->op = obj->mro_itr.op;
263    prev_state->kls_itr = obj->mro_itr.kls_itr;
264
265    /* If we are in a constructor/destructor or we changed an op - init. */
266    if ((op == EO_NOOP) || (obj->mro_itr.op != op))
267      {
268         obj->mro_itr.op = op;
269         obj->mro_itr.kls_itr = obj->klass->mro;
270      }
271 }
272
273 static inline void
274 _eo_kls_itr_end(Eo *obj, Eo_Kls_Itr *prev_state)
275 {
276    if (obj->mro_itr.op != prev_state->op)
277      {
278         obj->mro_itr.op = prev_state->op;
279         obj->mro_itr.kls_itr = prev_state->kls_itr;
280      }
281 }
282
283 static inline const Eo_Class *
284 _eo_kls_itr_get(Eo *obj)
285 {
286    return (obj->mro_itr.kls_itr) ? *(obj->mro_itr.kls_itr) : NULL;
287 }
288
289 static inline const Eo_Class *
290 _eo_kls_itr_next(Eo *obj, Eo_Op op)
291 {
292    if (obj->mro_itr.op != op)
293      {
294         Eo_Op node_op = obj->mro_itr.op;
295         ERR("Called with op %d ('%s') while expecting: %d ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
296               op, _eo_op_id_name_get(op),
297               node_op, _eo_op_id_name_get(node_op));
298         return NULL;
299      }
300
301    const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
302    if (*kls_itr)
303      {
304         kls_itr++;
305         obj->mro_itr.kls_itr = kls_itr;
306         return *kls_itr;
307      }
308    else
309      {
310         return NULL;
311      }
312 }
313
314 static inline Eina_Bool
315 _eo_kls_itr_reached_end(const Eo *obj)
316 {
317    const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
318    return !(*kls_itr && *(kls_itr + 1));
319 }
320
321 static Eina_Bool
322 _eo_op_internal(Eo *obj, Eina_Bool constant, Eo_Op op, va_list *p_list)
323 {
324    const Eo_Class *klass;
325    Eina_Bool ret = EINA_FALSE;
326
327    const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
328
329    if (op_desc &&
330          ((constant == EINA_TRUE) && (op_desc->constant == EINA_FALSE)))
331      {
332         ERR("Tried calling non-const or non-existant op '%s' (%d) from a const (query) function.", (op_desc) ? op_desc->name : NULL, op);
333         return EINA_FALSE;
334      }
335
336    Eo_Kls_Itr prev_state;
337    _eo_kls_itr_init(obj, op, &prev_state);
338    klass = _eo_kls_itr_get(obj);
339    while (klass)
340      {
341         eo_op_func_type func = dich_func_get(klass, op);
342
343         if (func)
344           {
345              func(obj, eo_data_get(obj, klass), p_list);
346              ret = EINA_TRUE;
347              goto end;
348           }
349
350         klass = _eo_kls_itr_next(obj, op);
351      }
352
353    /* Try composite objects */
354      {
355         Eina_List *itr;
356         Eo *emb_obj;
357         EINA_LIST_FOREACH(obj->composite_objects, itr, emb_obj)
358           {
359              if (_eo_op_internal(emb_obj, constant, op, p_list))
360                {
361                   ret = EINA_TRUE;
362                   goto end;
363                }
364           }
365      }
366
367 end:
368    _eo_kls_itr_end(obj, &prev_state);
369    return ret;
370 }
371
372 EAPI Eina_Bool
373 eo_do_internal(Eo *obj, Eina_Bool constant, ...)
374 {
375    Eina_Bool ret = EINA_TRUE;
376    Eo_Op op = EO_NOOP;
377    va_list p_list;
378
379    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
380
381    eo_ref(obj);
382
383    va_start(p_list, constant);
384
385    op = va_arg(p_list, Eo_Op);
386    while (op)
387      {
388         if (!_eo_op_internal(obj, constant, op, &p_list))
389           {
390              const Eo_Class *op_klass = OP_CLASS_GET(op);
391              const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
392              ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
393                    op, _eo_op_id_name_get(op), _dom_name,
394                    obj->klass->desc->name);
395              ret = EINA_FALSE;
396              break;
397           }
398         op = va_arg(p_list, Eo_Op);
399      }
400
401    va_end(p_list);
402
403    eo_unref(obj);
404    return ret;
405 }
406
407 EAPI Eina_Bool
408 eo_do_super_internal(Eo *obj, Eina_Bool constant, Eo_Op op, ...)
409 {
410    const Eo_Class *obj_klass;
411    Eina_Bool ret = EINA_TRUE;
412    va_list p_list;
413    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
414
415    /* Advance the kls itr. */
416    obj_klass = _eo_kls_itr_next(obj, op);
417
418    if (!obj_klass)
419      {
420         return EINA_FALSE;
421      }
422
423    va_start(p_list, op);
424    if (!_eo_op_internal(obj, constant, op, &p_list))
425      {
426         const Eo_Class *op_klass = OP_CLASS_GET(op);
427         const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
428         ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
429               op, _eo_op_id_name_get(op), _dom_name,
430               (obj_klass) ? obj_klass->desc->name : NULL);
431         ret = EINA_FALSE;
432      }
433    va_end(p_list);
434
435    return ret;
436 }
437
438 EAPI const Eo_Class *
439 eo_class_get(const Eo *obj)
440 {
441    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
442
443    return obj->klass;
444 }
445
446 EAPI const char *
447 eo_class_name_get(const Eo_Class *klass)
448 {
449    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
450
451    return klass->desc->name;
452 }
453
454 static void
455 _eo_class_base_op_init(Eo_Class *klass)
456 {
457    const Eo_Class_Description *desc = klass->desc;
458    if (!desc || !desc->ops.base_op_id)
459       return;
460
461    /* FIXME: Depends on values defined above! */
462    *(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
463 }
464
465 static Eina_Bool
466 _eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find)
467 {
468    const Eo_Class **itr;
469    for (itr = klass->mro ; *itr ; itr++)
470      {
471         if (*itr == find)
472           {
473              return EINA_TRUE;
474           }
475      }
476
477    return EINA_FALSE;
478 }
479
480 static Eina_List *
481 _eo_class_mro_add(Eina_List *mro, const Eo_Class *klass)
482 {
483    Eina_List *extn_pos = NULL;
484    Eina_Bool check_consistency = !mro;
485    if (!klass)
486       return mro;
487
488    mro = eina_list_append(mro, klass);
489
490    /* Recursively add extenions. */
491      {
492         Eo_Extension_Node *extn;
493         EINA_INLIST_FOREACH(klass->extensions, extn)
494           {
495              mro = _eo_class_mro_add(mro, extn->klass);
496              /* Not possible: if (!mro) return NULL; */
497
498              if (check_consistency)
499                {
500                   extn_pos = eina_list_append(extn_pos, eina_list_last(mro));
501                }
502           }
503      }
504
505    /* Check if we can create a consistent mro. We only do it for the class
506     * we are working on (i.e no parents). */
507    if (check_consistency)
508      {
509         Eo_Extension_Node *extn;
510
511         Eina_List *itr = extn_pos;
512         EINA_INLIST_FOREACH(klass->extensions, extn)
513           {
514              /* Get the first one after the extension. */
515              Eina_List *extn_list = eina_list_next(eina_list_data_get(itr));
516
517              /* If we found the extension again. */
518              if (eina_list_data_find_list(extn_list, extn->klass))
519                {
520                   eina_list_free(mro);
521                   ERR("Cannot create a consistent method resolution order for class '%s' because of '%s'.", klass->desc->name, extn->klass->desc->name);
522                   return NULL;
523                }
524
525              itr = eina_list_next(itr);
526           }
527      }
528
529
530    mro = _eo_class_mro_add(mro, klass->parent);
531
532    return mro;
533 }
534
535 static Eina_Bool
536 _eo_class_mro_init(Eo_Class *klass)
537 {
538    Eina_List *mro = NULL;
539
540    DBG("Started creating MRO for class '%s'", klass->desc->name);
541    mro = _eo_class_mro_add(mro, klass);
542
543    if (!mro)
544       return EINA_FALSE;
545
546    /* Remove duplicates and make them the right order. */
547      {
548         Eina_List *itr1, *itr2, *itr2n;
549
550         itr1 = eina_list_last(mro);
551         while (itr1)
552           {
553              itr2 = eina_list_prev(itr1);
554
555              while (itr2)
556                {
557                   itr2n = eina_list_prev(itr2);
558
559                   if (eina_list_data_get(itr1) == eina_list_data_get(itr2))
560                     {
561                        mro = eina_list_remove_list(mro, itr2);
562                     }
563
564                   itr2 = itr2n;
565                }
566
567              itr1 = eina_list_prev(itr1);
568           }
569      }
570
571    /* Copy the mro and free the list. */
572      {
573         const Eo_Class *kls_itr;
574         const Eo_Class **mro_itr;
575         klass->mro = calloc(sizeof(*klass->mro), eina_list_count(mro) + 1);
576
577         mro_itr = klass->mro;
578
579         EINA_LIST_FREE(mro, kls_itr)
580           {
581              *(mro_itr++) = kls_itr;
582
583              DBG("Added '%s' to MRO", kls_itr->desc->name);
584           }
585         *(mro_itr) = NULL;
586      }
587
588    DBG("Finished creating MRO for class '%s'", klass->desc->name);
589
590    return EINA_TRUE;
591 }
592
593 static void
594 _eo_class_constructor(Eo_Class *klass)
595 {
596    if (klass->constructed)
597       return;
598
599    klass->constructed = EINA_TRUE;
600
601    if (klass->desc->class_constructor)
602       klass->desc->class_constructor(klass);
603 }
604
605 EAPI void
606 eo_class_funcs_set(Eo_Class *klass, const Eo_Op_Func_Description *func_descs)
607 {
608    EO_MAGIC_RETURN(klass, EO_CLASS_EINA_MAGIC);
609
610    const Eo_Op_Func_Description *itr;
611    itr = func_descs;
612    if (itr)
613      {
614         for ( ; itr->op != 0 ; itr++)
615           {
616              const Eo_Op_Description *op_desc = _eo_op_id_desc_get(itr->op);
617
618              if (EINA_LIKELY(!op_desc || (itr->constant == op_desc->constant)))
619                {
620                   dich_func_set(klass, itr->op, itr->func);
621                }
622              else
623                {
624                   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);
625                }
626           }
627      }
628 }
629
630 static void
631 eo_class_free(Eo_Class *klass)
632 {
633    if (klass->constructed)
634      {
635         if (klass->desc->class_destructor)
636            klass->desc->class_destructor(klass);
637
638         dich_func_clean_all(klass);
639      }
640
641      {
642         Eina_Inlist *itrn;
643         Eo_Extension_Node *extn = NULL;
644         EINA_INLIST_FOREACH_SAFE(klass->extensions, itrn, extn)
645           {
646              free(extn);
647           }
648      }
649
650    if (klass->mro)
651       free(klass->mro);
652
653    if (klass->extn_data_off)
654       free(klass->extn_data_off);
655
656    free(klass);
657 }
658
659 /* DEVCHECK */
660 static Eina_Bool
661 _eo_class_check_op_descs(const Eo_Class *klass)
662 {
663    const Eo_Class_Description *desc = klass->desc;
664    const Eo_Op_Description *itr;
665    size_t i;
666
667    if (desc->ops.count > 0)
668      {
669         if (!desc->ops.base_op_id)
670           {
671              ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
672                    desc->name);
673              return EINA_FALSE;
674           }
675
676         if (!desc->ops.descs)
677           {
678              ERR("Class '%s' has a non-zero ops count, but there are no descs.",
679                    desc->name);
680              return EINA_FALSE;
681           }
682      }
683
684    itr = desc->ops.descs;
685    for (i = 0 ; i < desc->ops.count ; i++, itr++)
686      {
687         if (itr->sub_op != i)
688           {
689              if (itr->name)
690                {
691                   ERR("Wrong order in Ops description for class '%s'. Expected %d and got %d", desc->name, i, itr->sub_op);
692                }
693              else
694                {
695                   ERR("Found too few Ops description for class '%s'. Expected %d descriptions, but found %d.", desc->name, desc->ops.count, i);
696                }
697              return EINA_FALSE;
698           }
699      }
700
701    if (itr && itr->name)
702      {
703         ERR("Found extra Ops description for class '%s'. Expected %d descriptions, but found more.", desc->name, desc->ops.count);
704         return EINA_FALSE;
705      }
706
707    return EINA_TRUE;
708 }
709
710 EAPI const Eo_Class *
711 eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...)
712 {
713    Eo_Class *klass;
714    va_list p_list;
715
716    if (parent && !EINA_MAGIC_CHECK(parent, EO_CLASS_EINA_MAGIC))
717      {
718         EINA_MAGIC_FAIL(parent, EO_CLASS_EINA_MAGIC);
719         return NULL;
720      }
721
722    va_start(p_list, parent);
723
724    EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
725    EINA_SAFETY_ON_NULL_RETURN_VAL(desc->name, NULL);
726
727    /* Check restrictions on Interface types. */
728    if (desc->type == EO_CLASS_TYPE_INTERFACE)
729      {
730         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->constructor, NULL);
731         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->destructor, NULL);
732         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_constructor, NULL);
733         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_destructor, NULL);
734         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->data_size, NULL);
735      }
736
737    klass = calloc(1, sizeof(Eo_Class));
738    klass->parent = parent;
739
740    /* Handle class extensions */
741      {
742         Eo_Class *extn = NULL;
743
744         extn = va_arg(p_list, Eo_Class *);
745         while (extn)
746           {
747              switch (extn->desc->type)
748                {
749                 case EO_CLASS_TYPE_REGULAR:
750                 case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
751                    /* Use it like an interface. */
752                 case EO_CLASS_TYPE_INTERFACE:
753                    break;
754                 case EO_CLASS_TYPE_MIXIN:
755                      {
756                         Eo_Extension_Node *node = calloc(1, sizeof(*node));
757                         node->klass = extn;
758                         klass->extensions =
759                            eina_inlist_append(klass->extensions,
760                                  EINA_INLIST_GET(node));
761                      }
762                    break;
763                }
764
765              extn = va_arg(p_list, Eo_Class *);
766           }
767      }
768
769    klass->desc = desc;
770
771    /* Handle the inheritance */
772    if (klass->parent)
773      {
774         /* Verify the inheritance is allowed. */
775         switch (klass->desc->type)
776           {
777            case EO_CLASS_TYPE_REGULAR:
778            case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
779               if ((klass->parent->desc->type != EO_CLASS_TYPE_REGULAR) &&
780                     (klass->parent->desc->type != EO_CLASS_TYPE_REGULAR_NO_INSTANT))
781                 {
782                    ERR("Regular classes ('%s') aren't allowed to inherit from non-regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
783                    goto cleanup;
784                 }
785               break;
786            case EO_CLASS_TYPE_INTERFACE:
787            case EO_CLASS_TYPE_MIXIN:
788               if ((klass->parent->desc->type != EO_CLASS_TYPE_INTERFACE) &&
789                     (klass->parent->desc->type != EO_CLASS_TYPE_MIXIN))
790                 {
791                    ERR("Non-regular classes ('%s') aren't allowed to inherit from regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
792                    goto cleanup;
793                 }
794               break;
795           }
796
797
798         /* Update the current offset. */
799         /* FIXME: Make sure this alignment is enough. */
800         klass->data_offset = klass->parent->data_offset +
801            EO_ALIGN_SIZE(klass->parent->desc->data_size);
802      }
803
804    if (!_eo_class_check_op_descs(klass))
805      {
806         goto cleanup;
807      }
808
809    if (!_eo_class_mro_init(klass))
810      {
811         goto cleanup;
812      }
813
814    /* create MIXIN offset table. */
815      {
816         const Eo_Class **mro_itr = klass->mro;
817         Eo_Extension_Data_Offset *extn_data_itr;
818         size_t extn_num = 0;
819         size_t extn_data_off = klass->data_offset +
820            EO_ALIGN_SIZE(klass->desc->data_size);
821
822         /* FIXME: Make faster... */
823         while (*mro_itr)
824           {
825              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
826                    ((*mro_itr)->desc->data_size > 0))
827                {
828                   extn_num++;
829                }
830              mro_itr++;
831           }
832
833         klass->extn_data_off = calloc(extn_num + 1,
834               sizeof(*klass->extn_data_off));
835
836         extn_data_itr = klass->extn_data_off;
837         mro_itr = klass->mro;
838         while (*mro_itr)
839           {
840              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
841                    ((*mro_itr)->desc->data_size > 0))
842                {
843                   extn_data_itr->klass = *mro_itr;
844                   extn_data_itr->offset = extn_data_off;
845
846                   extn_data_off += EO_ALIGN_SIZE(extn_data_itr->klass->desc->data_size);
847                   extn_data_itr++;
848                }
849              mro_itr++;
850           }
851
852         klass->extn_data_size = extn_data_off;
853      }
854
855    eina_lock_take(&_eo_class_creation_lock);
856    klass->class_id = ++_eo_classes_last_id;
857      {
858         /* FIXME: Handle errors. */
859         Eo_Class **tmp;
860         tmp = realloc(_eo_classes, _eo_classes_last_id * sizeof(*_eo_classes));
861         _eo_classes = tmp;
862         _eo_classes[klass->class_id - 1] = klass;
863      }
864    eina_lock_release(&_eo_class_creation_lock);
865
866    EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC);
867
868    _eo_class_base_op_init(klass);
869
870    _eo_class_constructor(klass);
871
872    va_end(p_list);
873
874    return klass;
875
876 cleanup:
877    eo_class_free(klass);
878    return NULL;
879 }
880
881 EAPI Eo *
882 eo_add(const Eo_Class *klass, Eo *parent)
883 {
884    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
885
886    if (parent) EO_MAGIC_RETURN_VAL(parent, EO_EINA_MAGIC, NULL);
887
888    if (EINA_UNLIKELY(klass->desc->type != EO_CLASS_TYPE_REGULAR))
889      {
890         ERR("Class '%s' is not instantiate-able. Aborting.", klass->desc->name);
891         return NULL;
892      }
893
894    Eo *obj = calloc(1, EO_ALIGN_SIZE(sizeof(*obj)) +
895          (klass->data_offset + EO_ALIGN_SIZE(klass->desc->data_size)) +
896          klass->extn_data_size);
897    obj->klass = klass;
898    obj->parent = parent;
899
900    obj->refcount++;
901
902    Eo_Kls_Itr prev_state;
903
904    _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
905    eo_constructor_error_unset(obj);
906
907    EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
908    eo_ref(obj);
909    _eo_constructor(obj, klass);
910
911    if (EINA_UNLIKELY(eo_constructor_error_get(obj)))
912      {
913         ERR("Type '%s' - One of the object constructors have failed.", klass->desc->name);
914         goto fail;
915      }
916
917    if (EINA_UNLIKELY(!_eo_kls_itr_reached_end(obj)))
918      {
919         ERR("Type '%s' - Not all of the object constructors have been executed.", klass->desc->name);
920         goto fail;
921      }
922    _eo_kls_itr_end(obj, &prev_state);
923    eo_unref(obj);
924
925    return obj;
926
927 fail:
928    _eo_kls_itr_end(obj, &prev_state);
929    /* Unref twice, once for the ref above, and once for the basic object ref. */
930    eo_unref(obj);
931    eo_unref(obj);
932    return NULL;
933 }
934
935 typedef struct
936 {
937    EINA_INLIST;
938    const Eo *ref_obj;
939    const char *file;
940    int line;
941 } Eo_Xref_Node;
942
943 EAPI Eo *
944 eo_xref_internal(Eo *obj, const Eo *ref_obj, const char *file, int line)
945 {
946    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
947
948    eo_ref(obj);
949
950 #ifndef NDEBUG
951    Eo_Xref_Node *xref = calloc(1, sizeof(*xref));
952    xref->ref_obj = ref_obj;
953    xref->file = file;
954    xref->line = line;
955
956    /* FIXME: Make it sorted. */
957    obj->xrefs = eina_inlist_prepend(obj->xrefs, EINA_INLIST_GET(xref));
958 #else
959    (void) ref_obj;
960    (void) file;
961    (void) line;
962 #endif
963
964    return obj;
965 }
966
967 EAPI void
968 eo_xunref(Eo *obj, const Eo *ref_obj)
969 {
970    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
971 #ifndef NDEBUG
972    Eo_Xref_Node *xref = NULL;
973    EINA_INLIST_FOREACH(obj->xrefs, xref)
974      {
975         if (xref->ref_obj == ref_obj)
976            break;
977      }
978
979    if (xref)
980      {
981         obj->xrefs = eina_inlist_remove(obj->xrefs, EINA_INLIST_GET(xref));
982         free(xref);
983      }
984    else
985      {
986         ERR("ref_obj (%p) does not reference obj (%p). Aborting unref.", ref_obj, obj);
987         return;
988      }
989 #else
990    (void) ref_obj;
991 #endif
992    eo_unref(obj);
993 }
994
995 EAPI Eo *
996 eo_ref(Eo *obj)
997 {
998    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
999
1000    obj->refcount++;
1001    return obj;
1002 }
1003
1004 static void
1005 _eo_del_internal(Eo *obj)
1006 {
1007    if (obj->delete)
1008       return;
1009    /* We need that for the event callbacks that may ref/unref. */
1010    obj->refcount++;
1011
1012    eo_event_callback_call(obj, EO_EV_DEL, NULL);
1013    obj->delete = EINA_TRUE;
1014
1015    obj->refcount--;
1016
1017    const Eo_Class *klass = eo_class_get(obj);
1018    Eo_Kls_Itr prev_state;
1019
1020    _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
1021    eo_constructor_error_unset(obj);
1022    _eo_destructor(obj, klass);
1023    if (eo_constructor_error_get(obj))
1024      {
1025         ERR("Type '%s' - One of the object destructors have failed.", klass->desc->name);
1026      }
1027
1028    if (!_eo_kls_itr_reached_end(obj))
1029      {
1030         ERR("Type '%s' - Not all of the object destructors have been executed.", klass->desc->name);
1031      }
1032    _eo_kls_itr_end(obj, &prev_state);
1033    /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
1034
1035    Eina_List *itr, *itr_n;
1036    Eo *emb_obj;
1037    EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
1038      {
1039         eo_composite_object_detach(obj, emb_obj);
1040      }
1041 }
1042
1043 EAPI void
1044 eo_unref(Eo *obj)
1045 {
1046    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1047
1048    if (--(obj->refcount) == 0)
1049      {
1050         _eo_del_internal(obj);
1051         /* We need that for the event callbacks that may ref/unref. */
1052         obj->refcount++;
1053
1054         eo_event_callback_call(obj, EO_EV_FREE, NULL);
1055
1056         obj->refcount--;
1057
1058 #ifndef NDEBUG
1059    /* If for some reason it's not empty, clear it. */
1060    while (obj->xrefs)
1061      {
1062         WRN("obj->xrefs is not empty, possibly a bug, please report. - An error will be reported for each xref in the stack.");
1063         Eina_Inlist *nitr = obj->xrefs->next;
1064         free(EINA_INLIST_CONTAINER_GET(obj->xrefs, Eo_Xref_Node));
1065         obj->xrefs = nitr;
1066      }
1067 #endif
1068
1069         _eo_callback_remove_all(obj);
1070
1071         free(obj);
1072      }
1073 }
1074
1075 EAPI int
1076 eo_ref_get(const Eo *obj)
1077 {
1078    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, 0);
1079
1080    return obj->refcount;
1081 }
1082
1083 EAPI void
1084 eo_del(Eo *obj)
1085 {
1086    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1087
1088    _eo_del_internal(obj);
1089    eo_unref(obj);
1090 }
1091
1092 EAPI Eo *
1093 eo_parent_get(Eo *obj)
1094 {
1095    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1096
1097    return obj->parent;
1098 }
1099
1100 EAPI void
1101 eo_constructor_error_set(Eo *obj)
1102 {
1103    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1104
1105    obj->construct_error = EINA_TRUE;
1106 }
1107
1108 static void
1109 eo_constructor_error_unset(Eo *obj)
1110 {
1111    obj->construct_error = EINA_FALSE;
1112 }
1113
1114 EAPI Eina_Bool
1115 eo_constructor_error_get(const Eo *obj)
1116 {
1117    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_TRUE);
1118
1119    return obj->construct_error;
1120 }
1121
1122 static inline void
1123 _eo_constructor_default(Eo *obj)
1124 {
1125    eo_constructor_super(obj);
1126 }
1127
1128 static inline void
1129 _eo_destructor_default(Eo *obj)
1130 {
1131    eo_destructor_super(obj);
1132 }
1133
1134 static void
1135 _eo_constructor(Eo *obj, const Eo_Class *klass)
1136 {
1137    if (!klass)
1138       return;
1139
1140    if (klass->desc->constructor)
1141       klass->desc->constructor(obj, eo_data_get(obj, klass));
1142    else
1143       _eo_constructor_default(obj);
1144 }
1145
1146 static void
1147 _eo_destructor(Eo *obj, const Eo_Class *klass)
1148 {
1149    if (!klass)
1150       return;
1151
1152    if (klass->desc->destructor)
1153       klass->desc->destructor(obj, eo_data_get(obj, klass));
1154    else
1155       _eo_destructor_default(obj);
1156 }
1157
1158 EAPI void
1159 eo_constructor_super(Eo *obj)
1160 {
1161    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1162
1163    _eo_constructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
1164 }
1165
1166 EAPI void
1167 eo_destructor_super(Eo *obj)
1168 {
1169    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1170
1171    _eo_destructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
1172 }
1173
1174 EAPI void *
1175 eo_data_get(const Eo *obj, const Eo_Class *klass)
1176 {
1177    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1178
1179 #ifndef NDEBUG
1180    if (!_eo_class_mro_has(obj->klass, klass))
1181      {
1182         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);
1183         return NULL;
1184      }
1185 #endif
1186    if (EINA_LIKELY(klass->desc->data_size > 0))
1187      {
1188         if (EINA_UNLIKELY(klass->desc->type == EO_CLASS_TYPE_MIXIN))
1189           {
1190              Eo_Extension_Data_Offset *doff_itr =
1191                 eo_class_get(obj)->extn_data_off;
1192
1193              if (!doff_itr)
1194                 return NULL;
1195
1196              while (doff_itr->klass)
1197                {
1198                   if (doff_itr->klass == klass)
1199                      return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1200                            doff_itr->offset;
1201                   doff_itr++;
1202                }
1203           }
1204         else
1205           {
1206           return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1207              klass->data_offset;
1208           }
1209      }
1210    else
1211      {
1212         /* FIXME: Enable this to only work when called from the outside.
1213         ERR("Tried getting data of class '%s', but it has none..", klass->desc->name);
1214         */
1215      }
1216
1217    return NULL;
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    int 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