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 @@ -2134,6 +2134,19 @@ eina_value_object_get(Eina_Value *v) return r; } +/** + * @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 */ 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); }