From bef76f04073b4bdd7c530ed8394219db4a386ad0 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 12 Apr 2012 10:48:08 +0000 Subject: [PATCH] Eobj: Added some composite objects tests. SVN revision: 70134 --- legacy/eobj/CMakeLists.txt | 1 + .../examples/composite_objects/CMakeLists.txt | 23 ++++++ legacy/eobj/examples/composite_objects/comp.c | 61 +++++++++++++++ legacy/eobj/examples/composite_objects/comp.h | 9 +++ legacy/eobj/examples/composite_objects/main.c | 49 ++++++++++++ .../eobj/examples/composite_objects/simple.c | 75 +++++++++++++++++++ .../eobj/examples/composite_objects/simple.h | 30 ++++++++ 7 files changed, 248 insertions(+) create mode 100644 legacy/eobj/examples/composite_objects/CMakeLists.txt create mode 100644 legacy/eobj/examples/composite_objects/comp.c create mode 100644 legacy/eobj/examples/composite_objects/comp.h create mode 100644 legacy/eobj/examples/composite_objects/main.c create mode 100644 legacy/eobj/examples/composite_objects/simple.c create mode 100644 legacy/eobj/examples/composite_objects/simple.h diff --git a/legacy/eobj/CMakeLists.txt b/legacy/eobj/CMakeLists.txt index 6d08d0c75c..87dca0bb00 100644 --- a/legacy/eobj/CMakeLists.txt +++ b/legacy/eobj/CMakeLists.txt @@ -45,6 +45,7 @@ add_subdirectory(examples/signals) add_subdirectory(examples/access) add_subdirectory(examples/constructors) add_subdirectory(examples/function_overrides) +add_subdirectory(examples/composite_objects) add_subdirectory(tests EXCLUDE_FROM_ALL) diff --git a/legacy/eobj/examples/composite_objects/CMakeLists.txt b/legacy/eobj/examples/composite_objects/CMakeLists.txt new file mode 100644 index 0000000000..697fbbc608 --- /dev/null +++ b/legacy/eobj/examples/composite_objects/CMakeLists.txt @@ -0,0 +1,23 @@ +LIST(APPEND COMPOSITE_OBJECTS_CC_SOURCES + main.c + simple.c + comp.c + ) + +include_directories( + ${EINA_INCLUDE_DIRS} + ${EVAS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/lib + ) + +add_executable(composite_objects ${COMPOSITE_OBJECTS_CC_SOURCES}) + +get_target_property(eobj_LIB_FILE eobj LOCATION) +target_link_libraries(composite_objects + ${EINA_LIBRARIES} + ${eobj_LIB_FILE} + ) + +add_dependencies(composite_objects eobj) + +add_test(Example_composite_objects composite_objects) diff --git a/legacy/eobj/examples/composite_objects/comp.c b/legacy/eobj/examples/composite_objects/comp.c new file mode 100644 index 0000000000..8fbedd9f2f --- /dev/null +++ b/legacy/eobj/examples/composite_objects/comp.c @@ -0,0 +1,61 @@ +#include "Eobj.h" +#include "simple.h" + +#include "comp.h" + +EAPI Eobj_Op COMP_BASE_ID = 0; + +static Eobj_Class *_my_class = NULL; + +static void +_a_get(Eobj *obj, Eobj_Op op, va_list *list) +{ + (void) op; + int *a; + a = va_arg(*list, int *); + eobj_super_do(obj, SIMPLE_A_GET(a)); +} + +static void +_constructor(Eobj *obj) +{ + eobj_constructor_super(obj); + + Eobj *simple = eobj_add(SIMPLE_CLASS, obj); + eobj_composite_object_attach(obj, simple); + eobj_event_callback_forwarder_add(simple, SIG_A_CHANGED, obj); + + eobj_unref(simple); +} + +static void +_class_constructor(Eobj_Class *klass) +{ + const Eobj_Op_Func_Description func_desc[] = { + EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get), + EOBJ_OP_FUNC_DESCRIPTION_SENTINEL + }; + + eobj_class_funcs_set(klass, func_desc); +} + +const Eobj_Class * +comp_class_get(void) +{ + if (_my_class) return _my_class; + + static const Eobj_Class_Description class_desc = { + "Comp", + EOBJ_CLASS_TYPE_REGULAR, + EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + _constructor, + NULL, + _class_constructor, + NULL + }; + + return _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, + SIMPLE_CLASS, NULL); +} diff --git a/legacy/eobj/examples/composite_objects/comp.h b/legacy/eobj/examples/composite_objects/comp.h new file mode 100644 index 0000000000..e97a0a7302 --- /dev/null +++ b/legacy/eobj/examples/composite_objects/comp.h @@ -0,0 +1,9 @@ +#ifndef COMP_H +#define COMP_H + +#include "Eobj.h" + +#define COMP_CLASS comp_class_get() +const Eobj_Class *comp_class_get(void) EINA_CONST; + +#endif diff --git a/legacy/eobj/examples/composite_objects/main.c b/legacy/eobj/examples/composite_objects/main.c new file mode 100644 index 0000000000..ce61260952 --- /dev/null +++ b/legacy/eobj/examples/composite_objects/main.c @@ -0,0 +1,49 @@ +#include "Eobj.h" +#include "simple.h" +#include "comp.h" + +static int cb_called = EINA_FALSE; + +static Eina_Bool +_a_changed_cb(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *event_info) +{ + (void) desc; + (void) obj; + int new_a = *((int *) event_info); + printf("%s event_info:'%d' data:'%s'\n", __func__, new_a, (const char *) data); + + cb_called = EINA_TRUE; + + return EINA_TRUE; +} + +int +main(int argc, char *argv[]) +{ + (void) argc; + (void) argv; + eobj_init(); + + Eobj *obj = eobj_add(COMP_CLASS, NULL); + eobj_event_callback_add(obj, SIG_A_CHANGED, _a_changed_cb, NULL); + + int a; + eobj_do(obj, SIMPLE_A_SET(1)); + if (!cb_called) + { + printf("Error! %d\n", __LINE__); + return 1; + } + + eobj_do(obj, SIMPLE_A_GET(&a)); + if (a != 1) + { + printf("Error! %d\n", __LINE__); + return 1; + } + eobj_unref(obj); + + eobj_shutdown(); + return 0; +} + diff --git a/legacy/eobj/examples/composite_objects/simple.c b/legacy/eobj/examples/composite_objects/simple.c new file mode 100644 index 0000000000..e0bd7359a6 --- /dev/null +++ b/legacy/eobj/examples/composite_objects/simple.c @@ -0,0 +1,75 @@ +#include "Eobj.h" +#include "simple.h" + +EAPI Eobj_Op SIMPLE_BASE_ID = 0; + +EAPI const Eobj_Event_Description _SIG_A_CHANGED = + EOBJ_EVENT_DESCRIPTION("a,changed", "i", "Called when a has changed."); + +static Eobj_Class *_my_class = NULL; + +static void +_a_set(Eobj *obj, Eobj_Op op, va_list *list) +{ + Simple_Public_Data *pd = eobj_data_get(obj, _my_class); + (void) op; + int a; + a = va_arg(*list, int); + printf("%s %d\n", eobj_class_name_get(_my_class), a); + pd->a = a; + + eobj_event_callback_call(obj, SIG_A_CHANGED, &pd->a); +} + +static void +_a_get(Eobj *obj, Eobj_Op op, va_list *list) +{ + Simple_Public_Data *pd = eobj_data_get(obj, _my_class); + (void) op; + int *a; + a = va_arg(*list, int *); + *a = pd->a; +} + +static void +_class_constructor(Eobj_Class *klass) +{ + const Eobj_Op_Func_Description func_desc[] = { + EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set), + EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get), + EOBJ_OP_FUNC_DESCRIPTION_SENTINEL + }; + + eobj_class_funcs_set(klass, func_desc); +} + +const Eobj_Class * +simple_class_get(void) +{ + if (_my_class) return _my_class; + + static const Eobj_Op_Description op_desc[] = { + EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"), + EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "i", "Get property A"), + EOBJ_OP_DESCRIPTION_SENTINEL + }; + + static const Eobj_Event_Description *event_desc[] = { + SIG_A_CHANGED, + NULL + }; + + static const Eobj_Class_Description class_desc = { + "Simple", + EOBJ_CLASS_TYPE_REGULAR, + EOBJ_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST), + event_desc, + sizeof(Simple_Public_Data), + NULL, + NULL, + _class_constructor, + NULL + }; + + return _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, NULL); +} diff --git a/legacy/eobj/examples/composite_objects/simple.h b/legacy/eobj/examples/composite_objects/simple.h new file mode 100644 index 0000000000..827cbdafe3 --- /dev/null +++ b/legacy/eobj/examples/composite_objects/simple.h @@ -0,0 +1,30 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +#include "Eobj.h" + +extern EAPI Eobj_Op SIMPLE_BASE_ID; + +enum { + SIMPLE_SUB_ID_A_SET, + SIMPLE_SUB_ID_A_GET, + SIMPLE_SUB_ID_LAST +}; + +typedef struct +{ + int a; +} Simple_Public_Data; + +#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id) + +#define SIMPLE_A_SET(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EOBJ_TYPECHECK(int, a) +#define SIMPLE_A_GET(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EOBJ_TYPECHECK(int *, a) + +extern const Eobj_Event_Description _SIG_A_CHANGED; +#define SIG_A_CHANGED (&(_SIG_A_CHANGED)) + +#define SIMPLE_CLASS simple_class_get() +const Eobj_Class *simple_class_get(void) EINA_CONST; + +#endif