2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief Device Input Controllers(wayland processing)
11 * processing related wayland
22 #include "ico_dic-gtforce.h"
24 /* prototype of static function */
25 /* callback function from wayland global */
26 static void ico_dic_wayland_globalcb(void *data, struct wl_registry *registry,
27 uint32_t wldispid, const char *event,
31 extern Ico_Dic_Mng gIco_Dic_Mng;
33 static const struct wl_registry_listener registry_listener = {
34 ico_dic_wayland_globalcb
37 /*--------------------------------------------------------------------------*/
39 * @brief ico_dic_wayland_init
40 * connect to wayland of specified Display. specified NULL to
41 * connected Display, connect to the default Display.
43 * @param[in] display display to connect
44 * @param[in] callback callback function
46 * @retval ICO_DIC_EOK Success
47 * @retval ICO_DIC_ERR Failed
49 /*--------------------------------------------------------------------------*/
51 ico_dic_wayland_init(const char *display, Ico_Dic_Wayland_Cb callback)
53 ICO_TRA("ico_dic_wayland_init: Enter");
57 /* regist callback funtion */
58 gIco_Dic_Mng.Dic_CallBack = callback;
60 /* connect to wayland(retry max 5 sec) */
61 for (ret = 0; ret < (5000/20); ret++) {
62 gIco_Dic_Mng.Wayland_Display = wl_display_connect(display);
63 if (gIco_Dic_Mng.Wayland_Display) {
68 if (! gIco_Dic_Mng.Wayland_Display) {
69 ICO_ERR("ico_dic_wayland_init: Leave(ERR), Wayland Connect Error");
73 /* add listener of wayland registry */
74 gIco_Dic_Mng.Wayland_Registry =
75 wl_display_get_registry(gIco_Dic_Mng.Wayland_Display);
76 wl_registry_add_listener(gIco_Dic_Mng.Wayland_Registry,
77 ®istry_listener, &gIco_Dic_Mng);
79 /* display dispatch to wait */
82 wl_display_dispatch(gIco_Dic_Mng.Wayland_Display);
83 } while ((gIco_Dic_Mng.Wayland_WindowMgr == NULL) ||
84 (gIco_Dic_Mng.Wayland_InputCtl == NULL) ||
85 (gIco_Dic_Mng.Wayland_InputMgr == NULL));
87 /* get the Wayland descriptor */
88 gIco_Dic_Mng.WaylandFd = wl_display_get_fd(gIco_Dic_Mng.Wayland_Display);
89 ICO_DBG("ico_dic_wayland_init: Wayland FD = %d", gIco_Dic_Mng.WaylandFd);
91 /* create epoll file descriptor */
92 gIco_Dic_Mng.Dic_efd = epoll_create1(EPOLL_CLOEXEC);
93 if (gIco_Dic_Mng.Dic_efd < 0) {
94 ICO_ERR("ico_dic_wayland_init: Leave(ERR), Epoll Create Error");
97 struct epoll_event ev;
98 memset(&ev, 0, sizeof(ev));
100 ev.data.fd = gIco_Dic_Mng.WaylandFd;
101 if (epoll_ctl(gIco_Dic_Mng.Dic_efd, EPOLL_CTL_ADD,
102 gIco_Dic_Mng.WaylandFd, &ev) != 0) {
103 ICO_ERR("ico_dic_wayland_init: Leave(ERR), Epoll ctl Error");
106 ICO_TRA("ico_dic_wayland_init: Leave(EOK)");
110 /*--------------------------------------------------------------------------*/
112 * @brief ico_dic_wayland_globalcb
114 * @param[in] data the information that appointed at the time of
115 * callback registration
116 * @param[in] registry wayland registry
117 * @param[in] wldispid wayland displya id
118 * @param[in] event event name
119 * @param[in] version version of Wayland
122 /*--------------------------------------------------------------------------*/
124 ico_dic_wayland_globalcb(void *data, struct wl_registry *registry, uint32_t wldispid,
125 const char *event, uint32_t version)
127 ICO_DBG("ico_dic_wayland_globalcb: Event=%s DispId=%08x", event, wldispid);
129 if (strcmp(event, "ico_window_mgr") == 0) {
130 gIco_Dic_Mng.Wayland_WindowMgr = wl_registry_bind(gIco_Dic_Mng.Wayland_Registry,
132 &ico_window_mgr_interface, 1);
133 ICO_DBG("ico_dic_wayland_globalcb: wl_registry_bind(ico_window_mgr)");
135 else if (strcmp(event, "ico_input_mgr_control") == 0) {
136 /* conect to multi input manager control interface */
137 gIco_Dic_Mng.Wayland_InputCtl = wl_registry_bind(gIco_Dic_Mng.Wayland_Registry,
139 &ico_input_mgr_control_interface, 1);
140 ICO_DBG("ico_dic_wayland_globalcb: wl_registry_bind(ico_input_mgr_control)");
142 else if (strcmp(event, "ico_input_mgr_device") == 0) {
143 /* conect to multi input manager device interface */
144 gIco_Dic_Mng.Wayland_InputMgr = wl_registry_bind(gIco_Dic_Mng.Wayland_Registry,
146 &ico_input_mgr_device_interface, 1);
147 ICO_DBG("ico_dic_wayland_globalcb: wl_registry_bind(ico_input_mgr_device)");
151 /*--------------------------------------------------------------------------*/
153 * @brief ico_dic_wayland_iterate
154 * iterate processing of wayland
156 * @param[in] timeout wait time miri-sec
159 /*--------------------------------------------------------------------------*/
161 ico_dic_wayland_iterate(struct epoll_event *ev_ret, int timeout)
165 static int errcount = 0;
167 memset(ev_ret, 0, sizeof(struct epoll_event) * ICO_DIC_EVENT_NUM);
168 wl_display_flush(gIco_Dic_Mng.Wayland_Display);
171 if ((nfds = epoll_wait(gIco_Dic_Mng.Dic_efd, ev_ret,
172 ICO_DIC_EVENT_NUM, timeout)) > 0) {
173 for (ii = 0; ii < nfds; ii++) {
174 if (ev_ret[ii].data.fd == gIco_Dic_Mng.WaylandFd) {
175 wl_display_dispatch(gIco_Dic_Mng.Wayland_Display);
176 ICO_DBG("ico_dic_wayland_iterate: Event wayland fd");
179 ICO_ERR("ico_dic_wayland_iterate: Error wayland disconnect");
180 ICO_INF("END_MODULE GtForce device input controller"
181 "(Error: wayland disconnect)");
184 if ((errcount % 5) == 0) {
194 else if (nfds == 0) {
200 /*--------------------------------------------------------------------------*/
202 * @brief ico_dic_add_fd
203 * Add file descriptor to watch in pool.
205 * @param[in] fd File descriptor
207 * @retval ICO_DIC_EOK Success
208 * @retval ICO_DIC_ERR Failed
210 /*--------------------------------------------------------------------------*/
212 ico_dic_add_fd(int fd)
214 ICO_DBG("ico_dic_add_fd: Enter(fd=%d)", fd);
216 struct epoll_event ev;
218 if (gIco_Dic_Mng.Dic_efd <= 0) {
219 ICO_ERR("ico_dic_add_fd: Leave(ERR), Epoll Never Created");
223 memset(&ev, 0, sizeof(ev));
226 if (epoll_ctl(gIco_Dic_Mng.Dic_efd, EPOLL_CTL_ADD, fd, &ev) != 0) {
227 ICO_ERR("ico_dic_add_fd: Leave(ERR), Epoll ctl Error");
230 ICO_DBG("ico_dic_add_fd: Leave(EOK)");
235 /*--------------------------------------------------------------------------*/
237 * @brief ico_dic_wayland_finish
238 * Finish wayland connection
243 /*--------------------------------------------------------------------------*/
245 ico_dic_wayland_finish(void)
247 ICO_DBG("ico_dic_wayland_finish: Enter");
249 wl_display_flush(gIco_Dic_Mng.Wayland_Display);
250 wl_display_disconnect(gIco_Dic_Mng.Wayland_Display);
252 ICO_DBG("ico_dic_wayland_finish: Leave");