Rev 1447 | Rev 1499 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1447 | Rev 1451 | ||
---|---|---|---|
Line 46... | Line 46... | ||
46 | ipc_callid_t callid; |
46 | ipc_callid_t callid; |
47 | int res; |
47 | int res; |
48 | ipcarg_t phonead; |
48 | ipcarg_t phonead; |
49 | int phoneid; |
49 | int phoneid; |
50 | char connected = 0; |
50 | char connected = 0; |
51 | 51 | keybuffer_t keybuffer; |
|
52 | ipcarg_t retval, arg1, arg2; |
52 | ipcarg_t retval, arg1, arg2; |
53 | 53 | ||
54 | printf("Uspace kbd service started.\n"); |
54 | // printf("Uspace kbd service started.\n"); |
55 | 55 | ||
56 | /* Initialize arch dependent parts */ |
56 | /* Initialize arch dependent parts */ |
57 | if (!(res = kbd_arch_init())) { |
57 | if (!(res = kbd_arch_init())) { |
58 | printf("Kbd registration failed with retval %d.\n", res); |
58 | // printf("Kbd registration failed with retval %d.\n", res); |
59 | return -1; |
59 | return -1; |
60 | }; |
60 | }; |
61 | 61 | ||
62 | /* Initialize key buffer */ |
62 | /* Initialize key buffer */ |
63 | key_buffer_init(); |
63 | keybuffer_init(&keybuffer); |
64 | 64 | ||
65 | /* Register service at nameserver */ |
65 | /* Register service at nameserver */ |
66 | printf("%s: Registering at naming service.\n", NAME); |
66 | // printf("%s: Registering at naming service.\n", NAME); |
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 | printf("%s: Error: Registering at naming service failed.\n", NAME); |
69 | // printf("%s: Error: Registering at naming service failed.\n", NAME); |
70 | return -1; |
70 | return -1; |
71 | }; |
71 | }; |
72 | 72 | ||
73 | while (1) { |
73 | while (1) { |
74 | callid = ipc_wait_for_call(&call); |
74 | callid = ipc_wait_for_call(&call); |
75 | // printf("%s:Call phone=%lX..", NAME, call.in_phone_hash); |
75 | // printf("%s:Call phone=%lX..", NAME, call.in_phone_hash); |
76 | switch (IPC_GET_METHOD(call)) { |
76 | switch (IPC_GET_METHOD(call)) { |
77 | case IPC_M_PHONE_HUNGUP: |
77 | case IPC_M_PHONE_HUNGUP: |
78 | printf("%s: Phone hung up.\n", NAME); |
78 | // printf("%s: Phone hung up.\n", NAME); |
79 | connected = 0; |
79 | connected = 0; |
80 | retval = 0; |
80 | retval = 0; |
81 | break; |
81 | break; |
82 | case IPC_M_CONNECT_ME_TO: |
82 | case IPC_M_CONNECT_ME_TO: |
83 | // printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
83 | // printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
Line 95... | Line 95... | ||
95 | break; |
95 | break; |
96 | 96 | ||
97 | case IPC_M_INTERRUPT: |
97 | case IPC_M_INTERRUPT: |
98 | if (connected) { |
98 | if (connected) { |
99 | /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
99 | /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
100 | kbd_arch_process(IPC_GET_ARG2(call)); |
100 | kbd_arch_process(&keybuffer, IPC_GET_ARG2(call)); |
101 | 101 | ||
102 | //printf("%s: GOT INTERRUPT: %c\n", NAME, key); |
102 | //printf("%s: GOT INTERRUPT: %c\n", NAME, key); |
103 | 103 | ||
104 | /* Some callers could awaiting keypress - if its true, we have to send keys to them. |
104 | /* Some callers could awaiting keypress - if its true, we have to send keys to them. |
105 | * One interrupt can store more than one key into buffer. */ |
105 | * One interrupt can store more than one key into buffer. */ |
106 | 106 | ||
107 | retval = 0; |
107 | retval = 0; |
108 | 108 | ||
109 | while (!key_buffer_empty()) { |
109 | while (!keybuffer_empty(&keybuffer)) { |
110 | if (!key_buffer_pop((char *)&arg1)) { |
110 | if (!keybuffer_pop(&keybuffer, (char *)&arg1)) { |
111 | printf("%s: KeyBuffer is empty but it should not be.\n"); |
111 | // printf("%s: KeyBuffer is empty but it should not be.\n"); |
112 | break; |
112 | break; |
113 | } |
113 | } |
114 | /*FIXME: detection of closed connection */ |
114 | /*FIXME: detection of closed connection */ |
115 | ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, NULL); |
115 | ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL); |
116 | } |
116 | } |
117 | 117 | ||
118 | } |
118 | } |
119 | printf("%s: Interrupt processed.\n", NAME); |
119 | // printf("%s: Interrupt processed.\n", NAME); |
120 | break; |
120 | break; |
121 | default: |
121 | default: |
122 | printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
122 | // printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
123 | retval = ENOENT; |
123 | retval = ENOENT; |
124 | break; |
124 | break; |
125 | } |
125 | } |
126 | 126 | ||
127 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
127 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |