aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2018-08-01 16:41:14 +0200
committerStefan Schmidt <s.schmidt@samsung.com>2018-09-14 11:18:56 +0200
commit068e09cf2e23a4e80c28b8c1db4c23b3fdabaa14 (patch)
tree068af3ffef4a57675ae94e6fe0f82bdb9c92d0f1
parentbuild: make configure not error if cxx compiler is not found when not needed (diff)
downloadefl-068e09cf2e23a4e80c28b8c1db4c23b3fdabaa14.tar.gz
eo: add funktion for alive checks
The function simply checks if the object is finalized and not started to be invalidated or invalidated. Differential Revision: https://phab.enlightenment.org/D6723
-rw-r--r--src/lib/eo/Eo.h13
-rw-r--r--src/tests/eo/suite/eo_test_lifecycle.c21
2 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 727ebde297..01d569e1ce 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -2135,6 +2135,19 @@ eina_value_object_get(Eina_Value *v)
}
/**
+ * @brief Get if the object is in its main lifetime.
+ * @param obj the object to check
+ * @return true if the object is finalized, but not invalidating nor invalidated.
+ * @since 1.22
+ */
+
+static inline Eina_Bool
+efl_alive_get(const Eo *obj)
+{
+ return efl_finalized_get(obj) && !efl_invalidating_get(obj) && !efl_invalidated_get(obj);
+}
+
+/**
* @brief Event triggered when a callback was added to the object
*/
#define EFL_EVENT_CALLBACK_ADD (&(_EFL_EVENT_CALLBACK_ADD))
diff --git a/src/tests/eo/suite/eo_test_lifecycle.c b/src/tests/eo/suite/eo_test_lifecycle.c
index 190a7366ca..224c9c738c 100644
--- a/src/tests/eo/suite/eo_test_lifecycle.c
+++ b/src/tests/eo/suite/eo_test_lifecycle.c
@@ -162,7 +162,6 @@ EFL_START_TEST(eo_test_unref_noref)
}
EFL_END_TEST
-
typedef struct {
Eo *par;
Eina_Bool called;
@@ -191,6 +190,25 @@ EFL_START_TEST(eo_test_invalidating_get)
}
EFL_END_TEST
+EFL_START_TEST(eo_test_alive_get)
+{
+ Eina_Bool res;
+ Eo *par = efl_add_ref(SIMPLE_CLASS, NULL);
+ Eo *obj = efl_add(SIMPLE_CLASS, par,
+ res = efl_alive_get(efl_added)
+ );
+ ck_assert_int_eq(res, 0);
+ ck_assert_int_eq(efl_alive_get(obj), 1);
+ efl_ref(obj);
+ ck_assert_int_eq(efl_alive_get(obj), 1);
+ efl_del(obj);
+ ck_assert_int_eq(efl_alive_get(obj), 0);
+ efl_unref(obj);
+ ck_assert_ptr_eq(efl_class_name_get(obj), NULL);
+
+}
+EFL_END_TEST
+
void eo_test_lifecycle(TCase *tc)
{
tcase_add_test(tc, eo_test_base_del);
@@ -199,4 +217,5 @@ void eo_test_lifecycle(TCase *tc)
tcase_add_test(tc, eo_test_del_in_noref);
tcase_add_test(tc, eo_test_unref_noref);
tcase_add_test(tc, eo_test_invalidating_get);
+ tcase_add_test(tc, eo_test_alive_get);
}