Subversion Repositories HelenOS-historic

Rev

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

Rev 1445 Rev 1447
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
void hello(void *private, int retval, ipc_call_t *data) {
-
 
43
    printf("%s: got answer from console with retval %d.\n", NAME, retval);
-
 
44
}
42
 
45
int main(int argc, char **argv)
43
int main(int argc, char **argv)
46
{
44
{
47
    ipc_call_t call;
45
    ipc_call_t call;
48
    ipc_callid_t callid;
46
    ipc_callid_t callid;
49
    int res;
47
    int res;
50
    ipcarg_t phonead;
48
    ipcarg_t phonead;
51
    int phoneid;
49
    int phoneid;
52
    char connected = 0;
50
    char connected = 0;
53
   
51
   
54
    ipcarg_t retval, arg1, arg2;
52
    ipcarg_t retval, arg1, arg2;
55
 
53
 
56
    printf("Uspace kbd service started.\n");
54
    printf("Uspace kbd service started.\n");
57
 
55
 
58
    /* Initialize arch dependent parts */
56
    /* Initialize arch dependent parts */
59
    if (!(res = kbd_arch_init())) {
57
    if (!(res = kbd_arch_init())) {
60
            printf("Kbd registration failed with retval %d.\n", res);
58
            printf("Kbd registration failed with retval %d.\n", res);
61
            return -1;
59
            return -1;
62
            };
60
            };
63
   
61
   
64
    /* Initialize key buffer */
62
    /* Initialize key buffer */
65
    key_buffer_init();
63
    key_buffer_init();
66
   
64
   
67
    /* Register service at nameserver */
65
    /* Register service at nameserver */
68
    printf("%s: Registering at naming service.\n", NAME);
66
    printf("%s: Registering at naming service.\n", NAME);
69
 
67
 
70
    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) {
71
        printf("%s: Error: Registering at naming service failed.\n", NAME);
69
        printf("%s: Error: Registering at naming service failed.\n", NAME);
72
        return -1;
70
        return -1;
73
    };
71
    };
74
   
72
   
75
    while (1) {
73
    while (1) {
76
        callid = ipc_wait_for_call(&call);
74
        callid = ipc_wait_for_call(&call);
77
    //  printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
75
    //  printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
78
        switch (IPC_GET_METHOD(call)) {
76
        switch (IPC_GET_METHOD(call)) {
79
            case IPC_M_PHONE_HUNGUP:
77
            case IPC_M_PHONE_HUNGUP:
80
                printf("%s: Phone hung up.\n", NAME);
78
                printf("%s: Phone hung up.\n", NAME);
81
                connected = 0;
79
                connected = 0;
82
                retval = 0;
80
                retval = 0;
83
                break;
81
                break;
84
            case IPC_M_CONNECT_ME_TO:
82
            case IPC_M_CONNECT_ME_TO:
85
            //  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));
86
                /* Only one connected client allowed */
84
                /* Only one connected client allowed */
87
                if (connected) {
85
                if (connected) {
88
                    retval = ELIMIT;
86
                    retval = ELIMIT;
89
                } else {
87
                } else {
90
                    retval = 0;
88
                    retval = 0;
91
                    connected = 1;
89
                    connected = 1;
92
                }
90
                }
93
                break;
91
                break;
94
            case IPC_M_CONNECT_TO_ME:
92
            case IPC_M_CONNECT_TO_ME:
95
                phoneid = IPC_GET_ARG3(call);
93
                phoneid = IPC_GET_ARG3(call);
96
                retval = 0;
94
                retval = 0;
97
                break;
95
                break;
98
 
96
 
99
            case IPC_M_INTERRUPT:
97
            case IPC_M_INTERRUPT:
100
                if (connected) {
98
                if (connected) {
101
                    /* 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 */
102
                    kbd_arch_process(IPC_GET_ARG2(call));
100
                    kbd_arch_process(IPC_GET_ARG2(call));
103
 
101
 
104
                    //printf("%s: GOT INTERRUPT: %c\n", NAME, key);
102
                    //printf("%s: GOT INTERRUPT: %c\n", NAME, key);
105
 
103
 
106
                    /* 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.
107
                     * One interrupt can store more than one key into buffer. */
105
                     * One interrupt can store more than one key into buffer. */
108
                   
106
                   
109
                    retval = 0;
107
                    retval = 0;
110
 
108
 
111
                    while (!key_buffer_empty()) {
109
                    while (!key_buffer_empty()) {
112
                        if (!key_buffer_pop((char *)&arg1)) {
110
                        if (!key_buffer_pop((char *)&arg1)) {
113
                            printf("%s: KeyBuffer is empty but it should not be.\n");
111
                            printf("%s: KeyBuffer is empty but it should not be.\n");
114
                            break;
112
                            break;
115
                        }
113
                        }
116
                        /*FIXME: detection of closed connection */
114
                        /*FIXME: detection of closed connection */
117
                        ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, &hello);
115
                        ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, NULL);
118
                    }
116
                    }
119
 
117
 
120
                }
118
                }
121
                printf("%s: Interrupt processed.\n", NAME);
119
                printf("%s: Interrupt processed.\n", NAME);
122
                break;
120
                break;
123
            default:
121
            default:
124
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
122
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
125
                retval = ENOENT;
123
                retval = ENOENT;
126
                break;
124
                break;
127
        }
125
        }
128
 
126
 
129
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
127
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
130
            ipc_answer_fast(callid, retval, arg1, arg2);
128
            ipc_answer_fast(callid, retval, arg1, arg2);
131
        }
129
        }
132
    }
130
    }
133
}
131
}
134
 
132
 
135
 
133