Subversion Repositories HelenOS

Rev

Rev 1447 | Rev 1453 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1445 cejka 1
/*
2
 * Copyright (C) 2006 Josef Cejka
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
 
30
#include <kbd.h>
1451 cejka 31
#include <fb.h>
1445 cejka 32
#include <ipc/ipc.h>
1451 cejka 33
#include <ipc/fb.h>
1445 cejka 34
#include <ipc/services.h>
35
#include <errno.h>
1451 cejka 36
#include <key_buffer.h>
37
#include <console.h>
1445 cejka 38
 
1451 cejka 39
//#define CONSOLE_COUNT VFB_CONNECTIONS
40
#define CONSOLE_COUNT 6
41
 
1445 cejka 42
#define NAME "CONSOLE"
43
 
1451 cejka 44
typedef struct {
45
    keybuffer_t keybuffer;
46
    int client_phone;
47
    int vfb_number; /* Not used */
48
    int vfb_phone;
49
    int used;
50
} connection_t;
51
 
52
connection_t connections[CONSOLE_COUNT];
53
 
54
static int find_free_connection()
55
{
56
    int i = 0;
57
 
58
    while (i < CONSOLE_COUNT) {
59
        if (connections[i].used == 0)
60
            return i;
61
        ++i;
62
    }
63
    return CONSOLE_COUNT;
64
}
65
 
66
 
67
static int find_connection(int client_phone)
68
{
69
    int i = 0;
70
 
71
    while (i < CONSOLE_COUNT) {
72
        if (connections[i].client_phone == client_phone)
73
            return i;
74
        ++i;
75
    }
76
    return  CONSOLE_COUNT;
77
}
78
 
1445 cejka 79
int main(int argc, char *argv[])
80
{
81
    ipcarg_t phonead;
82
    ipc_call_t call;
83
    ipc_callid_t callid;
1451 cejka 84
    int kbd_phone, fb_phone;
1445 cejka 85
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
1451 cejka 86
    int i;
87
    int active_client = 0;
1445 cejka 88
 
89
    /* Connect to keyboard driver */
90
 
1451 cejka 91
    while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
1445 cejka 92
    };
93
 
1451 cejka 94
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) {
1445 cejka 95
        return -1;
96
    };
97
 
98
    /* Connect to framebuffer driver */
99
 
1451 cejka 100
    for (i = 0; i < CONSOLE_COUNT; i++) {
101
        connections[i].used = 0;
102
        keybuffer_init(&(connections[i].keybuffer));
103
        /* TODO: init key_buffer */
104
        while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
105
 
106
ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL);
107
        }
108
    }
1445 cejka 109
 
1451 cejka 110
 
1445 cejka 111
 
112
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
113
        return -1;
114
    };
115
 
116
    while (1) {
117
        callid = ipc_wait_for_call(&call);
118
        switch (IPC_GET_METHOD(call)) {
119
            case IPC_M_PHONE_HUNGUP:
1451 cejka 120
                /*FIXME: if its fb or kbd then panic! */
121
                /* free connection */
122
                if (i = find_connection(IPC_GET_ARG3(call)) < CONSOLE_COUNT) {
123
                    connections[i].used = 0;
124
                     /*TODO: free connection[i].key_buffer; */
125
                    /* FIXME: active_connection hungup */
126
                    retval = 0;
127
                } else {
128
                    /*FIXME: No such connection */
129
                }
1445 cejka 130
                break;
131
            case IPC_M_CONNECT_ME_TO:
1451 cejka 132
 
133
                /* find first free connection */
134
 
135
                if ((i = find_free_connection()) == CONSOLE_COUNT) {
136
                    retval = ELIMIT;
137
                    break;
138
                }
139
 
140
                connections[i].used = 1;
141
                connections[i].client_phone = IPC_GET_ARG3(call);
142
 
1445 cejka 143
                retval = 0;
144
                break;
145
            case KBD_PUSHCHAR:
1451 cejka 146
                /* got key from keyboard driver */
147
                /* find active console */
148
                /* if client is awaiting key, send it */
149
                /*FIXME: else store key to its buffer */
1445 cejka 150
                retval = 0;
1451 cejka 151
                i = IPC_GET_ARG1(call) & 0xff;
152
                /* switch to another virtual console */
153
                if ((i >= KBD_KEY_F1) && (i < KBD_KEY_F1 + CONSOLE_COUNT)) {
154
                    active_client = i - KBD_KEY_F1;
155
                    break;
156
                }
1447 cejka 157
 
1451 cejka 158
                keybuffer_push(&(connections[active_client].keybuffer), i);
159
 
1445 cejka 160
                break;
1451 cejka 161
            case CONSOLE_PUTCHAR:
162
                /* find sender client */
163
                /* ???
164
                 * if its active client, send it to vfb
165
                 **/
166
                /*FIXME: check, if its from active client, .... */
167
 
168
                if ((i = find_connection(IPC_GET_ARG3(call))) == CONSOLE_COUNT) {
169
                    break;
170
                };
171
 
172
                /* TODO: send message to fb */
173
                ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL);
174
 
175
                break;
176
            case CONSOLE_GETCHAR:
177
                /* FIXME: */
178
                if (!keybuffer_pop(&(connections[active_client].keybuffer), (char *)&arg1)) {
179
                    /* FIXME: buffer empty -> store request */
180
                    arg1 = 'X'; /* Only temporary */
181
                };
182
//ipc_call_async_2(connections[active_client].vfb_phone, FB_PUTCHAR, ' ', arg1, NULL, (void *)NULL); 
183
                break;
1445 cejka 184
            default:
185
                retval = ENOENT;
186
                break;
187
        }
188
 
189
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
190
            ipc_answer_fast(callid, retval, arg1, arg2);
191
        }
192
    }
193
 
194
    return 0;  
195
}