Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Commit

Permalink
eo: add API for querying the class type
Browse files Browse the repository at this point in the history
a class can be a interface mixin abstract or regular.
This adds a API for getting this information
  • Loading branch information
marcelhollerbach committed Feb 20, 2019
1 parent 8952c05 commit 4251df2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/eo/Eo.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,8 @@ enum _Efl_Class_Type
EFL_CLASS_TYPE_REGULAR = 0, /**< Regular class. */
EFL_CLASS_TYPE_REGULAR_NO_INSTANT, /**< Regular non instant-able class. */
EFL_CLASS_TYPE_INTERFACE, /**< Interface */
EFL_CLASS_TYPE_MIXIN /**< Mixin */
EFL_CLASS_TYPE_MIXIN, /**< Mixin */
EFL_CLASS_TYPE_INVALID
};

/**
Expand Down Expand Up @@ -2003,6 +2004,14 @@ EAPI Eina_Value efl_property_reflection_get(Eo *obj, const char *property_name);

#include "efl_class.eo.h"

/**
* @brief Get the type of this class.
* @param klass The Efl_Class to get the type from
*
* @return The type of this class or INVALID if the klass parameter was invalid
*/
EAPI Efl_Class_Type efl_class_type_get(const Efl_Class *klass);

/**
* @}
*/
Expand Down
14 changes: 14 additions & 0 deletions src/lib/eo/eo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,9 @@ efl_class_new(const Efl_Class_Description *desc, const Efl_Class *parent_id, ...
return NULL;
}
break;
default:
ERR("type cannot be INVALID");
return NULL;
}
}

Expand All @@ -1542,6 +1545,9 @@ efl_class_new(const Efl_Class_Description *desc, const Efl_Class *parent_id, ...
case EFL_CLASS_TYPE_MIXIN:
extn_list = eina_list_append(extn_list, extn);
break;
default:
ERR("type cannot be INVALID");
return NULL;
}
}
extn_id = va_arg(p_list, Eo_Id *);
Expand Down Expand Up @@ -3660,3 +3666,11 @@ efl_property_reflection_get(Eo *obj_id, const char *property_name)

return EINA_VALUE_EMPTY;
}

EAPI Efl_Class_Type
efl_class_type_get(const Efl_Class *klass_id)
{
EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, EFL_CLASS_TYPE_INVALID);

return klass->desc->type;
}
2 changes: 2 additions & 0 deletions src/tests/eo/interface/interface_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ main(int argc, char *argv[])
fail_if(!efl_isa(SIMPLE_CLASS, INTERFACE2_CLASS));
fail_if(efl_isa(INTERFACE_CLASS, INTERFACE2_CLASS));

fail_if(efl_class_type_get(INTERFACE_CLASS) != EFL_CLASS_TYPE_INTERFACE);

efl_unref(obj);
efl_object_shutdown();
return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/tests/eo/mixin/mixin_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ main(int argc, char *argv[])
printf("%d\n", a);
fail_if(a != 5);

fail_if(efl_class_type_get(MIXIN_CLASS) != EFL_CLASS_TYPE_MIXIN);


efl_unref(obj);
efl_object_shutdown();
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/tests/eo/suite/eo_test_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,13 @@ EFL_START_TEST(eo_test_class_replacement)
}
EFL_END_TEST

EFL_START_TEST(eo_test_class_type)
{
ck_assert_int_eq(efl_class_type_get(SIMPLE_CLASS), EFL_CLASS_TYPE_REGULAR);
ck_assert_int_eq(efl_class_type_get((void*)0xAFFE), EFL_CLASS_TYPE_INVALID);
}
EFL_END_TEST

void eo_test_general(TCase *tc)
{
tcase_add_test(tc, eo_simple);
Expand Down Expand Up @@ -1870,4 +1877,5 @@ void eo_test_general(TCase *tc)
tcase_add_test(tc, efl_object_destruct_test);
tcase_add_test(tc, efl_object_auto_unref_test);
tcase_add_test(tc, efl_object_size);
tcase_add_test(tc, eo_test_class_type);
}

0 comments on commit 4251df2

Please sign in to comment.