From aa4ee17c19c5690e656715f5acd5a32df7d43ad6 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 25 Jun 2012 09:07:39 +0000 Subject: [PATCH] Eo: Added an eo_isa example. SVN revision: 72793 --- legacy/eobj/CMakeLists.txt | 1 + .../eobj/src/examples/eo_isa/CMakeLists.txt | 24 ++++++ legacy/eobj/src/examples/eo_isa/complex.c | 18 +++++ legacy/eobj/src/examples/eo_isa/complex.h | 10 +++ legacy/eobj/src/examples/eo_isa/interface.c | 26 +++++++ legacy/eobj/src/examples/eo_isa/interface.h | 26 +++++++ legacy/eobj/src/examples/eo_isa/main.c | 32 ++++++++ legacy/eobj/src/examples/eo_isa/mixin.c | 50 +++++++++++++ legacy/eobj/src/examples/eo_isa/mixin.h | 26 +++++++ legacy/eobj/src/examples/eo_isa/simple.c | 75 +++++++++++++++++++ legacy/eobj/src/examples/eo_isa/simple.h | 35 +++++++++ 11 files changed, 323 insertions(+) create mode 100644 legacy/eobj/src/examples/eo_isa/CMakeLists.txt create mode 100644 legacy/eobj/src/examples/eo_isa/complex.c create mode 100644 legacy/eobj/src/examples/eo_isa/complex.h create mode 100644 legacy/eobj/src/examples/eo_isa/interface.c create mode 100644 legacy/eobj/src/examples/eo_isa/interface.h create mode 100644 legacy/eobj/src/examples/eo_isa/main.c create mode 100644 legacy/eobj/src/examples/eo_isa/mixin.c create mode 100644 legacy/eobj/src/examples/eo_isa/mixin.h create mode 100644 legacy/eobj/src/examples/eo_isa/simple.c create mode 100644 legacy/eobj/src/examples/eo_isa/simple.h diff --git a/legacy/eobj/CMakeLists.txt b/legacy/eobj/CMakeLists.txt index edd4300cca..c91b1bc7e7 100644 --- a/legacy/eobj/CMakeLists.txt +++ b/legacy/eobj/CMakeLists.txt @@ -41,6 +41,7 @@ include(EFLCheck) add_subdirectory(src/lib) add_subdirectory(src/examples/evas) add_subdirectory(src/examples/simple) +add_subdirectory(src/examples/eo_isa) add_subdirectory(src/tests/mixin) add_subdirectory(src/tests/signals) diff --git a/legacy/eobj/src/examples/eo_isa/CMakeLists.txt b/legacy/eobj/src/examples/eo_isa/CMakeLists.txt new file mode 100644 index 0000000000..b6986991ad --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/CMakeLists.txt @@ -0,0 +1,24 @@ +LIST(APPEND EO_ISA_CC_SOURCES + main.c + simple.c + complex.c + interface.c + mixin.c + ) + +include_directories( + ${EINA_INCLUDE_DIRS} + ${EVAS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src/lib + ) + +add_executable(eo_isa ${EO_ISA_CC_SOURCES}) + +get_target_property(eo_LIB_FILE eo LOCATION) +target_link_libraries(eo_isa + ${EINA_LIBRARIES} + ${EINA_LDFLAGS_OTHER} + ${eo_LIB_FILE} + ) + +add_dependencies(eo_isa eo) diff --git a/legacy/eobj/src/examples/eo_isa/complex.c b/legacy/eobj/src/examples/eo_isa/complex.c new file mode 100644 index 0000000000..03656f0cfd --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/complex.c @@ -0,0 +1,18 @@ +#include "Eo.h" +#include "complex.h" + +#include "config.h" + +#define MY_CLASS COMPLEX_CLASS + +static const Eo_Class_Description class_desc = { + "Complex", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + NULL, + NULL +}; + +EO_DEFINE_CLASS(complex_class_get, &class_desc, SIMPLE_CLASS, NULL); diff --git a/legacy/eobj/src/examples/eo_isa/complex.h b/legacy/eobj/src/examples/eo_isa/complex.h new file mode 100644 index 0000000000..29a0cea5a3 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/complex.h @@ -0,0 +1,10 @@ +#ifndef COMPLEX_H +#define COMPLEX_H + +#include "Eo.h" +#include "simple.h" + +#define COMPLEX_CLASS complex_class_get() +const Eo_Class *complex_class_get(void); + +#endif diff --git a/legacy/eobj/src/examples/eo_isa/interface.c b/legacy/eobj/src/examples/eo_isa/interface.c new file mode 100644 index 0000000000..763316a841 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/interface.c @@ -0,0 +1,26 @@ +#include "Eo.h" +#include "interface.h" + +#include "config.h" + +EAPI Eo_Op INTERFACE_BASE_ID = 0; + +#define MY_CLASS INTERFACE_CLASS + +static const Eo_Op_Description op_desc[] = { + EO_OP_DESCRIPTION_CONST(INTERFACE_SUB_ID_A_POWER_3_GET, "Get the a^3"), + EO_OP_DESCRIPTION_SENTINEL +}; + +static const Eo_Class_Description class_desc = { + "Interface", + EO_CLASS_TYPE_INTERFACE, + EO_CLASS_DESCRIPTION_OPS(&INTERFACE_BASE_ID, op_desc, INTERFACE_SUB_ID_LAST), + NULL, + 0, + NULL, + NULL +}; + +EO_DEFINE_CLASS(interface_class_get, &class_desc, NULL, NULL) + diff --git a/legacy/eobj/src/examples/eo_isa/interface.h b/legacy/eobj/src/examples/eo_isa/interface.h new file mode 100644 index 0000000000..c5bf43e135 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/interface.h @@ -0,0 +1,26 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +#include "Eo.h" + +extern EAPI Eo_Op INTERFACE_BASE_ID; + +enum { + INTERFACE_SUB_ID_A_POWER_3_GET, + INTERFACE_SUB_ID_LAST +}; + +#define INTERFACE_ID(sub_id) (INTERFACE_BASE_ID + sub_id) + + +/** + * @def interface_a_power_3_get(ret) + * @brief Get a^3 + * @param[out] ret integer pointer to ret - value + */ +#define interface_a_power_3_get(ret) INTERFACE_ID(INTERFACE_SUB_ID_A_POWER_3_GET), EO_TYPECHECK(int *, ret) + +#define INTERFACE_CLASS interface_class_get() +const Eo_Class *interface_class_get(void); + +#endif diff --git a/legacy/eobj/src/examples/eo_isa/main.c b/legacy/eobj/src/examples/eo_isa/main.c new file mode 100644 index 0000000000..b9be815964 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/main.c @@ -0,0 +1,32 @@ +#include "Eo.h" +#include "simple.h" +#include "complex.h" + +int +main(int argc, char *argv[]) +{ + (void) argc; + (void) argv; + eo_init(); + + Eo *simpleobj = eo_add(SIMPLE_CLASS, NULL); + Eo *complexobj = eo_add(COMPLEX_CLASS, NULL); + + printf("Simple: isa-simple:%d isa-complex:%d isa-mixin:%d isa-interface:%d\n", + eo_isa(simpleobj, SIMPLE_CLASS), + eo_isa(simpleobj, COMPLEX_CLASS), + eo_isa(simpleobj, MIXIN_CLASS), + eo_isa(simpleobj, INTERFACE_CLASS)); + printf("Complex: isa-simple:%d isa-complex:%d isa-mixin:%d isa-interface:%d\n", + eo_isa(complexobj, SIMPLE_CLASS), + eo_isa(complexobj, COMPLEX_CLASS), + eo_isa(complexobj, MIXIN_CLASS), + eo_isa(complexobj, INTERFACE_CLASS)); + + eo_unref(simpleobj); + eo_unref(complexobj); + + eo_shutdown(); + return 0; +} + diff --git a/legacy/eobj/src/examples/eo_isa/mixin.c b/legacy/eobj/src/examples/eo_isa/mixin.c new file mode 100644 index 0000000000..df89fce0c8 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/mixin.c @@ -0,0 +1,50 @@ +#include "Eo.h" +#include "mixin.h" +#include "simple.h" + +#include "config.h" + +EAPI Eo_Op MIXIN_BASE_ID = 0; + +#define MY_CLASS MIXIN_CLASS + +static void +_a_square_get(const Eo *obj, const void *class_data EINA_UNUSED, va_list *list) +{ + int a; + eo_query(obj, simple_a_get(&a)); + int *ret = va_arg(*list, int *); + if (ret) + *ret = a * a; + printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__); +} + +static void +_class_constructor(Eo_Class *klass) +{ + const Eo_Op_Func_Description func_desc[] = { + EO_OP_FUNC_CONST(MIXIN_ID(MIXIN_SUB_ID_A_SQUARE_GET), _a_square_get), + EO_OP_FUNC_SENTINEL + }; + + eo_class_funcs_set(klass, func_desc); +} + + +static const Eo_Op_Description op_desc[] = { + EO_OP_DESCRIPTION_CONST(MIXIN_SUB_ID_A_SQUARE_GET, "Get the value of A^2"), + EO_OP_DESCRIPTION_SENTINEL +}; + +static const Eo_Class_Description class_desc = { + "Mixin", + EO_CLASS_TYPE_MIXIN, + EO_CLASS_DESCRIPTION_OPS(&MIXIN_BASE_ID, op_desc, MIXIN_SUB_ID_LAST), + NULL, + 0, + _class_constructor, + NULL +}; + +EO_DEFINE_CLASS(mixin_class_get, &class_desc, NULL, NULL) + diff --git a/legacy/eobj/src/examples/eo_isa/mixin.h b/legacy/eobj/src/examples/eo_isa/mixin.h new file mode 100644 index 0000000000..539504d3ad --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/mixin.h @@ -0,0 +1,26 @@ +#ifndef MIXIN_H +#define MIXIN_H + +#include "Eo.h" + +extern EAPI Eo_Op MIXIN_BASE_ID; + +enum { + MIXIN_SUB_ID_A_SQUARE_GET, + MIXIN_SUB_ID_LAST +}; + +#define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id) + + +/** + * @def mixin_a_square_get(ret) + * @brief Get the square of a. + * @param[out] ret the square of a + */ +#define mixin_a_square_get(ret) MIXIN_ID(MIXIN_SUB_ID_A_SQUARE_GET), EO_TYPECHECK(int *, ret) + +#define MIXIN_CLASS mixin_class_get() +const Eo_Class *mixin_class_get(void); + +#endif diff --git a/legacy/eobj/src/examples/eo_isa/simple.c b/legacy/eobj/src/examples/eo_isa/simple.c new file mode 100644 index 0000000000..7a32757549 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/simple.c @@ -0,0 +1,75 @@ +#include "Eo.h" +#include "simple.h" + +#include "config.h" + +EAPI Eo_Op SIMPLE_BASE_ID = 0; + +typedef struct +{ + int a; +} Private_Data; + +#define MY_CLASS SIMPLE_CLASS + +static void +_a_get(const Eo *obj EINA_UNUSED, const void *class_data, va_list *list) +{ + const Private_Data *pd = class_data; + int *a; + a = va_arg(*list, int *); + *a = pd->a; + printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__); +} + +static void +_a_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list) +{ + Private_Data *pd = class_data; + int a; + a = va_arg(*list, int); + pd->a = a; + printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__); +} + +static void +_a_power_3_get(const Eo *obj EINA_UNUSED, const void *class_data, va_list *list) +{ + const Private_Data *pd = class_data; + int *ret; + ret = va_arg(*list, int *); + if (ret) + *ret = pd->a * pd->a * pd->a; + printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__); +} + +static void +_class_constructor(Eo_Class *klass) +{ + const Eo_Op_Func_Description func_desc[] = { + EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set), + EO_OP_FUNC_CONST(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get), + EO_OP_FUNC_CONST(INTERFACE_ID(INTERFACE_SUB_ID_A_POWER_3_GET), _a_power_3_get), + EO_OP_FUNC_SENTINEL + }; + + eo_class_funcs_set(klass, func_desc); +} + +static const Eo_Op_Description op_desc[] = { + EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"), + EO_OP_DESCRIPTION_CONST(SIMPLE_SUB_ID_A_GET, "Get property A"), + EO_OP_DESCRIPTION_SENTINEL +}; + +static const Eo_Class_Description class_desc = { + "Simple", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST), + NULL, + sizeof(Private_Data), + _class_constructor, + NULL +}; + +EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, INTERFACE_CLASS, MIXIN_CLASS, NULL); diff --git a/legacy/eobj/src/examples/eo_isa/simple.h b/legacy/eobj/src/examples/eo_isa/simple.h new file mode 100644 index 0000000000..e18f11d7d6 --- /dev/null +++ b/legacy/eobj/src/examples/eo_isa/simple.h @@ -0,0 +1,35 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +#include "Eo.h" +#include "interface.h" +#include "mixin.h" + +extern EAPI Eo_Op SIMPLE_BASE_ID; + +enum { + SIMPLE_SUB_ID_A_SET, + SIMPLE_SUB_ID_A_GET, + SIMPLE_SUB_ID_LAST +}; + +#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id) + +/** + * @def simple_a_set(a) + * @brief Set value to a-property + * @param[in] a integer value to set + */ +#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a) + +/** + * @def simple_a_get(a) + * @brief Get value of a-property + * @param[out] integer pointer to a-value + */ +#define simple_a_get(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EO_TYPECHECK(int *, a) + +#define SIMPLE_CLASS simple_class_get() +const Eo_Class *simple_class_get(void); + +#endif