eo: add helper for checking the ownable state
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Tue, 16 Jul 2019 13:29:56 +0000 (15:29 +0200)
committerSangHyeon Jade Lee <sh10233.lee@samsung.com>
Tue, 23 Jul 2019 05:04:43 +0000 (14:04 +0900)
if a object is ownable, then there is one free reference. If not, a
error will be printed.

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D9332

src/lib/eo/Eo.h
src/lib/eo/eo.c

index ddbad15..34c8a8c 100644 (file)
@@ -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 */
 
 /**
@@ -2360,6 +2361,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);
+/**
  * @}
  */
 
index c1156ec..e2aed3c 100644 (file)
@@ -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);
+}