From 1a5199d5d36648249c8d9eb26285a6993767b46a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 25 Jun 2012 06:52:08 +0000 Subject: [PATCH] Eo: Added a simple example. SVN revision: 72781 --- legacy/eobj/CMakeLists.txt | 1 + .../eobj/src/examples/simple/CMakeLists.txt | 23 ++++++ legacy/eobj/src/examples/simple/interface.c | 26 +++++++ legacy/eobj/src/examples/simple/interface.h | 26 +++++++ legacy/eobj/src/examples/simple/main.c | 27 +++++++ legacy/eobj/src/examples/simple/mixin.c | 50 +++++++++++++ legacy/eobj/src/examples/simple/mixin.h | 26 +++++++ legacy/eobj/src/examples/simple/simple.c | 75 +++++++++++++++++++ legacy/eobj/src/examples/simple/simple.h | 35 +++++++++ 9 files changed, 289 insertions(+) create mode 100644 legacy/eobj/src/examples/simple/CMakeLists.txt create mode 100644 legacy/eobj/src/examples/simple/interface.c create mode 100644 legacy/eobj/src/examples/simple/interface.h create mode 100644 legacy/eobj/src/examples/simple/main.c create mode 100644 legacy/eobj/src/examples/simple/mixin.c create mode 100644 legacy/eobj/src/examples/simple/mixin.h create mode 100644 legacy/eobj/src/examples/simple/simple.c create mode 100644 legacy/eobj/src/examples/simple/simple.h diff --git a/legacy/eobj/CMakeLists.txt b/legacy/eobj/CMakeLists.txt index f7934b8ede..edd4300cca 100644 --- a/legacy/eobj/CMakeLists.txt +++ b/legacy/eobj/CMakeLists.txt @@ -40,6 +40,7 @@ include(EFLCheck) add_subdirectory(src/lib) add_subdirectory(src/examples/evas) +add_subdirectory(src/examples/simple) add_subdirectory(src/tests/mixin) add_subdirectory(src/tests/signals) diff --git a/legacy/eobj/src/examples/simple/CMakeLists.txt b/legacy/eobj/src/examples/simple/CMakeLists.txt new file mode 100644 index 0000000000..c1b6562dbc --- /dev/null +++ b/legacy/eobj/src/examples/simple/CMakeLists.txt @@ -0,0 +1,23 @@ +LIST(APPEND SIMPLE_CC_SOURCES + main.c + simple.c + interface.c + mixin.c + ) + +include_directories( + ${EINA_INCLUDE_DIRS} + ${EVAS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src/lib + ) + +add_executable(simple ${SIMPLE_CC_SOURCES}) + +get_target_property(eo_LIB_FILE eo LOCATION) +target_link_libraries(simple + ${EINA_LIBRARIES} + ${EINA_LDFLAGS_OTHER} + ${eo_LIB_FILE} + ) + +add_dependencies(simple eo) diff --git a/legacy/eobj/src/examples/simple/interface.c b/legacy/eobj/src/examples/simple/interface.c new file mode 100644 index 0000000000..763316a841 --- /dev/null +++ b/legacy/eobj/src/examples/simple/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/simple/interface.h b/legacy/eobj/src/examples/simple/interface.h new file mode 100644 index 0000000000..c5bf43e135 --- /dev/null +++ b/legacy/eobj/src/examples/simple/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/simple/main.c b/legacy/eobj/src/examples/simple/main.c new file mode 100644 index 0000000000..1fedc83b08 --- /dev/null +++ b/legacy/eobj/src/examples/simple/main.c @@ -0,0 +1,27 @@ +#include "Eo.h" +#include "simple.h" + +int +main(int argc, char *argv[]) +{ + (void) argc; + (void) argv; + eo_init(); + + Eo *obj = eo_add(SIMPLE_CLASS, NULL); + + eo_do(obj, simple_a_set(4)); + + int a = 0, a2 = 0, a3 = 0; + + eo_do(obj, simple_a_get(&a), + interface_a_power_3_get(&a3), + mixin_a_square_get(&a2)); + + printf("Got %d %d %d\n", a, a2, a3); + + eo_unref(obj); + eo_shutdown(); + return 0; +} + diff --git a/legacy/eobj/src/examples/simple/mixin.c b/legacy/eobj/src/examples/simple/mixin.c new file mode 100644 index 0000000000..df89fce0c8 --- /dev/null +++ b/legacy/eobj/src/examples/simple/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/simple/mixin.h b/legacy/eobj/src/examples/simple/mixin.h new file mode 100644 index 0000000000..539504d3ad --- /dev/null +++ b/legacy/eobj/src/examples/simple/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/simple/simple.c b/legacy/eobj/src/examples/simple/simple.c new file mode 100644 index 0000000000..7a32757549 --- /dev/null +++ b/legacy/eobj/src/examples/simple/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/simple/simple.h b/legacy/eobj/src/examples/simple/simple.h new file mode 100644 index 0000000000..e18f11d7d6 --- /dev/null +++ b/legacy/eobj/src/examples/simple/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