Eo: Improved error reporting with failed constructors.
[profile/ivi/eobj.git] / examples / access / simple.c
1 #include "Eo.h"
2 #include "simple.h"
3 #include "simple_protected.h"
4
5 EAPI Eo_Op SIMPLE_BASE_ID = 0;
6
7 typedef struct
8 {
9    Simple_Protected_Data protected;
10    int a;
11 } Private_Data;
12
13 EAPI const Eo_Event_Description _EV_A_CHANGED =
14         EO_EVENT_DESCRIPTION("a,changed", "i", "Called when a has changed.");
15
16 #define MY_CLASS SIMPLE_CLASS
17
18 static void
19 _a_set(Eo *obj, void *class_data, va_list *list)
20 {
21    Private_Data *pd = class_data;
22    int a;
23    a = va_arg(*list, int);
24    pd->a = a;
25    printf("%s %d\n", __func__, pd->a);
26
27    pd->protected.protected_x1 = a + 1;
28    pd->protected.public.public_x2 = a + 2;
29
30    eo_do(obj, eo_event_callback_call(EV_A_CHANGED, &pd->a, NULL));
31 }
32
33 static void
34 _class_constructor(Eo_Class *klass)
35 {
36    const Eo_Op_Func_Description func_desc[] = {
37         EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
38         EO_OP_FUNC_SENTINEL
39    };
40
41    eo_class_funcs_set(klass, func_desc);
42 }
43
44 static const Eo_Op_Description op_desc[] = {
45      EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"),
46      EO_OP_DESCRIPTION_SENTINEL
47 };
48
49 static const Eo_Event_Description *event_desc[] = {
50      EV_A_CHANGED,
51      NULL
52 };
53
54 static const Eo_Class_Description class_desc = {
55      "Simple",
56      EO_CLASS_TYPE_REGULAR,
57      EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
58      event_desc,
59      sizeof(Private_Data),
60      NULL,
61      NULL,
62      _class_constructor,
63      NULL
64 };
65
66 EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL)
67