Subversion Repositories HelenOS

Rev

Rev 1343 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1343 Rev 1344
Line 51... Line 51...
51
    int c;
51
    int c;
52
    ipcarg_t phonead;
52
    ipcarg_t phonead;
53
   
53
   
54
    ipcarg_t retval, arg1, arg2;
54
    ipcarg_t retval, arg1, arg2;
55
   
55
 
-
 
56
    /* Counter of unsatisfied calls */
56
    fifo_count_t callers_counter = 0;
57
    fifo_count_t callers_counter = 0;
57
   
-
 
-
 
58
    /* Fifo with callid's of unsatisfied calls requred for answer */
58
    FIFO_INITIALIZE_STATIC(callers_buffer, ipc_callid_t, KBD_REQUEST_MAX);
59
    FIFO_INITIALIZE_STATIC(callers_buffer, ipc_callid_t, KBD_REQUEST_MAX);
59
 
60
 
60
    printf("Uspace kbd service started.\n");
61
    printf("Uspace kbd service started.\n");
61
 
62
 
62
    /* Initialize arch dependent parts */
63
    /* Initialize arch dependent parts */
Line 80... Line 81...
80
        callid = ipc_wait_for_call(&call, 0);
81
        callid = ipc_wait_for_call(&call, 0);
81
    //  printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
82
    //  printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
82
        switch (IPC_GET_METHOD(call)) {
83
        switch (IPC_GET_METHOD(call)) {
83
        case IPC_M_PHONE_HUNGUP:
84
            case IPC_M_PHONE_HUNGUP:
84
            if (connected) {
85
                if (connected) {
-
 
86
                    /* If nobody's connected, clear keybuffer and dont store new keys */
85
                if (--connected == 0) {
87
                    if (--connected == 0) {
86
                    callers_counter = 0;
88
                        callers_counter = 0;
87
                    callers_buffer.head = callers_buffer.tail = 0;
89
                        callers_buffer.head = callers_buffer.tail = 0;
88
                    key_buffer_free(); 
90
                        key_buffer_free(); 
89
                }
91
                    }
90
            }
-
 
91
           
92
                   
92
            printf("%s: Phone hung up.\n", NAME);
93
                    printf("%s: Phone hung up.\n", NAME);
-
 
94
                } else {
-
 
95
                    printf("%s: Oops, got phone hung up, but nobody connected.\n", NAME);
-
 
96
                }
-
 
97
               
93
            retval = 0;
98
                retval = 0;
94
            break;
99
                break;
95
        case IPC_M_CONNECT_TO_ME:
100
            case IPC_M_CONNECT_TO_ME:
96
            printf("%s: Somebody connecting phid=%zd.\n", NAME, IPC_GET_ARG3(call));
101
                printf("%s: Somebody connecting phid=%zd.\n", NAME, IPC_GET_ARG3(call));
97
            retval = 0;
102
                retval = 0;
98
            break;
103
                break;
99
        case IPC_M_CONNECT_ME_TO:
104
            case IPC_M_CONNECT_ME_TO:
100
        //  printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
105
            //  printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
-
 
106
                /* Only one connected client allowed */
101
            if (connected) {
107
                if (connected) {
102
                retval = ELIMIT;
108
                    retval = ELIMIT;
103
            } else {
109
                } else {
104
                retval = 0;
110
                    retval = 0;
105
                connected = 1;
111
                    connected = 1;
106
            }
112
                }
107
            break;
113
                break;
108
        case IPC_M_INTERRUPT:
114
            case IPC_M_INTERRUPT:
109
            if (connected) {
115
                if (connected) {
-
 
116
                    /* recode scancode and store it into key buffer */
110
                kbd_arch_process(IPC_GET_ARG2(call));
117
                    kbd_arch_process(IPC_GET_ARG2(call));
111
            }
-
 
112
            //printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call));
118
                    //printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call));
-
 
119
 
-
 
120
                    /* Some callers could awaiting keypress - if its true, we have to send keys to them.
-
 
121
                     * One interrupt can store more than one key into buffer. */
113
            if (!callers_counter)
122
                    retval = 0;
114
                break;
123
                    arg2 = 0xbeef;
115
            /* Small trick - interrupt does not need answer so we can change callid to caller awaiting key */
124
                    while ((callers_counter) && (!key_buffer_empty())) {
116
            callers_counter--;
125
                        callers_counter--;
-
 
126
                        if (!key_buffer_pop((char *)&arg1)) {
-
 
127
                            printf("%s: KeyBuffer empty but it should not be.\n");
-
 
128
                            break;
-
 
129
                        }
117
            callid = fifo_pop(callers_buffer);
130
                        ipc_answer_fast(fifo_pop(callers_buffer), retval, arg1, arg2);
-
 
131
                    }
-
 
132
                }
-
 
133
                break;
118
        case KBD_GETCHAR:
134
            case KBD_GETCHAR:
119
//          printf("%s: Getchar: ", NAME);
135
    //          printf("%s: Getchar: ", NAME);
120
            retval = 0;
136
                retval = 0;
121
            arg1 = 0;  
137
                arg1 = 0;  
122
            if (!key_buffer_pop((char *)&arg1)) {
138
                if (!key_buffer_pop((char *)&arg1)) {
Line 135... Line 151...
135
        default:
151
            default:
136
            printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
152
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
137
            retval = ENOENT;
153
                retval = ENOENT;
138
            break;
154
                break;
139
        }
155
        }
-
 
156
 
140
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
157
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
141
        //  printf("%s: Answering\n", NAME);
-
 
142
            ipc_answer_fast(callid, retval, arg1, arg2);
158
            ipc_answer_fast(callid, retval, arg1, arg2);
143
        }
159
        }
144
    }
160
    }
145
}
161
}
-
 
162