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