aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/eo/signals/signals_simple.c
blob: 5404f4da768cf4cf4c855abb9b9a0ce9f8e35d64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Eo.h"
#include "signals_simple.h"

typedef struct
{
   Simple_Public_Data pub;
   int a;
} Private_Data;

EAPI const Efl_Event_Description _EV_A_CHANGED =
        EFL_EVENT_DESCRIPTION("a,changed");
EAPI const Efl_Event_Description _EV_RESTART =
        EFL_EVENT_DESCRIPTION_RESTART("restart");

#define MY_CLASS SIMPLE_CLASS

static void
_a_set(Eo *obj, void *class_data, int a)
{
   Private_Data *pd = class_data;
   pd->a = a;
   printf("%s %d\n", __func__, pd->a);

   efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a);
}

void
_cb_added(void *data EINA_UNUSED, const Eo_Event *event)
{
   Simple_Public_Data *pd = efl_data_scope_get(event->object, MY_CLASS);
   const Efl_Callback_Array_Item *callback_array = event->info;

   if (callback_array->desc != EV_A_CHANGED)
      return;

   pd->cb_count++;

   printf("Added EV_A_CHANGED callback to %p. Count: %d\n", event->object, pd->cb_count);
}

void
_cb_deled(void *data EINA_UNUSED, const Eo_Event *event)
{
   Simple_Public_Data *pd = efl_data_scope_get(event->object, MY_CLASS);
   const Efl_Callback_Array_Item *callback_array = event->info;

   if (callback_array->desc != EV_A_CHANGED)
      return;

   pd->cb_count--;

   printf("Removed EV_A_CHANGED callback from %p. Count: %d\n", event->object, pd->cb_count);
}

static Eo *
_constructor(Eo *obj, void *class_data EINA_UNUSED)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));

   efl_event_callback_add(obj, EFL_EVENT_CALLBACK_ADD, _cb_added, NULL);
   efl_event_callback_add(obj, EFL_EVENT_CALLBACK_DEL, _cb_deled, NULL);

   efl_key_data_set(obj, "cb_count", NULL);

   return obj;
}

EAPI EFL_VOID_FUNC_BODYV(simple_a_set, EFL_FUNC_CALL(a), int a);

static Efl_Op_Description op_descs[] = {
     EFL_OBJECT_OP_FUNC_OVERRIDE(efl_constructor, _constructor),
     EFL_OBJECT_OP_FUNC(simple_a_set, _a_set),
};

static const Efl_Class_Description class_desc = {
     EO_VERSION,
     "Simple",
     EFL_CLASS_TYPE_REGULAR,
     EFL_CLASS_DESCRIPTION_OPS(op_descs),
     sizeof(Private_Data),
     NULL,
     NULL
};

EFL_DEFINE_CLASS(simple_class_get, &class_desc, EO_CLASS, NULL);