2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * @brief Multi Input Manager (Weston(Wayland) PlugIn)
35 #include <linux/input.h>
40 #include <sys/types.h>
42 #include <wayland-server.h>
43 #include <weston/compositor.h>
44 #include "ico_ivi_common.h"
45 #include "ico_ivi_shell.h"
46 #include "ico_window_mgr.h"
47 #include "ico_input_mgr.h"
48 #include "ico_input_mgr-server-protocol.h"
50 /* degine maximum length */
51 #define ICO_MINPUT_DEVICE_LEN 32
52 #define ICO_MINPUT_SW_LEN 20
53 #define ICO_MINPUT_MAX_CODES 20
55 /* structure definition */
56 /* working table of Multi Input Manager */
57 struct ico_input_mgr {
58 struct weston_compositor *compositor; /* Weston Compositor */
59 struct wl_list ictl_list; /* Input Controller List */
60 struct wl_list app_list; /* application List */
61 struct wl_resource *inputmgr;
64 /* Input Switch Table */
65 struct ico_ictl_code {
66 uint16_t code; /* input code numner */
67 char name[ICO_MINPUT_SW_LEN]; /* input code name */
70 struct ico_ictl_input {
71 struct wl_list link; /* link */
72 char swname[ICO_MINPUT_SW_LEN]; /* input switch name */
73 int32_t input; /* input Id */
74 uint16_t fix; /* fixed assign to application */
75 uint16_t ncode; /* number of codes */
76 struct ico_ictl_code code[ICO_MINPUT_MAX_CODES]; /* codes */
77 struct ico_app_mgr *app; /* send event tagret application */
80 /* Input Controller Management Table */
82 struct wl_list link; /* link */
83 struct wl_client *client; /* client */
84 struct wl_resource *resource; /* resource */
85 char device[ICO_MINPUT_DEVICE_LEN]; /* device name */
86 int type; /* device type */
87 struct wl_list ico_ictl_input; /* list of input switchs */
90 /* Application Management Table */
92 struct wl_list link; /* link */
93 struct wl_client *client; /* client */
94 struct wl_resource *resource; /* resource for send event */
95 struct wl_resource *mgr_resource; /* resource as manager(if NULL, client) */
96 char appid[ICO_IVI_APPID_LENGTH]; /* application id */
99 /* prototype of static function */
100 /* bind input manager form manager */
101 static void ico_control_bind(struct wl_client *client, void *data,
102 uint32_t version, uint32_t id);
103 /* unbind input manager form manager */
104 static void ico_control_unbind(struct wl_resource *resource);
105 /* bind input manager form input controller*/
106 static void ico_device_bind(struct wl_client *client, void *data,
107 uint32_t version, uint32_t id);
108 /* unbind input manager form input controller*/
109 static void ico_device_unbind(struct wl_resource *resource);
110 /* bind input manager(form application) */
111 static void ico_exinput_bind(struct wl_client *client, void *data,
112 uint32_t version, uint32_t id);
113 /* unbind input manager(form application)*/
114 static void ico_exinput_unbind(struct wl_resource *resource);
116 /* find ictl manager by device name */
117 static struct ico_ictl_mgr *find_ictlmgr_by_device(const char *device);
118 /* find ictl input switch by input Id */
119 static struct ico_ictl_input *find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr,
120 const int32_t input);
121 /* find app manager by application Id */
122 static struct ico_app_mgr *find_app_by_appid(const char *appid);
123 /* add input event to application */
124 static void ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
125 const char *appid, const char *device, int32_t input,
126 int32_t fix, int32_t keycode);
127 /* delete input event to application */
128 static void ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
129 const char *appid, const char *device, int32_t input);
130 /* send input event from manager */
131 static void ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
132 const char *appid, uint32_t surfaceid, int32_t type,
133 int32_t deviceno, int32_t code, int32_t value);
134 /* create and regist Input Controller table*/
135 static void ico_device_configure_input(struct wl_client *client,
136 struct wl_resource *resource, const char *device,
137 int32_t type, const char *swname, int32_t input,
138 const char *codename, int32_t code);
139 /* add input to from Input Controller table*/
140 static void ico_device_configure_code(struct wl_client *client,
141 struct wl_resource *resource, const char *device,
142 int32_t input, const char *codename, int32_t code);
143 /* device input event */
144 static void ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
145 uint32_t time, const char *device,
146 int32_t input, int32_t code, int32_t state);
148 /* definition of Wayland protocol */
150 static const struct ico_input_mgr_control_interface ico_input_mgr_implementation = {
151 ico_mgr_add_input_app,
152 ico_mgr_del_input_app,
153 ico_mgr_send_input_event
156 /* Input Controller interface */
157 static const struct ico_input_mgr_device_interface input_mgr_ictl_implementation = {
158 ico_device_configure_input,
159 ico_device_configure_code,
160 ico_device_input_event
163 /* definition of class variable */
164 struct ico_input_mgr *pInputMgr = NULL;
167 /*--------------------------------------------------------------------------*/
169 * @brief ico_mgr_add_input_app: add input event to application from HomeScreen.
171 * @param[in] client client(HomeScreen)
172 * @param[in] resource resource of request
173 * @param[in] appid target application id
174 * @param[in] device device name
175 * @param[in] input input switch number
176 * @param[in] fix fix to application(1=fix,0=general)
177 * @param[in] keycode switch map to keyboard operation(0=not map to keyboard)
180 /*--------------------------------------------------------------------------*/
182 ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
183 const char *appid, const char *device, int32_t input,
184 int32_t fix, int32_t keycode)
186 uifw_trace("ico_mgr_add_input_app: Enter(appid=%s,dev=%s,input=%d,fix=%d,key=%d)",
187 appid, device, input, fix, keycode);
189 struct ico_ictl_mgr *pIctlMgr;
190 struct ico_ictl_input *pInput;
191 struct ico_app_mgr *pAppMgr;
193 pIctlMgr = find_ictlmgr_by_device(device);
195 /* not configure input controller, create */
196 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
197 pIctlMgr = find_ictlmgr_by_device(device);
199 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
203 pInput = find_ictlinput_by_input(pIctlMgr, input);
205 /* not configure input switch, create */
206 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
207 pInput = find_ictlinput_by_input(pIctlMgr, input);
209 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
214 /* find application */
215 pAppMgr = find_app_by_appid(appid);
217 /* create Application Management Table */
218 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
220 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
223 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
224 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
225 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
228 pInput->app = pAppMgr;
230 uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
231 pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
235 /*--------------------------------------------------------------------------*/
237 * @brief ico_mgr_del_input_app: delete input event at application from HomeScreen.
239 * @param[in] client client(HomeScreen)
240 * @param[in] resource resource of request
241 * @param[in] appid target application id,
242 * if NULL, all applictions without fixed assign switch
243 * @param[in] device device name
244 * if NULL, all device without fixed assign switch
245 * @param[in] input input switch number
246 * if -1, all input without fixed assign switch
249 /*--------------------------------------------------------------------------*/
251 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
252 const char *appid, const char *device, int32_t input)
254 uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
255 appid ? appid : "(NULL)", device ? device : "(NULL)", input);
258 struct ico_ictl_mgr *pIctlMgr = NULL;
259 struct ico_ictl_input *pInput = NULL;
260 struct ico_app_mgr *pAppMgr;
262 if ((device != NULL) && (*device != 0)) {
263 pIctlMgr = find_ictlmgr_by_device(device);
265 /* not configure input controller, NOP */
266 uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
270 pInput = find_ictlinput_by_input(pIctlMgr, input);
272 /* not configure input switch, NOP */
273 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
283 /* find application */
284 if ((appid != NULL) && (*appid != 0)) {
285 pAppMgr = find_app_by_appid(appid);
287 /* application dose not exist, NOP */
288 uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
293 if (pInput->app != pAppMgr) {
294 /* not same application, NOP */
295 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d not app.%s, current %s)",
296 device, input, appid,
297 pInput->app ? pInput->app->appid : "(NULL)");
300 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
301 device, input, appid);
306 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
307 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
308 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
309 pIctlMgr->device, pInput->input, appid);
316 /* reset all device without fixed assign */
317 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
318 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
319 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
320 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
321 pIctlMgr->device, pInput->input, pInput->app->appid);
331 if ((pInput->fix == 0) && (pInput->app != NULL)) {
332 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
333 pIctlMgr->device, pInput->input, pInput->app->appid);
338 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
339 if ((pInput->fix == 0) && (pInput->app != NULL)) {
340 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
341 pIctlMgr->device, pInput->input, pInput->app->appid);
348 /* reset all application without fixed assign */
349 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
350 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
351 if ((pInput->fix == 0) && (pInput->app != NULL)) {
352 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
353 pIctlMgr->device, pInput->input, pInput->app->appid);
360 uifw_trace("ico_mgr_del_input_app: Leave");
363 /*--------------------------------------------------------------------------*/
365 * @brief ico_mgr_send_input_event: send input event from manager
367 * @param[in] client client(HomeScreen)
368 * @param[in] resource resource of request
369 * @param[in] appid target application id
370 * @param[in] surfaceid target surface id
371 * @param[in] type event device type
372 * @param[in] deviceno device number
373 * @param[in] code event code
374 * @param[in] value event value
377 /*--------------------------------------------------------------------------*/
379 ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
380 const char *appid, uint32_t surfaceid, int32_t type,
381 int32_t deviceno, int32_t code, int32_t value)
383 uifw_trace("ico_mgr_send_input_event: Enter(app=%s surf=%08x dev=%d code=%x value=%d)",
384 appid ? appid : "(NULL)", surfaceid, deviceno, code, value);
386 uifw_trace("ico_mgr_send_input_event: Leave");
389 /*--------------------------------------------------------------------------*/
391 * @brief ico_device_configure_input: configure input device and input switch
392 * from Device Input Controller.
394 * @param[in] client client(Device Input Controller)
395 * @param[in] resource resource of request
396 * @param[in] device device name
397 * @param[in] type device type(saved but unused)
398 * @param[in] swname input switch name
399 * @param[in] input input switch number
400 * @param[in] codename input code name
401 * @param[in] code input code number
404 /*--------------------------------------------------------------------------*/
406 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
407 const char *device, int32_t type, const char *swname,
408 int32_t input, const char *codename, int32_t code)
410 uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
411 "input=%d,code=%d[%s])", (int)client, device, type,
412 swname ? swname : "(NULL)", input, code, codename ? codename : " ");
414 struct ico_ictl_mgr *pIctlMgr;
415 struct ico_ictl_input *pInput;
416 struct ico_app_mgr *pAppMgr;
418 pIctlMgr = find_ictlmgr_by_device(device);
420 /* create ictl mgr table */
421 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
422 if (pIctlMgr == NULL) {
423 uifw_error("ico_device_configure_input: Leave(No Memory)");
426 uifw_trace("ico_device_configure_input: create pIctlMgr(mgr=%08x,input=%d)",
427 (int)pIctlMgr, input);
428 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
429 wl_list_init(&pIctlMgr->ico_ictl_input);
430 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
433 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
435 pIctlMgr->client = client;
436 pIctlMgr->resource = resource;
438 pIctlMgr->type = type;
441 /* search and add input switch */
442 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
443 if (pInput->input == input) break;
445 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
446 uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
447 device, swname, input);
448 pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
449 if (pInput == NULL) {
450 uifw_error("ico_device_configure_input: Leave(No Memory)");
453 memset(pInput, 0, sizeof(struct ico_ictl_input));
455 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
458 strcpy(pInput->swname, "(Unknown)");
460 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
463 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
465 pInput->input = input;
466 memset(pInput->code, 0, sizeof(pInput->code));
468 pInput->code[0].code = code;
470 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
473 if (client == NULL) {
474 /* internal call for table create */
475 uifw_trace("ico_device_configure_input: Leave(table create)");
479 /* send to application and manager(ex.HomeScreen) */
480 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
481 if (pAppMgr->resource == NULL) continue;
482 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
484 uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
485 pAppMgr->appid, device, pInput->swname, input);
486 ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
487 pInput->swname, input,
488 pInput->code[0].name, pInput->code[0].code);
490 uifw_trace("ico_device_configure_input: Leave");
493 /*--------------------------------------------------------------------------*/
495 * @brief ico_device_configure_code: add input switch from Device Input Controller.
497 * @param[in] client client(Device Input Controller)
498 * @param[in] resource resource of request
499 * @param[in] device device name
500 * @param[in] input input switch number
501 * @param[in] codename input code name
502 * @param[in] code input code number
505 /*--------------------------------------------------------------------------*/
507 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
508 const char *device, int32_t input,
509 const char *codename, int32_t code)
511 uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
512 (int)client, device, input, code, codename ? codename : " ");
515 struct ico_ictl_mgr *pIctlMgr;
516 struct ico_ictl_input *pInput;
517 struct ico_app_mgr *pAppMgr;
519 pIctlMgr = find_ictlmgr_by_device(device);
521 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
524 /* search input switch */
525 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
526 if (pInput->input == input) break;
528 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
529 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
534 /* search input code */
535 for (i = 0; i < pInput->ncode; i++) {
536 if (pInput->code[i].code == code) break;
538 if (i >= pInput->ncode) {
539 /* code dose not exist, add */
540 if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
541 uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
547 pInput->code[i].code = code;
549 memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
550 strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
552 /* send to application and manager(ex.HomeScreen) */
553 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
554 if (pAppMgr->resource == NULL) continue;
555 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
556 uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
557 pAppMgr->appid, device, pInput->swname, input);
558 ico_exinput_send_code(pAppMgr->resource, device, input,
559 pInput->code[i].name, pInput->code[i].code);
561 uifw_trace("ico_device_configure_code: Leave");
564 /*--------------------------------------------------------------------------*/
566 * @brief ico_device_input_event: device input event from Device Input Controller.
568 * @param[in] client client(Device Input Controller)
569 * @param[in] resource resource of request
570 * @param[in] time device input time(miri-sec)
571 * @param[in] device device name
572 * @param[in] input input switch number
573 * @param[in] code input code number
574 * @param[in] state input state(1=On, 0=Off)
577 /*--------------------------------------------------------------------------*/
579 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
580 uint32_t time, const char *device,
581 int32_t input, int32_t code, int32_t state)
583 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
584 time, device, input, code, state);
586 struct ico_ictl_mgr *pIctlMgr;
587 struct ico_ictl_input *pInput;
589 /* find input devcie by client */
590 pIctlMgr = find_ictlmgr_by_device(device);
592 uifw_error("ico_device_input_event: Leave(Unknown client(%08x))", (int)client);
595 /* find input switch by input Id */
596 pInput = find_ictlinput_by_input(pIctlMgr, input);
598 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
599 pIctlMgr->device, input);
604 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
605 pIctlMgr->device, pInput->swname);
609 /* send event to application */
610 uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
611 pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
612 ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
615 uifw_trace("ico_device_input_event: Leave");
618 /*--------------------------------------------------------------------------*/
620 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
622 * @param[in] client client(HomeScreen)
623 * @param[in] data data(unused)
624 * @param[in] version protocol version(unused)
625 * @param[in] id client object id
628 /*--------------------------------------------------------------------------*/
630 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
633 struct ico_app_mgr *pAppMgr;
635 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
636 appid = ico_window_mgr_get_appid(client);
639 /* client dose not exist */
640 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
644 /* find application */
645 pAppMgr = find_app_by_appid(appid);
647 /* create Application Management Table */
648 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
650 uifw_error("ico_control_bind: Leave(No Memory)");
653 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
654 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
655 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
657 pAppMgr->client = client;
658 if (! pAppMgr->mgr_resource) {
659 pAppMgr->mgr_resource = wl_resource_create(client,
660 &ico_input_mgr_control_interface, 1, id);
661 if (pAppMgr->mgr_resource) {
662 wl_resource_set_implementation(pAppMgr->mgr_resource,
663 &ico_input_mgr_implementation,
664 pInputMgr, ico_control_unbind);
667 uifw_trace("ico_control_bind: Leave");
670 /*--------------------------------------------------------------------------*/
672 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
674 * @param[in] resource client resource(HomeScreen)
677 /*--------------------------------------------------------------------------*/
679 ico_control_unbind(struct wl_resource *resource)
681 struct ico_app_mgr *pAppMgr;
683 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
685 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
686 if (pAppMgr->mgr_resource == resource) {
687 uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
688 pAppMgr->mgr_resource = NULL;
692 uifw_trace("ico_control_unbind: Leave");
695 /*--------------------------------------------------------------------------*/
697 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
699 * @param[in] client client(Device Input Controller)
700 * @param[in] data data(unused)
701 * @param[in] version protocol version(unused)
702 * @param[in] id client object id
705 /*--------------------------------------------------------------------------*/
707 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
709 struct wl_resource *mgr_resource;
711 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
713 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
715 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
716 NULL, ico_device_unbind);
718 uifw_trace("ico_device_bind: Leave");
721 /*--------------------------------------------------------------------------*/
723 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
725 * @param[in] resource client resource(Device Input Controller)
728 /*--------------------------------------------------------------------------*/
730 ico_device_unbind(struct wl_resource *resource)
732 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
733 uifw_trace("ico_device_unbind: Leave");
736 /*--------------------------------------------------------------------------*/
738 * @brief ico_exinput_bind: ico_exinput bind from Application
740 * @param[in] client client(Application)
741 * @param[in] data data(unused)
742 * @param[in] version protocol version(unused)
743 * @param[in] id client object id
746 /*--------------------------------------------------------------------------*/
748 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
752 struct ico_app_mgr *pAppMgr;
753 struct ico_ictl_mgr *pIctlMgr;
754 struct ico_ictl_input *pInput;
756 appid = ico_window_mgr_get_appid(client);
757 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
758 appid ? appid : "(NULL)");
761 /* client dose not exist */
762 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
766 /* find application */
767 pAppMgr = find_app_by_appid(appid);
769 /* create Application Management Table */
770 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
772 uifw_error("ico_exinput_bind: Leave(No Memory)");
775 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
776 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
777 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
778 uifw_trace("ico_exinput_bind: Create App.%s table", appid);
780 pAppMgr->client = client;
781 if (! pAppMgr->resource) {
782 pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
783 if (pAppMgr->resource) {
784 wl_resource_set_implementation(pAppMgr->resource, NULL,
785 pInputMgr, ico_exinput_unbind);
789 /* send all capabilities */
790 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
791 if (pIctlMgr->client == NULL) {
792 uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
797 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
798 if (pInput->swname[0] == 0) {
799 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
802 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
803 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
804 pIctlMgr->device, pInput->swname, pInput->app->appid);
807 uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
808 pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
809 ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
810 pIctlMgr->type, pInput->swname, pInput->input,
811 pInput->code[0].name, pInput->code[0].code);
812 for (i = 1; i < pInput->ncode; i++) {
813 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
814 pInput->code[i].name, pInput->code[i].code);
818 uifw_trace("ico_exinput_bind: Leave");
821 /*--------------------------------------------------------------------------*/
823 * @brief ico_exinput_unbind: ico_exinput unbind from Application
825 * @param[in] resource client resource(Application)
828 /*--------------------------------------------------------------------------*/
830 ico_exinput_unbind(struct wl_resource *resource)
832 struct ico_app_mgr *pAppMgr;
833 struct ico_app_mgr *pAppMgrTmp;
834 struct ico_ictl_mgr *pIctlMgr;
835 struct ico_ictl_input *pInput;
838 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
840 wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
841 if (pAppMgr->resource == resource) {
842 uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
844 /* release application from input switch */
845 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
846 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
847 if (pInput->app == pAppMgr) {
848 if (pInput->fix == 0) {
849 uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
850 pAppMgr->appid, pIctlMgr->device, pInput->swname);
854 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
855 pAppMgr->appid, pIctlMgr->device, pInput->swname);
862 wl_list_remove(&pAppMgr->link);
866 pAppMgr->client = NULL;
867 pAppMgr->resource = NULL;
871 uifw_trace("ico_exinput_unbind: Leave");
874 /*--------------------------------------------------------------------------*/
876 * @brief find_ictlmgr_by_device: find Input Controller by device name
878 * @param[in] device device name
879 * @return Input Controller Manager table address
880 * @retval !=NULL address
881 * @retval ==NULL not exist
883 /*--------------------------------------------------------------------------*/
884 static struct ico_ictl_mgr *
885 find_ictlmgr_by_device(const char *device)
887 struct ico_ictl_mgr *pIctlMgr;
889 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
890 if (strcmp(pIctlMgr->device, device) == 0) {
897 /*--------------------------------------------------------------------------*/
899 * @brief find_ictlinput_by_input: find Input Switch by input Id
901 * @param[in] pIctlMgr Input Controller device
902 * @param[in] input Input Id
903 * @return Input Switch table address
904 * @retval !=NULL address
905 * @retval ==NULL not exist
907 /*--------------------------------------------------------------------------*/
908 static struct ico_ictl_input *
909 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
911 struct ico_ictl_input *pInput;
913 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
914 if (pInput->input == input) {
921 /*--------------------------------------------------------------------------*/
923 * @brief find_app_by_appid: find Application by application Id
925 * @param[in] appid application Id
926 * @return Application Management table address
927 * @retval !=NULL address
928 * @retval ==NULL not exist
930 /*--------------------------------------------------------------------------*/
931 static struct ico_app_mgr *
932 find_app_by_appid(const char *appid)
934 struct ico_app_mgr *pAppMgr;
936 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
937 if (strcmp(pAppMgr->appid, appid) == 0) {
944 /*--------------------------------------------------------------------------*/
946 * @brief module_init: initialization of this plugin
948 * @param[in] ec weston compositor
949 * @param[in] argc number of arguments(unused)
950 * @param[in] argv argument list(unused)
955 /*--------------------------------------------------------------------------*/
957 module_init(struct weston_compositor *ec, int *argc, char *argv[])
959 uifw_info("ico_input_mgr: Enter(module_init)");
961 /* initialize management table */
962 pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
963 if (pInputMgr == NULL) {
964 uifw_trace("ico_input_mgr: malloc failed");
967 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
968 pInputMgr->compositor = ec;
970 /* interface to desktop manager(ex.HomeScreen) */
971 if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
972 pInputMgr, ico_control_bind) == NULL) {
973 uifw_trace("ico_input_mgr: wl_global_create mgr failed");
977 /* interface to Input Controller(ictl) */
978 if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
979 pInputMgr, ico_device_bind) == NULL) {
980 uifw_trace("ico_input_mgr: wl_global_create ictl failed");
984 /* interface to App(exinput) */
985 if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
986 pInputMgr, ico_exinput_bind) == NULL) {
987 uifw_trace("ico_input_mgr: wl_global_create exseat failed");
991 /* initialize list */
992 wl_list_init(&pInputMgr->ictl_list);
993 wl_list_init(&pInputMgr->app_list);
995 uifw_info("ico_input_mgr: Leave(module_init)");