Subversion Repositories HelenOS

Rev

Rev 1451 | Rev 1508 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1451 Rev 1499
1
/*
1
/*
2
 * Copyright (C) 2006 Josef Cejka
2
 * Copyright (C) 2006 Josef Cejka
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include <ipc/ipc.h>
29
#include <ipc/ipc.h>
30
#include <ipc/services.h>
30
#include <ipc/services.h>
31
#include <stdio.h>
31
#include <stdio.h>
32
#include <unistd.h>
32
#include <unistd.h>
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 <libadt/fifo.h>
38
#include <libadt/fifo.h>
39
#include <key_buffer.h>
39
#include <key_buffer.h>
40
 
40
 
41
#define NAME "KBD"
41
#define NAME "KBD"
42
 
42
 
43
int main(int argc, char **argv)
43
int main(int argc, char **argv)
44
{
44
{
45
    ipc_call_t call;
45
    ipc_call_t call;
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
    keybuffer_t keybuffer; 
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");
-
 
55
 
-
 
56
    /* Initialize arch dependent parts */
54
    /* Initialize arch dependent parts */
57
    if (!(res = kbd_arch_init())) {
55
    if (!(res = kbd_arch_init())) {
58
//          printf("Kbd registration failed with retval %d.\n", res);
-
 
59
            return -1;
56
            return -1;
60
            };
57
            };
61
   
58
   
62
    /* Initialize key buffer */
59
    /* Initialize key buffer */
63
    keybuffer_init(&keybuffer);
60
    keybuffer_init(&keybuffer);
64
   
61
   
65
    /* Register service at nameserver */
62
    /* Register service at nameserver */
66
//  printf("%s: Registering at naming service.\n", NAME);
-
 
67
 
63
   
68
    if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
64
    if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
69
//      printf("%s: Error: Registering at naming service failed.\n", NAME);
-
 
70
        return -1;
65
        return -1;
71
    };
66
    };
72
   
67
   
73
    while (1) {
68
    while (1) {
74
        callid = ipc_wait_for_call(&call);
69
        callid = ipc_wait_for_call(&call);
75
    //  printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
-
 
76
        switch (IPC_GET_METHOD(call)) {
70
        switch (IPC_GET_METHOD(call)) {
77
            case IPC_M_PHONE_HUNGUP:
71
            case IPC_M_PHONE_HUNGUP:
78
//              printf("%s: Phone hung up.\n", NAME);
-
 
79
                connected = 0;
72
                connected = 0;
80
                retval = 0;
73
                retval = 0;
81
                break;
74
                break;
82
            case IPC_M_CONNECT_ME_TO:
75
            case IPC_M_CONNECT_ME_TO:
83
            //  printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
-
 
84
                /* Only one connected client allowed */
76
                /* Only one connected client allowed */
85
                if (connected) {
77
                if (connected) {
86
                    retval = ELIMIT;
78
                    retval = ELIMIT;
87
                } else {
79
                } else {
88
                    retval = 0;
80
                    retval = 0;
89
                    connected = 1;
81
                    connected = 1;
90
                }
82
                }
91
                break;
83
                break;
92
            case IPC_M_CONNECT_TO_ME:
84
            case IPC_M_CONNECT_TO_ME:
93
                phoneid = IPC_GET_ARG3(call);
85
                phoneid = IPC_GET_ARG3(call);
94
                retval = 0;
86
                retval = 0;
95
                break;
87
                break;
96
 
88
 
97
            case IPC_M_INTERRUPT:
89
            case IPC_M_INTERRUPT:
98
                if (connected) {
90
                if (connected) {
99
                    /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
91
                    /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
100
                    kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
92
                    kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
101
 
93
 
102
                    //printf("%s: GOT INTERRUPT: %c\n", NAME, key);
-
 
103
 
-
 
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. */
-
 
106
                   
-
 
107
                    retval = 0;
94
                    retval = 0;
108
 
95
 
109
                    while (!keybuffer_empty(&keybuffer)) {
96
                    while (!keybuffer_empty(&keybuffer)) {
110
                        if (!keybuffer_pop(&keybuffer, (char *)&arg1)) {
97
                        if (!keybuffer_pop(&keybuffer, (char *)&arg1)) {
111
//                          printf("%s: KeyBuffer is empty but it should not be.\n");
-
 
112
                            break;
98
                            break;
113
                        }
99
                        }
114
                        /*FIXME: detection of closed connection */
-
 
115
                        ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL);
100
                        ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL);
116
                    }
101
                    }
117
 
102
 
118
                }
103
                }
119
//              printf("%s: Interrupt processed.\n", NAME);
-
 
120
                break;
104
                break;
121
            default:
105
            default:
122
//              printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
-
 
123
                retval = ENOENT;
106
                retval = ENOENT;
124
                break;
107
                break;
125
        }
108
        }
126
 
109
 
127
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
110
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
128
            ipc_answer_fast(callid, retval, arg1, arg2);
111
            ipc_answer_fast(callid, retval, arg1, arg2);
129
        }
112
        }
130
    }
113
    }
131
}
114
}
132
 
115
 
133
 
116