Eo: Removed "type" property from event/op descriptions.
[profile/ivi/eobj.git] / examples / interface / simple.c
1 #include "Eo.h"
2 #include "interface.h"
3 #include "interface2.h"
4 #include "simple.h"
5
6 #include "config.h"
7
8 EAPI Eo_Op SIMPLE_BASE_ID = 0;
9
10 typedef struct
11 {
12    int a;
13    int b;
14 } Private_Data;
15
16 #define MY_CLASS SIMPLE_CLASS
17
18 #define _GET_SET_FUNC(name) \
19 static void \
20 _##name##_get(const Eo *obj EINA_UNUSED, const void *class_data, va_list *list) \
21 { \
22    const Private_Data *pd = class_data; \
23    int *name; \
24    name = va_arg(*list, int *); \
25    *name = pd->name; \
26    printf("%s %d\n", __func__, pd->name); \
27 } \
28 static void \
29 _##name##_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list) \
30 { \
31    Private_Data *pd = class_data; \
32    int name; \
33    name = va_arg(*list, int); \
34    pd->name = name; \
35    printf("%s %d\n", __func__, pd->name); \
36 }
37
38 _GET_SET_FUNC(a)
39 _GET_SET_FUNC(b)
40
41 static void
42 _ab_sum_get(const Eo *obj, const void *class_data EINA_UNUSED, va_list *list)
43 {
44    int a, b;
45    eo_query(obj, simple_a_get(&a), simple_b_get(&b));
46    int *sum = va_arg(*list, int *);
47    if (sum)
48       *sum = a + b;
49    printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
50 }
51
52 static void
53 _ab_sum_get2(const Eo *obj, const void *class_data EINA_UNUSED, va_list *list)
54 {
55    int a, b;
56    eo_query(obj, simple_a_get(&a), simple_b_get(&b));
57    int *sum = va_arg(*list, int *);
58    if (sum)
59       *sum = a + b + 1;
60    printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
61 }
62
63 static void
64 _class_constructor(Eo_Class *klass)
65 {
66    const Eo_Op_Func_Description func_desc[] = {
67         EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
68         EO_OP_FUNC_CONST(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
69         EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_SET), _b_set),
70         EO_OP_FUNC_CONST(SIMPLE_ID(SIMPLE_SUB_ID_B_GET), _b_get),
71         EO_OP_FUNC_CONST(INTERFACE_ID(INTERFACE_SUB_ID_AB_SUM_GET), _ab_sum_get),
72         EO_OP_FUNC_CONST(INTERFACE2_ID(INTERFACE2_SUB_ID_AB_SUM_GET2), _ab_sum_get2),
73         EO_OP_FUNC_SENTINEL
74    };
75
76    eo_class_funcs_set(klass, func_desc);
77 }
78
79 static const Eo_Op_Description op_desc[] = {
80      EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
81      EO_OP_DESCRIPTION_CONST(SIMPLE_SUB_ID_A_GET, "Get property A"),
82      EO_OP_DESCRIPTION(SIMPLE_SUB_ID_B_SET, "Set property B"),
83      EO_OP_DESCRIPTION_CONST(SIMPLE_SUB_ID_B_GET, "Get property B"),
84      EO_OP_DESCRIPTION_SENTINEL
85 };
86
87 static const Eo_Class_Description class_desc = {
88      "Simple",
89      EO_CLASS_TYPE_REGULAR,
90      EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
91      NULL,
92      sizeof(Private_Data),
93      NULL,
94      NULL,
95      _class_constructor,
96      NULL
97 };
98
99 EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, INTERFACE2_CLASS, NULL);