tasn pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=2a0937b8891fac31520771f64f3e667e9996496b

commit 2a0937b8891fac31520771f64f3e667e9996496b
Author: Tom Hacohen <[email protected]>
Date:   Fri Aug 29 09:55:02 2014 +0100

    Eo base: Add a property to indicate if the object is finalized;
    
    This enables checking if an object is being created, or has already been
    finalized. This is useful in functions that you want to allow
    only during the creation phase (i.e inside the eo_add()).
---
 src/lib/eo/eo.c                      | 2 ++
 src/lib/eo/eo_base.eo                | 8 ++++++++
 src/lib/eo/eo_base_class.c           | 8 ++++++++
 src/lib/eo/eo_private.h              | 1 +
 src/tests/eo/suite/eo_test_general.c | 8 ++++++++
 5 files changed, 27 insertions(+)

diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index bb54d1c..d21853b 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -951,6 +951,8 @@ _eo_add_internal_end(Eo *eo_id)
         return NULL;
      }
 
+   fptr->o.obj->finalized = EINA_TRUE;
+
    _eo_unref(fptr->o.obj);
 
    return (Eo *)eo_id;
diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index 562119e..37ba6c7 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -34,6 +34,14 @@ Return event freeze count. */
             int fcount; /*@ The event freeze count of the object */
          }
       }
+      finalized {
+         /*@ True if the object is already finalized, false otherwise. */
+         get {
+         }
+         values {
+            bool finalized;
+         }
+      }
    }
    methods {
       constructor @constructor {
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 64146db..344e221 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -162,6 +162,14 @@ _eo_base_parent_get(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
    return pd->parent;
 }
 
+EOLIAN static Eina_Bool
+_eo_base_finalized_get(Eo *obj_id, Eo_Base_Data *pd EINA_UNUSED)
+{
+   EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, EINA_FALSE);
+
+   return obj->finalized;
+}
+
 /* Children accessor */
 typedef struct _Eo_Children_Iterator Eo_Children_Iterator;
 struct _Eo_Children_Iterator
diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h
index 3820a9c..c7b6348 100644
--- a/src/lib/eo/eo_private.h
+++ b/src/lib/eo/eo_private.h
@@ -100,6 +100,7 @@ struct _Eo_Object
 
      Eina_Bool do_error:1;
      Eina_Bool condtor_done:1;
+     Eina_Bool finalized:1;
 
      Eina_Bool composite:1;
      Eina_Bool del:1;
diff --git a/src/tests/eo/suite/eo_test_general.c 
b/src/tests/eo/suite/eo_test_general.c
index 78561e8..9830d6f 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -788,6 +788,14 @@ START_TEST(eo_add_do_and_custom)
    fail_if(pd->a != 7);
    eo_unref(obj);
 
+   Eina_Bool finalized;
+   obj = eo_add(SIMPLE_CLASS, NULL, finalized = eo_finalized_get());
+   fail_if(finalized);
+
+   finalized = eo_do(obj, eo_finalized_get());
+   fail_if(!finalized);
+   eo_unref(obj);
+
    eo_shutdown();
 }
 END_TEST

-- 


Reply via email to