eo - add object names/ids esp useful for erigo as it wants object names

also evas objects have names too, so add this as this was discussed
and now the feature is in. there is nothing to find objects by name
yet. that's more api's and features to add after this.

@feature
This commit is contained in:
Carsten Haitzler 2016-04-19 16:34:53 +09:00
parent 1bf509548c
commit 86e7d642d5
3 changed files with 66 additions and 0 deletions

View File

@ -73,6 +73,23 @@ abstract Eo.Base ()
parent: Eo.Base * @nullable; [[the new parent]]
}
}
@property id {
[[ The id/name of the object.
Every object can have a string name. Names may not contain
the slash "/" character. It is illegal. Using it in a name
will result in undefined behavior later on. An empty string
is considered the same as a NULL string or no string for the
name/id at all.
]]
set {
}
get {
}
values {
id: const(char)* @nullable; [[the id/name]]
}
}
@property event_global_freeze_count @class {
get {
[[Return freeze events of object.

View File

@ -23,6 +23,7 @@ typedef struct
Eina_Inlist *generic_data;
Eo ***wrefs;
const char *id;
Eo_Callback_Description *callbacks;
unsigned short walking_list;
unsigned short event_freeze_count;
@ -261,6 +262,20 @@ _eo_base_key_obj_del(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key)
}
}
EOLIAN static void
_eo_base_id_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *id)
{
if ((id) && (!id[0])) id = NULL;
eina_stringshare_replace(&(pd->id), id);
}
EOLIAN static const char *
_eo_base_id_get(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
{
return pd->id;
}
EOLIAN static void
_eo_base_parent_set(Eo *obj, Eo_Base_Data *pd, Eo *parent_id)
{
@ -1146,6 +1161,9 @@ _eo_base_destructor(Eo *obj, Eo_Base_Data *pd)
_wref_destruct(pd);
_eo_callback_remove_all(pd);
eina_stringshare_del(pd->id);
pd->id = NULL;
_eo_condtor_done(obj);
}

View File

@ -1037,6 +1037,36 @@ START_TEST(eo_del_intercept)
}
END_TEST
START_TEST(eo_name)
{
eo_init();
Eo *obj = eo_add(SIMPLE_CLASS, NULL);
const char *id;
id = eo_id_get(obj);
fail_if(NULL != id);
eo_id_set(obj, "Hello");
id = eo_id_get(obj);
fail_if(NULL == id);
fail_if(!!strcmp(id, "Hello"));
eo_id_set(obj, "Hello");
eo_id_set(obj, "");
id = eo_id_get(obj);
fail_if(NULL != id);
eo_id_set(obj, "Hello");
eo_id_set(obj, NULL);
id = eo_id_get(obj);
fail_if(NULL != id);
eo_del(obj);
eo_shutdown();
}
END_TEST
void eo_test_general(TCase *tc)
{
tcase_add_test(tc, eo_simple);
@ -1055,4 +1085,5 @@ void eo_test_general(TCase *tc)
tcase_add_test(tc, eo_pointers_indirection);
tcase_add_test(tc, eo_add_failures);
tcase_add_test(tc, eo_del_intercept);
tcase_add_test(tc, eo_name);
}