53,8 → 53,9 |
|
ipcarg_t retval, arg1, arg2; |
|
/* Counter of unsatisfied calls */ |
fifo_count_t callers_counter = 0; |
|
/* Fifo with callid's of unsatisfied calls requred for answer */ |
FIFO_INITIALIZE_STATIC(callers_buffer, ipc_callid_t, KBD_REQUEST_MAX); |
|
printf("Uspace kbd service started.\n"); |
82,14 → 83,18 |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
if (connected) { |
/* If nobody's connected, clear keybuffer and dont store new keys */ |
if (--connected == 0) { |
callers_counter = 0; |
callers_buffer.head = callers_buffer.tail = 0; |
key_buffer_free(); |
} |
|
printf("%s: Phone hung up.\n", NAME); |
} else { |
printf("%s: Oops, got phone hung up, but nobody connected.\n", NAME); |
} |
|
printf("%s: Phone hung up.\n", NAME); |
retval = 0; |
break; |
case IPC_M_CONNECT_TO_ME: |
98,6 → 103,7 |
break; |
case IPC_M_CONNECT_ME_TO: |
// printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
/* Only one connected client allowed */ |
if (connected) { |
retval = ELIMIT; |
} else { |
107,14 → 113,24 |
break; |
case IPC_M_INTERRUPT: |
if (connected) { |
/* recode scancode and store it into key buffer */ |
kbd_arch_process(IPC_GET_ARG2(call)); |
} |
//printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call)); |
if (!callers_counter) |
|
/* Some callers could awaiting keypress - if its true, we have to send keys to them. |
* One interrupt can store more than one key into buffer. */ |
retval = 0; |
arg2 = 0xbeef; |
while ((callers_counter) && (!key_buffer_empty())) { |
callers_counter--; |
if (!key_buffer_pop((char *)&arg1)) { |
printf("%s: KeyBuffer empty but it should not be.\n"); |
break; |
/* Small trick - interrupt does not need answer so we can change callid to caller awaiting key */ |
callers_counter--; |
callid = fifo_pop(callers_buffer); |
} |
ipc_answer_fast(fifo_pop(callers_buffer), retval, arg1, arg2); |
} |
} |
break; |
case KBD_GETCHAR: |
// printf("%s: Getchar: ", NAME); |
retval = 0; |
137,9 → 153,10 |
retval = ENOENT; |
break; |
} |
|
if (! (callid & IPC_CALLID_NOTIFICATION)) { |
// printf("%s: Answering\n", NAME); |
ipc_answer_fast(callid, retval, arg1, arg2); |
} |
} |
} |
|