Rev 1392 | Rev 1447 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1392 | Rev 1445 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | #include <stdlib.h> |
33 | #include <stdlib.h> |
34 | #include <ipc/ns.h> |
34 | #include <ipc/ns.h> |
35 | #include <errno.h> |
35 | #include <errno.h> |
36 | #include <arch/kbd.h> |
36 | #include <arch/kbd.h> |
37 | #include <kbd.h> |
37 | #include <kbd.h> |
38 | #include <key_buffer.h> |
- | |
39 | #include <libadt/fifo.h> |
38 | #include <libadt/fifo.h> |
- | 39 | #include <key_buffer.h> |
|
40 | 40 | ||
41 | #define NAME "KBD" |
41 | #define NAME "KBD" |
42 | - | ||
- | 42 | void hello(void *private, int retval, ipc_call_t *data) { |
|
43 | #define KBD_REQUEST_MAX 32 /**< Maximum requests buffered until keypress */ |
43 | printf("%s: got answer from console with retval %d.\n", NAME, retval); |
44 | 44 | } |
|
45 | int main(int argc, char **argv) |
45 | int main(int argc, char **argv) |
46 | { |
46 | { |
47 | ipc_call_t call; |
47 | ipc_call_t call; |
48 | ipc_callid_t callid; |
48 | ipc_callid_t callid; |
49 | char connected = 0; |
- | |
50 | int res; |
49 | int res; |
51 | int c; |
- | |
52 | ipcarg_t phonead; |
50 | ipcarg_t phonead; |
- | 51 | int phoneid; |
|
- | 52 | char connected = 0; |
|
53 | 53 | ||
54 | ipcarg_t retval, arg1, arg2; |
54 | ipcarg_t retval, arg1, arg2; |
55 | 55 | ||
56 | /* Counter of unsatisfied calls */ |
- | |
57 | fifo_count_t callers_counter = 0; |
- | |
58 | /* Fifo with callid's of unsatisfied calls requred for answer */ |
- | |
59 | FIFO_INITIALIZE_STATIC(callers_buffer, ipc_callid_t, KBD_REQUEST_MAX); |
- | |
60 | - | ||
61 | printf("Uspace kbd service started.\n"); |
56 | printf("Uspace kbd service started.\n"); |
62 | 57 | ||
63 | /* Initialize arch dependent parts */ |
58 | /* Initialize arch dependent parts */ |
64 | if (!(res = kbd_arch_init())) { |
59 | if (!(res = kbd_arch_init())) { |
65 | printf("Kbd registration failed with retval %d.\n", res); |
60 | printf("Kbd registration failed with retval %d.\n", res); |
Line 80... | Line 75... | ||
80 | while (1) { |
75 | while (1) { |
81 | callid = ipc_wait_for_call(&call); |
76 | callid = ipc_wait_for_call(&call); |
82 | // printf("%s:Call phone=%lX..", NAME, call.in_phone_hash); |
77 | // printf("%s:Call phone=%lX..", NAME, call.in_phone_hash); |
83 | switch (IPC_GET_METHOD(call)) { |
78 | switch (IPC_GET_METHOD(call)) { |
84 | case IPC_M_PHONE_HUNGUP: |
79 | case IPC_M_PHONE_HUNGUP: |
85 | if (connected) { |
- | |
86 | /* If nobody's connected, clear keybuffer and dont store new keys */ |
- | |
87 | if (--connected == 0) { |
- | |
88 | callers_counter = 0; |
- | |
89 | callers_buffer.head = callers_buffer.tail = 0; |
- | |
90 | key_buffer_free(); |
- | |
91 | } |
- | |
92 | - | ||
93 | printf("%s: Phone hung up.\n", NAME); |
80 | printf("%s: Phone hung up.\n", NAME); |
94 | } else { |
81 | connected = 0; |
95 | printf("%s: Oops, got phone hung up, but nobody connected.\n", NAME); |
- | |
96 | } |
- | |
97 | - | ||
98 | retval = 0; |
82 | retval = 0; |
99 | break; |
83 | break; |
100 | case IPC_M_CONNECT_ME_TO: |
84 | case IPC_M_CONNECT_ME_TO: |
101 | // printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
85 | // printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
102 | /* Only one connected client allowed */ |
86 | /* Only one connected client allowed */ |
Line 105... | Line 89... | ||
105 | } else { |
89 | } else { |
106 | retval = 0; |
90 | retval = 0; |
107 | connected = 1; |
91 | connected = 1; |
108 | } |
92 | } |
109 | break; |
93 | break; |
- | 94 | case IPC_M_CONNECT_TO_ME: |
|
- | 95 | phoneid = IPC_GET_ARG3(call); |
|
- | 96 | retval = 0; |
|
- | 97 | break; |
|
- | 98 | ||
110 | case IPC_M_INTERRUPT: |
99 | case IPC_M_INTERRUPT: |
111 | if (connected) { |
100 | if (connected) { |
112 | /* recode scancode and store it into key buffer */ |
101 | /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
113 | kbd_arch_process(IPC_GET_ARG2(call)); |
102 | kbd_arch_process(IPC_GET_ARG2(call)); |
- | 103 | ||
114 | //printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call)); |
104 | //printf("%s: GOT INTERRUPT: %c\n", NAME, key); |
115 | 105 | ||
116 | /* Some callers could awaiting keypress - if its true, we have to send keys to them. |
106 | /* Some callers could awaiting keypress - if its true, we have to send keys to them. |
117 | * One interrupt can store more than one key into buffer. */ |
107 | * One interrupt can store more than one key into buffer. */ |
- | 108 | ||
118 | retval = 0; |
109 | retval = 0; |
119 | arg2 = 0xbeef; |
- | |
- | 110 | ||
120 | while ((callers_counter) && (!key_buffer_empty())) { |
111 | while (!key_buffer_empty()) { |
121 | callers_counter--; |
- | |
122 | if (!key_buffer_pop((char *)&arg1)) { |
112 | if (!key_buffer_pop((char *)&arg1)) { |
123 | printf("%s: KeyBuffer empty but it should not be.\n"); |
113 | printf("%s: KeyBuffer is empty but it should not be.\n"); |
124 | break; |
114 | break; |
125 | } |
115 | } |
- | 116 | /*FIXME: detection of closed connection */ |
|
126 | ipc_answer_fast(fifo_pop(callers_buffer), retval, arg1, arg2); |
117 | ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, &hello); |
127 | } |
118 | } |
- | 119 | ||
128 | } |
120 | } |
129 | break; |
- | |
130 | case KBD_GETCHAR: |
- | |
131 | // printf("%s: Getchar: ", NAME); |
121 | printf("%s: Interrupt processed.\n", NAME); |
132 | retval = 0; |
- | |
133 | arg1 = 0; |
- | |
134 | if (!key_buffer_pop((char *)&arg1)) { |
- | |
135 | if (callers_counter < KBD_REQUEST_MAX) { |
- | |
136 | callers_counter++; |
- | |
137 | fifo_push(callers_buffer, callid); |
- | |
138 | } else { |
- | |
139 | retval = ELIMIT; |
- | |
140 | } |
- | |
141 | continue; |
- | |
142 | }; |
- | |
143 | arg2 = 0xbeef; |
- | |
144 | // printf("GetChar return %c\n", arg1); |
- | |
145 | - | ||
146 | break; |
122 | break; |
147 | default: |
123 | default: |
148 | printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
124 | printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
149 | retval = ENOENT; |
125 | retval = ENOENT; |
150 | break; |
126 | break; |