Eobj: Add a mixin inheritance test.
[profile/ivi/eobj.git] / examples / mixin / mixin2.c
1 #include "Eobj.h"
2 #include "mixin.h"
3 #include "mixin2.h"
4 #include "simple.h"
5
6 #include "config.h"
7
8 static const Eobj_Class *_my_class = NULL;
9
10 static void
11 _add_and_print_set(Eobj *obj, void *class_data __UNUSED__, va_list *list)
12 {
13    int a, b, x;
14    eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b));
15    x = va_arg(*list, const int);
16    printf("%s %d\n", eobj_class_name_get(eobj_class_get(obj)), a + b + x);
17    eobj_do_super(obj, MIXIN_ADD_AND_PRINT(x));
18 }
19
20 static void
21 _constructor(Eobj *obj, void *class_data __UNUSED__)
22 {
23    eobj_constructor_super(obj);
24 }
25
26 static void
27 _destructor(Eobj *obj, void *class_data __UNUSED__)
28 {
29    eobj_destructor_super(obj);
30 }
31
32 static void
33 _class_constructor(Eobj_Class *klass)
34 {
35    const Eobj_Op_Func_Description func_desc[] = {
36         EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), _add_and_print_set),
37         EOBJ_OP_FUNC_SENTINEL
38    };
39
40    eobj_class_funcs_set(klass, func_desc);
41 }
42
43 const Eobj_Class *
44 mixin2_class_get(void)
45 {
46    if (_my_class) return _my_class;
47
48    static const Eobj_Class_Description class_desc = {
49         "Mixin2",
50         EOBJ_CLASS_TYPE_MIXIN,
51         EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
52         NULL,
53         0,
54         _constructor,
55         _destructor,
56         _class_constructor,
57         NULL
58    };
59
60    _my_class = eobj_class_new(&class_desc, MIXIN_CLASS, NULL);
61
62    return _my_class;
63 }