efl/src/tests/eo/signals/signals_main.c

184 lines
5.6 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "Eo.h"
2012-09-25 23:56:52 -07:00
#include "signals_simple.h"
#include "../eunit_tests.h"
static int cb_count = 0;
static Eina_Bool
_null_cb(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
{
(void) desc;
(void) obj;
(void) data;
(void) event_info;
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
_a_changed_cb(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
{
(void) desc;
(void) obj;
int new_a = *((int *) event_info);
printf("%s event_info:'%d' data:'%d'\n", __func__, new_a, (int) (intptr_t) data);
cb_count++;
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _null_cb, (void *) 23423));
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _null_cb, (void *) 23423));
/* Stop as we reached the 3rd one. */
return (cb_count != 3);
}
int
main(int argc, char *argv[])
{
(void) argc;
(void) argv;
eo_init();
Eo *obj = eo_add(SIMPLE_CLASS, NULL);
Eo: Add reference functions for objects data We want to introduce a new mechanism concerning the data of the Eo objects. The goal is to improve the memory management by defragmenting the memory banks used by the Eo objects. The first phase has been done by raster and consists in allocating the objects into a separate memory region that the one used by malloc. So now, we know where our objects are located. Now, moving objects means moving data of objects. The issue we have here is that a lot of data pointers are stored into data of other objects, e.g Evas Object data into lists for rendering... We need a way to reference the data and eo_data_get doesn't provide us that. So we need to improve the API for data extraction by requesting from the developer if the data will be stored or not. Five functions are supplied: - eo_data_scope_get: no referencing, the data pointer is no more used after exiting the function. - eo_data_ref: reference the data of the object. It means that while the data is referenced, the object cannot be moved. - eo_data_xref: reference the data of the object but for debug purpose, we associate the objects that references. Same behavior as eo_data_ref for non-debug. - eo_data_unref: unreference the data of an object. - eo_data_xunref: unreference the data of an object previously referenced by another object. I deprecated the eo_data_get function. Most of the time, eo_data_scope_get needs to be used. In the next patches, I changed the eo_data_get to the corresponding functions, according to the usage of the data pointer. The next step is to find all the places in the code where the data is stored but not yet referenced. This will be done by: - requesting from every object to unreference all data to other objects. - moving all the objects from one region to another - requesting from every object to rerefenrence the data. - debugging by hunting the segmentation faults and other weird creatures.
2013-03-19 23:56:15 -07:00
Simple_Public_Data *pd = eo_data_scope_get(obj, SIMPLE_CLASS);
/* The order of these two is undetermined. */
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
/* This will be called afterwards. */
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_DEFAULT, _a_changed_cb, (void *) 3));
/* This will never be called because the previous callback returns NULL. */
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_AFTER, _a_changed_cb, (void *) 4));
eo_do(obj, simple_a_set(1));
fail_if(cb_count != 3);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 3));
fail_if(pd->cb_count != 3);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 12));
fail_if(pd->cb_count != 3);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 4));
fail_if(pd->cb_count != 2);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 2));
fail_if(pd->cb_count != 1);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 1));
fail_if(pd->cb_count != 0);
/* Freeze/thaw. */
int fcount = 0;
cb_count = 0;
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
fail_if(pd->cb_count != 1);
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 0);
eo_do(obj, eo_event_freeze());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 1);
eo_do(obj, eo_event_freeze());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 2);
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
fail_if(pd->cb_count != 1);
eo_do(obj, simple_a_set(2));
fail_if(cb_count != 0);
eo_do(obj, eo_event_thaw());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 1);
eo_do(obj, eo_event_thaw());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 0);
eo_do(obj, simple_a_set(3));
fail_if(cb_count != 2);
cb_count = 0;
eo_do(obj, eo_event_thaw());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 0);
eo_do(obj, eo_event_freeze());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 1);
eo_do(obj, simple_a_set(2));
fail_if(cb_count != 0);
eo_do(obj, eo_event_thaw());
eo_do(obj, eo_event_freeze_get(&fcount));
fail_if(fcount != 0);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 1));
fail_if(pd->cb_count != 0);
eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 2));
fail_if(pd->cb_count != -1);
/* Global Freeze/thaw. */
fcount = 0;
cb_count = 0;
pd->cb_count = 0;
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
fail_if(pd->cb_count != 1);
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 0);
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 1);
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 2);
eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
fail_if(pd->cb_count != 1);
eo_do(obj, simple_a_set(2));
fail_if(cb_count != 0);
eo_class_do(EO_BASE_CLASS, eo_event_global_thaw());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 1);
eo_class_do(EO_BASE_CLASS, eo_event_global_thaw());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 0);
eo_do(obj, simple_a_set(3));
fail_if(cb_count != 2);
cb_count = 0;
eo_class_do(EO_BASE_CLASS, eo_event_global_thaw());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 0);
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 1);
eo_do(obj, simple_a_set(2));
fail_if(cb_count != 0);
eo_class_do(EO_BASE_CLASS, eo_event_global_thaw());
eo_class_do(EO_BASE_CLASS, eo_event_global_freeze_get(&fcount));
fail_if(fcount != 0);
eo_unref(obj);
eo_shutdown();
return 0;
}