Eobj: s/__UNUSED__/EINA_UNUSED/ I had no idea that exists.
[profile/ivi/eobj.git] / examples / constructors / simple.c
1 #include "Eobj.h"
2 #include "mixin.h"
3 #include "simple.h"
4
5 #include "config.h"
6
7 EAPI Eobj_Op SIMPLE_BASE_ID = 0;
8
9 typedef struct
10 {
11    int a;
12    int b;
13 } Private_Data;
14
15 static const Eobj_Class *_my_class = NULL;
16
17 static char *class_var = NULL;
18
19 #define _GET_SET_FUNC(name) \
20 static void \
21 _##name##_get(Eobj *obj EINA_UNUSED, void *class_data, va_list *list) \
22 { \
23    Private_Data *pd = class_data; \
24    int *name; \
25    name = va_arg(*list, int *); \
26    *name = pd->name; \
27    printf("%s %d\n", __func__, pd->name); \
28 } \
29 static void \
30 _##name##_set(Eobj *obj EINA_UNUSED, void *class_data, va_list *list) \
31 { \
32    Private_Data *pd = class_data; \
33    int name; \
34    name = va_arg(*list, int); \
35    pd->name = name; \
36    printf("%s %d\n", __func__, pd->name); \
37 }
38
39 _GET_SET_FUNC(a)
40 _GET_SET_FUNC(b)
41
42 extern int my_init_count;
43
44 static void
45 _constructor(Eobj *obj, void *class_data EINA_UNUSED)
46 {
47    eobj_constructor_super(obj);
48
49    my_init_count++;
50 }
51
52 static void
53 _destructor(Eobj *obj, void *class_data EINA_UNUSED)
54 {
55    eobj_destructor_super(obj);
56
57    my_init_count--;
58 }
59
60 static void
61 _class_constructor(Eobj_Class *klass)
62 {
63    const Eobj_Op_Func_Description func_desc[] = {
64         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
65         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
66         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_SET), _b_set),
67         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_GET), _b_get),
68         EOBJ_OP_FUNC_SENTINEL
69    };
70
71    eobj_class_funcs_set(klass, func_desc);
72
73    class_var = malloc(10);
74 }
75
76 static void
77 _class_destructor(Eobj_Class *klass EINA_UNUSED)
78 {
79    free(class_var);
80 }
81
82 const Eobj_Class *
83 simple_class_get(void)
84 {
85    if (_my_class) return _my_class;
86
87    static const Eobj_Op_Description op_desc[] = {
88         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"),
89         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "i", "Get property A"),
90         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_B_SET, "i", "Set property B"),
91         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_B_GET, "i", "Get property B"),
92         EOBJ_OP_DESCRIPTION_SENTINEL
93    };
94
95    static const Eobj_Class_Description class_desc = {
96         "Simple",
97         EOBJ_CLASS_TYPE_REGULAR,
98         EOBJ_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
99         NULL,
100         sizeof(Private_Data),
101         _constructor,
102         _destructor,
103         _class_constructor,
104         _class_destructor
105    };
106
107    return _my_class = eobj_class_new(&class_desc, EOBJ_BASE_CLASS, MIXIN_CLASS, NULL);
108 }