Subversion Repositories HelenOS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1339 cejka 1
/*
2
 * Copyright (C) 2006 Josef Cejka
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1352 palkovsky 29
#include <ipc/ipc.h>
30
#include <ipc/services.h>
1339 cejka 31
#include <stdio.h>
32
#include <unistd.h>
33
#include <stdlib.h>
1352 palkovsky 34
#include <ipc/ns.h>
1339 cejka 35
#include <errno.h>
36
#include <arch/kbd.h>
37
#include <kbd.h>
1445 cejka 38
#include <libadt/fifo.h>
1339 cejka 39
#include <key_buffer.h>
40
 
41
#define NAME "KBD"
1447 cejka 42
 
1339 cejka 43
int main(int argc, char **argv)
44
{
45
	ipc_call_t call;
46
	ipc_callid_t callid;
47
	int res;
48
	ipcarg_t phonead;
1445 cejka 49
	int phoneid;
50
	char connected = 0;
1451 cejka 51
	keybuffer_t keybuffer;	
1339 cejka 52
	ipcarg_t retval, arg1, arg2;
1344 cejka 53
 
1339 cejka 54
	/* Initialize arch dependent parts */
55
	if (!(res = kbd_arch_init())) {
56
			return -1;
57
			};
58
 
59
	/* Initialize key buffer */
1451 cejka 60
	keybuffer_init(&keybuffer);
1339 cejka 61
 
62
	/* Register service at nameserver */
1499 cejka 63
 
1343 jermar 64
	if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
1339 cejka 65
		return -1;
66
	};
67
 
68
	while (1) {
1365 jermar 69
		callid = ipc_wait_for_call(&call);
1339 cejka 70
		switch (IPC_GET_METHOD(call)) {
1344 cejka 71
			case IPC_M_PHONE_HUNGUP:
1445 cejka 72
				connected = 0;
1339 cejka 73
				retval = 0;
74
				break;
1344 cejka 75
			case IPC_M_CONNECT_ME_TO:
76
				/* Only one connected client allowed */
77
				if (connected) {
78
					retval = ELIMIT;
1339 cejka 79
				} else {
1344 cejka 80
					retval = 0;
81
					connected = 1;
1339 cejka 82
				}
1344 cejka 83
				break;
1445 cejka 84
			case IPC_M_CONNECT_TO_ME:
85
				phoneid = IPC_GET_ARG3(call);
86
				retval = 0;
87
				break;
88
 
1344 cejka 89
			case IPC_M_INTERRUPT:
90
				if (connected) {
1445 cejka 91
					/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
1451 cejka 92
					kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
1344 cejka 93
 
94
					retval = 0;
1445 cejka 95
 
1451 cejka 96
					while (!keybuffer_empty(&keybuffer)) {
97
						if (!keybuffer_pop(&keybuffer, (char *)&arg1)) {
1344 cejka 98
							break;
99
						}
1451 cejka 100
						ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL);
1344 cejka 101
					}
1445 cejka 102
 
1344 cejka 103
				}
104
				break;
105
			default:
106
				retval = ENOENT;
107
				break;
1339 cejka 108
		}
1344 cejka 109
 
1339 cejka 110
		if (! (callid & IPC_CALLID_NOTIFICATION)) {
1343 jermar 111
			ipc_answer_fast(callid, retval, arg1, arg2);
1339 cejka 112
		}
113
	}
114
}
1344 cejka 115