eo - add object names/ids esp useful for erigo as it wants object names
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Tue, 19 Apr 2016 07:34:53 +0000 (16:34 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Tue, 19 Apr 2016 07:34:53 +0000 (16:34 +0900)
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
src/lib/eo/eo_base_class.c
src/tests/eo/suite/eo_test_general.c

index 9ca1c24..b1a24fc 100644 (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.
index 7b6ff05..1b16ba3 100644 (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;
@@ -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);
 }
 
index 9f689f3..d4fb693 100644 (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);
 }