e_devicemgr: make an internal header
[platform/upstream/enlightenment.git] / src / bin / e_devicemgr.c
1 #include "e.h"
2 #include "e_devicemgr_intern.h"
3 #include "e_devicemgr_private.h"
4
5 E_API E_Devicemgr *e_devicemgr;
6
7 static int _e_devicemgr_intercept_hooks_delete = 0;
8 static int _e_devicemgr_intercept_hooks_walking = 0;
9
10 static Eina_Inlist *_e_devicemgr_intercept_hooks[] =
11 {
12    [E_DEVICEMGR_INTERCEPT_HOOK_DETENT] = NULL,
13 };
14
15 int _devicemgr_log_dom = -1;
16
17 EINTERN E_Devicemgr_Intercept_Hook *
18 e_devicemgr_intercept_hook_add(E_Devicemgr_Intercept_Hook_Point hookpoint, E_Devicemgr_Intercept_Hook_Cb func, const void *data)
19 {
20    E_Devicemgr_Intercept_Hook *ch;
21
22    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint < 0 || hookpoint >= E_DEVICEMGR_INTERCEPT_HOOK_LAST,
23                                   EINA_FALSE);
24
25    ch = E_NEW(E_Devicemgr_Intercept_Hook, 1);
26    if (!ch) return NULL;
27    ch->hookpoint = hookpoint;
28    ch->func = func;
29    ch->data = (void*)data;
30    _e_devicemgr_intercept_hooks[hookpoint] = eina_inlist_append(_e_devicemgr_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
31    return ch;
32 }
33
34 EINTERN void
35 e_devicemgr_intercept_hook_del(E_Devicemgr_Intercept_Hook *ch)
36 {
37    EINA_SAFETY_ON_NULL_RETURN(ch);
38
39    ch->delete_me = 1;
40    if (_e_devicemgr_intercept_hooks_walking == 0)
41      {
42         _e_devicemgr_intercept_hooks[ch->hookpoint] = eina_inlist_remove(_e_devicemgr_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
43         free(ch);
44      }
45    else
46      _e_devicemgr_intercept_hooks_delete++;
47 }
48
49 static void
50 _e_devicemgr_intercept_hooks_clean(void)
51 {
52    Eina_Inlist *l;
53    E_Devicemgr_Intercept_Hook *ch;
54    unsigned int x;
55    for (x = 0; x < E_DEVICEMGR_INTERCEPT_HOOK_LAST; x++)
56      EINA_INLIST_FOREACH_SAFE(_e_devicemgr_intercept_hooks[x], l, ch)
57        {
58           if (!ch->delete_me) continue;
59           _e_devicemgr_intercept_hooks[x] = eina_inlist_remove(_e_devicemgr_intercept_hooks[x], EINA_INLIST_GET(ch));
60          free(ch);
61        }
62 }
63
64 EINTERN Eina_Bool
65 e_devicemgr_intercept_hook_call(E_Devicemgr_Intercept_Hook_Point hookpoint, void *event)
66 {
67    E_Devicemgr_Intercept_Hook *ch;
68    Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
69
70    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint < 0 || hookpoint >= E_DEVICEMGR_INTERCEPT_HOOK_LAST,
71                                   EINA_FALSE);
72
73    _e_devicemgr_intercept_hooks_walking++;
74    EINA_INLIST_FOREACH(_e_devicemgr_intercept_hooks[hookpoint], ch)
75      {
76         if (ch->delete_me) continue;
77         res = ch->func(ch->data, hookpoint, event);
78         if (!res) ret = EINA_FALSE;
79      }
80    _e_devicemgr_intercept_hooks_walking--;
81    if ((_e_devicemgr_intercept_hooks_walking == 0) && (_e_devicemgr_intercept_hooks_delete > 0))
82      _e_devicemgr_intercept_hooks_clean();
83
84    return ret;
85 }
86
87 E_API Eina_Bool
88 e_devicemgr_is_blocking_event(Ecore_Device_Class clas)
89 {
90    unsigned int dev_clas = 0x0;
91
92    switch (clas)
93      {
94         case ECORE_DEVICE_CLASS_KEYBOARD:
95           dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
96           break;
97         case ECORE_DEVICE_CLASS_MOUSE:
98           dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
99           break;
100         case ECORE_DEVICE_CLASS_TOUCH:
101           dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
102           break;
103         default:
104           return EINA_FALSE;
105      }
106
107    if (e_devicemgr->block.devtype & dev_clas)
108      return EINA_TRUE;
109
110    return EINA_FALSE;
111 }
112
113 EINTERN int
114 e_devicemgr_init(void)
115 {
116    E_Devicemgr_Config_Data *dconfig = NULL;
117    Eina_Bool res = EINA_FALSE;
118
119    EINA_SAFETY_ON_NULL_GOTO(e_comp, failed);
120
121    _devicemgr_log_dom = eina_log_domain_register("e-devicemgr", EINA_COLOR_BLUE);
122    EINA_SAFETY_ON_FALSE_GOTO(_devicemgr_log_dom >= 0, failed);
123    eina_log_domain_level_set("e-devicemgr", EINA_LOG_LEVEL_INFO);
124
125    e_devicemgr = E_NEW(E_Devicemgr, 1);
126    EINA_SAFETY_ON_NULL_GOTO(e_devicemgr, failed);
127
128    dconfig = E_NEW(E_Devicemgr_Config_Data, 1);
129    EINA_SAFETY_ON_NULL_GOTO(dconfig, failed);
130
131    e_devicemgr_conf_init(dconfig);
132    e_devicemgr->dconfig = dconfig;
133
134    g_rec_mutex_init(&e_devicemgr->device_list_mutex);
135
136    res = e_devicemgr_wl_init();
137    EINA_SAFETY_ON_FALSE_GOTO(res, wl_failed);
138
139    res = e_devicemgr_input_init();
140    EINA_SAFETY_ON_FALSE_GOTO(res, input_failed);
141
142    return EINA_TRUE;
143
144 input_failed:
145    e_devicemgr_input_shutdown();
146
147 wl_failed:
148    e_devicemgr_wl_shutdown();
149
150 failed:
151    if (e_devicemgr)
152      {
153
154         if (e_devicemgr->dconfig)
155           {
156              e_devicemgr_conf_fini(e_devicemgr->dconfig);
157              E_FREE(e_devicemgr->dconfig);
158              e_devicemgr->dconfig = NULL;
159           }
160
161         E_FREE(e_devicemgr);
162         e_devicemgr = NULL;
163      }
164    eina_log_domain_unregister(_devicemgr_log_dom);
165    _devicemgr_log_dom = -1;
166    return EINA_FALSE;
167 }
168
169 EINTERN int
170 e_devicemgr_shutdown(void)
171 {
172    g_rec_mutex_clear(&e_devicemgr->device_list_mutex);
173
174    eina_log_domain_unregister(_devicemgr_log_dom);
175    _devicemgr_log_dom = -1;
176    if (e_devicemgr->dconfig)
177      {
178         e_devicemgr_conf_fini(e_devicemgr->dconfig);
179         E_FREE(e_devicemgr->dconfig);
180         e_devicemgr->dconfig = NULL;
181      }
182    E_FREE(e_devicemgr);
183    return EINA_TRUE;
184 }
185
186 EINTERN Eina_Bool
187 e_devicemgr_block_internal_add(Ecore_Device_Class clas, Eina_Bool all_class, uint32_t duration, E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
188 {
189    unsigned int dev_clas = 0x0;
190
191    if (all_class)
192      dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD |
193                 TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE |
194                 TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
195    else
196      {
197         switch (clas)
198           {
199            case ECORE_DEVICE_CLASS_KEYBOARD:
200               dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
201               break;
202            case ECORE_DEVICE_CLASS_MOUSE:
203               dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
204               break;
205            case ECORE_DEVICE_CLASS_TOUCH:
206               dev_clas = TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
207               break;
208            default:
209               return EINA_FALSE;
210           }
211      }
212
213    return e_devicemgr_block_add_internal(dev_clas, duration, cb_func, cb_data);
214 }
215
216 EINTERN Eina_Bool
217 e_devicemgr_block_internal_remove(E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
218 {
219    return e_devicemgr_block_remove_internal(cb_func, cb_data);
220 }
221
222 E_API Eina_Bool
223 e_devicemgr_block_reset(void)
224 {
225    int ret;
226
227    if (!e_devicemgr->block.client) return EINA_FALSE;
228    ret = e_devicemgr_block_remove(e_devicemgr->block.client);
229    if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
230      return EINA_TRUE;
231
232    return EINA_FALSE;
233 }
234