1 #include "e_devicemgr_private.h"
2 #include "e_input_intern.h"
3 #include "e_comp_wl_intern.h"
6 #define E_DEVMGR_CYNARA_ERROR_CHECK_GOTO(func_name, ret, label) \
9 if (EINA_UNLIKELY(CYNARA_API_SUCCESS != ret)) \
11 _e_devicemgr_util_cynara_log(func_name, ret); \
18 _e_devicemgr_util_cynara_log(const char *func_name, int err)
20 #define CYNARA_BUFSIZE 128
21 char buf[CYNARA_BUFSIZE] = "\0";
24 ret = cynara_strerror(err, buf, CYNARA_BUFSIZE);
25 if (ret != CYNARA_API_SUCCESS)
27 DMDBG("Failed to cynara_strerror: %d (error log about %s: %d)\n", ret, func_name, err);
30 DMDBG("%s is failed: %s\n", func_name, buf);
34 _e_devicemgr_util_do_privilege_check(struct wl_client *client, int socket_fd, const char *rule)
37 char *clientSmack=NULL, *uid=NULL, *client_session=NULL;
38 Eina_Bool res = EINA_FALSE;
40 /* If initialization of cynara has been failed, let's not to do further permission checks. */
41 if (e_devicemgr->wl_data->p_cynara == NULL && e_devicemgr->wl_data->cynara_initialized) return EINA_TRUE;
42 if (socket_fd < 0) return EINA_FALSE;
44 ret = cynara_creds_socket_get_client(socket_fd, CLIENT_METHOD_SMACK, &clientSmack);
45 E_DEVMGR_CYNARA_ERROR_CHECK_GOTO("cynara_creds_socket_get_client", ret, finish);
47 ret = cynara_creds_socket_get_user(socket_fd, USER_METHOD_UID, &uid);
48 E_DEVMGR_CYNARA_ERROR_CHECK_GOTO("cynara_creds_socket_get_user", ret, finish);
50 ret = cynara_creds_socket_get_pid(socket_fd, &pid);
51 E_DEVMGR_CYNARA_ERROR_CHECK_GOTO("cynara_creds_socket_get_pid", ret, finish);
53 client_session = cynara_session_from_pid(pid);
55 ret = cynara_check(e_devicemgr->wl_data->p_cynara, clientSmack, client_session, uid, rule);
57 if (CYNARA_API_ACCESS_ALLOWED == ret)
61 E_FREE(client_session);
70 _e_devicemgr_wl_device_cb_axes_select(struct wl_client *client, struct wl_resource *resource, struct wl_array *axes)
76 _e_devicemgr_wl_device_cb_release(struct wl_client *client, struct wl_resource *resource)
78 wl_resource_destroy(resource);
81 static const struct tizen_input_device_interface _e_devicemgr_wl_device_interface =
83 _e_devicemgr_wl_device_cb_axes_select,
84 _e_devicemgr_wl_device_cb_release,
88 _e_devicemgr_wl_device_data_destroy(E_Devicemgr_Input_Device_User_Data *device_user_data)
90 if (!device_user_data) return;
92 DMDBG("Destroy device user data. (res: %u)", device_user_data->dev_res ? wl_resource_get_id(device_user_data->dev_res) : 0x0);
94 if (device_user_data->mgr_data)
95 device_user_data->mgr_data->user_data_list = eina_list_remove(device_user_data->mgr_data->user_data_list, device_user_data);
97 if (device_user_data->dev)
98 device_user_data->dev->resources = eina_list_remove(device_user_data->dev->resources, device_user_data->dev_res);
100 if (device_user_data->dev_res)
101 wl_resource_set_user_data(device_user_data->dev_res, NULL);
103 E_FREE(device_user_data);
107 _e_devicemgr_wl_device_cb_unbind(struct wl_resource *resource)
109 E_Devicemgr_Input_Device_User_Data *device_user_data;
111 DMDBG("Unbind tizen_input_device: %u (client: %p)", wl_resource_get_id(resource), wl_resource_get_client(resource));
112 if (!(device_user_data = wl_resource_get_user_data(resource))) return;
114 _e_devicemgr_wl_device_data_destroy(device_user_data);
118 e_devicemgr_wl_device_update(E_Devicemgr_Input_Device *dev)
120 struct wl_array axes;
122 struct wl_resource *res;
124 wl_array_init(&axes);
126 EINA_LIST_FOREACH(dev->resources, l, res)
128 tizen_input_device_send_device_info(res, dev->name, dev->clas, dev->subclas, &axes);
133 e_devicemgr_wl_device_add(E_Devicemgr_Input_Device *dev)
135 struct wl_resource *res, *seat_res, *dev_mgr_res;
138 struct wl_client *wc;
139 E_Devicemgr_Input_Device_User_Data *device_user_data;
140 struct wl_array axes;
141 E_Devicemgr_Input_Device_Mgr_Data *mgr_data;
142 E_Comp_Wl_Seat *seat_data;
144 /* TODO: find the seat corresponding to event */
145 serial = wl_display_next_serial(e_comp_wl->wl.disp);
146 wl_array_init(&axes);
148 EINA_LIST_FOREACH(e_comp_wl->seat.resources, l, seat_res)
150 seat_data = wl_resource_get_user_data(seat_res);
151 if (!seat_data) continue;
152 if (!seat_data->is_first_resource)
154 DMDBG("The seat (res:%d) is not the first resource bound to client (%p)",
155 wl_resource_get_id(seat_res), wl_resource_get_client(seat_res));
159 wc = wl_resource_get_client(seat_res);
161 EINA_LIST_FOREACH(e_devicemgr->wl_data->mgr_data_list, ll, mgr_data)
163 dev_mgr_res = mgr_data->resource;
164 if (wl_resource_get_client(dev_mgr_res) != wc) continue;
165 if (!mgr_data->is_first_resource)
167 DMDBG("This device_manager (res:%d) not the first resource bound to client (%p)",
168 wl_resource_get_id(dev_mgr_res), wc);
171 res = wl_resource_create(wc, &tizen_input_device_interface, 1, 0);
174 DMERR("Could not create tizen_input_device resource");
175 wl_client_post_no_memory(wc);
179 device_user_data = E_NEW(E_Devicemgr_Input_Device_User_Data, 1);
180 if (!device_user_data)
182 DMERR("Failed to allocate memory for input device user data\n");
183 wl_client_post_no_memory(wc);
184 wl_resource_destroy(res);
187 device_user_data->dev = dev;
188 device_user_data->dev_mgr_res = dev_mgr_res;
189 device_user_data->seat_res = seat_res;
190 device_user_data->dev_res = res;
191 device_user_data->mgr_data = mgr_data;
193 dev->resources = eina_list_append(dev->resources, res);
194 mgr_data->user_data_list = eina_list_append(mgr_data->user_data_list, device_user_data);
196 wl_resource_set_implementation(res, &_e_devicemgr_wl_device_interface, device_user_data,
197 _e_devicemgr_wl_device_cb_unbind);
198 tizen_input_device_manager_send_device_add(dev_mgr_res, serial, dev->identifier, res, seat_res);
199 tizen_input_device_send_device_info(res, dev->name, dev->clas, dev->subclas, &axes);
205 e_devicemgr_wl_device_del(E_Devicemgr_Input_Device *dev)
207 struct wl_resource *res;
209 E_Devicemgr_Input_Device_User_Data *device_user_data;
211 serial = wl_display_next_serial(e_comp_wl->wl.disp);
213 EINA_LIST_FREE(dev->resources, res)
215 device_user_data = wl_resource_get_user_data(res);
216 if (!device_user_data) continue;
217 if (!device_user_data->dev_mgr_res || !device_user_data->seat_res ||
218 !device_user_data->dev_res)
221 device_user_data->dev = NULL;
222 tizen_input_device_manager_send_device_remove(
223 device_user_data->dev_mgr_res,
224 serial, dev->identifier,
225 device_user_data->dev_res,
226 device_user_data->seat_res);
228 _e_devicemgr_wl_device_data_destroy(device_user_data); // Make inert
233 e_devicemgr_wl_detent_send_event(int detent)
235 E_Devicemgr_Input_Device *input_dev;
236 struct wl_resource *dev_res;
237 struct wl_client *wc;
241 struct wl_resource *surface = NULL;
243 ec = e_client_focused_get();
246 if (e_object_is_del(E_OBJECT(ec))) return;
247 if (ec->ignored) return;
248 if (!ec->comp_data) return;
250 surface = e_comp_wl_client_surface_get(ec);
251 if (!surface) return;
253 f_value = wl_fixed_from_double(detent * 1.0);
254 wc = wl_resource_get_client(surface);
256 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
257 EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
259 if (!strncmp(input_dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
261 EINA_LIST_FOREACH(input_dev->resources, ll, dev_res)
263 if (wl_resource_get_client(dev_res) != wc) continue;
264 tizen_input_device_send_axis(dev_res, TIZEN_INPUT_DEVICE_AXIS_TYPE_DETENT, f_value);
266 DMINF("DETENT : %d => E_Client: %p (pid: %d) (pname: %s)",
267 detent, ec, ec->netwm.pid, e_client_util_name_get(ec));
271 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
275 e_devicemgr_wl_block_send_expired(struct wl_resource *resource)
277 if (!resource) return;
278 tizen_input_device_manager_send_block_expired(resource);
282 e_devicemgr_wl_touch_max_count_send(int slot, struct wl_resource *res, struct wl_resource *seat_res)
284 struct wl_resource *seat_resource, *dev_mgr_resource;
287 struct wl_client *wc;
288 E_Devicemgr_Input_Device_Mgr_Data *mgr_data;
290 serial = wl_display_next_serial(e_comp_wl->wl.disp);
294 if (wl_resource_get_version(res) < 4) return;
295 tizen_input_device_manager_send_max_touch_count(res, serial, slot, seat_res);
299 EINA_LIST_FOREACH(e_comp_wl->seat.resources, l, seat_resource)
301 wc = wl_resource_get_client(seat_resource);
303 EINA_LIST_FOREACH(e_devicemgr->wl_data->mgr_data_list, ll, mgr_data)
305 dev_mgr_resource = mgr_data->resource;
306 if (wl_resource_get_client(dev_mgr_resource) != wc) continue;
307 if (wl_resource_get_version(dev_mgr_resource) < 4) continue;
308 tizen_input_device_manager_send_max_touch_count(dev_mgr_resource, serial, slot, seat_resource);
315 e_devicemgr_wl_generator_with_sync_send_event(struct wl_resource *resource, int result)
317 if (!resource) return;
318 DMDBG("Init Generator with sync. send result: %d", result);
319 tizen_input_device_manager_send_error(resource, result);
323 _e_devicemgr_wl_cb_block_events(struct wl_client *client, struct wl_resource *resource, uint32_t serial, uint32_t clas, uint32_t duration)
325 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
328 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
329 "http://tizen.org/privilege/internal/inputdevice.block"))
331 DMERR("block_events request:priv check failed");
332 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
337 ret = e_devicemgr_block_add(client, resource, clas, duration);
338 tizen_input_device_manager_send_error(resource, ret);
342 _e_devicemgr_wl_cb_unblock_events(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
347 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
348 "http://tizen.org/privilege/internal/inputdevice.block"))
350 DMERR("unblock_events request:priv check failed");
351 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
356 ret = e_devicemgr_block_remove(client);
357 tizen_input_device_manager_send_error(resource, ret);
361 _e_devicemgr_wl_cb_init_generator(struct wl_client *client, struct wl_resource *resource, uint32_t clas)
363 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
366 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
367 "http://tizen.org/privilege/inputgenerator"))
369 DMERR("init_generator request:priv check failed");
370 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
375 ret = e_devicemgr_inputgen_add(client, resource, clas, INPUT_GENERATOR_DEVICE);
376 tizen_input_device_manager_send_error(resource, ret);
380 _e_devicemgr_wl_cb_init_generator_with_name(struct wl_client *client, struct wl_resource *resource, uint32_t clas, const char *name)
382 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
385 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
386 "http://tizen.org/privilege/inputgenerator"))
388 DMERR("init_generator_with_name request:priv check failed");
389 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
394 ret = e_devicemgr_inputgen_add(client, resource, clas, name);
395 tizen_input_device_manager_send_error(resource, ret);
399 _e_devicemgr_wl_cb_init_generator_with_sync(struct wl_client *client, struct wl_resource *resource, uint32_t clas, const char *name)
402 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
403 "http://tizen.org/privilege/inputgenerator"))
405 DMERR("_e_devicemgr_wl_cb_init_generator_with_sync request:priv check failed");
406 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
411 e_devicemgr_inputgen_add_with_sync(client, resource, clas, name);
415 _e_devicemgr_wl_cb_deinit_generator(struct wl_client *client, struct wl_resource *resource, uint32_t clas)
417 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
420 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
421 "http://tizen.org/privilege/inputgenerator"))
423 DMERR("deinit_generator request:priv check failed");
424 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
429 e_devicemgr_inputgen_remove(client, resource, clas);
430 tizen_input_device_manager_send_error(resource, ret);
434 _e_devicemgr_wl_cb_generate_key(struct wl_client *client, struct wl_resource *resource, const char *keyname, uint32_t pressed)
436 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
439 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
440 "http://tizen.org/privilege/inputgenerator"))
442 DMERR("generate_key request:priv check failed");
443 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
448 ret = e_devicemgr_inputgen_generate_key(client, resource, keyname, (Eina_Bool)!!pressed);
449 tizen_input_device_manager_send_error(resource, ret);
453 _e_devicemgr_wl_cb_generate_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, uint32_t button)
455 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
458 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
459 "http://tizen.org/privilege/inputgenerator"))
461 DMERR("_generate_pointer request:priv check failed");
462 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
467 ret = e_devicemgr_inputgen_generate_pointer(client, resource, type, x, y, button);
468 tizen_input_device_manager_send_error(resource, ret);
472 _e_devicemgr_wl_cb_generate_touch(struct wl_client *client, struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, uint32_t finger)
474 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
477 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client), "http://tizen.org/privilege/inputgenerator"))
479 DMERR("_e_input_devmgr_cb_generate_touch:priv check failed");
480 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
485 ret = e_devicemgr_inputgen_generate_touch(client, resource, type, x, y, finger);
486 tizen_input_device_manager_send_error(resource, ret);
490 _e_devicemgr_wl_cb_pointer_warp(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface, wl_fixed_t x, wl_fixed_t y)
492 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
494 ret = e_devicemgr_input_pointer_warp(client, resource, surface, x, y);
496 tizen_input_device_manager_send_error(resource, ret);
500 _e_devicemgr_wl_cb_destroy(struct wl_client *client, struct wl_resource *resource)
502 wl_resource_destroy(resource);
506 _e_devicemgr_wl_cb_generate_axis(struct wl_client *client, struct wl_resource *resource, uint32_t type, wl_fixed_t value)
508 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
511 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
512 "http://tizen.org/privilege/inputgenerator"))
514 DMERR("_generate_pointer request:priv check failed");
515 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
520 if (type == TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_WHEEL ||
521 type == TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_HWHEEL)
522 ret = e_devicemgr_inputgen_generate_wheel(client, resource, type, (int)wl_fixed_to_double(value));
524 ret = e_devicemgr_inputgen_touch_axis_store(client, resource, type, wl_fixed_to_double(value));
525 tizen_input_device_manager_send_error(resource, ret);
529 _e_devicemgr_wl_cb_set_touch_count(struct wl_client *client, struct wl_resource *resource, int32_t max_count)
531 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
534 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
535 "http://tizen.org/privilege/inputgenerator"))
537 DMERR("_generate_pointer request:priv check failed");
538 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
543 if (e_config->configured_max_touch.use)
545 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
549 if (max_count > e_input_touch_max_count_get())
551 e_input_touch_max_count_set(max_count);
555 tizen_input_device_manager_send_error(resource, ret);
559 _e_devicemgr_wl_cb_keyboard_grab(struct wl_client *client, struct wl_resource *resource,
560 struct wl_resource *surface, uint32_t subclas)
562 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
565 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
566 E_PRIVILEGE_INTERNAL_DEFAULT_PLATFORM))
568 DMERR("keyboard_grab request:priv check failed");
569 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
574 ret = e_devicemgr_keyboard_grab(client, surface, subclas);
575 tizen_input_device_manager_send_error(resource, ret);
579 _e_devicemgr_wl_cb_keyboard_ungrab(struct wl_client *client, struct wl_resource *resource,
580 struct wl_resource *surface)
582 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
585 if (EINA_FALSE == _e_devicemgr_util_do_privilege_check(client, wl_client_get_fd(client),
586 E_PRIVILEGE_INTERNAL_DEFAULT_PLATFORM))
588 DMERR("keyboard_ungrab request:priv check failed");
589 tizen_input_device_manager_send_error(resource, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION);
594 ret = e_devicemgr_keyboard_ungrab(client, surface);
595 tizen_input_device_manager_send_error(resource, ret);
599 static const struct tizen_input_device_manager_interface _e_devicemgr_wl_implementation = {
600 _e_devicemgr_wl_cb_block_events,
601 _e_devicemgr_wl_cb_unblock_events,
602 _e_devicemgr_wl_cb_init_generator,
603 _e_devicemgr_wl_cb_deinit_generator,
604 _e_devicemgr_wl_cb_generate_key,
605 _e_devicemgr_wl_cb_generate_pointer,
606 _e_devicemgr_wl_cb_generate_touch,
607 _e_devicemgr_wl_cb_pointer_warp,
608 _e_devicemgr_wl_cb_init_generator_with_name,
609 _e_devicemgr_wl_cb_destroy,
610 _e_devicemgr_wl_cb_generate_axis,
611 _e_devicemgr_wl_cb_set_touch_count,
612 _e_devicemgr_wl_cb_init_generator_with_sync,
613 _e_devicemgr_wl_cb_keyboard_grab,
614 _e_devicemgr_wl_cb_keyboard_ungrab
618 _e_devicemgr_wl_cb_unbind(struct wl_resource *resource)
620 E_Devicemgr_Input_Device_Mgr_Data *mgr_data;
621 E_Devicemgr_Input_Device_User_Data *device_user_data;
623 if(!e_comp_wl) return;
625 mgr_data = wl_resource_get_user_data(resource);
626 if (!mgr_data) return;
628 DMDBG("Unbind tizen_input_device_manager: %u (client: %p)", wl_resource_get_id(resource), wl_resource_get_client(resource));
630 EINA_LIST_FREE(mgr_data->user_data_list, device_user_data)
632 device_user_data->mgr_data = NULL;
633 _e_devicemgr_wl_device_data_destroy(device_user_data);
635 e_devicemgr->wl_data->mgr_data_list = eina_list_remove(e_devicemgr->wl_data->mgr_data_list, mgr_data);
641 _e_devicemgr_wl_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
643 struct wl_resource *res, *seat_res, *device_res;
646 E_Devicemgr_Input_Device *dev;
647 struct wl_array axes;
648 E_Devicemgr_Input_Device_User_Data *device_user_data;
649 E_Devicemgr_Input_Device_Mgr_Data *mgr_data, *tmp_data;
651 mgr_data = E_NEW(E_Devicemgr_Input_Device_Mgr_Data, 1);
654 DMERR("Failed to allocate memory for input device mgr data\n");
655 wl_client_post_no_memory(client);
658 mgr_data->is_first_resource = 1;
660 EINA_LIST_FOREACH(e_devicemgr->wl_data->mgr_data_list, l, tmp_data)
662 if (wl_resource_get_client(tmp_data->resource) != client) continue;
663 DMDBG("tizen_input_device_manager (res: %d) is already bound to client (%p)",
664 wl_resource_get_id(tmp_data->resource), client);
665 mgr_data->is_first_resource = 0;
669 if (!(res = wl_resource_create(client, &tizen_input_device_manager_interface, version, id)))
671 DMERR("Could not create tizen_input_device_manager_interface resource: %m");
672 wl_client_post_no_memory(client);
677 DMDBG("Bind tizen_input_device_manager: %u (client: %p)", wl_resource_get_id(res), wl_resource_get_client(res));
679 mgr_data->resource = res;
680 mgr_data->user_data_list = NULL;
681 e_devicemgr->wl_data->mgr_data_list = eina_list_append(e_devicemgr->wl_data->mgr_data_list, mgr_data);
683 wl_resource_set_implementation(res, &_e_devicemgr_wl_implementation, mgr_data,
684 _e_devicemgr_wl_cb_unbind);
686 EINA_LIST_FOREACH(e_comp_wl->seat.resources, l, seat_res)
688 if (wl_resource_get_client(seat_res) != client) continue;
690 wl_array_init(&axes);
691 serial = wl_display_next_serial(e_comp_wl->wl.disp);
693 if (e_devicemgr->max_touch_count > 0)
695 e_devicemgr_wl_touch_max_count_send(e_devicemgr->max_touch_count, res, seat_res);
698 if (!mgr_data->is_first_resource)
700 DMDBG("This device_manager (res:%d) is not the first resource bound to client (%p)",
701 wl_resource_get_id(res), client);
705 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
706 EINA_LIST_FOREACH(e_devicemgr->device_list, ll, dev)
708 device_res = wl_resource_create(client, &tizen_input_device_interface, 1, 0);
711 DMERR("Could not create tizen_input_device resource: %m");
712 wl_client_post_no_memory(client);
713 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
716 device_user_data = E_NEW(E_Devicemgr_Input_Device_User_Data, 1);
717 if (!device_user_data)
719 DMERR("Failed to allocate memory for input device user data\n");
720 wl_client_post_no_memory(client);
721 wl_resource_destroy(device_res);
722 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
725 device_user_data->dev = dev;
726 device_user_data->dev_mgr_res = res;
727 device_user_data->seat_res = seat_res;
728 device_user_data->dev_res = device_res;
729 device_user_data->mgr_data = mgr_data;
731 dev->resources = eina_list_append(dev->resources, device_res);
732 mgr_data->user_data_list = eina_list_append(mgr_data->user_data_list, device_user_data);
734 wl_resource_set_implementation(device_res, &_e_devicemgr_wl_device_interface, device_user_data,
735 _e_devicemgr_wl_device_cb_unbind);
737 tizen_input_device_manager_send_device_add(res, serial, dev->identifier, device_res, seat_res);
738 tizen_input_device_send_device_info(device_res, dev->name, dev->clas, dev->subclas, &axes);
740 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
745 e_devicemgr_wl_init(void)
747 if (!e_comp_wl) return EINA_FALSE;
748 if (!e_comp_wl->wl.disp) return EINA_FALSE;
750 if (e_devicemgr->wl_data) return EINA_TRUE;
752 e_devicemgr->wl_data = E_NEW(E_Devicemgr_Wl_Data, 1);
753 EINA_SAFETY_ON_NULL_RETURN_VAL(e_devicemgr->wl_data, EINA_FALSE);
755 /* try to add tizen_input_device_manager to wayland globals */
756 e_devicemgr->wl_data->global = wl_global_create(e_comp_wl->wl.disp,
757 &tizen_input_device_manager_interface, 6,
758 NULL, _e_devicemgr_wl_cb_bind);
759 if (!e_devicemgr->wl_data->global)
761 DMERR("Could not add tizen_input_device_manager to wayland globals");
764 e_devicemgr->wl_data->mgr_data_list = NULL;
766 /* initialization of cynara for checking privilege */
770 ret = cynara_initialize(&e_devicemgr->wl_data->p_cynara, NULL);
771 if (EINA_UNLIKELY(CYNARA_API_SUCCESS != ret))
773 _e_devicemgr_util_cynara_log("cynara_initialize", ret);
774 e_devicemgr->wl_data->p_cynara = NULL;
776 e_devicemgr->wl_data->cynara_initialized = EINA_TRUE;
783 e_devicemgr_wl_shutdown(void)
785 if (!e_devicemgr->wl_data) return;
786 /* destroy the global seat resource */
787 if (e_devicemgr->wl_data->global)
788 wl_global_destroy(e_devicemgr->wl_data->global);
789 e_devicemgr->wl_data->global = NULL;
790 eina_list_free(e_devicemgr->wl_data->mgr_data_list);
792 /* deinitialization of cynara if it has been initialized */
794 if (e_devicemgr->wl_data->p_cynara) cynara_finish(e_devicemgr->wl_data->p_cynara);
795 e_devicemgr->wl_data->cynara_initialized = EINA_FALSE;
798 E_FREE(e_devicemgr->wl_data);