raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=86e7d642d595e242137f1c1387f5969e47d9f166

commit 86e7d642d595e242137f1c1387f5969e47d9f166
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Tue Apr 19 16:34:53 2016 +0900

    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
---
 src/lib/eo/eo_base.eo                | 17 +++++++++++++++++
 src/lib/eo/eo_base_class.c           | 18 ++++++++++++++++++
 src/tests/eo/suite/eo_test_general.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index 9ca1c24..b1a24fc 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -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.
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 7b6ff05..1b16ba3 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -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;
@@ -262,6 +263,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)
 {
    if (pd->parent == 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);
 }
 
diff --git a/src/tests/eo/suite/eo_test_general.c 
b/src/tests/eo/suite/eo_test_general.c
index 9f689f3..d4fb693 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -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);
 }

-- 


Reply via email to