Eobj: s/__UNUSED__/EINA_UNUSED/ I had no idea that exists.
[profile/ivi/eobj.git] / examples / constructors / mixin.c
1 #include "Eobj.h"
2 #include "mixin.h"
3 #include "simple.h"
4
5 #include "config.h"
6
7 EAPI Eobj_Op MIXIN_BASE_ID = 0;
8
9 static const Eobj_Class *_my_class = NULL;
10
11 static void
12 _add_and_print_set(Eobj *obj, void *class_data EINA_UNUSED, va_list *list)
13 {
14    int a, b, x;
15    eobj_do(obj, SIMPLE_A_GET(&a), SIMPLE_B_GET(&b));
16    x = va_arg(*list, const int);
17    printf("%s %d\n", __func__, a + b + x);
18 }
19
20 extern int my_init_count;
21
22 static void
23 _constructor(Eobj *obj, void *class_data EINA_UNUSED)
24 {
25    eobj_constructor_super(obj);
26
27    my_init_count++;
28 }
29
30 static void
31 _destructor(Eobj *obj, void *class_data EINA_UNUSED)
32 {
33    eobj_destructor_super(obj);
34
35    my_init_count--;
36 }
37
38 static void
39 _class_constructor(Eobj_Class *klass)
40 {
41    const Eobj_Op_Func_Description func_desc[] = {
42         EOBJ_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), _add_and_print_set),
43         EOBJ_OP_FUNC_SENTINEL
44    };
45
46    eobj_class_funcs_set(klass, func_desc);
47 }
48
49 const Eobj_Class *
50 mixin_class_get(void)
51 {
52    if (_my_class) return _my_class;
53
54    static const Eobj_Op_Description op_desc[] = {
55         EOBJ_OP_DESCRIPTION(MIXIN_SUB_ID_ADD_AND_SET, "i", "Add A + B + param and print it"),
56         EOBJ_OP_DESCRIPTION_SENTINEL
57    };
58
59    static const Eobj_Class_Description class_desc = {
60         "Mixin",
61         EOBJ_CLASS_TYPE_MIXIN,
62         EOBJ_CLASS_DESCRIPTION_OPS(&MIXIN_BASE_ID, op_desc, MIXIN_SUB_ID_LAST),
63         NULL,
64         0,
65         _constructor,
66         _destructor,
67         _class_constructor,
68         NULL
69    };
70
71    return _my_class = eobj_class_new(&class_desc, NULL, NULL);
72 }