source: mainline/uspace/srv/hid/input/input.c@ 6feb444

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6feb444 was 2a72d9f, checked in by Jakub Jermar <jakub@…>, 9 years ago

Consider serial devices input devices

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