Eobj: s/__UNUSED__/EINA_UNUSED/ I had no idea that exists.
[profile/ivi/eobj.git] / examples / composite_objects / simple.c
1 #include "Eobj.h"
2 #include "simple.h"
3
4 #include "config.h"
5
6 EAPI Eobj_Op SIMPLE_BASE_ID = 0;
7
8 EAPI const Eobj_Event_Description _SIG_A_CHANGED =
9         EOBJ_EVENT_DESCRIPTION("a,changed", "i", "Called when a has changed.");
10
11 static const Eobj_Class *_my_class = NULL;
12
13 static void
14 _a_set(Eobj *obj, void *class_data, va_list *list)
15 {
16    Simple_Public_Data *pd = class_data;
17    int a;
18    a = va_arg(*list, int);
19    printf("%s %d\n", eobj_class_name_get(_my_class), a);
20    pd->a = a;
21
22    eobj_event_callback_call(obj, SIG_A_CHANGED, &pd->a);
23 }
24
25 static void
26 _a_get(Eobj *obj EINA_UNUSED, void *class_data, va_list *list)
27 {
28    Simple_Public_Data *pd = class_data;
29    int *a;
30    a = va_arg(*list, int *);
31    *a = pd->a;
32 }
33
34 static void
35 _class_constructor(Eobj_Class *klass)
36 {
37    const Eobj_Op_Func_Description func_desc[] = {
38         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
39         EOBJ_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
40         EOBJ_OP_FUNC_SENTINEL
41    };
42
43    eobj_class_funcs_set(klass, func_desc);
44 }
45
46 const Eobj_Class *
47 simple_class_get(void)
48 {
49    if (_my_class) return _my_class;
50
51    static const Eobj_Op_Description op_desc[] = {
52         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"),
53         EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "i", "Get property A"),
54         EOBJ_OP_DESCRIPTION_SENTINEL
55    };
56
57    static const Eobj_Event_Description *event_desc[] = {
58         SIG_A_CHANGED,
59         NULL
60    };
61
62    static const Eobj_Class_Description class_desc = {
63         "Simple",
64         EOBJ_CLASS_TYPE_REGULAR,
65         EOBJ_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
66         event_desc,
67         sizeof(Simple_Public_Data),
68         NULL,
69         NULL,
70         _class_constructor,
71         NULL
72    };
73
74    return _my_class = eobj_class_new(&class_desc, EOBJ_BASE_CLASS, NULL);
75 }