Eo: added a version field to the class description.
[profile/ivi/eobj.git] / src / examples / simple / simple.c
1 #include "Eo.h"
2 #include "simple.h"
3
4 #include "config.h"
5
6 EAPI Eo_Op SIMPLE_BASE_ID = 0;
7
8 typedef struct
9 {
10    int a;
11 } Private_Data;
12
13 #define MY_CLASS SIMPLE_CLASS
14
15 static void
16 _a_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
17 {
18    const Private_Data *pd = class_data;
19    int *a;
20    a = va_arg(*list, int *);
21    *a = pd->a;
22    printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
23 }
24
25 static void
26 _a_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
27 {
28    Private_Data *pd = class_data;
29    int a;
30    a = va_arg(*list, int);
31    pd->a = a;
32    printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
33 }
34
35 static void
36 _a_power_3_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
37 {
38    const Private_Data *pd = class_data;
39    int *ret;
40    ret = va_arg(*list, int *);
41    if (ret)
42       *ret = pd->a * pd->a * pd->a;
43    printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
44 }
45
46 static void
47 _class_constructor(Eo_Class *klass)
48 {
49    const Eo_Op_Func_Description func_desc[] = {
50         EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
51         EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
52         EO_OP_FUNC(INTERFACE_ID(INTERFACE_SUB_ID_A_POWER_3_GET), _a_power_3_get),
53         EO_OP_FUNC_SENTINEL
54    };
55
56    eo_class_funcs_set(klass, func_desc);
57 }
58
59 static const Eo_Op_Description op_desc[] = {
60      EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
61      EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "Get property A"),
62      EO_OP_DESCRIPTION_SENTINEL
63 };
64
65 static const Eo_Class_Description class_desc = {
66      EO_VERSION,
67      "Simple",
68      EO_CLASS_TYPE_REGULAR,
69      EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
70      NULL,
71      sizeof(Private_Data),
72      _class_constructor,
73      NULL
74 };
75
76 EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, INTERFACE_CLASS, MIXIN_CLASS, NULL);