Rev 1560 | Rev 1640 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1560 | Rev 1610 | ||
---|---|---|---|
Line 36... | Line 36... | ||
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 | #include <async.h> |
|
41 | 42 | ||
42 | #define NAME "KBD" |
43 | #define NAME "KBD" |
43 | 44 | ||
- | 45 | int cons_connected = 0; |
|
- | 46 | int phone2cons = -1; |
|
- | 47 | keybuffer_t keybuffer; |
|
- | 48 | ||
- | 49 | static void irq_handler(ipc_callid_t iid, ipc_call_t *call) |
|
- | 50 | { |
|
- | 51 | int chr; |
|
- | 52 | ||
- | 53 | if (cons_connected && phone2cons != -1) { |
|
- | 54 | /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
|
- | 55 | kbd_arch_process(&keybuffer, IPC_GET_ARG2(*call)); |
|
- | 56 | ||
- | 57 | while (!keybuffer_empty(&keybuffer)) { |
|
- | 58 | if (!keybuffer_pop(&keybuffer, (int *)&chr)) |
|
- | 59 | break; |
|
- | 60 | ||
- | 61 | async_msg(phone2cons, KBD_PUSHCHAR, chr); |
|
- | 62 | } |
|
- | 63 | } |
|
- | 64 | } |
|
- | 65 | ||
- | 66 | static void console_connection(ipc_callid_t iid, ipc_call_t *icall) |
|
- | 67 | { |
|
- | 68 | ipc_callid_t callid; |
|
- | 69 | ipc_call_t call; |
|
- | 70 | int retval; |
|
- | 71 | ||
- | 72 | if (cons_connected) { |
|
- | 73 | ipc_answer_fast(iid, ELIMIT, 0, 0); |
|
- | 74 | return; |
|
- | 75 | } |
|
- | 76 | cons_connected = 1; |
|
- | 77 | ipc_answer_fast(iid, 0, 0, 0); |
|
- | 78 | ||
- | 79 | while (1) { |
|
- | 80 | callid = async_get_call(&call); |
|
- | 81 | switch (IPC_GET_METHOD(call)) { |
|
- | 82 | case IPC_M_PHONE_HUNGUP: |
|
- | 83 | cons_connected = 0; |
|
- | 84 | ipc_hangup(phone2cons); |
|
- | 85 | phone2cons = -1; |
|
- | 86 | ipc_answer_fast(callid, 0,0,0); |
|
- | 87 | return; |
|
- | 88 | case IPC_M_CONNECT_TO_ME: |
|
- | 89 | if (phone2cons != -1) { |
|
- | 90 | retval = ELIMIT; |
|
- | 91 | break; |
|
- | 92 | } |
|
- | 93 | phone2cons = IPC_GET_ARG3(call); |
|
- | 94 | retval = 0; |
|
- | 95 | break; |
|
- | 96 | } |
|
- | 97 | ipc_answer_fast(callid, retval, 0, 0); |
|
- | 98 | } |
|
- | 99 | } |
|
- | 100 | ||
- | 101 | ||
44 | int main(int argc, char **argv) |
102 | int main(int argc, char **argv) |
45 | { |
103 | { |
46 | ipc_call_t call; |
104 | ipc_call_t call; |
47 | ipc_callid_t callid; |
105 | ipc_callid_t callid; |
48 | int res; |
106 | int res; |
49 | ipcarg_t phonead; |
107 | ipcarg_t phonead; |
50 | ipcarg_t phoneid; |
108 | ipcarg_t phoneid; |
51 | char connected = 0; |
109 | char connected = 0; |
52 | keybuffer_t keybuffer; |
- | |
53 | ipcarg_t retval, arg1, arg2; |
110 | ipcarg_t retval, arg1, arg2; |
54 | 111 | ||
55 | //open("null",0); |
- | |
56 | //open("stdout",0); |
- | |
57 | - | ||
58 | /* Initialize arch dependent parts */ |
112 | /* Initialize arch dependent parts */ |
59 | if (!(res = kbd_arch_init())) { |
113 | if (!(res = kbd_arch_init())) { |
60 | return -1; |
114 | return -1; |
61 | }; |
115 | }; |
62 | 116 | ||
Line 65... | Line 119... | ||
65 | 119 | ||
66 | /* Register service at nameserver */ |
120 | /* Register service at nameserver */ |
67 | 121 | ||
68 | if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) { |
122 | if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) { |
69 | return -1; |
123 | return -1; |
70 | }; |
124 | } |
71 | while (1) { |
- | |
72 | callid = ipc_wait_for_call(&call); |
- | |
73 | switch (IPC_GET_METHOD(call)) { |
- | |
74 | case IPC_M_PHONE_HUNGUP: |
- | |
75 | connected = 0; |
- | |
76 | retval = 0; |
- | |
77 | break; |
- | |
78 | case IPC_M_CONNECT_ME_TO: |
- | |
79 | /* Only one connected client allowed */ |
- | |
80 | if (connected) { |
- | |
81 | retval = ELIMIT; |
- | |
82 | } else { |
- | |
83 | retval = 0; |
- | |
84 | connected = 1; |
- | |
85 | } |
- | |
86 | break; |
- | |
87 | case IPC_M_CONNECT_TO_ME: |
- | |
88 | phoneid = IPC_GET_ARG3(call); |
- | |
89 | retval = 0; |
- | |
90 | break; |
- | |
91 | 125 | ||
92 | case IPC_M_INTERRUPT: |
- | |
93 | if (connected) { |
- | |
94 | int chr; |
- | |
95 | /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
- | |
96 | kbd_arch_process(&keybuffer, IPC_GET_ARG2(call)); |
126 | async_set_client_connection(console_connection); |
97 | - | ||
98 | retval = 0; |
- | |
99 | - | ||
100 | - | ||
101 | while (!keybuffer_empty(&keybuffer)) { |
127 | async_set_interrupt_received(irq_handler); |
102 | if (!keybuffer_pop(&keybuffer, (int *)&chr)) { |
- | |
103 | break; |
- | |
104 | } |
- | |
105 | { |
- | |
106 | arg1=chr; |
128 | async_manager(); |
107 | send_call(phoneid, KBD_PUSHCHAR, arg1); |
- | |
108 | } |
- | |
109 | } |
- | |
110 | 129 | ||
111 | } |
- | |
112 | break; |
- | |
113 | default: |
- | |
114 | retval = ENOENT; |
- | |
115 | break; |
- | |
116 | } |
- | |
117 | - | ||
118 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
- | |
119 | ipc_answer_fast(callid, retval, arg1, arg2); |
- | |
120 | } |
- | |
121 | } |
- | |
122 | } |
130 | } |
123 | - |