source: mainline/uspace/srv/hid/input/input.c@ c4c6025

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c4c6025 was a2afd8f, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Move ADB keyboard and mouse support to separate drivers.

  • Property mode set to 100644
File size: 18.8 KB
Line 
1/*
2 * Copyright (c) 2006 Josef Cejka
3 * Copyright (c) 2011 Jiri Svoboda
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/**
31 * @addtogroup inputgen generic
32 * @brief HelenOS input server.
33 * @ingroup input
34 * @{
35 */
36/** @file
37 */
38
39#include <adt/list.h>
40#include <stdbool.h>
41#include <fibril_synch.h>
42#include <ipc/services.h>
43#include <ipc/input.h>
44#include <config.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <ns.h>
48#include <async.h>
49#include <errno.h>
50#include <adt/fifo.h>
51#include <io/console.h>
52#include <io/keycode.h>
53#include <loc.h>
54#include <str_error.h>
55#include <char_dev_iface.h>
56#include <fibril.h>
57#include "layout.h"
58#include "kbd.h"
59#include "kbd_port.h"
60#include "kbd_ctl.h"
61#include "mouse.h"
62#include "mouse_proto.h"
63#include "serial.h"
64#include "input.h"
65
66#define NUM_LAYOUTS 4
67
68static layout_ops_t *layout[NUM_LAYOUTS] = {
69 &us_qwerty_ops,
70 &us_dvorak_ops,
71 &cz_ops,
72 &ar_ops
73};
74
75typedef struct {
76 /** Link into the list of clients */
77 link_t link;
78
79 /** Indicate whether the client is active */
80 bool active;
81
82 /** Client callback session */
83 async_sess_t *sess;
84} client_t;
85
86/** List of clients */
87static list_t clients;
88static client_t *active_client = NULL;
89
90/** Kernel override */
91static bool active = true;
92
93/** Serial console specified by the user */
94static char *serial_console;
95
96/** List of keyboard devices */
97static list_t kbd_devs;
98
99/** List of mouse devices */
100static list_t mouse_devs;
101
102/** List of serial devices */
103static list_t serial_devs;
104
105static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
106
107static void *client_data_create(void)
108{
109 client_t *client = (client_t *) calloc(1, sizeof(client_t));
110 if (client == NULL)
111 return NULL;
112
113 link_initialize(&client->link);
114 client->active = false;
115 client->sess = NULL;
116
117 list_append(&client->link, &clients);
118
119 return client;
120}
121
122static void client_data_destroy(void *data)
123{
124 client_t *client = (client_t *) data;
125
126 list_remove(&client->link);
127 free(client);
128}
129
130void kbd_push_data(kbd_dev_t *kdev, sysarg_t data)
131{
132 (*kdev->ctl_ops->parse)(data);
133}
134
135void mouse_push_data(mouse_dev_t *mdev, sysarg_t data)
136{
137 (*mdev->proto_ops->parse)(data);
138}
139
140void kbd_push_event(kbd_dev_t *kdev, int type, unsigned int key)
141{
142 kbd_event_t ev;
143 unsigned int mod_mask;
144
145 switch (key) {
146 case KC_LCTRL:
147 mod_mask = KM_LCTRL;
148 break;
149 case KC_RCTRL:
150 mod_mask = KM_RCTRL;
151 break;
152 case KC_LSHIFT:
153 mod_mask = KM_LSHIFT;
154 break;
155 case KC_RSHIFT:
156 mod_mask = KM_RSHIFT;
157 break;
158 case KC_LALT:
159 mod_mask = KM_LALT;
160 break;
161 case KC_RALT:
162 mod_mask = KM_RALT;
163 break;
164 default:
165 mod_mask = 0;
166 }
167
168 if (mod_mask != 0) {
169 if (type == KEY_PRESS)
170 kdev->mods = kdev->mods | mod_mask;
171 else
172 kdev->mods = kdev->mods & ~mod_mask;
173 }
174
175 switch (key) {
176 case KC_CAPS_LOCK:
177 mod_mask = KM_CAPS_LOCK;
178 break;
179 case KC_NUM_LOCK:
180 mod_mask = KM_NUM_LOCK;
181 break;
182 case KC_SCROLL_LOCK:
183 mod_mask = KM_SCROLL_LOCK;
184 break;
185 default:
186 mod_mask = 0;
187 }
188
189 if (mod_mask != 0) {
190 if (type == KEY_PRESS) {
191 /*
192 * Only change lock state on transition from released
193 * to pressed. This prevents autorepeat from messing
194 * up the lock state.
195 */
196 kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys);
197 kdev->lock_keys = kdev->lock_keys | mod_mask;
198
199 /* Update keyboard lock indicator lights. */
200 (*kdev->ctl_ops->set_ind)(kdev, kdev->mods);
201 } else {
202 kdev->lock_keys = kdev->lock_keys & ~mod_mask;
203 }
204 }
205
206 // TODO: More elegant layout switching
207
208 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
209 (key == KC_F1)) {
210 layout_destroy(kdev->active_layout);
211 kdev->active_layout = layout_create(layout[0]);
212 return;
213 }
214
215 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
216 (key == KC_F2)) {
217 layout_destroy(kdev->active_layout);
218 kdev->active_layout = layout_create(layout[1]);
219 return;
220 }
221
222 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
223 (key == KC_F3)) {
224 layout_destroy(kdev->active_layout);
225 kdev->active_layout = layout_create(layout[2]);
226 return;
227 }
228
229 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
230 (key == KC_F4)) {
231 layout_destroy(kdev->active_layout);
232 kdev->active_layout = layout_create(layout[3]);
233 return;
234 }
235
236 ev.type = type;
237 ev.key = key;
238 ev.mods = kdev->mods;
239
240 ev.c = layout_parse_ev(kdev->active_layout, &ev);
241
242 list_foreach(clients, link, client_t, client) {
243 if (client->active) {
244 async_exch_t *exch = async_exchange_begin(client->sess);
245 async_msg_4(exch, INPUT_EVENT_KEY, ev.type, ev.key, ev.mods, ev.c);
246 async_exchange_end(exch);
247 }
248 }
249}
250
251/** Mouse pointer has moved (relative mode). */
252void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy, int dz)
253{
254 list_foreach(clients, link, client_t, client) {
255 if (client->active) {
256 async_exch_t *exch = async_exchange_begin(client->sess);
257
258 if ((dx) || (dy))
259 async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
260
261 if (dz) {
262 // TODO: Implement proper wheel support
263 keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
264
265 for (unsigned int i = 0; i < 3; i++)
266 async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
267
268 async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
269 }
270
271 async_exchange_end(exch);
272 }
273 }
274}
275
276/** Mouse pointer has moved (absolute mode). */
277void mouse_push_event_abs_move(mouse_dev_t *mdev, unsigned int x, unsigned int y,
278 unsigned int max_x, unsigned int max_y)
279{
280 list_foreach(clients, link, client_t, client) {
281 if (client->active) {
282 if ((max_x) && (max_y)) {
283 async_exch_t *exch = async_exchange_begin(client->sess);
284 async_msg_4(exch, INPUT_EVENT_ABS_MOVE, x, y, max_x, max_y);
285 async_exchange_end(exch);
286 }
287 }
288 }
289}
290
291/** Mouse button has been pressed. */
292void mouse_push_event_button(mouse_dev_t *mdev, int bnum, int press)
293{
294 list_foreach(clients, link, client_t, client) {
295 if (client->active) {
296 async_exch_t *exch = async_exchange_begin(client->sess);
297 async_msg_2(exch, INPUT_EVENT_BUTTON, bnum, press);
298 async_exchange_end(exch);
299 }
300 }
301}
302
303/** Arbitrate client actiovation */
304static void client_arbitration(void)
305{
306 /* Mutual exclusion of active clients */
307 list_foreach(clients, link, client_t, client)
308 client->active = ((active) && (client == active_client));
309
310 /* Notify clients about the arbitration */
311 list_foreach(clients, link, client_t, client) {
312 async_exch_t *exch = async_exchange_begin(client->sess);
313 async_msg_0(exch, client->active ?
314 INPUT_EVENT_ACTIVE : INPUT_EVENT_DEACTIVE);
315 async_exchange_end(exch);
316 }
317}
318
319/** New client connection */
320static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
321{
322 client_t *client = (client_t *) async_get_client_data();
323 if (client == NULL) {
324 async_answer_0(iid, ENOMEM);
325 return;
326 }
327
328 async_answer_0(iid, EOK);
329
330 while (true) {
331 ipc_call_t call;
332 ipc_callid_t callid = async_get_call(&call);
333
334 if (!IPC_GET_IMETHOD(call)) {
335 if (client->sess != NULL) {
336 async_hangup(client->sess);
337 client->sess = NULL;
338 }
339
340 async_answer_0(callid, EOK);
341 return;
342 }
343
344 async_sess_t *sess =
345 async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
346 if (sess != NULL) {
347 if (client->sess == NULL) {
348 client->sess = sess;
349 async_answer_0(callid, EOK);
350 } else
351 async_answer_0(callid, ELIMIT);
352 } else {
353 switch (IPC_GET_IMETHOD(call)) {
354 case INPUT_ACTIVATE:
355 active_client = client;
356 client_arbitration();
357 async_answer_0(callid, EOK);
358 break;
359 default:
360 async_answer_0(callid, EINVAL);
361 }
362 }
363 }
364}
365
366static void kconsole_event_handler(ipc_callid_t callid, ipc_call_t *call,
367 void *arg)
368{
369 if (IPC_GET_ARG1(*call)) {
370 /* Kernel console activated */
371 active = false;
372 } else {
373 /* Kernel console deactivated */
374 active = true;
375 }
376
377 client_arbitration();
378}
379
380static kbd_dev_t *kbd_dev_new(void)
381{
382 kbd_dev_t *kdev = calloc(1, sizeof(kbd_dev_t));
383 if (kdev == NULL) {
384 printf("%s: Error allocating keyboard device. "
385 "Out of memory.\n", NAME);
386 return NULL;
387 }
388
389 link_initialize(&kdev->link);
390
391 kdev->mods = KM_NUM_LOCK;
392 kdev->lock_keys = 0;
393 kdev->active_layout = layout_create(layout[0]);
394
395 return kdev;
396}
397
398static mouse_dev_t *mouse_dev_new(void)
399{
400 mouse_dev_t *mdev = calloc(1, sizeof(mouse_dev_t));
401 if (mdev == NULL) {
402 printf("%s: Error allocating mouse device. "
403 "Out of memory.\n", NAME);
404 return NULL;
405 }
406
407 link_initialize(&mdev->link);
408
409 return mdev;
410}
411
412static serial_dev_t *serial_dev_new(void)
413{
414 serial_dev_t *sdev = calloc(1, sizeof(serial_dev_t));
415 if (sdev == NULL) {
416 printf("%s: Error allocating serial device. "
417 "Out of memory.\n", NAME);
418 return NULL;
419 }
420
421 sdev->kdev = kbd_dev_new();
422 if (sdev->kdev == NULL) {
423 free(sdev);
424 return NULL;
425 }
426
427 link_initialize(&sdev->link);
428
429 return sdev;
430}
431
432/** Add new legacy keyboard device. */
433static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl)
434{
435 kbd_dev_t *kdev = kbd_dev_new();
436 if (kdev == NULL)
437 return;
438
439 kdev->port_ops = port;
440 kdev->ctl_ops = ctl;
441 kdev->svc_id = 0;
442
443 /* Initialize port driver. */
444 if ((*kdev->port_ops->init)(kdev) != 0)
445 goto fail;
446
447 /* Initialize controller driver. */
448 if ((*kdev->ctl_ops->init)(kdev) != 0) {
449 /* XXX Uninit port */
450 goto fail;
451 }
452
453 list_append(&kdev->link, &kbd_devs);
454 return;
455
456fail:
457 free(kdev);
458}
459
460/** Add new kbdev device.
461 *
462 * @param service_id Service ID of the keyboard device
463 *
464 */
465static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp)
466{
467 kbd_dev_t *kdev = kbd_dev_new();
468 if (kdev == NULL)
469 return -1;
470
471 kdev->svc_id = service_id;
472 kdev->port_ops = NULL;
473 kdev->ctl_ops = &kbdev_ctl;
474
475 int rc = loc_service_get_name(service_id, &kdev->svc_name);
476 if (rc != EOK) {
477 kdev->svc_name = NULL;
478 goto fail;
479 }
480
481 /* Initialize controller driver. */
482 if ((*kdev->ctl_ops->init)(kdev) != 0) {
483 goto fail;
484 }
485
486 list_append(&kdev->link, &kbd_devs);
487 *kdevp = kdev;
488 return EOK;
489
490fail:
491 if (kdev->svc_name != NULL)
492 free(kdev->svc_name);
493 free(kdev);
494 return -1;
495}
496
497/** Add new mousedev device.
498 *
499 * @param service_id Service ID of the mouse device
500 *
501 */
502static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp)
503{
504 mouse_dev_t *mdev = mouse_dev_new();
505 if (mdev == NULL)
506 return -1;
507
508 mdev->svc_id = service_id;
509 mdev->port_ops = NULL;
510 mdev->proto_ops = &mousedev_proto;
511
512 int rc = loc_service_get_name(service_id, &mdev->svc_name);
513 if (rc != EOK) {
514 mdev->svc_name = NULL;
515 goto fail;
516 }
517
518 /* Initialize controller driver. */
519 if ((*mdev->proto_ops->init)(mdev) != 0) {
520 goto fail;
521 }
522
523 list_append(&mdev->link, &mouse_devs);
524 *mdevp = mdev;
525 return EOK;
526
527fail:
528 free(mdev);
529 return -1;
530}
531
532static int serial_consumer(void *arg)
533{
534 serial_dev_t *sdev = (serial_dev_t *) arg;
535
536 while (true) {
537 uint8_t data;
538
539 char_dev_read(sdev->sess, &data, sizeof(data));
540 kbd_push_data(sdev->kdev, data);
541 }
542
543 return EOK;
544}
545
546/** Add new serial console device.
547 *
548 * @param service_id Service ID of the chardev device
549 *
550 */
551static int serial_add_srldev(service_id_t service_id, serial_dev_t **sdevp)
552{
553 bool match = false;
554
555 serial_dev_t *sdev = serial_dev_new();
556 if (sdev == NULL)
557 return -1;
558
559 sdev->kdev->svc_id = service_id;
560
561 int rc = loc_service_get_name(service_id, &sdev->kdev->svc_name);
562 if (rc != EOK)
563 goto fail;
564
565 list_append(&sdev->link, &serial_devs);
566
567 /*
568 * Is this the device the user wants to use as a serial console?
569 */
570 match = (serial_console != NULL) &&
571 !str_cmp(serial_console, sdev->kdev->svc_name);
572
573 if (match) {
574 sdev->kdev->ctl_ops = &stty_ctl;
575
576 /* Initialize controller driver. */
577 if ((*sdev->kdev->ctl_ops->init)(sdev->kdev) != 0) {
578 list_remove(&sdev->link);
579 goto fail;
580 }
581
582 sdev->sess = loc_service_connect(service_id, INTERFACE_DDF,
583 IPC_FLAG_BLOCKING);
584
585 fid_t fid = fibril_create(serial_consumer, sdev);
586 fibril_add_ready(fid);
587 }
588
589 *sdevp = sdev;
590 return EOK;
591
592fail:
593 if (sdev->kdev->svc_name != NULL)
594 free(sdev->kdev->svc_name);
595 free(sdev->kdev);
596 free(sdev);
597 return -1;
598}
599
600
601/** Add legacy drivers/devices. */
602static void kbd_add_legacy_devs(void)
603{
604 /*
605 * Need to add these drivers based on config unless we can probe
606 * them automatically.
607 */
608#if defined(UARCH_arm32) && defined(MACHINE_gta02)
609 kbd_add_dev(&chardev_port, &stty_ctl);
610#endif
611#if defined(UARCH_ia64) && defined(MACHINE_ski)
612 kbd_add_dev(&chardev_port, &stty_ctl);
613#endif
614#if defined(MACHINE_msim)
615 kbd_add_dev(&chardev_port, &stty_ctl);
616#endif
617#if defined(UARCH_sparc64) && defined(PROCESSOR_sun4v)
618 kbd_add_dev(&chardev_port, &stty_ctl);
619#endif
620 /* Silence warning on abs32le about kbd_add_dev() being unused */
621 (void) kbd_add_dev;
622}
623
624static int dev_check_new_kbdevs(void)
625{
626 category_id_t keyboard_cat;
627 service_id_t *svcs;
628 size_t count, i;
629 bool already_known;
630 int rc;
631
632 rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
633 if (rc != EOK) {
634 printf("%s: Failed resolving category 'keyboard'.\n", NAME);
635 return ENOENT;
636 }
637
638 /*
639 * Check for new keyboard devices
640 */
641 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
642 if (rc != EOK) {
643 printf("%s: Failed getting list of keyboard devices.\n",
644 NAME);
645 return EIO;
646 }
647
648 for (i = 0; i < count; i++) {
649 already_known = false;
650
651 /* Determine whether we already know this device. */
652 list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
653 if (kdev->svc_id == svcs[i]) {
654 already_known = true;
655 break;
656 }
657 }
658
659 if (!already_known) {
660 kbd_dev_t *kdev;
661 if (kbd_add_kbdev(svcs[i], &kdev) == EOK) {
662 printf("%s: Connected keyboard device '%s'\n",
663 NAME, kdev->svc_name);
664 }
665 }
666 }
667
668 free(svcs);
669
670 /* XXX Handle device removal */
671
672 return EOK;
673}
674
675static int dev_check_new_mousedevs(void)
676{
677 category_id_t mouse_cat;
678 service_id_t *svcs;
679 size_t count, i;
680 bool already_known;
681 int rc;
682
683 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
684 if (rc != EOK) {
685 printf("%s: Failed resolving category 'mouse'.\n", NAME);
686 return ENOENT;
687 }
688
689 /*
690 * Check for new mouse devices
691 */
692 rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
693 if (rc != EOK) {
694 printf("%s: Failed getting list of mouse devices.\n",
695 NAME);
696 return EIO;
697 }
698
699 for (i = 0; i < count; i++) {
700 already_known = false;
701
702 /* Determine whether we already know this device. */
703 list_foreach(mouse_devs, link, mouse_dev_t, mdev) {
704 if (mdev->svc_id == svcs[i]) {
705 already_known = true;
706 break;
707 }
708 }
709
710 if (!already_known) {
711 mouse_dev_t *mdev;
712 if (mouse_add_mousedev(svcs[i], &mdev) == EOK) {
713 printf("%s: Connected mouse device '%s'\n",
714 NAME, mdev->svc_name);
715 }
716 }
717 }
718
719 free(svcs);
720
721 /* XXX Handle device removal */
722
723 return EOK;
724}
725
726static int dev_check_new_serialdevs(void)
727{
728 category_id_t serial_cat;
729 service_id_t *svcs;
730 size_t count, i;
731 bool already_known;
732 int rc;
733
734 rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING);
735 if (rc != EOK) {
736 printf("%s: Failed resolving category 'serial'.\n", NAME);
737 return ENOENT;
738 }
739
740 /*
741 * Check for new serial devices
742 */
743 rc = loc_category_get_svcs(serial_cat, &svcs, &count);
744 if (rc != EOK) {
745 printf("%s: Failed getting list of serial devices.\n",
746 NAME);
747 return EIO;
748 }
749
750 for (i = 0; i < count; i++) {
751 already_known = false;
752
753 /* Determine whether we already know this device. */
754 list_foreach(serial_devs, link, serial_dev_t, sdev) {
755 if (sdev->kdev->svc_id == svcs[i]) {
756 already_known = true;
757 break;
758 }
759 }
760
761 if (!already_known) {
762 serial_dev_t *sdev;
763 if (serial_add_srldev(svcs[i], &sdev) == EOK) {
764 printf("%s: Connected serial device '%s'\n",
765 NAME, sdev->kdev->svc_name);
766 }
767 }
768 }
769
770 free(svcs);
771
772 /* XXX Handle device removal */
773
774 return EOK;
775}
776
777static int dev_check_new(void)
778{
779 int rc;
780
781 fibril_mutex_lock(&discovery_lock);
782
783 if (!serial_console) {
784 rc = dev_check_new_kbdevs();
785 if (rc != EOK) {
786 fibril_mutex_unlock(&discovery_lock);
787 return rc;
788 }
789
790 rc = dev_check_new_mousedevs();
791 if (rc != EOK) {
792 fibril_mutex_unlock(&discovery_lock);
793 return rc;
794 }
795 } else {
796 rc = dev_check_new_serialdevs();
797 if (rc != EOK) {
798 fibril_mutex_unlock(&discovery_lock);
799 return rc;
800 }
801 }
802
803 fibril_mutex_unlock(&discovery_lock);
804
805 return EOK;
806}
807
808static void cat_change_cb(void)
809{
810 dev_check_new();
811}
812
813/** Start listening for new devices. */
814static int input_start_dev_discovery(void)
815{
816 int rc = loc_register_cat_change_cb(cat_change_cb);
817 if (rc != EOK) {
818 printf("%s: Failed registering callback for device discovery. "
819 "(%d)\n", NAME, rc);
820 return rc;
821 }
822
823 return dev_check_new();
824}
825
826static void usage(char *name)
827{
828 printf("Usage: %s <service_name>\n", name);
829}
830
831int main(int argc, char **argv)
832{
833 int rc;
834
835 if (argc < 2) {
836 usage(argv[0]);
837 return 1;
838 }
839
840 printf("%s: HelenOS input service\n", NAME);
841
842 list_initialize(&clients);
843 list_initialize(&kbd_devs);
844 list_initialize(&mouse_devs);
845 list_initialize(&serial_devs);
846
847 serial_console = config_get_value("console");
848
849 /* Add legacy keyboard devices. */
850 kbd_add_legacy_devs();
851
852 /* Register driver */
853 async_set_client_data_constructor(client_data_create);
854 async_set_client_data_destructor(client_data_destroy);
855 async_set_fallback_port_handler(client_connection, NULL);
856
857 rc = loc_server_register(NAME);
858 if (rc != EOK) {
859 printf("%s: Unable to register server\n", NAME);
860 return rc;
861 }
862
863 service_id_t service_id;
864 rc = loc_service_register(argv[1], &service_id);
865 if (rc != EOK) {
866 printf("%s: Unable to register service %s\n", NAME, argv[1]);
867 return rc;
868 }
869
870 /* Receive kernel notifications */
871 rc = async_event_subscribe(EVENT_KCONSOLE, kconsole_event_handler, NULL);
872 if (rc != EOK)
873 printf("%s: Failed to register kconsole notifications (%s)\n",
874 NAME, str_error(rc));
875
876 /* Start looking for new input devices */
877 input_start_dev_discovery();
878
879 printf("%s: Accepting connections\n", NAME);
880 task_retval(0);
881 async_manager();
882
883 /* Not reached. */
884 return 0;
885}
886
887/**
888 * @}
889 */
Note: See TracBrowser for help on using the repository browser.