a992cb9cf96be17a76d871b6bfcdee3f7a1c8f85
[profile/ivi/eobj.git] / examples / mixin / mixin3.c
1 #include "Eobj.h"
2 #include "mixin.h"
3 #include "mixin3.h"
4 #include "simple.h"
5
6 #include "config.h"
7
8 #include "../eunit_tests.h"
9
10 static const Eobj_Class *_my_class = NULL;
11
12 static void
13 _ab_sum_get(Eobj *obj, void *class_data __UNUSED__, va_list *list)
14 {
15    int *sum = va_arg(*list, int *);
16    printf("%s %s\n", eobj_class_name_get(_my_class), __func__);
17    eobj_do_super(obj, MIXIN_AB_SUM_GET(sum));
18
19    ++*sum;
20
21      {
22         int _a, _b;
23         eobj_do(obj, SIMPLE_A_GET(&_a), SIMPLE_B_GET(&_b));
24         fail_if(*sum != _a + _b + 2);
25      }
26 }
27
28 static void
29 _constructor(Eobj *obj, void *class_data __UNUSED__)
30 {
31    eobj_constructor_super(obj);
32 }
33
34 static void
35 _destructor(Eobj *obj, void *class_data __UNUSED__)
36 {
37    eobj_destructor_super(obj);
38 }
39
40 static void
41 _class_constructor(Eobj_Class *klass)
42 {
43    const Eobj_Op_Func_Description func_desc[] = {
44         EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
45         EOBJ_OP_FUNC_SENTINEL
46    };
47
48    eobj_class_funcs_set(klass, func_desc);
49 }
50
51 const Eobj_Class *
52 mixin3_class_get(void)
53 {
54    if (_my_class) return _my_class;
55
56    static const Eobj_Class_Description class_desc = {
57         "Mixin3",
58         EOBJ_CLASS_TYPE_MIXIN,
59         EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
60         NULL,
61         0,
62         _constructor,
63         _destructor,
64         _class_constructor,
65         NULL
66    };
67
68    _my_class = eobj_class_new(&class_desc, MIXIN_CLASS, NULL);
69
70    return _my_class;
71 }