9
#include "eo_internal.h"
11
#include "eo_ptr_indirection.h"
12
#include "eo_private.h"
13
#include "eina_promise_private.h"
15
EO_API const Efl_Event_Description _EFL_EVENT_CALLBACK_ADD =
16
EFL_EVENT_DESCRIPTION_HOT("callback,add");
18
EO_API const Efl_Event_Description _EFL_EVENT_CALLBACK_DEL =
19
EFL_EVENT_DESCRIPTION_HOT("callback,del");
21
static int event_freeze_count = 0;
23
typedef struct _Eo_Callback_Description Eo_Callback_Description;
24
typedef struct _Efl_Event_Callback_Frame Efl_Event_Callback_Frame;
25
typedef struct _Efl_Event_Forwarder Efl_Event_Forwarder;
27
struct _Efl_Event_Forwarder
29
const Efl_Event_Description *desc;
35
Eina_Bool inserted : 1;
38
struct _Efl_Event_Callback_Frame
40
const Efl_Event_Description *desc;
41
Efl_Event_Callback_Frame *next;
43
unsigned int inserted_before;
44
unsigned short generation;
52
Eina_Inlist *generic_data;
55
Eina_Hash *schedulers;
56
Eina_Hash *forwarders;
57
} Efl_Object_Extension;
59
#define EFL_OBJECT_EVENT_CALLBACK(Event) Eina_Bool event_cb_##Event : 1;
61
struct _Efl_Object_Data
63
Eina_Inlist *children;
66
Efl_Object_Extension *ext;
68
Efl_Event_Callback_Frame *event_frame;
69
Eo_Callback_Description **callbacks;
71
uint64_t callbacks_mask;
73
uint32_t callbacks_mask;
75
Eina_Inlist *pending_futures;
76
unsigned int callbacks_count;
78
unsigned short event_freeze_count;
80
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_CALLBACK_ADD);
81
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_CALLBACK_DEL);
82
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_DEL);
83
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_NOREF);
85
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_INVALIDATE);
86
EFL_OBJECT_EVENT_CALLBACK(EFL_EVENT_DESTRUCT);
87
Eina_Bool callback_stopped : 1;
88
Eina_Bool need_cleaning : 1;
90
Eina_Bool allow_parent_unref : 1;
99
} Eo_Generic_Data_Node_Type;
105
Eina_Stringshare *key;
111
Eo_Generic_Data_Node_Type d_type;
112
} Eo_Generic_Data_Node;
114
typedef struct _Efl_Future_Pending
119
Efl_Future_Cb_Desc desc;
126
const Efl_Event_Description *desc;
127
unsigned int current;
128
} Eo_Current_Callback_Description;
130
#define EVENT_STACK_PUSH(pd, fr) do { \
131
(fr)->next = (pd)->event_frame; \
132
(pd)->event_frame = (fr); \
134
#define EVENT_STACK_POP(pd) do { \
135
if ((pd)->event_frame) (pd)->event_frame = (pd)->event_frame->next; \
138
static void _efl_event_forwarder_callback(void *data, const Efl_Event *event);
140
static int _eo_nostep_alloc = -1;
143
_efl_pending_futures_clear(Efl_Object_Data *pd)
145
while (pd->pending_futures)
147
Efl_Future_Pending *pending = EINA_INLIST_CONTAINER_GET(pd->pending_futures, Efl_Future_Pending);
148
Eina_Future *future = *pending->desc.storage;
150
eina_future_cancel(future);
155
_efl_object_extension_free(Efl_Object_Extension *ext)
157
eina_freeq_ptr_main_add(ext, free, sizeof(*ext));
160
static inline Efl_Object_Extension *
161
_efl_object_extension_need(Efl_Object_Data *pd)
163
if (!pd->ext) pd->ext = calloc(1, sizeof(Efl_Object_Extension));
168
_efl_object_extension_noneed(Efl_Object_Data *pd)
170
Efl_Object_Extension *ext = pd->ext;
174
(ext->generic_data) ||
176
(ext->composite_parent) ||
179
(ext->forwarders)) return;
180
_efl_object_extension_free(pd->ext);
185
_efl_object_invalidate(Eo *obj_id, Efl_Object_Data *pd)
187
_efl_pending_futures_clear(pd);
189
if (pd->ext && pd->ext->forwarders)
191
eina_hash_free(pd->ext->forwarders);
192
pd->ext->forwarders = NULL;
193
_efl_object_extension_noneed(pd);
196
if (pd->ext && pd->ext->providers)
198
eina_hash_free(pd->ext->providers);
199
pd->ext->providers = NULL;
200
_efl_object_extension_noneed(pd);
202
if (pd->ext && pd->ext->schedulers)
204
eina_hash_free(pd->ext->schedulers);
205
pd->ext->schedulers = NULL;
206
_efl_object_extension_noneed(pd);
209
EO_OBJ_POINTER_RETURN(obj_id, obj);
215
if (!obj->is_invalidating)
216
efl_parent_set(obj_id, NULL);
226
_efl_invalidate(_Eo_Object *obj)
228
Eina_Array stash = { 0 };
233
if (obj->is_invalidating) return ;
234
obj->is_invalidating = EINA_TRUE;
235
if (obj->invalidate) return;
237
id = _eo_obj_id_get(obj);
239
pd = efl_data_scope_get(id, EFL_OBJECT_CLASS);
240
if (pd->event_cb_EFL_EVENT_INVALIDATE)
241
efl_event_callback_call(id, EFL_EVENT_INVALIDATE, NULL);
245
eina_array_step_set(&stash, sizeof (stash), 4);
248
EINA_INLIST_FOREACH(pd->children, child)
249
eina_array_push(&stash, _efl_ref(child));
251
while ((child = eina_array_pop(&stash)))
253
Eo *child_id = _eo_obj_id_get(child);
255
efl_parent_set(child_id, NULL);
259
eina_array_flush(&stash);
261
obj->invalidate = EINA_TRUE;
264
static void _key_generic_cb_del(void *data, const Efl_Event *event);
267
_eo_generic_data_node_free(Eo_Generic_Data_Node *node)
269
switch (node->d_type)
275
efl_event_callback_del(node->d.obj, EFL_EVENT_DEL, _key_generic_cb_del, node);
276
efl_unref(node->d.obj);
280
efl_event_callback_del(node->d.obj, EFL_EVENT_DEL, _key_generic_cb_del, node);
283
eina_value_free(node->d.val);
286
eina_stringshare_del(node->key);
287
eina_freeq_ptr_main_add(node, free, sizeof(*node));
291
_eo_generic_data_del_all(Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
293
Eo_Generic_Data_Node *node;
294
Efl_Object_Extension *ext = pd->ext;
298
while (ext->generic_data)
300
node = (Eo_Generic_Data_Node *)ext->generic_data;
301
ext->generic_data = eina_inlist_remove(ext->generic_data,
302
EINA_INLIST_GET(node));
304
_eo_generic_data_node_free(node);
309
_eo_key_generic_direct_del(Efl_Object_Data *pd, Eo_Generic_Data_Node *node, Eina_Bool call_free)
311
Efl_Object_Extension *ext = pd->ext;
313
ext->generic_data = eina_inlist_remove
314
(ext->generic_data, EINA_INLIST_GET(node));
315
if (call_free) _eo_generic_data_node_free(node);
319
_eo_key_generic_del(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *key, Eina_Bool call_free)
321
Eo_Generic_Data_Node *node;
322
Efl_Object_Extension *ext = pd->ext;
324
EINA_INLIST_FOREACH(ext->generic_data, node)
326
if (!strcmp(node->key, key))
328
ext->generic_data = eina_inlist_remove
329
(ext->generic_data, EINA_INLIST_GET(node));
330
if (call_free) _eo_generic_data_node_free(node);
337
static Eo_Generic_Data_Node *
338
_key_generic_set(const Eo *obj, Efl_Object_Data *pd, const char *key, const void *data, Eo_Generic_Data_Node_Type d_type, Eina_Bool call_free)
340
Eo_Generic_Data_Node *node;
341
Efl_Object_Extension *ext = pd->ext;
343
if (!key) return NULL;
348
_eo_key_generic_del(obj, pd, key, call_free);
351
EINA_INLIST_FOREACH(ext->generic_data, node)
353
if (!strcmp(node->key, key))
355
if ((node->d_type == d_type) && (node->d.ptr == data))
357
ext->generic_data = eina_inlist_remove
358
(ext->generic_data, EINA_INLIST_GET(node));
359
_eo_generic_data_node_free(node);
365
if (!data) return NULL;
367
ext = _efl_object_extension_need(pd);
370
node = calloc(1, sizeof(Eo_Generic_Data_Node));
371
if (!node) return NULL;
373
node->key = eina_stringshare_add(key);
374
node->d.ptr = (void *) data;
375
node->d_type = d_type;
376
ext->generic_data = eina_inlist_prepend
377
(ext->generic_data, EINA_INLIST_GET(node));
385
_key_generic_get(const Eo *obj, Efl_Object_Data *pd, const char *key, Eo_Generic_Data_Node_Type d_type)
387
Eo_Generic_Data_Node *node;
388
Efl_Object_Extension *ext = pd->ext;
390
if (!key) return NULL;
391
if (!ext) return NULL;
392
EINA_INLIST_FOREACH(ext->generic_data, node)
394
if (node->key && !strcmp(node->key, key))
396
if (node->d_type == d_type)
398
ext->generic_data = eina_inlist_promote
399
(ext->generic_data, EINA_INLIST_GET(node));
404
ERR("Object %p key '%s' asked for %d but is %d'",
405
obj, key, d_type, node->d_type);
414
_key_generic_cb_del(void *data, const Efl_Event *event EINA_UNUSED)
416
Eo_Generic_Data_Node *node = data;
417
Efl_Object_Data *pd = efl_data_scope_get(node->obj, EFL_OBJECT_CLASS);
418
_eo_key_generic_direct_del(pd, node, EINA_TRUE);
422
_efl_object_key_data_set(Eo *obj, Efl_Object_Data *pd, const char *key, const void *data)
424
_key_generic_set(obj, pd, key, data, DATA_PTR, EINA_TRUE);
427
EO_API EFL_VOID_FUNC_BODYV(efl_key_data_set, EFL_FUNC_CALL(key, data),
428
const char *key, const void *data);
431
_efl_object_key_data_get(Eo *obj, Efl_Object_Data *pd, const char *key)
433
return _key_generic_get(obj, pd, key, DATA_PTR);
436
EO_API EFL_FUNC_BODYV_CONST(efl_key_data_get, void *, NULL, EFL_FUNC_CALL(key),
440
_efl_object_key_ref_set(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *key, const Eo *objdata)
442
Eo_Generic_Data_Node *node;
444
if (!_eo_id_domain_compatible(obj, objdata)) return;
445
node = _key_generic_set(obj, pd, key, objdata, DATA_OBJ, EINA_TRUE);
449
efl_event_callback_add((Eo *)objdata, EFL_EVENT_DEL, _key_generic_cb_del, node);
453
EO_API EFL_VOID_FUNC_BODYV(efl_key_ref_set, EFL_FUNC_CALL(key, objdata),
454
const char *key, const Efl_Object *objdata);
457
_efl_object_key_ref_get(Eo *obj, Efl_Object_Data *pd, const char *key)
459
return _key_generic_get(obj, pd, key, DATA_OBJ);
462
EO_API EFL_FUNC_BODYV_CONST(efl_key_ref_get, Efl_Object *, NULL,
463
EFL_FUNC_CALL(key), const char *key);
466
_efl_object_key_wref_set(Eo *obj, Efl_Object_Data *pd, const char * key, const Efl_Object *objdata)
468
Eo_Generic_Data_Node *node;
470
if (!_eo_id_domain_compatible(obj, objdata)) return;
471
node = _key_generic_set(obj, pd, key, objdata, DATA_OBJ_WEAK, EINA_TRUE);
474
efl_event_callback_add((Eo *)objdata, EFL_EVENT_DEL, _key_generic_cb_del, node);
478
EO_API EFL_VOID_FUNC_BODYV(efl_key_wref_set, EFL_FUNC_CALL(key, objdata),
479
const char *key, const Efl_Object *objdata);
482
_efl_object_key_wref_get(Eo *obj, Efl_Object_Data *pd, const char * key)
484
return _key_generic_get(obj, pd, key, DATA_OBJ_WEAK);
487
EO_API EFL_FUNC_BODYV_CONST(efl_key_wref_get, Efl_Object *, NULL,
488
EFL_FUNC_CALL(key), const char *key);
491
_efl_object_key_value_set(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *key, Eina_Value *value)
493
_key_generic_set(obj, pd, key, value, DATA_VAL, EINA_TRUE);
496
EO_API EFL_VOID_FUNC_BODYV(efl_key_value_set, EFL_FUNC_CALL(key, value),
497
const char *key, Eina_Value *value);
499
EOLIAN static Eina_Value *
500
_efl_object_key_value_get(Eo *obj, Efl_Object_Data *pd, const char *key)
502
return _key_generic_get(obj, pd, key, DATA_VAL);
505
EO_API EFL_FUNC_BODYV_CONST(efl_key_value_get, Eina_Value *, NULL,
506
EFL_FUNC_CALL(key), const char *key);
509
_efl_object_name_set(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *name)
511
if ((name) && (!name[0])) name = NULL;
514
_efl_object_extension_need(pd);
515
if (pd->ext) eina_stringshare_replace(&(pd->ext->name), name);
519
if (!pd->ext) return;
522
eina_stringshare_replace(&(pd->ext->name), name);
523
_efl_object_extension_noneed(pd);
528
EOLIAN static const char *
529
_efl_object_name_get(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
531
if (!pd->ext) return NULL;
532
return pd->ext->name;
535
static inline Eina_Bool
536
_name_match(const char *match, Eina_Bool is_glob, const char *str)
543
if (!match[0]) return EINA_TRUE;
545
if ((match[0] == '*') && (match[1] == 0)) return EINA_TRUE;
547
if (eina_fnmatch(match, str, 0)) return EINA_TRUE;
552
if (!match[0]) return EINA_TRUE;
554
if (match == str) return EINA_TRUE;
556
if (!strcmp(match, str)) return EINA_TRUE;
562
static inline Eina_Bool
563
_matchall(const char *match)
565
if ((match[0] == 0) || ((match[0] == '*') && (match[1] == 0)))
571
_hasglob(const char *match)
573
if (strpbrk(match, "*?[")) return EINA_TRUE;
578
_ismultiglob(const char *match)
580
if ((match[0] == '*') && (match[1] == '*') && (match[2] == 0))
582
if ((match[0] == '*') && (match[1] == '*') && (match[2] == '/'))
584
if ((match[0] == '/') && (match[1] == '*') && (match[2] == '*') && (match[3] == 0))
586
if ((match[0] == '/') && (match[1] == '*') && (match[2] == '*') && (match[3] == '/'))
591
EOLIAN static Efl_Object *
592
_efl_object_name_find(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *search)
595
_Eo_Object *child_eo;
596
const char *name, *p, *klass_name;
611
if (!search) return NULL;
612
if (!search[0]) return NULL;
614
if (strchr(search, '/'))
616
ERR("Looking up object by path '%s' is not supported", search);
623
if (_ismultiglob(search)) return NULL;
625
if ((p = strchr(search, ':')))
630
size_t colon_location = p - search;
631
Eina_Bool klass_glob = EINA_FALSE;
632
Eina_Bool name_glob = EINA_FALSE;
635
klass = alloca(strlen(search) + 1);
636
strcpy(klass, search);
637
klass[colon_location] = '\0';
638
search_name = klass + colon_location + 1;
641
klass_glob = _hasglob(klass);
642
name_glob = _hasglob(search_name);
643
EINA_INLIST_FOREACH(pd->children, child_eo)
645
child = _eo_obj_id_get(child_eo);
646
name = efl_name_get(child);
647
klass_name = efl_class_name_get(efl_class_get(child));
648
if (_name_match(klass, klass_glob, klass_name) &&
649
(((!_matchall(klass)) && (!name) && (_matchall(search_name))) ||
650
((name) && _name_match(search_name, name_glob, name))))
652
child = efl_name_find(child, search);
653
if (child) return child;
658
if (_hasglob(search))
661
EINA_INLIST_FOREACH(pd->children, child_eo)
663
child = _eo_obj_id_get(child_eo);
664
name = efl_name_get(child);
665
if ((name) && (_name_match(search, EINA_TRUE, name)))
667
child = efl_name_find(child, search);
668
if (child) return child;
674
EINA_INLIST_FOREACH(pd->children, child_eo)
676
child = _eo_obj_id_get(child_eo);
677
name = efl_name_get(child);
678
if ((name) && (_name_match(search, EINA_FALSE, name)))
680
child = efl_name_find(child, search);
681
if (child) return child;
690
_efl_object_comment_set(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const char *comment)
692
if ((comment) && (!comment[0])) comment = NULL;
695
_efl_object_extension_need(pd);
696
if (pd->ext) eina_stringshare_replace(&(pd->ext->comment), comment);
700
if (!pd->ext) return;
701
if (pd->ext->comment)
703
eina_stringshare_replace(&(pd->ext->comment), comment);
704
_efl_object_extension_noneed(pd);
709
EOLIAN static const char *
710
_efl_object_comment_get(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
712
if (!pd->ext) return NULL;
713
return pd->ext->comment;
717
_efl_object_debug_name_override(Eo *obj_id EINA_UNUSED, Efl_Object_Data *pd EINA_UNUSED, Eina_Strbuf *sb EINA_UNUSED)
722
efl_del(const Eo *obj)
725
EO_OBJ_POINTER_RETURN(obj, oid);
727
if (efl_parent_get((Eo *) obj))
729
efl_parent_set((Eo *) obj, NULL);
733
ERR("Calling efl_del on object %s with no parent is not advised any more.", efl_debug_name_get(obj));
741
_efl_object_reuse(_Eo_Object *obj)
743
obj->is_invalidating = EINA_FALSE;
744
obj->invalidate = EINA_FALSE;
748
_efl_object_parent_set(Eo *obj, Efl_Object_Data *pd, Eo *parent_id)
750
Eo *prev_parent = pd->parent;
751
Eina_Bool bad_parent = EINA_FALSE;
753
if ((pd->parent == parent_id) ||
754
((parent_id) && (!_eo_id_domain_compatible(parent_id, obj))))
757
if (parent_id != NULL)
759
EO_OBJ_POINTER_GOTO(parent_id, parent_obj, err_impossible);
760
bad_parent = parent_obj->invalidate || (obj == parent_id);
761
EO_OBJ_DONE(parent_id);
764
if (bad_parent) goto err_parent;
766
EO_OBJ_POINTER_GOTO(obj, eo_obj, err_impossible);
769
if (eo_obj->invalidate)
771
ERR("Call of efl_parent_set(%p, %p) when object of clas '%s' is already invalidated.\n", obj, parent_id, efl_class_name_get(obj));
777
if (prev_parent) _efl_invalidate(eo_obj);
782
Efl_Object_Data *old_parent_pd = efl_data_scope_get(pd->parent,
786
old_parent_pd->children = eina_inlist_remove(old_parent_pd->children,
787
EINA_INLIST_GET(eo_obj));
790
else goto err_impossible;
796
Efl_Object_Data *parent_pd = efl_data_scope_get(parent_id,
799
if (EINA_LIKELY(parent_pd != NULL))
801
pd->parent = parent_id;
802
parent_pd->children = eina_inlist_append(parent_pd->children,
803
EINA_INLIST_GET(eo_obj));
804
if (!prev_parent) efl_ref(obj);
809
if (prev_parent) efl_unref(obj);
812
goto err_parent_done;
815
eo_obj->parent = EINA_TRUE;
820
eo_obj->parent = EINA_FALSE;
822
if (prev_parent && !eo_obj->del_triggered) efl_unref(obj);
831
if (obj == parent_id)
832
ERR("New parent %p for object %p will not be set: THIS IS THE SAME OBJECT.",
835
ERR("New parent %p for object %p is not a valid Eo object.",
840
ERR("CONTACT DEVS!!! SHOULD NEVER HAPPEN!!! Old parent %p for object %p is not a valid Eo object.",
845
_efl_object_parent_get(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
850
EOLIAN static Eina_Bool
851
_efl_object_finalized_get(const Eo *obj_id, Efl_Object_Data *pd EINA_UNUSED)
854
EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, EINA_FALSE);
855
finalized = obj->finalized;
860
EOLIAN static Eina_Bool
861
_efl_object_invalidated_get(const Eo *obj_id, Efl_Object_Data *pd)
863
Eina_Bool invalidate;
864
EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, EINA_TRUE);
865
invalidate = obj->invalidate;
867
if (!invalidate && pd && pd->parent)
868
return efl_invalidated_get(pd->parent);
872
EOLIAN static Eina_Bool
873
_efl_object_invalidating_get(const Eo *obj_id, Efl_Object_Data *pd EINA_UNUSED)
875
Eina_Bool invalidating;
876
EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, EINA_TRUE);
877
invalidating = obj->is_invalidating;
882
EOLIAN static Efl_Object *
883
_efl_object_provider_find(const Eo *obj, Efl_Object_Data *pd, const Efl_Object *klass)
885
Eina_Bool invalidate;
886
Efl_Object *r = NULL;
888
invalidate = _efl_object_invalidated_get((Eo*) obj, NULL);
891
ERR("Calling efl_provider_find(%p) after the object was invalidated.", obj);
895
if (efl_isa(obj, klass)) return (Eo *) obj;
897
if (pd->ext) r = eina_hash_find(pd->ext->providers, &klass);
900
if (pd->parent) return efl_provider_find(pd->parent, klass);
905
_efl_object_provider_register(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const Efl_Class *klass, const Efl_Object *provider)
908
if (!efl_isa(provider, klass)) return EINA_FALSE;
910
_efl_object_extension_need(pd);
911
if (!pd->ext) return EINA_FALSE;
912
if (!pd->ext->providers) pd->ext->providers = eina_hash_pointer_new(EINA_FREE_CB(efl_unref));
915
if (eina_hash_find(pd->ext->providers, &klass)) return EINA_FALSE;
919
return eina_hash_add(pd->ext->providers, &klass, efl_ref(provider));
923
_efl_object_provider_unregister(Eo *obj EINA_UNUSED, Efl_Object_Data *pd, const Efl_Class *klass, const Efl_Object *provider)
927
if (!pd->ext) return EINA_FALSE;
928
r = eina_hash_del(pd->ext->providers, &klass, provider);
930
if (eina_hash_population(pd->ext->providers) != 0) return r;
931
eina_hash_free(pd->ext->providers);
932
pd->ext->providers = NULL;
933
_efl_object_extension_noneed(pd);
939
typedef struct _Eo_Children_Iterator Eo_Children_Iterator;
940
struct _Eo_Children_Iterator
942
Eina_Iterator iterator;
943
Eina_Inlist *current;
949
_efl_children_iterator_next(Eo_Children_Iterator *it, void **data)
951
if (!it->current) return EINA_FALSE;
955
_Eo_Object *eo_obj = EINA_INLIST_CONTAINER_GET(it->current, _Eo_Object);
956
*data = _eo_obj_id_get(eo_obj);
958
it->current = it->current->next;
964
_efl_children_iterator_container(Eo_Children_Iterator *it)
970
_efl_children_iterator_free(Eo_Children_Iterator *it)
975
klass = (_Efl_Class*) it->obj->klass;
978
eina_spinlock_take(&klass->iterators.trash_lock);
979
if (klass->iterators.trash_count < 8)
981
klass->iterators.trash_count++;
982
eina_trash_push(&klass->iterators.trash, it);
986
eina_freeq_ptr_main_add(it, free, sizeof(*it));
988
eina_spinlock_release(&klass->iterators.trash_lock);
993
EOLIAN static Eina_Iterator *
994
_efl_object_children_iterator_new(Eo *obj_id, Efl_Object_Data *pd)
997
Eo_Children_Iterator *it = NULL;
999
EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, NULL);
1003
klass = (_Efl_Class *)obj->klass;
1005
eina_spinlock_take(&klass->iterators.trash_lock);
1006
it = eina_trash_pop(&klass->iterators.trash);
1009
klass->iterators.trash_count--;
1010
memset(it, 0, sizeof (Eo_Children_Iterator));
1012
else it = calloc(1, sizeof (Eo_Children_Iterator));
1013
eina_spinlock_release(&klass->iterators.trash_lock);
1018
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
1019
it->current = pd->children;
1020
it->obj = _efl_ref(obj);
1021
it->obj_id = obj_id;
1022
it->iterator.next = FUNC_ITERATOR_NEXT(_efl_children_iterator_next);
1023
it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_efl_children_iterator_container);
1024
it->iterator.free = FUNC_ITERATOR_FREE(_efl_children_iterator_free);
1027
EO_OBJ_DONE(obj_id);
1028
return (Eina_Iterator *)it;
1032
_efl_object_dbg_info_get(Eo *obj EINA_UNUSED, Efl_Object_Data *pd EINA_UNUSED, Efl_Dbg_Info *root_node EINA_UNUSED)
1037
EO_API EFL_VOID_FUNC_BODYV(efl_dbg_info_get, EFL_FUNC_CALL(root_node), Efl_Dbg_Info *root_node);
1042
_wref_count(Efl_Object_Data *pd)
1046
Efl_Object_Extension *ext = pd->ext;
1048
if ((!ext) || (!ext->wrefs)) return 0;
1049
for (itr = ext->wrefs; *itr; itr++) count++;
1055
_efl_object_wref_add(Eo *obj, Efl_Object_Data *pd, Eo **wref)
1059
Efl_Object_Extension *ext;
1061
count = _wref_count(pd);
1064
ext = _efl_object_extension_need(pd);
1067
tmp = realloc(ext->wrefs, sizeof(*ext->wrefs) * (count + 1));
1071
ext->wrefs[count - 1] = wref;
1072
ext->wrefs[count] = NULL;
1078
EO_API EFL_VOID_FUNC_BODYV(efl_wref_add, EFL_FUNC_CALL(wref), Efl_Object **wref);
1081
_efl_object_wref_del(Eo *obj, Efl_Object_Data *pd, Eo **wref)
1084
Efl_Object_Extension *ext = pd->ext;
1087
if (*wref != obj) goto err_wref_not_obj;
1090
if ((!ext) || (!ext->wrefs)) goto err_wref_none;
1093
count = _wref_count(pd);
1097
for (itr = ext->wrefs; *itr; itr++)
1101
*itr = ext->wrefs[count - 1];
1106
if (!*itr) goto err_noiter;
1113
tmp = realloc(ext->wrefs, sizeof(*ext->wrefs) * count);
1116
ext->wrefs[count - 1] = NULL;
1122
eina_freeq_ptr_main_add(ext->wrefs, free, 0);
1124
_efl_object_extension_noneed(pd);
1131
ERR("Wref %p is not associated with object %p", wref, obj);
1134
ERR("There are no weak refs for object %p", obj);
1139
ERR("Wref is a weak ref to %p, while this function was called on %p.",
1144
EO_API EFL_VOID_FUNC_BODYV(efl_wref_del, EFL_FUNC_CALL(wref), Efl_Object **wref);
1147
_wref_destruct(Efl_Object_Data *pd)
1150
Efl_Object_Extension *ext = pd->ext;
1152
if ((!ext) || (!ext->wrefs)) return;
1153
for (itr = ext->wrefs; *itr; itr++) **itr = NULL;
1154
eina_freeq_ptr_main_add(ext->wrefs, free, 0);
1165
static Eina_Hash *_legacy_events_hash = NULL;
1167
EO_API const Efl_Event_Description *
1168
efl_object_legacy_only_event_description_get(const char *_event_name)
1170
Eina_Stringshare *event_name = eina_stringshare_add(_event_name);
1171
Efl_Event_Description *event_desc = eina_hash_find(_legacy_events_hash, event_name);
1174
event_desc = calloc(1, sizeof(Efl_Event_Description));
1175
event_desc->name = event_name;
1176
event_desc->legacy_is = EINA_TRUE;
1177
event_desc->unfreezable = EINA_TRUE;
1178
eina_hash_add(_legacy_events_hash, event_name, event_desc);
1182
eina_stringshare_del(event_name);
1188
static inline Eina_Bool
1189
_legacy_event_desc_is(const Efl_Event_Description *desc)
1191
return desc->legacy_is;
1195
_legacy_events_hash_free_cb(void *_desc)
1197
Efl_Event_Description *desc = _desc;
1198
eina_stringshare_del(desc->name);
1199
eina_freeq_ptr_main_add(desc, free, sizeof(*desc));
1203
struct _Eo_Callback_Description
1207
Efl_Callback_Array_Item item;
1208
const Efl_Callback_Array_Item *item_array;
1212
Efl_Callback_Priority priority;
1214
unsigned short generation;
1216
Eina_Bool delete_me : 1;
1217
Eina_Bool func_array : 1;
1220
static Eina_Mempool *_eo_callback_mempool = NULL;
1221
static Eina_Mempool *_efl_pending_future_mempool = NULL;
1222
static Eina_Mempool *_efl_future_scheduler_entry_mempool = NULL;
1225
_eo_callback_free(Eo_Callback_Description *cb)
1227
eina_mempool_free(_eo_callback_mempool, cb);
1230
static Eo_Callback_Description *
1231
_eo_callback_new(void)
1233
return eina_mempool_calloc(_eo_callback_mempool,
1234
sizeof(Eo_Callback_Description));
1238
_efl_pending_future_free(Efl_Future_Pending *pending)
1240
eina_mempool_free(_efl_pending_future_mempool, pending);
1243
static Efl_Future_Pending *
1244
_efl_pending_future_new(void)
1246
return eina_mempool_calloc(_efl_pending_future_mempool,
1247
sizeof(Efl_Future_Pending));
1250
#define CB_COUNT_INC(cnt) do { if ((cnt) != 0xffff) (cnt)++; } while(0)
1251
#define CB_COUNT_DEC(cnt) do { if ((cnt) != 0xffff) (cnt)--; } while(0)
1253
static inline unsigned char
1254
_pointer_hash(const uintptr_t val)
1256
static unsigned char shift = 0;
1260
if (EINA_UNLIKELY((!shift)))
1261
shift = (unsigned char) log2(1 + sizeof (Efl_Event_Description));
1263
return (unsigned char)(((val) >> shift) & 0x3F);
1265
return (unsigned char)(((val) >> shift) & 0x1F);
1269
#define EFL_OBJECT_EVENT_CB_INC(Obj, It, Pd, Event, Update_Hash) \
1270
if (It->desc == Event && !Pd->event_cb_##Event) \
1272
Update_Hash = EINA_FALSE; \
1273
Pd->event_cb_##Event = EINA_TRUE; \
1276
#define EFL_OBJECT_EVENT_CB_DEC(Obj, It, Pd, Event) \
1277
if (It->desc == Event && Pd->event_cb_##Event) \
1279
if (!efl_event_callback_count(Obj, Event)) \
1280
Pd->event_cb_##Event = EINA_FALSE; \
1284
_special_event_count_inc(Eo *obj_id, Efl_Object_Data *pd, const Efl_Callback_Array_Item *it)
1286
Eina_Bool update_hash = EINA_TRUE;
1288
EFL_OBJECT_EVENT_CB_INC(obj_id, it, pd, EFL_EVENT_CALLBACK_ADD, update_hash)
1289
else EFL_OBJECT_EVENT_CB_INC(obj_id, it, pd, EFL_EVENT_CALLBACK_DEL, update_hash)
1290
else EFL_OBJECT_EVENT_CB_INC(obj_id, it, pd, EFL_EVENT_DEL, update_hash)
1291
else EFL_OBJECT_EVENT_CB_INC(obj_id, it, pd, EFL_EVENT_INVALIDATE, update_hash)
1292
else EFL_OBJECT_EVENT_CB_INC(obj_id, it, pd, EFL_EVENT_DESTRUCT, update_hash)
1293
else if (it->desc == EFL_EVENT_NOREF && !pd->event_cb_EFL_EVENT_NOREF)
1295
update_hash = EINA_FALSE;
1296
EO_OBJ_POINTER_RETURN(obj_id, obj);
1297
obj->noref_event = EINA_TRUE;
1298
EO_OBJ_DONE(obj_id);
1299
pd->event_cb_EFL_EVENT_NOREF = EINA_TRUE;
1301
else if (it->desc == EFL_EVENT_OWNERSHIP_SHARED || it->desc == EFL_EVENT_OWNERSHIP_UNIQUE)
1303
EO_OBJ_POINTER_RETURN(obj_id, obj);
1304
obj->ownership_track = EINA_TRUE;
1305
EO_OBJ_DONE(obj_id);
1308
if (pd->ext && pd->ext->forwarders)
1310
Efl_Event_Forwarder *forwarder;
1314
EINA_LIST_FOREACH(eina_hash_find(pd->ext->forwarders, it->desc), l, forwarder)
1316
if (!forwarder->source) continue;
1317
if (forwarder->inserted) continue;
1318
efl_event_callback_priority_add(forwarder->source,
1320
forwarder->priority,
1321
_efl_event_forwarder_callback, obj_id);
1322
forwarder->inserted = EINA_TRUE;
1328
unsigned char event_hash;
1330
event_hash = _pointer_hash((uintptr_t) it->desc);
1332
pd->callbacks_mask |= 1ULL << event_hash;
1337
_special_event_count_dec(Eo *obj_id, Efl_Object_Data *pd, const Efl_Callback_Array_Item *it)
1339
EFL_OBJECT_EVENT_CB_DEC(obj_id, it, pd, EFL_EVENT_CALLBACK_ADD)
1340
else EFL_OBJECT_EVENT_CB_DEC(obj_id, it, pd, EFL_EVENT_CALLBACK_DEL)
1341
else EFL_OBJECT_EVENT_CB_DEC(obj_id, it, pd, EFL_EVENT_DEL)
1342
else EFL_OBJECT_EVENT_CB_DEC(obj_id, it, pd, EFL_EVENT_INVALIDATE)
1343
else if (it->desc == EFL_EVENT_NOREF && pd->event_cb_EFL_EVENT_NOREF)
1345
if (efl_event_callback_count(obj_id, EFL_EVENT_NOREF) == 0)
1347
EO_OBJ_POINTER_RETURN(obj_id, obj);
1348
obj->noref_event = EINA_FALSE;
1349
EO_OBJ_DONE(obj_id);
1351
pd->event_cb_EFL_EVENT_NOREF = EINA_FALSE;
1358
_eo_callback_remove(Eo *obj, Efl_Object_Data *pd, Eo_Callback_Description **cb)
1360
Eo_Callback_Description *tmp = *cb;
1361
unsigned int length;
1362
const Efl_Callback_Array_Item *it;
1364
length = pd->callbacks_count - (cb - pd->callbacks);
1366
memmove(cb, cb + 1, (length - 1) * sizeof(Eo_Callback_Description *));
1367
pd->callbacks_count--;
1369
if (_eo_nostep_alloc) pd->callbacks = realloc(pd->callbacks, pd->callbacks_count * sizeof (Eo_Callback_Description*));
1371
if (pd->callbacks_count == 0)
1373
free(pd->callbacks);
1374
pd->callbacks = NULL;
1377
if (tmp->func_array)
1379
for (it = tmp->items.item_array; it->func; it++)
1380
_special_event_count_dec(obj, pd, it);
1382
else _special_event_count_dec(obj, pd, &(tmp->items.item));
1384
_eo_callback_free(tmp);
1389
_eo_callback_remove_all(Efl_Object_Data *pd)
1393
for (i = 0; i < pd->callbacks_count; i++)
1394
_eo_callback_free(pd->callbacks[i]);
1396
eina_freeq_ptr_main_add(pd->callbacks, free, 0);
1397
pd->callbacks = NULL;
1398
pd->callbacks_count = 0;
1399
pd->event_cb_EFL_EVENT_DESTRUCT = EINA_FALSE;
1400
pd->event_cb_EFL_EVENT_CALLBACK_ADD = EINA_FALSE;
1401
pd->event_cb_EFL_EVENT_CALLBACK_DEL = EINA_FALSE;
1402
pd->event_cb_EFL_EVENT_DEL = EINA_FALSE;
1403
pd->event_cb_EFL_EVENT_NOREF = EINA_FALSE;
1404
pd->event_cb_EFL_EVENT_INVALIDATE = EINA_FALSE;
1408
_eo_callbacks_clear(Eo *obj, Efl_Object_Data *pd)
1410
Eo_Callback_Description **itr;
1412
Eina_Bool remove_callbacks;
1413
unsigned int generation_clamp;
1416
if (!pd->need_cleaning) return;
1419
if (pd->event_frame)
1422
remove_callbacks = EINA_FALSE;
1424
generation_clamp = pd->event_frame->generation;
1430
remove_callbacks = EINA_TRUE;
1432
generation_clamp = 0;
1434
pd->need_cleaning = EINA_FALSE;
1437
while (i < pd->callbacks_count)
1439
itr = pd->callbacks + i;
1440
if (remove_callbacks && (*itr)->delete_me)
1442
_eo_callback_remove(obj, pd, itr);
1446
if ((*itr)->generation > generation_clamp)
1447
(*itr)->generation = generation_clamp;
1453
static inline unsigned int
1454
_eo_callback_search_sorted_near(const Efl_Object_Data *pd, const Eo_Callback_Description *look)
1456
unsigned int start, last, middle;
1457
const Eo_Callback_Description *p;
1460
if (pd->callbacks_count == 0) return 0;
1461
else if (pd->callbacks_count == 1) return 0;
1464
last = pd->callbacks_count - 1;
1467
middle = start + ((last - start) / 2);
1468
p = pd->callbacks[middle];
1470
cmp = p->priority - look->priority;
1471
if (cmp == 0) return middle;
1472
else if (cmp > 0) start = middle + 1;
1473
else if (middle > 0) last = middle - 1;
1476
while (start <= last);
1481
_eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1483
Eo_Callback_Description **itr;
1484
unsigned int length, j;
1485
Efl_Event_Callback_Frame *frame;
1488
j = _eo_callback_search_sorted_near(pd, cb);
1490
while ((j < pd->callbacks_count) &&
1491
(pd->callbacks[j]->priority >= cb->priority)) j++;
1494
if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0)
1496
Eo_Callback_Description **tmp;
1497
unsigned int new_len = (pd->callbacks_count | 0xF) + 1;
1499
if (_eo_nostep_alloc) new_len = pd->callbacks_count + 1;
1501
tmp = realloc(pd->callbacks,
1502
new_len * sizeof(Eo_Callback_Description *));
1503
if (EINA_UNLIKELY(!tmp)) return;
1504
pd->callbacks = tmp;
1509
itr = pd->callbacks + j;
1510
length = pd->callbacks_count - j;
1511
if (length > 0) memmove(itr + 1, itr,
1512
length * sizeof(Eo_Callback_Description *));
1515
pd->callbacks_count++;
1518
for (frame = pd->event_frame; frame; frame = frame->next)
1520
if ((itr - pd->callbacks) < (ptrdiff_t)frame->idx)
1521
frame->inserted_before++;
1525
static unsigned short
1526
_efl_event_generation(Efl_Object_Data *pd)
1528
if (!pd->event_frame) return 0;
1530
return ((Efl_Event_Callback_Frame*)pd->event_frame)->generation;
1533
EOLIAN static Eina_Bool
1534
_efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd,
1535
const Efl_Event_Description *desc,
1536
Efl_Callback_Priority priority,
1538
const void *user_data)
1540
const Efl_Callback_Array_Item_Full arr[] =
1541
{ {desc, priority, func, (void *)user_data}, {NULL, 0, NULL, NULL}};
1542
Eo_Callback_Description *cb = _eo_callback_new();
1544
unsigned int idx, r = 0, entries = 0;
1546
for (idx = pd->callbacks_count ; idx > 0; idx--)
1548
Eo_Callback_Description **cb;
1550
cb = pd->callbacks + idx - 1;
1551
if (!(*cb)->func_array)
1553
if (((*cb)->items.item.desc == desc) &&
1554
((*cb)->items.item.func == func) &&
1555
((*cb)->priority == priority) &&
1556
((*cb)->generation == _efl_event_generation(pd)))
1561
if (r > 1) INF("Object '%s' got %i callback with event '%s' registered.",
1562
efl_debug_name_get(obj), r, desc->name);
1563
if (entries > 10) INF("Object '%s' got %i callbacks.",
1564
efl_debug_name_get(obj), entries);
1568
if (EINA_UNLIKELY(!cb || !desc || !func)) goto err;
1569
cb->items.item.desc = desc;
1570
cb->items.item.func = func;
1571
cb->func_data = (void *)user_data;
1572
cb->priority = priority;
1573
cb->generation = _efl_event_generation(pd);
1574
if (cb->generation) pd->need_cleaning = EINA_TRUE;
1576
_eo_callbacks_sorted_insert(pd, cb);
1577
_special_event_count_inc(obj, pd, &(cb->items.item));
1579
if (pd->event_cb_EFL_EVENT_CALLBACK_ADD)
1580
efl_event_callback_call(obj, EFL_EVENT_CALLBACK_ADD, (void *)arr);
1585
ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func);
1586
_eo_callback_free(cb);
1590
EO_API EFL_FUNC_BODYV(efl_event_callback_priority_add,
1591
Eina_Bool, 0, EFL_FUNC_CALL(desc, priority, cb, data),
1592
const Efl_Event_Description *desc,
1593
Efl_Callback_Priority priority,
1594
Efl_Event_Cb cb, const void *data);
1597
_efl_object_event_callback_clean(Eo *obj, Efl_Object_Data *pd,
1598
const Efl_Callback_Array_Item_Full *array,
1599
Eo_Callback_Description **cb)
1601
(*cb)->delete_me = EINA_TRUE;
1602
if (pd->event_frame)
1603
pd->need_cleaning = EINA_TRUE;
1605
_eo_callback_remove(obj, pd, cb);
1606
if (pd->event_cb_EFL_EVENT_CALLBACK_DEL)
1607
efl_event_callback_call(obj, EFL_EVENT_CALLBACK_DEL, (void *)array);
1610
EOLIAN static Eina_Bool
1611
_efl_object_event_callback_del(Eo *obj, Efl_Object_Data *pd,
1612
const Efl_Event_Description *desc,
1614
const void *user_data)
1616
Eo_Callback_Description **cb;
1619
for (cb = pd->callbacks, i = 0;
1620
i < pd->callbacks_count;
1623
if (!(*cb)->delete_me &&
1624
((*cb)->items.item.desc == desc) &&
1625
((*cb)->items.item.func == func) &&
1626
((*cb)->func_data == user_data))
1628
const Efl_Callback_Array_Item_Full arr[] =
1629
{ {desc, (*cb)->priority, func, (*cb)->func_data}, {NULL, 0, NULL, NULL}};
1631
_efl_object_event_callback_clean(obj, pd, arr, cb);
1636
DBG("Callback of object %p with function %p and data %p not found.", obj, func, user_data);
1640
EO_API EFL_FUNC_BODYV(efl_event_callback_del,
1641
Eina_Bool, 0, EFL_FUNC_CALL(desc, func, user_data),
1642
const Efl_Event_Description *desc,
1643
Efl_Event_Cb func, const void *user_data);
1645
EOLIAN static Eina_Bool
1646
_efl_object_event_callback_array_priority_add(Eo *obj, Efl_Object_Data *pd,
1647
const Efl_Callback_Array_Item *array,
1648
Efl_Callback_Priority priority,
1649
const void *user_data)
1651
Eo_Callback_Description *cb = _eo_callback_new();
1652
const Efl_Callback_Array_Item *it;
1653
unsigned int num, i;
1654
Efl_Callback_Array_Item_Full *ev_array;
1656
const Efl_Callback_Array_Item *prev;
1657
unsigned int idx, r = 0, entries = 0;
1661
if (!cb || !array) goto err;
1664
for (it = prev + 1; prev->func && it->func; it++, prev++)
1666
if (efl_callbacks_cmp(prev, it) > 0)
1668
ERR("Trying to insert a non sorted array callbacks (%p).", array);
1669
_eo_callback_free(cb);
1675
cb->func_data = (void *) user_data;
1676
cb->priority = priority;
1677
cb->items.item_array = array;
1678
cb->func_array = EINA_TRUE;
1679
cb->generation = _efl_event_generation(pd);
1680
if (!!cb->generation) pd->need_cleaning = EINA_TRUE;
1683
for (idx = pd->callbacks_count ; idx > 0; idx--)
1685
Eo_Callback_Description **cb;
1687
cb = pd->callbacks + idx - 1;
1688
if ((*cb)->func_array)
1690
if (((*cb)->items.item_array == array) &&
1691
((*cb)->priority == priority) &&
1692
((*cb)->generation == _efl_event_generation(pd)))
1699
Eina_Strbuf *buf = eina_strbuf_new();
1700
Eina_Bool first = EINA_TRUE;
1702
for (it = array; it->func; it++)
1704
if (first) eina_strbuf_append(buf, it->desc->name);
1705
else eina_strbuf_append_printf(buf, ", %s", it->desc->name);
1708
INF("Object '%s' got %i callback with events array %s registered.",
1709
efl_debug_name_get(obj), r, eina_strbuf_string_get(buf));
1710
eina_strbuf_free(buf);
1712
if (entries > 10) INF("Object '%s' got %i callbacks.",
1713
efl_debug_name_get(obj), entries);
1716
_eo_callbacks_sorted_insert(pd, cb);
1717
for (it = cb->items.item_array; it->func; it++)
1718
_special_event_count_inc(obj, pd, it);
1721
for (it = cb->items.item_array; it->func; it++) num++;
1722
ev_array = alloca((num + 1) * sizeof(Efl_Callback_Array_Item_Full));
1723
for (i = 0, it = cb->items.item_array; it->func; it++, i++)
1725
ev_array[i].desc = cb->items.item_array[i].desc;
1726
ev_array[i].priority = cb->priority;
1727
ev_array[i].func = cb->items.item_array[i].func;
1728
ev_array[i].user_data = cb->func_data;
1730
ev_array[i].desc = NULL;
1731
ev_array[i].priority = 0;
1732
ev_array[i].func = NULL;
1733
ev_array[i].user_data = NULL;
1734
if (pd->event_cb_EFL_EVENT_CALLBACK_ADD)
1735
efl_event_callback_call(obj, EFL_EVENT_CALLBACK_ADD, ev_array);
1740
ERR("Tried adding array of callbacks with invalid values: cb: %p array: %p.", cb, array);
1741
_eo_callback_free(cb);
1745
EO_API EFL_FUNC_BODYV(efl_event_callback_array_priority_add,
1746
Eina_Bool, 0, EFL_FUNC_CALL(array, priority, data),
1747
const Efl_Callback_Array_Item *array,
1748
Efl_Callback_Priority priority, const void *data);
1750
EOLIAN static Eina_Bool
1751
_efl_object_event_callback_array_del(Eo *obj, Efl_Object_Data *pd,
1752
const Efl_Callback_Array_Item *array,
1753
const void *user_data)
1755
Eo_Callback_Description **cb;
1758
for (cb = pd->callbacks, j = 0;
1759
j < pd->callbacks_count;
1762
if (!(*cb)->delete_me &&
1763
((*cb)->items.item_array == array) &&
1764
((*cb)->func_data == user_data))
1766
const Efl_Callback_Array_Item *it;
1767
unsigned int num, i;
1768
Efl_Callback_Array_Item_Full *ev_array;
1771
for (it = (*cb)->items.item_array; it->func; it++) num++;
1772
ev_array = alloca((num + 1) * sizeof(Efl_Callback_Array_Item_Full));
1773
for (i = 0, it = (*cb)->items.item_array; it->func; it++, i++)
1775
ev_array[i].desc = (*cb)->items.item_array[i].desc;
1776
ev_array[i].priority = (*cb)->priority;
1777
ev_array[i].func = (*cb)->items.item_array[i].func;
1778
ev_array[i].user_data = (*cb)->func_data;
1780
ev_array[i].desc = NULL;
1781
ev_array[i].priority = 0;
1782
ev_array[i].func = NULL;
1783
ev_array[i].user_data = NULL;
1784
_efl_object_event_callback_clean(obj, pd, ev_array, cb);
1789
DBG("Callback of object %p with function array %p and data %p not found.", obj, array, user_data);
1793
EO_API EFL_FUNC_BODYV(efl_event_callback_array_del,
1794
Eina_Bool, 0, EFL_FUNC_CALL(array, user_data),
1795
const Efl_Callback_Array_Item *array,
1796
const void *user_data);
1798
typedef struct _Efl_Future_Scheduler Efl_Future_Scheduler;
1799
typedef struct _Efl_Future_Scheduler_Entry Efl_Future_Scheduler_Entry;
1801
struct _Efl_Future_Scheduler
1803
Eina_Future_Scheduler scheduler;
1805
const Efl_Callback_Array_Item *array;
1810
Eina_Bool listener : 1;
1813
struct _Efl_Future_Scheduler_Entry
1815
Eina_Future_Schedule_Entry base;
1816
Eina_Future_Scheduler_Cb cb;
1817
Eina_Future *future;
1821
static Eina_Trash *schedulers_trash = NULL;
1822
static unsigned char schedulers_count = 0;
1825
_future_scheduler_cleanup(Efl_Object_Data *pd)
1827
if (eina_hash_population(pd->ext->schedulers)) return ;
1829
eina_hash_free(pd->ext->schedulers);
1830
pd->ext->schedulers = NULL;
1831
_efl_object_extension_noneed(pd);
1835
_futures_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED)
1837
Efl_Future_Scheduler *sched = data;
1838
Eina_List *entries = sched->futures;
1839
Efl_Future_Scheduler_Entry *entry;
1841
sched->futures = NULL;
1843
efl_event_callback_array_del((Eo *) sched->self, sched->array, sched);
1844
sched->listener = EINA_FALSE;
1847
EINA_LIST_FREE(entries, entry)
1849
entry->cb(entry->future, entry->value);
1850
eina_mempool_free(_efl_future_scheduler_entry_mempool, entry);
1855
_futures_cancel_cb(void *data)
1857
Efl_Future_Scheduler *sched = data;
1858
Eina_List *entries = sched->futures;
1859
Efl_Future_Scheduler_Entry *entry;
1861
efl_event_callback_array_del((Eo *) sched->self, sched->array, sched);
1862
sched->listener = EINA_FALSE;
1863
sched->futures = NULL;
1865
EINA_LIST_FREE(entries, entry)
1867
eina_future_cancel(entry->future);
1868
eina_value_flush(&entry->value);
1869
eina_mempool_free(_efl_future_scheduler_entry_mempool, entry);
1872
if (schedulers_count > 8)
1878
eina_trash_push(&schedulers_trash, sched);
1883
static Eina_Future_Schedule_Entry *
1884
_efl_event_future_scheduler(Eina_Future_Scheduler *s_sched,
1885
Eina_Future_Scheduler_Cb cb,
1886
Eina_Future *future,
1889
Efl_Future_Scheduler *sched = (Efl_Future_Scheduler *)s_sched;
1890
Efl_Future_Scheduler_Entry *entry;
1892
entry = eina_mempool_malloc(_efl_future_scheduler_entry_mempool, sizeof(*entry));
1893
EINA_SAFETY_ON_NULL_RETURN_VAL(entry, NULL);
1895
entry->base.scheduler = &sched->scheduler;
1897
entry->future = future;
1898
entry->value = value;
1900
if (!sched->listener)
1902
efl_event_callback_array_add((Eo *) sched->self, sched->array, sched);
1903
sched->listener = EINA_TRUE;
1906
sched->futures = eina_list_append(sched->futures, entry);
1907
return &entry->base;
1911
_efl_event_future_recall(Eina_Future_Schedule_Entry *s_entry)
1913
Efl_Future_Scheduler_Entry *entry = (Efl_Future_Scheduler_Entry *)s_entry;
1914
Efl_Future_Scheduler *sched;
1917
sched = (Efl_Future_Scheduler *) entry->base.scheduler;
1919
lookup = eina_list_data_find_list(sched->futures, entry);
1920
if (!lookup) return;
1922
sched->futures = eina_list_remove_list(sched->futures, lookup);
1923
if (!sched->futures)
1925
Efl_Object_Data *pd = efl_data_scope_get(sched->self, EFL_OBJECT_CLASS);
1927
_future_scheduler_cleanup(pd);
1930
eina_value_flush(&entry->value);
1931
eina_mempool_free(_efl_future_scheduler_entry_mempool, entry);
1934
EOLIAN static Eina_Future_Scheduler *
1935
_efl_object_event_future_scheduler_get(const Eo *obj, Efl_Object_Data *pd, Efl_Callback_Array_Item *array)
1937
Efl_Object_Extension *ext;
1938
Efl_Future_Scheduler *sched;
1941
if (!array) return NULL;
1943
ext = _efl_object_extension_need(pd);
1944
EINA_SAFETY_ON_NULL_RETURN_VAL(ext, NULL);
1947
if (!ext->schedulers) ext->schedulers = eina_hash_pointer_new(_futures_cancel_cb);
1948
sched = eina_hash_find(ext->schedulers, &array);
1949
if (sched) return &sched->scheduler;
1953
for (i = 0; array[i].desc; i++)
1954
array[i].func = _futures_dispatch_cb;
1956
if (schedulers_count)
1959
sched = eina_trash_pop(&schedulers_trash);
1965
sched = calloc(1, sizeof (Efl_Future_Scheduler));
1967
sched->scheduler.schedule = _efl_event_future_scheduler;
1968
sched->scheduler.recall = _efl_event_future_recall;
1969
sched->array = array;
1972
eina_hash_add(ext->schedulers, &array, sched);
1974
return &sched->scheduler;
1977
EO_API EFL_FUNC_BODYV_CONST(efl_event_future_scheduler_get,
1978
Eina_Future_Scheduler *, 0, EFL_FUNC_CALL(array),
1979
Efl_Callback_Array_Item *array);
1982
_efl_object_event_callback_count(const Eo *obj EINA_UNUSED,
1983
Efl_Object_Data *pd,
1984
const Efl_Event_Description *desc)
1989
for (idx = pd->callbacks_count ; idx > 0; idx--)
1991
Eo_Callback_Description **cb;
1993
cb = pd->callbacks + idx - 1;
1995
if ((*cb)->func_array)
1997
const Efl_Callback_Array_Item *it;
1999
for (it = (*cb)->items.item_array; it->func; it++)
2001
if (it->desc > desc) break;
2002
if (it->desc == desc) r++;
2007
if ((*cb)->items.item.desc == desc) r++;
2013
EO_API EFL_FUNC_BODYV_CONST(efl_event_callback_count,
2014
unsigned int, 0, EFL_FUNC_CALL(desc),
2015
const Efl_Event_Description *desc);
2018
_cb_desc_match(const Efl_Event_Description *a, const Efl_Event_Description *b, Eina_Bool legacy_compare)
2021
if (!EINA_UNLIKELY(legacy_compare && (_legacy_event_desc_is(a) != _legacy_event_desc_is(b))))
2023
return !strcmp(a->name, b->name);
2026
#define EFL_OBJECT_EVENT_CALLBACK_BLOCK(Pd, Desc, Event, Need_Hash) \
2027
if (Desc == Event) \
2029
if (!(Pd->event_cb_##Event)) return EINA_TRUE; \
2030
Need_Hash = EINA_FALSE; \
2033
static inline Eina_Bool
2034
_event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
2035
const Efl_Event_Description *desc,
2037
Eina_Bool legacy_compare)
2039
Eo_Callback_Description **cb;
2040
Efl_Event_Callback_Frame *restart_lookup = NULL;
2043
Eina_Bool callback_already_stopped, ret;
2044
Efl_Event_Callback_Frame frame = {
2048
.inserted_before = 0,
2051
Eina_Bool need_hash = EINA_TRUE;
2053
if (pd->callbacks_count == 0) return EINA_TRUE;
2054
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_CALLBACK_ADD, need_hash)
2055
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_CALLBACK_DEL, need_hash)
2056
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_DEL, need_hash)
2057
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_INVALIDATE, need_hash)
2058
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_NOREF, need_hash)
2059
else EFL_OBJECT_EVENT_CALLBACK_BLOCK(pd, desc, EFL_EVENT_DESTRUCT, need_hash)
2061
if (EINA_LIKELY(!legacy_compare && need_hash))
2063
unsigned char event_hash;
2065
event_hash = _pointer_hash((uintptr_t) desc);
2066
if (!(pd->callbacks_mask & (1ULL << event_hash)))
2070
if (pd->event_frame)
2071
frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1;
2073
EVENT_STACK_PUSH(pd, &frame);
2075
callback_already_stopped = pd->callback_stopped;
2076
pd->callback_stopped = EINA_FALSE;
2081
ev.info = event_info;
2085
if (desc->restart) goto restart;
2086
else idx = pd->callbacks_count;
2089
for (; idx > 0; idx--)
2092
cb = pd->callbacks + idx - 1;
2093
if (!(*cb)->delete_me)
2095
if ((*cb)->generation >= frame.generation)
2098
if ((*cb)->func_array)
2100
const Efl_Callback_Array_Item *it;
2102
for (it = (*cb)->items.item_array; it->func; it++)
2105
if (!legacy_compare &&
2106
((const unsigned char *) desc < (const unsigned char *) it->desc))
2108
if (!_cb_desc_match(it->desc, desc, legacy_compare))
2110
if (!it->desc->unfreezable &&
2111
(event_freeze_count || pd->event_freeze_count))
2114
it->func((void *) (*cb)->func_data, &ev);
2116
if (pd->callback_stopped)
2125
if (!_cb_desc_match((*cb)->items.item.desc, desc, legacy_compare))
2127
if (!(*cb)->items.item.desc->unfreezable &&
2128
(event_freeze_count || pd->event_freeze_count))
2131
(*cb)->items.item.func((void *) (*cb)->func_data, &ev);
2133
if (pd->callback_stopped)
2144
idx = frame.idx + frame.inserted_before;
2145
frame.inserted_before = 0;
2152
if (restart_lookup) restart_lookup->idx = 1;
2154
EVENT_STACK_POP(pd);
2156
_eo_callbacks_clear(obj_id, pd);
2158
pd->callback_stopped = callback_already_stopped;
2163
for (restart_lookup = frame.next; restart_lookup; restart_lookup = restart_lookup->next)
2165
if (restart_lookup->desc == desc) break;
2169
if (restart_lookup) {
2170
idx = restart_lookup->idx - 1;
2176
idx = pd->callbacks_count;
2181
EOLIAN static Eina_Bool
2182
_efl_object_event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
2183
const Efl_Event_Description *desc,
2186
return _event_callback_call(obj_id, pd, desc, event_info, EINA_FALSE);
2189
EO_API EFL_FUNC_BODYV(efl_event_callback_call,
2190
Eina_Bool, 0, EFL_FUNC_CALL(desc, event_info),
2191
const Efl_Event_Description *desc, void *event_info);
2193
EOLIAN static Eina_Bool
2194
_efl_object_event_callback_legacy_call(Eo *obj_id, Efl_Object_Data *pd,
2195
const Efl_Event_Description *desc,
2198
return _event_callback_call(obj_id, pd, desc, event_info, EINA_TRUE);
2201
EO_API EFL_FUNC_BODYV(efl_event_callback_legacy_call,
2202
Eina_Bool, 0, EFL_FUNC_CALL(desc, event_info),
2203
const Efl_Event_Description *desc, void *event_info);
2206
_efl_object_event_callback_stop(Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
2208
pd->callback_stopped = EINA_TRUE;
2212
_efl_event_forwarder_callback(void *data, const Efl_Event *event)
2214
Eo *new_obj = (Eo *) data;
2215
Eina_Bool ret = EINA_FALSE;
2217
ret = efl_event_callback_call(new_obj, event->desc, event->info);
2220
efl_event_callback_stop(event->object);
2225
_forwarders_list_clean(void *data)
2227
Efl_Event_Forwarder *forwarder;
2228
Eina_List *l = data;
2230
EINA_LIST_FREE(l, forwarder)
2232
if (forwarder->source)
2234
if (forwarder->inserted)
2235
efl_event_callback_del(forwarder->source,
2237
_efl_event_forwarder_callback,
2238
forwarder->new_obj);
2239
efl_wref_del(forwarder->source, &forwarder->source);
2246
_efl_object_event_callback_forwarder_priority_add(Eo *obj, Efl_Object_Data *pd EINA_UNUSED,
2247
const Efl_Event_Description *desc,
2251
EO_OBJ_POINTER_RETURN(new_obj, new_data);
2252
EO_OBJ_DONE(new_obj);
2253
Efl_Event_Forwarder *forwarder;
2254
Efl_Object_Extension *ext;
2255
Efl_Object_Data *dpd;
2258
dpd = efl_data_scope_safe_get(new_obj, EFL_OBJECT_CLASS);
2259
EINA_SAFETY_ON_NULL_RETURN(dpd);
2261
ext = _efl_object_extension_need(dpd);
2262
EINA_SAFETY_ON_NULL_RETURN(ext);
2265
EINA_LIST_FOREACH(eina_hash_find(ext->forwarders, desc), l, forwarder)
2267
if (forwarder->desc == desc &&
2268
forwarder->new_obj == new_obj &&
2269
forwarder->source == obj)
2271
ERR("Forwarder added on '%s' for event '%s' toward '%s' has already been set.\n",
2272
efl_debug_name_get(obj), desc->name, efl_debug_name_get(new_obj));
2277
forwarder = malloc(sizeof (Efl_Event_Forwarder));
2278
EINA_SAFETY_ON_NULL_RETURN(forwarder);
2279
forwarder->desc = desc;
2280
forwarder->priority = priority;
2281
forwarder->new_obj = new_obj;
2282
efl_wref_add(obj, &forwarder->source);
2284
if (efl_event_callback_count(new_obj, desc) > 0)
2286
efl_event_callback_priority_add(obj, desc, priority, _efl_event_forwarder_callback, new_obj);
2287
forwarder->inserted = EINA_TRUE;
2291
forwarder->inserted = EINA_FALSE;
2294
if (!ext->forwarders)
2295
ext->forwarders = eina_hash_pointer_new(_forwarders_list_clean);
2296
eina_hash_list_direct_append(ext->forwarders, forwarder->desc, forwarder);
2300
_efl_object_event_callback_forwarder_del(Eo *obj, Efl_Object_Data *pd EINA_UNUSED,
2301
const Efl_Event_Description *desc,
2304
EO_OBJ_POINTER_RETURN(new_obj, new_data);
2305
EO_OBJ_DONE(new_obj);
2306
Efl_Event_Forwarder *forwarder;
2307
Efl_Object_Extension *ext;
2308
Efl_Object_Data *dpd;
2309
Eina_List *l, *tofree = NULL;
2311
dpd = efl_data_scope_safe_get(new_obj, EFL_OBJECT_CLASS);
2317
EINA_LIST_FOREACH(eina_hash_find(ext->forwarders, desc), l, forwarder)
2320
if (forwarder->source == obj || forwarder->source == NULL)
2321
tofree = eina_list_append(tofree, forwarder);
2324
EINA_LIST_FREE(tofree, forwarder)
2326
if (forwarder->source)
2328
if (forwarder->inserted)
2329
efl_event_callback_del(obj, desc, _efl_event_forwarder_callback, new_obj);
2330
efl_wref_del(obj, &forwarder->source);
2332
eina_hash_list_remove(ext->forwarders, desc, forwarder);
2338
_efl_object_event_freeze(Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
2340
pd->event_freeze_count++;
2344
_efl_object_event_thaw(Eo *obj, Efl_Object_Data *pd)
2346
if (pd->event_freeze_count > 0)
2348
pd->event_freeze_count--;
2352
ERR("Events for object %p have already been thawed.", obj);
2357
_efl_object_event_freeze_count_get(const Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
2359
return pd->event_freeze_count;
2363
_efl_object_event_global_freeze(void)
2365
event_freeze_count++;
2369
_efl_object_event_global_thaw(void)
2371
if (event_freeze_count > 0)
2373
event_freeze_count--;
2377
ERR("Global events have already been thawed.");
2382
_efl_object_event_global_freeze_count_get(void)
2384
return event_freeze_count;
2387
EOLIAN static Eina_Bool
2388
_efl_object_composite_attach(Eo *parent_id, Efl_Object_Data *pd EINA_UNUSED, Eo *comp_obj_id)
2390
Efl_Object_Optional *opt;
2391
Eo *emb_obj_id = NULL;
2393
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
2394
EO_OBJ_POINTER_GOTO(parent_id, parent, err_parent);
2401
EINA_LIST_FOREACH(parent->opt->composite_objects, itr, emb_obj_id)
2403
EO_OBJ_POINTER_GOTO(emb_obj_id, emb_obj, err_klass);
2404
if (EINA_UNLIKELY(emb_obj->klass == comp_obj->klass)) goto err_klass;
2409
Efl_Object_Data *comp_pd = efl_data_scope_get(comp_obj_id, EFL_OBJECT_CLASS);
2411
if (efl_composite_part_is(comp_obj_id))
2412
efl_composite_detach(comp_pd->ext->composite_parent, comp_obj_id);
2415
_efl_object_extension_need(comp_pd);
2416
comp_pd->ext->composite_parent = parent_id;
2418
opt = EO_OPTIONAL_COW_WRITE(parent);
2419
opt->composite_objects = eina_list_prepend(opt->composite_objects, comp_obj_id);
2420
EO_OPTIONAL_COW_END(opt, parent);
2422
if (emb_obj_id) EO_OBJ_DONE(emb_obj_id);
2423
EO_OBJ_DONE(parent_id);
2424
EO_OBJ_DONE(comp_obj_id);
2428
if (emb_obj_id) EO_OBJ_DONE(emb_obj_id);
2429
EO_OBJ_DONE(parent_id);
2431
EO_OBJ_DONE(comp_obj_id);
2435
EOLIAN static Eina_Bool
2436
_efl_object_composite_detach(Eo *parent_id, Efl_Object_Data *pd EINA_UNUSED, Eo *comp_obj_id)
2438
Efl_Object_Optional *opt;
2440
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
2441
EO_OBJ_POINTER_GOTO(parent_id, parent, err_parent);
2444
if (!efl_composite_part_is(comp_obj_id)) goto err_part;
2446
opt = EO_OPTIONAL_COW_WRITE(parent);
2447
opt->composite_objects = eina_list_remove(opt->composite_objects, comp_obj_id);
2448
EO_OPTIONAL_COW_END(opt, parent);
2452
Efl_Object_Data *comp_pd = efl_data_scope_get(comp_obj_id, EFL_OBJECT_CLASS);
2453
comp_pd->ext->composite_parent = NULL;
2454
_efl_object_extension_noneed(comp_pd);
2457
EO_OBJ_DONE(parent_id);
2458
EO_OBJ_DONE(comp_obj_id);
2462
EO_OBJ_DONE(parent_id);
2464
EO_OBJ_DONE(comp_obj_id);
2468
EOLIAN static Eina_Bool
2469
_efl_object_composite_part_is(Eo *comp_obj_id EINA_UNUSED, Efl_Object_Data *pd)
2471
return pd->ext && pd->ext->composite_parent;
2476
efl_dbg_info_free(Efl_Dbg_Info *info)
2478
eina_value_flush(&(info->value));
2479
eina_freeq_ptr_main_add(info, free, sizeof(*info));
2483
_eo_dbg_info_setup(const Eina_Value_Type *type, void *mem)
2485
memset(mem, 0, type->value_size);
2490
_eo_dbg_info_flush(const Eina_Value_Type *type EINA_UNUSED, void *_mem)
2492
Efl_Dbg_Info *mem = *(Efl_Dbg_Info **) _mem;
2493
eina_stringshare_del(mem->name);
2494
eina_value_flush(&(mem->value));
2495
eina_freeq_ptr_main_add(mem, free, sizeof(*mem));
2500
_eo_dbg_info_copy(const Eina_Value_Type *type EINA_UNUSED, const void *_src, void *_dst)
2502
const Efl_Dbg_Info **src = (const Efl_Dbg_Info **) _src;
2503
Efl_Dbg_Info **dst = _dst;
2505
*dst = calloc(1, sizeof(Efl_Dbg_Info));
2506
if (!*dst) return EINA_FALSE;
2507
(*dst)->name = eina_stringshare_ref((*src)->name);
2508
eina_value_copy(&((*src)->value), &((*dst)->value));
2513
_eo_dbg_info_convert_to(const Eina_Value_Type *type EINA_UNUSED, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2516
const Efl_Dbg_Info **src = (const Efl_Dbg_Info **) type_mem;
2517
if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
2518
convert == EINA_VALUE_TYPE_STRING)
2521
const char *other_mem;
2522
char *inner_val = eina_value_to_string(&(*src)->value);
2523
other_mem = inner_val;
2524
ret = eina_value_type_pset(convert, convert_mem, &other_mem);
2525
eina_freeq_ptr_main_add(inner_val, free, 0);
2529
eina_error_set(EINA_ERROR_VALUE_FAILED);
2534
_eo_dbg_info_pset(const Eina_Value_Type *type EINA_UNUSED, void *_mem, const void *_ptr)
2536
Efl_Dbg_Info **mem = _mem;
2537
if (*mem) free(*mem);
2538
*mem = (void *) _ptr;
2543
_eo_dbg_info_pget(const Eina_Value_Type *type EINA_UNUSED, const void *_mem, void *_ptr)
2545
Efl_Dbg_Info **ptr = _ptr;
2546
*ptr = (void *) _mem;
2550
static const Eina_Value_Type _EFL_DBG_INFO_TYPE = {
2551
EINA_VALUE_TYPE_VERSION,
2552
sizeof(Efl_Dbg_Info *),
2558
_eo_dbg_info_convert_to,
2565
EO_API const Eina_Value_Type *EFL_DBG_INFO_TYPE = &_EFL_DBG_INFO_TYPE;
2571
#define MY_CLASS EFL_OBJECT_CLASS
2574
_efl_future_cb(void *data, const Eina_Value value, const Eina_Future *dead_future)
2576
Efl_Future_Pending *pending = data;
2577
Eina_Value ret = value;
2579
Efl_Object_Data *pd;
2581
EINA_SAFETY_ON_NULL_GOTO(pending, err);
2583
pd = efl_data_scope_get(o, EFL_OBJECT_CLASS);
2584
EINA_SAFETY_ON_NULL_GOTO(pd, err);
2586
pd->pending_futures = eina_inlist_remove(pd->pending_futures,
2587
EINA_INLIST_GET(pending));
2589
EASY_FUTURE_DISPATCH(ret, value, dead_future, &pending->desc, (void*) o, (void*) pending->desc.data);
2591
_efl_pending_future_free(pending);
2596
eina_value_setup(&ret, EINA_VALUE_TYPE_ERROR);
2597
eina_value_set(&ret, ENOMEM);
2601
EO_API Eina_Future_Desc
2602
efl_future_cb_from_desc(const Eo *o, const Efl_Future_Cb_Desc desc)
2604
Efl_Future_Pending *pending = NULL;
2605
Eina_Future **storage = NULL;
2606
Efl_Object_Data *pd;
2607
Eina_Bool invalidate;
2609
EINA_SAFETY_ON_NULL_GOTO(o, end);
2610
pd = efl_data_scope_get(o, EFL_OBJECT_CLASS);
2611
EINA_SAFETY_ON_NULL_GOTO(pd, end);
2612
EO_OBJ_POINTER_GOTO(o, eo_obj, end);
2613
invalidate = eo_obj->invalidate;
2615
EINA_SAFETY_ON_TRUE_GOTO(invalidate, end);
2616
pending = _efl_pending_future_new();
2617
EINA_SAFETY_ON_NULL_GOTO(pending, end);
2618
memcpy(&pending->desc, &desc, sizeof(Efl_Future_Cb_Desc));
2620
pending->future = NULL;
2621
if (!pending->desc.storage) pending->desc.storage = &pending->future;
2622
pd->pending_futures = eina_inlist_append(pd->pending_futures,
2623
EINA_INLIST_GET(pending));
2624
storage = pending->desc.storage;
2626
return (Eina_Future_Desc){ .cb = _efl_future_cb, .data = pending, .storage = storage };
2630
efl_future_chain_array(Eo *obj,
2632
const Efl_Future_Cb_Desc descs[])
2635
Eina_Future *f = prev;
2637
for (i = 0; descs[i].success || descs[i].error || descs[i].free || descs[i].success_type; i++)
2639
Eina_Future_Desc eina_desc = efl_future_cb_from_desc(obj, descs[i]);
2640
f = eina_future_then_from_desc(f, eina_desc);
2641
EINA_SAFETY_ON_NULL_GOTO(f, err);
2652
for (i = i + 1; descs[i].error || descs[i].free; i++)
2656
Eina_Value r = descs[i].error(obj, (void*) descs[i].data, ENOMEM);
2657
eina_value_flush(&r);
2659
if (descs[i].free) descs[i].free(obj, (void*) descs[i].data, NULL);
2665
_efl_object_constructor(Eo *obj, Efl_Object_Data *pd EINA_UNUSED)
2667
DBG("%p - %s.", obj, efl_class_name_get(obj));
2669
_eo_condtor_done(obj);
2675
_efl_object_destructor(Eo *obj, Efl_Object_Data *pd)
2677
_Eo_Object *obj_child;
2679
Efl_Object_Extension *ext;
2680
_Eo_Object *obj_data2 = NULL;
2682
DBG("%p - %s.", obj, efl_class_name_get(obj));
2690
if (pd->children) goto children;
2697
EO_OBJ_POINTER_RETURN(obj, obj_data);
2698
obj_data2 = obj_data;
2699
if (obj_data->opt->composite_objects) goto composite_obj;
2704
if (pd->ext && pd->ext->composite_parent)
2705
efl_composite_detach(pd->ext->composite_parent, obj);
2709
if (pd->parent) goto err_parent;
2715
if (EINA_UNLIKELY(pd->event_cb_EFL_EVENT_DESTRUCT))
2716
_event_callback_call(obj, pd, EFL_EVENT_DESTRUCT, NULL, EINA_FALSE);
2719
_eo_generic_data_del_all(obj, pd);
2720
_eo_callback_remove_all(pd);
2730
_eo_condtor_done(obj);
2733
eina_stringshare_del(ext->name);
2735
eina_stringshare_del(ext->comment);
2736
ext->comment = NULL;
2737
_efl_object_extension_noneed(pd);
2738
_eo_condtor_done(obj);
2742
ERR("Object %p of type '%s' is still holding child at time of destruction.\n",
2743
obj, efl_class_name_get(obj));
2744
EINA_INLIST_FOREACH_SAFE(pd->children, l, obj_child)
2748
child = _eo_obj_id_get(obj_child);
2749
efl_parent_set(child, NULL);
2755
Eina_List *itr, *next;
2758
EINA_LIST_FOREACH_SAFE(obj_data2->opt->composite_objects, itr, next, emb_obj_id)
2760
efl_composite_detach(obj, emb_obj_id);
2763
goto composite_obj_back;
2766
if (EINA_LIKELY(!pd->allow_parent_unref))
2767
ERR("Object '%p' of type '%s' still has a parent at the time of destruction.", obj, efl_class_name_get(obj));
2768
efl_parent_set(obj, NULL);
2769
goto err_parent_back;
2773
_efl_object_allow_parent_unref_set(Eo *obj_id, Efl_Object_Data *pd, Eina_Bool allow)
2775
EO_OBJ_POINTER_RETURN(obj_id, obj);
2776
obj->allow_parent_unref = !!allow;
2777
pd->allow_parent_unref = !!allow;
2778
EO_OBJ_DONE(obj_id);
2781
EOLIAN static Eina_Bool
2782
_efl_object_allow_parent_unref_get(const Eo *obj_id EINA_UNUSED, Efl_Object_Data *pd)
2784
return pd->allow_parent_unref;
2788
___efl_auto_unref_set(Eo *obj_id, Eina_Bool enable)
2791
EO_OBJ_POINTER_RETURN(obj_id, obj);
2792
obj->auto_unref = enable ? 1 : 0;
2793
EO_OBJ_DONE(obj_id);
2797
_efl_object_finalize(Eo *obj, Efl_Object_Data *pd EINA_UNUSED)
2803
_efl_object_class_constructor(Efl_Class *klass EINA_UNUSED)
2805
event_freeze_count = 0;
2806
_legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb);
2808
_eo_callback_mempool =
2809
eina_mempool_add("chained_mempool", NULL, NULL,
2810
sizeof(Eo_Callback_Description), 256);
2812
_efl_pending_future_mempool =
2813
eina_mempool_add("chained_mempool", NULL, NULL,
2814
sizeof(Efl_Future_Pending), 256);
2816
_efl_future_scheduler_entry_mempool =
2817
eina_mempool_add("chained_mempool", NULL, NULL,
2818
sizeof(Efl_Future_Scheduler_Entry), 256);
2820
_eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC");
2824
_efl_object_class_destructor(Efl_Class *klass EINA_UNUSED)
2826
eina_mempool_del(_efl_future_scheduler_entry_mempool);
2827
eina_mempool_del(_efl_pending_future_mempool);
2828
eina_mempool_del(_eo_callback_mempool);
2829
eina_hash_free(_legacy_events_hash);
2832
#define EFL_OBJECT_EXTRA_OPS \
2833
EFL_OBJECT_OP_FUNC(efl_event_callback_priority_add, _efl_object_event_callback_priority_add), \
2834
EFL_OBJECT_OP_FUNC(efl_event_callback_del, _efl_object_event_callback_del), \
2835
EFL_OBJECT_OP_FUNC(efl_event_callback_array_priority_add, _efl_object_event_callback_array_priority_add), \
2836
EFL_OBJECT_OP_FUNC(efl_event_callback_array_del, _efl_object_event_callback_array_del), \
2837
EFL_OBJECT_OP_FUNC(efl_event_callback_call, _efl_object_event_callback_call), \
2838
EFL_OBJECT_OP_FUNC(efl_event_callback_legacy_call, _efl_object_event_callback_legacy_call), \
2839
EFL_OBJECT_OP_FUNC(efl_event_future_scheduler_get, _efl_object_event_future_scheduler_get), \
2840
EFL_OBJECT_OP_FUNC(efl_event_callback_count, _efl_object_event_callback_count), \
2841
EFL_OBJECT_OP_FUNC(efl_dbg_info_get, _efl_object_dbg_info_get), \
2842
EFL_OBJECT_OP_FUNC(efl_wref_add, _efl_object_wref_add), \
2843
EFL_OBJECT_OP_FUNC(efl_wref_del, _efl_object_wref_del), \
2844
EFL_OBJECT_OP_FUNC(efl_key_data_set, _efl_object_key_data_set), \
2845
EFL_OBJECT_OP_FUNC(efl_key_data_get, _efl_object_key_data_get), \
2846
EFL_OBJECT_OP_FUNC(efl_key_ref_set, _efl_object_key_ref_set), \
2847
EFL_OBJECT_OP_FUNC(efl_key_ref_get, _efl_object_key_ref_get), \
2848
EFL_OBJECT_OP_FUNC(efl_key_wref_set, _efl_object_key_wref_set), \
2849
EFL_OBJECT_OP_FUNC(efl_key_wref_get, _efl_object_key_wref_get), \
2850
EFL_OBJECT_OP_FUNC(efl_key_value_set, _efl_object_key_value_set), \
2851
EFL_OBJECT_OP_FUNC(efl_key_value_get, _efl_object_key_value_get) \
2853
#include "efl_object.eo.c"