7 typedef int Eobj_Class_Id;
9 static int _eobj_log_dom = -1;
11 static Eobj_Class **_eobj_classes;
12 static Eobj_Class_Id _eobj_classes_last_id;
13 static Eina_Bool _eobj_init_count = 0;
15 static void _eobj_callback_remove_all(Eobj *obj);
16 static void _eobj_generic_data_del_all(Eobj *obj);
17 static void eobj_class_constructor(Eobj *obj, const Eobj_Class *klass);
18 static void eobj_class_destructor(Eobj *obj, const Eobj_Class *klass);
19 static void eobj_constructor_error_unset(Eobj *obj);
24 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_eobj_log_dom, __VA_ARGS__)
29 #define ERR(...) EINA_LOG_DOM_ERR(_eobj_log_dom, __VA_ARGS__)
34 #define WRN(...) EINA_LOG_DOM_WARN(_eobj_log_dom, __VA_ARGS__)
39 #define INF(...) EINA_LOG_DOM_INFO(_eobj_log_dom, __VA_ARGS__)
44 #define DBG(...) EINA_LOG_DOM_DBG(_eobj_log_dom, __VA_ARGS__)
46 typedef struct _Eobj_Callback_Description Eobj_Callback_Description;
51 const Eobj_Class *klass;
54 Eina_List *composite_objects;
56 Eina_Inlist *callbacks;
59 Eina_Inlist *generic_data;
64 Eina_Bool construct_error:1;
68 /* Dich search, split to 0xff 0xff 0xffff */
70 #define DICH_CHAIN1_MASK (0xff)
71 #define DICH_CHAIN2_MASK (0xff)
72 #define DICH_CHAIN_LAST_MASK (0xffff)
73 #define DICH_CHAIN1_SIZE (DICH_CHAIN1_MASK + 1)
74 #define DICH_CHAIN2_SIZE (DICH_CHAIN2_MASK + 1)
75 #define DICH_CHAIN_LAST_SIZE (DICH_CHAIN_LAST_MASK + 1)
76 #define DICH_CHAIN1(x) (((x) >> 24) & DICH_CHAIN1_MASK)
77 #define DICH_CHAIN2(x) (((x) >> 16) & DICH_CHAIN2_MASK)
78 #define DICH_CHAIN_LAST(x) ((x) & DICH_CHAIN_LAST_MASK)
80 #define OP_CLASS_OFFSET 16
81 #define OP_CLASS_OFFSET_GET(x) (((x) >> OP_CLASS_OFFSET) & 0xffff)
82 #define OP_CLASS_GET(op) ({ \
83 Eobj_Class_Id tmp = OP_CLASS_OFFSET_GET(op); \
84 (Eobj_Class *) ((tmp <= _eobj_classes_last_id) && (tmp > 0)) ? \
85 (_eobj_classes[tmp - 1]) : NULL; \
87 #define OP_SUB_ID_GET(op) ((op) & 0xffff)
89 /* Structure of Eobj_Op is:
94 typedef struct _Dich_Chain1 Dich_Chain1;
98 eobj_op_func_type func;
103 op_type_funcs *funcs;
114 const Eobj_Class *klass;
115 } Eobj_Extension_Node;
119 Eobj_Class_Id class_id;
120 const Eobj_Class *parent;
121 const Eobj_Class_Description *desc;
122 Dich_Chain1 chain[DICH_CHAIN1_SIZE];
123 Eina_Inlist *extensions;
125 const Eobj_Class **mro;
127 size_t data_offset; /* < Offset of the data within object data. */
129 Eina_Bool constructed : 1;
132 static inline eobj_op_func_type
133 dich_func_get(const Eobj_Class *klass, Eobj_Op op)
135 const Dich_Chain1 *chain1 = &klass->chain[DICH_CHAIN1(op)];
136 if (!chain1) return NULL;
137 if (!chain1->chain) return NULL;
138 Dich_Chain2 *chain2 = &chain1->chain[DICH_CHAIN2(op)];
139 if (!chain2) return NULL;
140 if (!chain2->funcs) return NULL;
142 /* num_ops is calculated from the class. */
143 const Eobj_Class *op_klass = OP_CLASS_GET(op);
144 if (!op_klass || (DICH_CHAIN_LAST(op) >= op_klass->desc->ops.count))
147 return chain2->funcs[DICH_CHAIN_LAST(op)].func;
151 dich_func_set(Eobj_Class *klass, Eobj_Op op, eobj_op_func_type func)
153 const Eobj_Class *op_klass = OP_CLASS_GET(op);
156 /* Verify op is valid. */
159 /* num_ops is calculated from the class. */
160 num_ops = op_klass->desc->ops.count;
161 if (DICH_CHAIN_LAST(op) >= num_ops)
163 ERR("OP %x is too big for the domain '%s', expected value < %x.",
164 op, op_klass->desc->name, op_klass->desc->ops.count);
169 ERR("OP %x is from an illegal class.", op);
173 Dich_Chain1 *chain1 = &klass->chain[DICH_CHAIN1(op)];
176 klass->chain[DICH_CHAIN1(op)].chain =
178 calloc(DICH_CHAIN2_SIZE, sizeof(*(chain1->chain)));
181 Dich_Chain2 *chain2 = &chain1->chain[DICH_CHAIN2(op)];
184 chain2->funcs = chain1->chain[DICH_CHAIN2(op)].funcs =
185 calloc(num_ops, sizeof(*(chain2->funcs)));
188 chain2->funcs[DICH_CHAIN_LAST(op)].func = func;
192 dich_func_clean_all(Eobj_Class *klass)
195 Dich_Chain1 *chain1 = klass->chain;
197 for (i = 0 ; i < DICH_CHAIN1_SIZE ; i++, chain1++)
200 Dich_Chain2 *chain2 = chain1->chain;
205 for (j = 0 ; j < DICH_CHAIN2_SIZE ; j++, chain2++)
210 chain1->chain = NULL;
220 const Eobj_Class **kls_itr;
223 static inline Eina_Bool
224 _eobj_kls_itr_init(Eobj *obj, Eobj_Op op)
228 Eobj_Kls_Itr_Node *node =
229 EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node);
238 Eobj_Kls_Itr_Node *node = calloc(1, sizeof(*node));
240 node->kls_itr = obj->klass->mro;
241 obj->kls_itr = eina_inlist_prepend(obj->kls_itr,
242 EINA_INLIST_GET(node));
249 _eobj_kls_itr_end(Eobj *obj, Eobj_Op op)
251 Eobj_Kls_Itr_Node *node =
252 EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node);
257 obj->kls_itr = eina_inlist_remove(obj->kls_itr, obj->kls_itr);
261 static inline const Eobj_Class *
262 _eobj_kls_itr_get(Eobj *obj)
264 Eobj_Kls_Itr_Node *node =
265 EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node);
267 return (node) ? *(node->kls_itr) : NULL;
270 static inline const Eobj_Class *
271 _eobj_kls_itr_next(Eobj *obj)
273 Eobj_Kls_Itr_Node *node =
274 EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node);
275 const Eobj_Class **kls_itr = node->kls_itr;
279 node->kls_itr = kls_itr;
288 static inline Eina_Bool
289 _eobj_kls_itr_reached_end(const Eobj *obj)
291 Eobj_Kls_Itr_Node *node =
292 EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node);
293 const Eobj_Class **kls_itr = node->kls_itr;
294 return !(*kls_itr && *(kls_itr + 1));
297 static const Eobj_Op_Description *
298 _eobj_op_id_desc_get(Eobj_Op op)
300 const Eobj_Class *klass = OP_CLASS_GET(op);
301 Eobj_Op sub_id = OP_SUB_ID_GET(op);
303 if (klass && (sub_id < klass->desc->ops.count))
304 return klass->desc->ops.descs + sub_id;
310 _eobj_op_internal(Eobj *obj, Eobj_Op op, va_list *p_list)
312 const Eobj_Class *klass;
313 Eina_Bool ret = EINA_FALSE;
316 _itr_init = _eobj_kls_itr_init(obj, op);
317 klass = _eobj_kls_itr_get(obj);
320 eobj_op_func_type func = dich_func_get(klass, op);
324 func(obj, eobj_data_get(obj, klass), p_list);
329 klass = _eobj_kls_itr_next(obj);
332 /* Try composite objects */
336 EINA_LIST_FOREACH(obj->composite_objects, itr, emb_obj)
338 if (_eobj_op_internal(emb_obj, op, p_list))
348 if (_itr_init) _eobj_kls_itr_end(obj, op);
352 static inline Eina_Bool
353 _eobj_ops_internal(Eobj *obj, va_list *p_list)
355 Eina_Bool ret = EINA_TRUE;
358 op = va_arg(*p_list, Eobj_Op);
361 if (!_eobj_op_internal(obj, op, p_list))
363 const Eobj_Op_Description *desc = _eobj_op_id_desc_get(op);
364 const char *_id_name = (desc) ? desc->name : NULL;
365 const Eobj_Class *op_klass = OP_CLASS_GET(op);
366 const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
367 ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
368 op, _id_name, _dom_name,
369 obj->klass->desc->name);
373 op = va_arg(*p_list, Eobj_Op);
380 eobj_do_internal(Eobj *obj, ...)
385 va_start(p_list, obj);
386 ret = _eobj_ops_internal(obj, &p_list);
393 eobj_do_super(Eobj *obj, Eobj_Op op, ...)
395 const Eobj_Class *obj_klass;
396 Eina_Bool ret = EINA_TRUE;
399 va_start(p_list, op);
401 /* Advance the kls itr. */
402 obj_klass = _eobj_kls_itr_next(obj);
403 if (!_eobj_op_internal(obj, op, &p_list))
405 const Eobj_Op_Description *desc = _eobj_op_id_desc_get(op);
406 const char *_id_name = (desc) ? desc->name : NULL;
407 const Eobj_Class *op_klass = OP_CLASS_GET(op);
408 const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
409 ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
410 op, _id_name, _dom_name,
411 (obj_klass) ? obj_klass->desc->name : NULL);
419 EAPI const Eobj_Class *
420 eobj_class_get(const Eobj *obj)
426 eobj_class_name_get(const Eobj_Class *klass)
428 return klass->desc->name;
432 _eobj_class_base_op_init(Eobj_Class *klass)
434 const Eobj_Class_Description *desc = klass->desc;
435 if (!desc || !desc->ops.base_op_id)
438 /* FIXME: Depends on values defined above! */
439 *(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
443 _eobj_class_mro_add(Eina_List *mro, const Eobj_Class *klass)
448 mro = eina_list_append(mro, klass);
451 Eobj_Extension_Node *extn;
452 EINA_INLIST_FOREACH(klass->extensions, extn)
454 mro = _eobj_class_mro_add(mro, extn->klass);
458 mro = _eobj_class_mro_add(mro, klass->parent);
464 _eobj_class_mro_init(Eobj_Class *klass)
466 Eina_List *mro = NULL;
468 DBG("Started creating MRO for class '%s'", klass->desc->name);
469 mro = _eobj_class_mro_add(mro, klass);
472 Eina_List *itr1, *itr2, *itr2n;
474 itr1 = eina_list_last(mro);
477 itr2 = eina_list_prev(itr1);
481 itr2n = eina_list_prev(itr2);
483 if (eina_list_data_get(itr1) == eina_list_data_get(itr2))
485 mro = eina_list_remove_list(mro, itr2);
491 itr1 = eina_list_prev(itr1);
495 /* Copy the mro and free the list. */
497 const Eobj_Class *kls_itr;
498 const Eobj_Class **mro_itr;
499 klass->mro = calloc(sizeof(*klass->mro), eina_list_count(mro) + 1);
501 mro_itr = klass->mro;
503 EINA_LIST_FREE(mro, kls_itr)
505 *(mro_itr++) = kls_itr;
507 DBG("Added '%s' to MRO", kls_itr->desc->name);
512 DBG("Finished creating MRO for class '%s'", klass->desc->name);
516 _eobj_class_constructor(Eobj_Class *klass)
518 if (klass->constructed)
521 klass->constructed = EINA_TRUE;
523 if (klass->desc->class_constructor)
524 klass->desc->class_constructor(klass);
526 _eobj_class_mro_init(klass);
530 eobj_class_funcs_set(Eobj_Class *klass, const Eobj_Op_Func_Description *func_descs)
532 const Eobj_Op_Func_Description *itr;
536 for ( ; itr->op != 0 ; itr++)
538 dich_func_set(klass, itr->op, itr->func);
544 eobj_class_free(Eobj_Class *klass)
546 if (klass->constructed)
548 if (klass->desc->class_destructor)
549 klass->desc->class_destructor(klass);
551 dich_func_clean_all(klass);
556 Eobj_Extension_Node *extn;
557 EINA_INLIST_FOREACH_SAFE(klass->extensions, itrn, extn)
570 _eobj_class_check_op_descs(const Eobj_Class *klass)
572 const Eobj_Class_Description *desc = klass->desc;
573 const Eobj_Op_Description *itr;
576 if (desc->ops.count > 0)
578 if (!desc->ops.base_op_id)
580 ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
585 if (!desc->ops.descs)
587 ERR("Class '%s' has a non-zero ops count, but there are no descs.",
593 itr = desc->ops.descs;
594 for (i = 0 ; i < desc->ops.count ; i++, itr++)
596 if (itr->sub_op != i)
600 ERR("Wrong order in Ops description for class '%s'. Expected %d and got %d", desc->name, i, itr->sub_op);
604 ERR("Found too few Ops description for class '%s'. Expected %d descriptions, but found %d.", desc->name, desc->ops.count, i);
610 if (itr && itr->name)
612 ERR("Found extra Ops description for class '%s'. Expected %d descriptions, but found more.", desc->name, desc->ops.count);
619 EAPI const Eobj_Class *
620 eobj_class_new(const Eobj_Class_Description *desc, const Eobj_Class *parent, ...)
625 va_start(p_list, parent);
627 #define _CLS_NEW_CHECK(x) \
632 ERR("%s must not be NULL! Aborting.", #x); \
638 _CLS_NEW_CHECK(desc);
639 _CLS_NEW_CHECK(desc->name);
641 klass = calloc(1, sizeof(Eobj_Class));
642 klass->parent = parent;
644 /* Handle class extensions */
646 Eobj_Class *extn = NULL;
648 extn = va_arg(p_list, Eobj_Class *);
651 switch (extn->desc->type)
653 case EOBJ_CLASS_TYPE_REGULAR:
654 case EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT:
655 /* Use it like an interface. */
656 case EOBJ_CLASS_TYPE_INTERFACE:
658 case EOBJ_CLASS_TYPE_MIXIN:
660 Eobj_Extension_Node *node = calloc(1, sizeof(*node));
663 eina_inlist_append(klass->extensions,
664 EINA_INLIST_GET(node));
669 extn = va_arg(p_list, Eobj_Class *);
675 /* Handle the inheritance */
678 /* Verify the inheritance is allowed. */
679 switch (klass->desc->type)
681 case EOBJ_CLASS_TYPE_REGULAR:
682 case EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT:
683 if ((klass->parent->desc->type != EOBJ_CLASS_TYPE_REGULAR) &&
684 (klass->parent->desc->type != EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT))
686 /* FIXME: Actually handle it. */
687 ERR("Regular classes ('%s') aren't allowed to inherit from non-regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
691 case EOBJ_CLASS_TYPE_INTERFACE:
692 case EOBJ_CLASS_TYPE_MIXIN:
693 if ((klass->parent->desc->type != EOBJ_CLASS_TYPE_REGULAR) &&
694 (klass->parent->desc->type != EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT))
696 /* FIXME: Actually handle it. */
697 ERR("Non-regular classes ('%s') aren't allowed to inherit from regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
704 /* Update the current offset. */
705 /* FIXME: Make sure this alignment is enough. */
706 klass->data_offset = klass->parent->data_offset +
707 klass->parent->desc->data_size +
709 (klass->parent->desc->data_size % sizeof(void *)));
712 if (!_eobj_class_check_op_descs(klass))
717 klass->class_id = ++_eobj_classes_last_id;
719 /* FIXME: Handle errors. */
721 tmp = realloc(_eobj_classes, _eobj_classes_last_id * sizeof(*_eobj_classes));
723 _eobj_classes[klass->class_id - 1] = klass;
726 _eobj_class_base_op_init(klass);
728 /* FIXME: Shouldn't be called here - should be called from eobj_add. */
729 _eobj_class_constructor(klass);
736 eobj_class_free(klass);
739 #undef _CLS_NEW_CHECK
742 eobj_add(const Eobj_Class *klass, Eobj *parent)
744 if (klass->desc->type != EOBJ_CLASS_TYPE_REGULAR)
746 ERR("Class '%s' is not instantiate-able. Aborting.", klass->desc->name);
750 Eobj *obj = calloc(1, sizeof(*obj));
752 obj->parent = parent;
756 obj->data_blob = calloc(1, klass->data_offset + klass->desc->data_size);
758 _eobj_kls_itr_init(obj, EOBJ_NOOP);
759 eobj_constructor_error_unset(obj);
762 eobj_class_constructor(obj, klass);
764 if (eobj_constructor_error_get(obj))
766 ERR("Type '%s' - One of the object constructors have failed.", klass->desc->name);
770 if (!_eobj_kls_itr_reached_end(obj))
772 ERR("Type '%s' - Not all of the object constructors have been executed.", klass->desc->name);
775 _eobj_kls_itr_end(obj, EOBJ_NOOP);
781 /* Unref twice, once for the ref above, and once for the basic object ref. */
795 eobj_unref(Eobj *obj)
797 if (--(obj->refcount) == 0)
799 /* We need that for the event callbacks that may ref/unref. */
804 eobj_event_callback_call(obj, EOBJ_EV_DEL, NULL);
805 obj->delete = EINA_TRUE;
807 eobj_event_callback_call(obj, EOBJ_EV_FREE, NULL);
811 const Eobj_Class *klass = eobj_class_get(obj);
812 _eobj_kls_itr_init(obj, EOBJ_NOOP);
813 eobj_constructor_error_unset(obj);
814 eobj_class_destructor(obj, klass);
815 if (eobj_constructor_error_get(obj))
817 ERR("Type '%s' - One of the object destructors have failed.", klass->desc->name);
820 if (!_eobj_kls_itr_reached_end(obj))
822 ERR("Type '%s' - Not all of the object destructors have been executed.", klass->desc->name);
824 _eobj_kls_itr_end(obj, EOBJ_NOOP);
825 /*FIXME: add eobj_class_unref(klass) ? - just to clear the caches. */
827 /* If for some reason it's not empty, clear it. */
830 WRN("Kls_Itr is not empty, possibly a bug, please report. - An error will be reported for each kls_itr in the stack.");
831 Eina_Inlist *nitr = nitr->next;
832 free(EINA_INLIST_CONTAINER_GET(obj->kls_itr, Eobj_Kls_Itr_Node));
836 Eina_List *itr, *itr_n;
838 EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
840 /* FIXME: Should probably be unref. */
842 obj->composite_objects =
843 eina_list_remove_list(obj->composite_objects, itr);
846 _eobj_callback_remove_all(obj);
849 free(obj->data_blob);
851 _eobj_generic_data_del_all(obj);
858 eobj_ref_get(const Eobj *obj)
860 return obj->refcount;
868 eobj_event_callback_call(obj, EOBJ_EV_DEL, NULL);
869 obj->delete = EINA_TRUE;
875 eobj_parent_get(Eobj *obj)
881 eobj_constructor_error_set(Eobj *obj)
883 obj->construct_error = EINA_TRUE;
887 eobj_constructor_error_unset(Eobj *obj)
889 obj->construct_error = EINA_FALSE;
893 eobj_constructor_error_get(const Eobj *obj)
895 return obj->construct_error;
899 _eobj_constructor_default(Eobj *obj)
901 eobj_constructor_super(obj);
905 _eobj_destructor_default(Eobj *obj)
907 eobj_destructor_super(obj);
911 eobj_class_constructor(Eobj *obj, const Eobj_Class *klass)
916 if (klass->desc->constructor)
917 klass->desc->constructor(obj, eobj_data_get(obj, klass));
919 _eobj_constructor_default(obj);
923 eobj_class_destructor(Eobj *obj, const Eobj_Class *klass)
928 if (klass->desc->destructor)
929 klass->desc->destructor(obj, eobj_data_get(obj, klass));
931 _eobj_destructor_default(obj);
935 eobj_constructor_super(Eobj *obj)
937 eobj_class_constructor(obj, _eobj_kls_itr_next(obj));
941 eobj_destructor_super(Eobj *obj)
943 eobj_class_destructor(obj, _eobj_kls_itr_next(obj));
947 eobj_data_get(Eobj *obj, const Eobj_Class *klass)
949 /* FIXME: Add a check that this is of the right klass and we don't seg.
950 * Probably just return NULL. */
951 if (klass->desc->data_size > 0)
952 return ((char *) obj->data_blob) + klass->data_offset;
960 Eina_Stringshare *key;
962 } Eobj_Generic_Data_Node;
965 _eobj_generic_data_node_free(Eobj_Generic_Data_Node *node)
967 eina_stringshare_del(node->key);
972 _eobj_generic_data_del_all(Eobj *obj)
975 Eobj_Generic_Data_Node *node;
977 EINA_INLIST_FOREACH_SAFE(obj->generic_data, nnode, node)
979 obj->generic_data = eina_inlist_remove(obj->generic_data,
980 EINA_INLIST_GET(node));
982 _eobj_generic_data_node_free(node);
987 eobj_generic_data_set(Eobj *obj, const char *key, const void *data)
990 Eobj_Generic_Data_Node *node;
992 if (!key) return NULL;
993 if (!data) return NULL;
995 prev_data = eobj_generic_data_del(obj, key);
997 node = malloc(sizeof(Eobj_Generic_Data_Node));
998 node->key = eina_stringshare_add(key);
999 node->data = (void *) data;
1000 obj->generic_data = eina_inlist_prepend(obj->generic_data,
1001 EINA_INLIST_GET(node));
1007 eobj_generic_data_get(const Eobj *obj, const char *key)
1009 Eobj_Generic_Data_Node *node;
1011 if (!key) return NULL;
1013 EINA_INLIST_FOREACH(obj->generic_data, node)
1015 if (!strcmp(node->key, key))
1017 ((Eobj *) obj)->generic_data =
1018 eina_inlist_promote(obj->generic_data, EINA_INLIST_GET(node));
1026 eobj_generic_data_del(Eobj *obj, const char *key)
1028 Eobj_Generic_Data_Node *node;
1030 if (!key) return NULL;
1032 EINA_INLIST_FOREACH(obj->generic_data, node)
1034 if (!strcmp(node->key, key))
1039 obj->generic_data = eina_inlist_remove(obj->generic_data,
1040 EINA_INLIST_GET(node));
1041 _eobj_generic_data_node_free(node);
1051 const char *log_dom = "eobj";
1052 if (_eobj_init_count++ > 0)
1057 _eobj_classes = NULL;
1058 _eobj_classes_last_id = 0;
1059 _eobj_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_LIGHTBLUE);
1060 if (_eobj_log_dom < 0)
1062 EINA_LOG_ERR("Could not register log domain: %s", log_dom);
1073 Eobj_Class **cls_itr = _eobj_classes;
1075 if (--_eobj_init_count > 0)
1078 for (i = 0 ; i < _eobj_classes_last_id ; i++, cls_itr++)
1081 eobj_class_free(*cls_itr);
1085 free(_eobj_classes);
1087 eina_log_domain_unregister(_eobj_log_dom);
1095 eobj_composite_object_attach(Eobj *obj, Eobj *emb_obj)
1098 obj->composite_objects = eina_list_prepend(obj->composite_objects, emb_obj);
1102 eobj_composite_object_detach(Eobj *obj, Eobj *emb_obj)
1104 obj->composite_objects = eina_list_remove(obj->composite_objects, emb_obj);
1105 eobj_unref(emb_obj);
1109 eobj_composite_is(Eobj *emb_obj)
1111 Eobj *obj = eobj_parent_get(emb_obj);
1118 EINA_LIST_FOREACH(obj->composite_objects, itr, tmp)
1128 struct _Eobj_Callback_Description
1131 const Eobj_Event_Description *event;
1134 Eobj_Callback_Priority priority;
1135 Eina_Bool delete_me : 1;
1138 /* Actually remove, doesn't care about walking list, or delete_me */
1140 _eobj_callback_remove(Eobj *obj, Eobj_Callback_Description *cb)
1142 obj->callbacks = eina_inlist_remove(obj->callbacks,
1143 EINA_INLIST_GET(cb));
1147 /* Actually remove, doesn't care about walking list, or delete_me */
1149 _eobj_callback_remove_all(Eobj *obj)
1152 Eobj_Callback_Description *cb;
1153 EINA_INLIST_FOREACH_SAFE(obj->callbacks, initr, cb)
1155 _eobj_callback_remove(obj, cb);
1160 _eobj_callbacks_clear(Eobj *obj)
1163 Eobj_Callback_Description *cb;
1165 /* Abort if we are currently walking the list. */
1166 if (obj->walking_list > 0)
1169 EINA_INLIST_FOREACH_SAFE(obj->callbacks, itn, cb)
1173 _eobj_callback_remove(obj, cb);
1179 _callback_priority_cmp(const void *_a, const void *_b)
1181 const Eobj_Callback_Description *a, *b;
1182 a = (const Eobj_Callback_Description *) _a;
1183 b = (const Eobj_Callback_Description *) _b;
1184 if (a->priority < b->priority)
1191 eobj_event_callback_priority_add(Eobj *obj,
1192 const Eobj_Event_Description *desc,
1193 Eobj_Callback_Priority priority,
1197 Eobj_Callback_Description *cb = calloc(1, sizeof(*cb));
1200 cb->func_data = (void *) data;
1201 cb->priority = priority;
1202 obj->callbacks = eina_inlist_sorted_insert(obj->callbacks,
1203 EINA_INLIST_GET(cb), _callback_priority_cmp);
1205 eobj_event_callback_call(obj, EOBJ_EV_CALLBACK_ADD, desc);
1211 eobj_event_callback_del(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Event_Cb func)
1214 Eobj_Callback_Description *cb;
1215 EINA_INLIST_FOREACH(obj->callbacks, cb)
1217 if ((cb->event == desc) && (cb->func == func))
1221 data = cb->func_data;
1222 cb->delete_me = EINA_TRUE;
1223 _eobj_callbacks_clear(obj);
1232 eobj_event_callback_call(obj, EOBJ_EV_CALLBACK_DEL, desc);
1237 eobj_event_callback_del_full(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Event_Cb func, const void *user_data)
1240 Eobj_Callback_Description *cb;
1241 EINA_INLIST_FOREACH(obj->callbacks, cb)
1243 if ((cb->event == desc) && (cb->func == func) &&
1244 (cb->func_data == user_data))
1248 data = cb->func_data;
1249 cb->delete_me = EINA_TRUE;
1250 _eobj_callbacks_clear(obj);
1259 eobj_event_callback_call(obj, EOBJ_EV_CALLBACK_DEL, desc);
1264 eobj_event_callback_call(Eobj *obj, const Eobj_Event_Description *desc,
1265 const void *event_info)
1267 Eina_Bool ret = EINA_TRUE;
1268 Eobj_Callback_Description *cb;
1271 obj->walking_list++;
1273 EINA_INLIST_FOREACH(obj->callbacks, cb)
1275 if (!cb->delete_me && (cb->event == desc))
1277 /* Abort callback calling if the func says so. */
1278 if (!cb->func((void *) cb->func_data, obj, desc,
1279 (void *) event_info))
1288 obj->walking_list--;
1289 _eobj_callbacks_clear(obj);
1296 _eobj_event_forwarder_callback(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *event_info)
1299 Eobj *new_obj = (Eobj *) data;
1300 return eobj_event_callback_call(new_obj, desc, event_info);
1303 /* FIXME: Change default priority? Maybe call later? */
1305 eobj_event_callback_forwarder_add(Eobj *obj, const Eobj_Event_Description *desc, Eobj *new_obj)
1307 return eobj_event_callback_add(obj, desc, _eobj_event_forwarder_callback, new_obj);
1311 eobj_event_callback_forwarder_del(Eobj *obj, const Eobj_Event_Description *desc, Eobj *new_obj)
1313 eobj_event_callback_del_full(obj, desc, _eobj_event_forwarder_callback, new_obj);
1317 /* EOBJ_CLASS_BASE stuff */
1318 static const Eobj_Class *_my_class = NULL;
1320 /* FIXME: Set proper type descriptions. */
1321 EAPI const Eobj_Event_Description _EOBJ_EV_CALLBACK_ADD =
1322 EOBJ_EVENT_DESCRIPTION("callback,add", "?", "A callback was added.");
1323 EAPI const Eobj_Event_Description _EOBJ_EV_CALLBACK_DEL =
1324 EOBJ_EVENT_DESCRIPTION("callback,del", "?", "A callback was deleted.");
1325 EAPI const Eobj_Event_Description _EOBJ_EV_FREE =
1326 EOBJ_EVENT_DESCRIPTION("free", "", "Obj is being freed.");
1327 EAPI const Eobj_Event_Description _EOBJ_EV_DEL =
1328 EOBJ_EVENT_DESCRIPTION("del", "", "Obj is being deleted.");
1331 _constructor(Eobj *obj, void *class_data __UNUSED__)
1333 DBG("%p - %s.", obj, _my_class->desc->name);
1337 _destructor(Eobj *obj, void *class_data __UNUSED__)
1339 DBG("%p - %s.", obj, _my_class->desc->name);
1342 EAPI const Eobj_Class *
1343 eobj_base_class_get(void)
1345 if (_my_class) return _my_class;
1347 static const Eobj_Event_Description *event_desc[] = {
1348 EOBJ_EV_CALLBACK_ADD,
1349 EOBJ_EV_CALLBACK_DEL,
1355 static const Eobj_Class_Description class_desc = {
1357 EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT,
1358 EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
1367 return _my_class = eobj_class_new(&class_desc, NULL, NULL);