summaryrefslogtreecommitdiff
path: root/src/lib/eldbus/eldbus_model_signal.c
blob: 406c451398609262ba651f9582187d8b23669c47 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "eldbus_model_arguments_private.h"
#include "eldbus_model_signal_private.h"
#include "eldbus_model_private.h"

#include <Eina.h>

#define MY_CLASS ELDBUS_MODEL_SIGNAL_CLASS
#define MY_CLASS_NAME "Eldbus_Model_Signal"

static void _eldbus_model_signal_handler_cb(void *, const Eldbus_Message *);
static void _eldbus_model_signal_callback_add(Eldbus_Model_Signal_Data *);
static void _eldbus_model_signal_callback_del(Eldbus_Model_Signal_Data *);

static Eo_Base*
_eldbus_model_signal_eo_base_constructor(Eo *obj, Eldbus_Model_Signal_Data *pd)
{
   eo_constructor(eo_super(obj, MY_CLASS));

   pd->obj = obj;
   pd->handler = NULL;
   pd->signal = NULL;
   return obj;
}

static void
_eldbus_model_signal_constructor(Eo *obj EINA_UNUSED,
                                 Eldbus_Model_Signal_Data *pd,
                                 Eldbus_Proxy *proxy,
                                 const Eldbus_Introspection_Signal *signal)
{
   EINA_SAFETY_ON_NULL_RETURN(proxy);
   EINA_SAFETY_ON_NULL_RETURN(signal);

   eldbus_model_arguments_constructor(eo_super(obj, MY_CLASS), proxy, signal->name, signal->arguments);

   pd->signal = signal;
}

static void
_eldbus_model_signal_eo_base_destructor(Eo *obj, Eldbus_Model_Signal_Data *pd)
{
   _eldbus_model_signal_callback_del(pd);

   eo_destructor(eo_super(obj, MY_CLASS));
}

static void
_eldbus_model_signal_efl_model_base_properties_load(Eo *obj, Eldbus_Model_Signal_Data *pd)
{
   Eldbus_Model_Arguments_Data *args_data = eo_data_scope_get(pd->obj, ELDBUS_MODEL_ARGUMENTS_CLASS);
   EINA_SAFETY_ON_NULL_RETURN(args_data);

   if (args_data->load.status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)
     return;

   _eldbus_model_signal_callback_add(pd);

   efl_model_properties_load(eo_super(obj, MY_CLASS));
}

static void
_eldbus_model_signal_efl_model_base_unload(Eo *obj EINA_UNUSED, Eldbus_Model_Signal_Data *pd)
{
   _eldbus_model_signal_callback_del(pd);
   efl_model_unload(eo_super(obj, MY_CLASS));
}

static void
_eldbus_model_signal_callback_add(Eldbus_Model_Signal_Data *pd)
{
   EINA_SAFETY_ON_NULL_RETURN(pd);
   EINA_SAFETY_ON_FALSE_RETURN(NULL == pd->handler);

   Eldbus_Model_Arguments_Data *args_data = eo_data_scope_get(pd->obj, ELDBUS_MODEL_ARGUMENTS_CLASS);
   EINA_SAFETY_ON_NULL_RETURN(args_data);

   pd->handler = eldbus_proxy_signal_handler_add(args_data->proxy, pd->signal->name, _eldbus_model_signal_handler_cb, pd);
}

static void
_eldbus_model_signal_callback_del(Eldbus_Model_Signal_Data *pd)
{
   EINA_SAFETY_ON_NULL_RETURN(pd);

   if (pd->handler)
     {
        eldbus_signal_handler_unref(pd->handler);
        pd->handler = NULL;
     }
}

static void
_eldbus_model_signal_handler_cb(void *data, const Eldbus_Message *msg)
{
   Eldbus_Model_Signal_Data *pd = (Eldbus_Model_Signal_Data*)data;

   Eldbus_Model_Arguments_Data *args_data = eo_data_scope_get(pd->obj, ELDBUS_MODEL_ARGUMENTS_CLASS);

   eldbus_model_arguments_process_arguments(args_data, msg, NULL);
}

#include "eldbus_model_signal.eo.c"