cedric pushed a commit to branch master.

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

commit a0952b0c01594e34f74a959d5dc4e8d54ab847c9
Author: Marcel Hollerbach <m...@marcel-hollerbach.de>
Date:   Tue Jul 16 15:29:56 2019 +0200

    eo: add helper for checking the ownable state
    
    if a object is ownable, then there is one free reference. If not, a
    error will be printed.
    
    Reviewed-by: Cedric BAIL <cedric.b...@free.fr>
    Differential Revision: https://phab.enlightenment.org/D9332
---
 src/lib/eo/Eo.h | 10 ++++++++++
 src/lib/eo/eo.c | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index ddbad15de2..34c8a8c4b2 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -2318,6 +2318,7 @@ efl_alive_get(const Eo *obj)
 {
   return efl_finalized_get(obj) && !efl_invalidating_get(obj) && 
!efl_invalidated_get(obj);
 }
+
 #endif /* EFL_BETA_API_SUPPORT */
 
 /**
@@ -2359,6 +2360,15 @@ EAPI Eina_Iterator *eo_classes_iterator_new(void);
  */
 EAPI Eina_Iterator *eo_objects_iterator_new(void);
 
+/**
+ * @brief Check if a object can be owned
+ *
+ * This API checks if the passed object has at least one free reference that 
is not taken by the parent relation.
+ * If this is not the case, a ERR will be printed.
+ *
+ * @return EINA_TRUE if the object is ownable. EINA_FALSE if not.
+ */
+EAPI Eina_Bool efl_ownable_get(const Eo *obj);
 /**
  * @}
  */
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index c1156ec386..e2aed3c1ef 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -3718,3 +3718,17 @@ efl_class_type_get(const Efl_Class *klass_id)
 
    return klass->desc->type;
 }
+
+
+EAPI Eina_Bool
+efl_ownable_get(const Eo *obj)
+{
+   int ref = efl_ref_count(obj);
+
+   if (efl_parent_get(obj))
+     ref --;
+
+   if (ref <= 0)
+     ERR("There is no free reference to pass this object. Please check that 
this object is really owned by you.");
+   return (ref > 0);
+}

-- 


Reply via email to