forked from enlightenment/efl
Eobj: Added some composite objects tests.
SVN revision: 70134
This commit is contained in:
parent
a0ee8a4aa7
commit
bef76f0407
|
@ -45,6 +45,7 @@ add_subdirectory(examples/signals)
|
||||||
add_subdirectory(examples/access)
|
add_subdirectory(examples/access)
|
||||||
add_subdirectory(examples/constructors)
|
add_subdirectory(examples/constructors)
|
||||||
add_subdirectory(examples/function_overrides)
|
add_subdirectory(examples/function_overrides)
|
||||||
|
add_subdirectory(examples/composite_objects)
|
||||||
|
|
||||||
add_subdirectory(tests EXCLUDE_FROM_ALL)
|
add_subdirectory(tests EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue