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(ex.HomeScreen) */
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(ex.HomeScreen) */
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 /* create and regist Input Controller table */
131 static void ico_device_configure_input(struct wl_client *client,
132 struct wl_resource *resource, const char *device,
133 int32_t type, const char *swname, int32_t input,
134 const char *codename, int32_t code);
135 /* add input to from Input Controller table */
136 static void ico_device_configure_code(struct wl_client *client,
137 struct wl_resource *resource, const char *device,
138 int32_t input, const char *codename, int32_t code);
139 /* device input event */
140 static void ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
141 uint32_t time, const char *device,
142 int32_t input, int32_t code, int32_t state);
144 /* definition of Wayland protocol */
146 static const struct ico_input_mgr_control_interface ico_input_mgr_implementation = {
147 ico_mgr_add_input_app,
148 ico_mgr_del_input_app,
151 /* Input Controller interface */
152 static const struct ico_input_mgr_device_interface input_mgr_ictl_implementation = {
153 ico_device_configure_input,
154 ico_device_configure_code,
155 ico_device_input_event
158 /* definition of class variable */
159 struct ico_input_mgr *pInputMgr = NULL;
162 /*--------------------------------------------------------------------------*/
164 * @brief ico_mgr_add_input_app: add input event to application from HomeScreen.
166 * @param[in] client client(HomeScreen)
167 * @param[in] resource resource of request
168 * @param[in] appid target application id
169 * @param[in] device device name
170 * @param[in] input input switch number
171 * @param[in] fix fix to application(1=fix,0=general)
172 * @param[in] keycode switch map to keyboard operation(0=not map to keyboard)
175 /*--------------------------------------------------------------------------*/
177 ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
178 const char *appid, const char *device, int32_t input,
179 int32_t fix, int32_t keycode)
181 uifw_trace("ico_mgr_add_input_app: Enter(appid=%s,dev=%s,input=%d,fix=%d,key=%d)",
182 appid, device, input, fix, keycode);
184 struct ico_ictl_mgr *pIctlMgr;
185 struct ico_ictl_input *pInput;
186 struct ico_app_mgr *pAppMgr;
188 pIctlMgr = find_ictlmgr_by_device(device);
190 /* not configure input controller, create */
191 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
192 pIctlMgr = find_ictlmgr_by_device(device);
194 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
198 pInput = find_ictlinput_by_input(pIctlMgr, input);
200 /* not configure input switch, create */
201 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
202 pInput = find_ictlinput_by_input(pIctlMgr, input);
204 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
209 /* find application */
210 pAppMgr = find_app_by_appid(appid);
212 /* create Application Management Table */
213 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
215 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
218 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
219 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
220 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
223 pInput->app = pAppMgr;
225 uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
226 pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
230 /*--------------------------------------------------------------------------*/
232 * @brief ico_mgr_del_input_app: delete input event at application from HomeScreen.
234 * @param[in] client client(HomeScreen)
235 * @param[in] resource resource of request
236 * @param[in] appid target application id,
237 * if NULL, all applictions without fixed assign switch
238 * @param[in] device device name
239 * if NULL, all device without fixed assign switch
240 * @param[in] input input switch number
241 * if -1, all input without fixed assign switch
244 /*--------------------------------------------------------------------------*/
246 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
247 const char *appid, const char *device, int32_t input)
249 uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
250 appid ? appid : "(NULL)", device ? device : "(NULL)", input);
253 struct ico_ictl_mgr *pIctlMgr = NULL;
254 struct ico_ictl_input *pInput = NULL;
255 struct ico_app_mgr *pAppMgr;
257 if ((device != NULL) && (*device != 0)) {
258 pIctlMgr = find_ictlmgr_by_device(device);
260 /* not configure input controller, NOP */
261 uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
265 pInput = find_ictlinput_by_input(pIctlMgr, input);
267 /* not configure input switch, NOP */
268 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
278 /* find application */
279 if ((appid != NULL) && (*appid != 0)) {
280 pAppMgr = find_app_by_appid(appid);
282 /* application dose not exist, NOP */
283 uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
288 if (pInput->app != pAppMgr) {
289 /* not same application, NOP */
290 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d not app.%s, current %s)",
291 device, input, appid,
292 pInput->app ? pInput->app->appid : "(NULL)");
295 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
296 device, input, appid);
301 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
302 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
303 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
304 pIctlMgr->device, pInput->input, appid);
311 /* reset all device without fixed assign */
312 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
313 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
314 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
315 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
316 pIctlMgr->device, pInput->input, pInput->app->appid);
326 if ((pInput->fix == 0) && (pInput->app != NULL)) {
327 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
328 pIctlMgr->device, pInput->input, pInput->app->appid);
333 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
334 if ((pInput->fix == 0) && (pInput->app != NULL)) {
335 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
336 pIctlMgr->device, pInput->input, pInput->app->appid);
343 /* reset all application without fixed assign */
344 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
345 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
346 if ((pInput->fix == 0) && (pInput->app != NULL)) {
347 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
348 pIctlMgr->device, pInput->input, pInput->app->appid);
355 uifw_trace("ico_mgr_del_input_app: Leave");
358 /*--------------------------------------------------------------------------*/
360 * @brief ico_device_configure_input: configure input device and input switch
361 * from Device Input Controller.
363 * @param[in] client client(Device Input Controller)
364 * @param[in] resource resource of request
365 * @param[in] device device name
366 * @param[in] type device type(saved but unused)
367 * @param[in] swname input switch name
368 * @param[in] input input switch number
369 * @param[in] codename input code name
370 * @param[in] code input code number
373 /*--------------------------------------------------------------------------*/
375 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
376 const char *device, int32_t type, const char *swname,
377 int32_t input, const char *codename, int32_t code)
379 uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
380 "input=%d,code=%d[%s])", (int)client, device, type,
381 swname ? swname : "(NULL)", input, code, codename ? codename : " ");
383 struct ico_ictl_mgr *pIctlMgr;
384 struct ico_ictl_input *pInput;
385 struct ico_app_mgr *pAppMgr;
387 pIctlMgr = find_ictlmgr_by_device(device);
389 /* create ictl mgr table */
390 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
391 if (pIctlMgr == NULL) {
392 uifw_error("ico_device_configure_input: Leave(No Memory)");
395 uifw_trace("ico_device_configure_input: create pIctlMgr(mgr=%08x,input=%d)",
396 (int)pIctlMgr, input);
397 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
398 wl_list_init(&pIctlMgr->ico_ictl_input);
399 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
402 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
404 pIctlMgr->client = client;
405 pIctlMgr->resource = resource;
407 pIctlMgr->type = type;
410 /* search and add input switch */
411 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
412 if (pInput->input == input) break;
414 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
415 uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
416 device, swname, input);
417 pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
418 if (pInput == NULL) {
419 uifw_error("ico_device_configure_input: Leave(No Memory)");
422 memset(pInput, 0, sizeof(struct ico_ictl_input));
424 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
427 strcpy(pInput->swname, "(Unknown)");
429 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
432 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
434 pInput->input = input;
435 memset(pInput->code, 0, sizeof(pInput->code));
437 pInput->code[0].code = code;
439 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
442 if (client == NULL) {
443 /* internal call for table create */
444 uifw_trace("ico_device_configure_input: Leave(table create)");
448 /* send to application and manager(ex.HomeScreen) */
449 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
450 if (pAppMgr->resource == NULL) continue;
451 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
453 uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
454 pAppMgr->appid, device, pInput->swname, input);
455 ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
456 pInput->swname, input,
457 pInput->code[0].name, pInput->code[0].code);
459 uifw_trace("ico_device_configure_input: Leave");
462 /*--------------------------------------------------------------------------*/
464 * @brief ico_device_configure_code: add input switch from Device Input Controller.
466 * @param[in] client client(Device Input Controller)
467 * @param[in] resource resource of request
468 * @param[in] device device name
469 * @param[in] input input switch number
470 * @param[in] codename input code name
471 * @param[in] code input code number
474 /*--------------------------------------------------------------------------*/
476 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
477 const char *device, int32_t input,
478 const char *codename, int32_t code)
480 uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
481 (int)client, device, input, code, codename ? codename : " ");
484 struct ico_ictl_mgr *pIctlMgr;
485 struct ico_ictl_input *pInput;
486 struct ico_app_mgr *pAppMgr;
488 pIctlMgr = find_ictlmgr_by_device(device);
490 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
493 /* search input switch */
494 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
495 if (pInput->input == input) break;
497 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
498 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
503 /* search input code */
504 for (i = 0; i < pInput->ncode; i++) {
505 if (pInput->code[i].code == code) break;
507 if (i >= pInput->ncode) {
508 /* code dose not exist, add */
509 if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
510 uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
516 pInput->code[i].code = code;
518 memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
519 strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
521 /* send to application and manager(ex.HomeScreen) */
522 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
523 if (pAppMgr->resource == NULL) continue;
524 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
525 uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
526 pAppMgr->appid, device, pInput->swname, input);
527 ico_exinput_send_code(pAppMgr->resource, device, input,
528 pInput->code[i].name, pInput->code[i].code);
530 uifw_trace("ico_device_configure_code: Leave");
533 /*--------------------------------------------------------------------------*/
535 * @brief ico_device_input_event: device input event from Device Input Controller.
537 * @param[in] client client(Device Input Controller)
538 * @param[in] resource resource of request
539 * @param[in] time device input time(miri-sec)
540 * @param[in] device device name
541 * @param[in] input input switch number
542 * @param[in] code input code number
543 * @param[in] state input state(1=On, 0=Off)
546 /*--------------------------------------------------------------------------*/
548 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
549 uint32_t time, const char *device,
550 int32_t input, int32_t code, int32_t state)
552 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
553 time, device, input, code, state);
555 struct ico_ictl_mgr *pIctlMgr;
556 struct ico_ictl_input *pInput;
558 /* find input devcie by client */
559 pIctlMgr = find_ictlmgr_by_device(device);
561 uifw_error("ico_device_input_event: Leave(Unknown client(%08x))", (int)client);
564 /* find input switch by input Id */
565 pInput = find_ictlinput_by_input(pIctlMgr, input);
567 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
568 pIctlMgr->device, input);
573 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
574 pIctlMgr->device, pInput->swname);
578 /* send event to application */
579 uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
580 pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
581 ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
584 uifw_trace("ico_device_input_event: Leave");
587 /*--------------------------------------------------------------------------*/
589 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
591 * @param[in] client client(HomeScreen)
592 * @param[in] data data(unused)
593 * @param[in] version protocol version(unused)
594 * @param[in] id client object id
597 /*--------------------------------------------------------------------------*/
599 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
602 struct ico_app_mgr *pAppMgr;
604 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
605 appid = ico_window_mgr_get_appid(client);
608 /* client dose not exist */
609 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
613 /* find application */
614 pAppMgr = find_app_by_appid(appid);
616 /* create Application Management Table */
617 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
619 uifw_error("ico_control_bind: Leave(No Memory)");
622 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
623 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
624 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
626 pAppMgr->client = client;
627 if (! pAppMgr->mgr_resource) {
628 pAppMgr->mgr_resource = wl_resource_create(client,
629 &ico_input_mgr_control_interface, 1, id);
630 if (pAppMgr->mgr_resource) {
631 wl_resource_set_implementation(pAppMgr->mgr_resource,
632 &ico_input_mgr_implementation,
633 pInputMgr, ico_control_unbind);
636 uifw_trace("ico_control_bind: Leave");
639 /*--------------------------------------------------------------------------*/
641 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
643 * @param[in] resource client resource(HomeScreen)
646 /*--------------------------------------------------------------------------*/
648 ico_control_unbind(struct wl_resource *resource)
650 struct ico_app_mgr *pAppMgr;
652 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
654 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
655 if (pAppMgr->mgr_resource == resource) {
656 uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
657 pAppMgr->mgr_resource = NULL;
661 uifw_trace("ico_control_unbind: Leave");
664 /*--------------------------------------------------------------------------*/
666 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
668 * @param[in] client client(Device Input Controller)
669 * @param[in] data data(unused)
670 * @param[in] version protocol version(unused)
671 * @param[in] id client object id
674 /*--------------------------------------------------------------------------*/
676 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
678 struct wl_resource *mgr_resource;
680 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
682 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
684 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
685 NULL, ico_device_unbind);
687 uifw_trace("ico_device_bind: Leave");
690 /*--------------------------------------------------------------------------*/
692 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
694 * @param[in] resource client resource(Device Input Controller)
697 /*--------------------------------------------------------------------------*/
699 ico_device_unbind(struct wl_resource *resource)
701 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
702 uifw_trace("ico_device_unbind: Leave");
705 /*--------------------------------------------------------------------------*/
707 * @brief ico_exinput_bind: ico_exinput bind from Application
709 * @param[in] client client(Application)
710 * @param[in] data data(unused)
711 * @param[in] version protocol version(unused)
712 * @param[in] id client object id
715 /*--------------------------------------------------------------------------*/
717 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
721 struct ico_app_mgr *pAppMgr;
722 struct ico_ictl_mgr *pIctlMgr;
723 struct ico_ictl_input *pInput;
725 appid = ico_window_mgr_get_appid(client);
726 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
727 appid ? appid : "(NULL)");
730 /* client dose not exist */
731 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
735 /* find application */
736 pAppMgr = find_app_by_appid(appid);
738 /* create Application Management Table */
739 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
741 uifw_error("ico_exinput_bind: Leave(No Memory)");
744 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
745 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
746 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
747 uifw_trace("ico_exinput_bind: Create App.%s table", appid);
749 pAppMgr->client = client;
750 if (! pAppMgr->resource) {
751 pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
752 if (pAppMgr->resource) {
753 wl_resource_set_implementation(pAppMgr->resource, NULL,
754 pInputMgr, ico_exinput_unbind);
758 /* send all capabilities */
759 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
760 if (pIctlMgr->client == NULL) {
761 uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
766 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
767 if (pInput->swname[0] == 0) {
768 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
771 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
772 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
773 pIctlMgr->device, pInput->swname, pInput->app->appid);
776 uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
777 pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
778 ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
779 pIctlMgr->type, pInput->swname, pInput->input,
780 pInput->code[0].name, pInput->code[0].code);
781 for (i = 1; i < pInput->ncode; i++) {
782 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
783 pInput->code[i].name, pInput->code[i].code);
787 uifw_trace("ico_exinput_bind: Leave");
790 /*--------------------------------------------------------------------------*/
792 * @brief ico_exinput_unbind: ico_exinput unbind from Application
794 * @param[in] resource client resource(Application)
797 /*--------------------------------------------------------------------------*/
799 ico_exinput_unbind(struct wl_resource *resource)
801 struct ico_app_mgr *pAppMgr;
802 struct ico_app_mgr *pAppMgrTmp;
803 struct ico_ictl_mgr *pIctlMgr;
804 struct ico_ictl_input *pInput;
807 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
809 wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
810 if (pAppMgr->resource == resource) {
811 uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
813 /* release application from input switch */
814 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
815 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
816 if (pInput->app == pAppMgr) {
817 if (pInput->fix == 0) {
818 uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
819 pAppMgr->appid, pIctlMgr->device, pInput->swname);
823 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
824 pAppMgr->appid, pIctlMgr->device, pInput->swname);
831 wl_list_remove(&pAppMgr->link);
835 pAppMgr->client = NULL;
836 pAppMgr->resource = NULL;
840 uifw_trace("ico_exinput_unbind: Leave");
843 /*--------------------------------------------------------------------------*/
845 * @brief find_ictlmgr_by_device: find Input Controller by device name
847 * @param[in] device device name
848 * @return Input Controller Manager table address
849 * @retval !=NULL address
850 * @retval ==NULL not exist
852 /*--------------------------------------------------------------------------*/
853 static struct ico_ictl_mgr *
854 find_ictlmgr_by_device(const char *device)
856 struct ico_ictl_mgr *pIctlMgr;
858 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
859 if (strcmp(pIctlMgr->device, device) == 0) {
866 /*--------------------------------------------------------------------------*/
868 * @brief find_ictlinput_by_input: find Input Switch by input Id
870 * @param[in] pIctlMgr Input Controller device
871 * @param[in] input Input Id
872 * @return Input Switch table address
873 * @retval !=NULL address
874 * @retval ==NULL not exist
876 /*--------------------------------------------------------------------------*/
877 static struct ico_ictl_input *
878 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
880 struct ico_ictl_input *pInput;
882 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
883 if (pInput->input == input) {
890 /*--------------------------------------------------------------------------*/
892 * @brief find_app_by_appid: find Application by application Id
894 * @param[in] appid application Id
895 * @return Application Management table address
896 * @retval !=NULL address
897 * @retval ==NULL not exist
899 /*--------------------------------------------------------------------------*/
900 static struct ico_app_mgr *
901 find_app_by_appid(const char *appid)
903 struct ico_app_mgr *pAppMgr;
905 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
906 if (strcmp(pAppMgr->appid, appid) == 0) {
913 /*--------------------------------------------------------------------------*/
915 * @brief module_init: initialization of this plugin
917 * @param[in] ec weston compositor
918 * @param[in] argc number of arguments(unused)
919 * @param[in] argv argument list(unused)
924 /*--------------------------------------------------------------------------*/
926 module_init(struct weston_compositor *ec, int *argc, char *argv[])
928 uifw_info("ico_input_mgr: Enter(module_init)");
930 /* initialize management table */
931 pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
932 if (pInputMgr == NULL) {
933 uifw_trace("ico_input_mgr: malloc failed");
936 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
937 pInputMgr->compositor = ec;
939 /* interface to desktop manager(ex.HomeScreen) */
940 if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
941 pInputMgr, ico_control_bind) == NULL) {
942 uifw_trace("ico_input_mgr: wl_global_create mgr failed");
946 /* interface to Input Controller(ictl) */
947 if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
948 pInputMgr, ico_device_bind) == NULL) {
949 uifw_trace("ico_input_mgr: wl_global_create ictl failed");
953 /* interface to App(exinput) */
954 if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
955 pInputMgr, ico_exinput_bind) == NULL) {
956 uifw_trace("ico_input_mgr: wl_global_create exseat failed");
960 /* initialize list */
961 wl_list_init(&pInputMgr->ictl_list);
962 wl_list_init(&pInputMgr->app_list);
964 uifw_info("ico_input_mgr: Leave(module_init)");