Subversion Repositories HelenOS-historic

Rev

Rev 1451 | Rev 1459 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1451 Rev 1453
Line 33... Line 33...
33
#include <ipc/fb.h>
33
#include <ipc/fb.h>
34
#include <ipc/services.h>
34
#include <ipc/services.h>
35
#include <errno.h>
35
#include <errno.h>
36
#include <key_buffer.h>
36
#include <key_buffer.h>
37
#include <console.h>
37
#include <console.h>
-
 
38
#include <unistd.h>
-
 
39
#include <async.h>
38
 
40
 
39
//#define CONSOLE_COUNT VFB_CONNECTIONS
41
//#define CONSOLE_COUNT VFB_CONNECTIONS
40
#define CONSOLE_COUNT 6
42
#define CONSOLE_COUNT 6
41
 
43
 
42
#define NAME "CONSOLE"
44
#define NAME "CONSOLE"
43
 
45
 
-
 
46
int active_client = 0;
-
 
47
 
-
 
48
 
44
typedef struct {
49
typedef struct {
45
    keybuffer_t keybuffer;
50
    keybuffer_t keybuffer;
46
    int client_phone;
51
    int client_phone;
47
    int vfb_number; /* Not used */
52
    int vfb_number; /* Not used */
48
    int vfb_phone;
53
    int vfb_phone;
Line 74... Line 79...
74
        ++i;
79
        ++i;
75
    }
80
    }
76
    return  CONSOLE_COUNT;
81
    return  CONSOLE_COUNT;
77
}
82
}
78
 
83
 
79
int main(int argc, char *argv[])
84
/* Handler for keyboard */
-
 
85
static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
80
{
86
{
81
    ipcarg_t phonead;
87
    ipc_callid_t callid;
82
    ipc_call_t call;
88
    ipc_call_t call;
-
 
89
    int retval;
-
 
90
    int i;
-
 
91
 
-
 
92
    /* Ignore parameters, the connection is alread opened */
-
 
93
    while (1) {
-
 
94
        callid = async_get_call(&call);
-
 
95
        switch (IPC_GET_METHOD(call)) {
-
 
96
        case IPC_M_PHONE_HUNGUP:
-
 
97
            ipc_answer_fast(callid,0,0,0);
-
 
98
            /* TODO: Handle hangup */
-
 
99
            return;
-
 
100
        case KBD_PUSHCHAR:
-
 
101
            /* got key from keyboard driver */
-
 
102
            /* find active console */
-
 
103
            /* if client is awaiting key, send it */
-
 
104
            /*FIXME: else store key to its buffer */
-
 
105
            retval = 0;
-
 
106
            i = IPC_GET_ARG1(call) & 0xff;
-
 
107
            /* switch to another virtual console */
-
 
108
            if ((i >= KBD_KEY_F1) && (i < KBD_KEY_F1 + CONSOLE_COUNT)) {
-
 
109
                active_client = i - KBD_KEY_F1;
-
 
110
                break;
-
 
111
            }
-
 
112
            keybuffer_push(&(connections[active_client].keybuffer), i);
-
 
113
            /* Send it to first FB, DEBUG */
-
 
114
            ipc_call_async_2(connections[0].vfb_phone, FB_PUTCHAR, 0, IPC_GET_ARG1(call),NULL,NULL);
-
 
115
            ipc_answer_fast(callid, 0, 0, 0);
-
 
116
            break;
-
 
117
        default:
-
 
118
            ipc_answer_fast(callid,ENOENT,0,0);
-
 
119
        }      
-
 
120
    }
-
 
121
}
-
 
122
 
-
 
123
/** Default thread for new connections */
-
 
124
void client_connection(ipc_callid_t iid, ipc_call_t *icall)
-
 
125
{
83
    ipc_callid_t callid;
126
    ipc_callid_t callid;
-
 
127
    ipc_call_t call;
-
 
128
    int consnum;
-
 
129
    ipcarg_t arg1;
-
 
130
 
-
 
131
    if ((consnum = find_free_connection()) == CONSOLE_COUNT) {
-
 
132
        ipc_answer_fast(iid,ELIMIT,0,0);
-
 
133
        return;
-
 
134
    }
-
 
135
    connections[consnum].used = 1;
-
 
136
    connections[consnum].client_phone = IPC_GET_ARG3(call);
-
 
137
 
-
 
138
    /* Accept the connection */
-
 
139
    ipc_answer_fast(iid,0,0,0);
-
 
140
   
-
 
141
    while (1) {
-
 
142
        callid = async_get_call(&call);
-
 
143
        switch (IPC_GET_METHOD(call)) {
-
 
144
        case IPC_M_PHONE_HUNGUP:
-
 
145
            /* TODO */
-
 
146
            ipc_answer_fast(callid, 0,0,0);
-
 
147
            return;
-
 
148
        case CONSOLE_PUTCHAR:
-
 
149
            /* TODO: send message to fb */
-
 
150
            ipc_call_async_2(connections[consnum].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL);
-
 
151
            break;
-
 
152
        case CONSOLE_GETCHAR:
-
 
153
            /* FIXME: */
-
 
154
            if (!keybuffer_pop(&(connections[active_client].keybuffer), (char *)&arg1)) {
-
 
155
                /* FIXME: buffer empty -> store request */
-
 
156
                arg1 = 'X'; /* Only temporary */
-
 
157
            };
-
 
158
//ipc_call_async_2(connections[active_client].vfb_phone, FB_PUTCHAR, ' ', arg1, NULL, (void *)NULL); 
-
 
159
            break;
-
 
160
        }
-
 
161
        ipc_answer_fast(callid, 0,0,0);
-
 
162
    }
-
 
163
}
-
 
164
 
-
 
165
int main(int argc, char *argv[])
-
 
166
{
-
 
167
    ipcarg_t phonehash;
84
    int kbd_phone, fb_phone;
168
    int kbd_phone, fb_phone;
85
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
169
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
86
    int i;
170
    int i;
87
    int active_client = 0;
-
 
88
   
171
   
89
    /* Connect to keyboard driver */
172
    /* Connect to keyboard driver */
90
 
173
 
91
    while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
174
    while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
-
 
175
        usleep(10000);
92
    };
176
    };
93
   
177
   
94
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) {
178
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) {
95
        return -1;
179
        return -1;
96
    };
180
    };
-
 
181
    async_new_connection(phonehash, 0, NULL, keyboard_events);
97
 
182
 
98
    /* Connect to framebuffer driver */
183
    /* Connect to framebuffer driver */
99
   
184
   
100
    for (i = 0; i < CONSOLE_COUNT; i++) {
185
    for (i = 0; i < CONSOLE_COUNT; i++) {
101
        connections[i].used = 0;
186
        connections[i].used = 0;
102
        keybuffer_init(&(connections[i].keybuffer));
187
        keybuffer_init(&(connections[i].keybuffer));
103
        /* TODO: init key_buffer */
188
        /* TODO: init key_buffer */
104
        while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
189
        while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
105
               
190
               
106
ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL);
191
            ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL);
107
        }
192
        }
108
    }
193
    }
109
   
194
   
110
 
-
 
111
   
-
 
112
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
195
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) {
113
        return -1;
196
        return -1;
114
    };
197
    };
115
   
198
   
116
    while (1) {
-
 
117
        callid = ipc_wait_for_call(&call);
-
 
118
        switch (IPC_GET_METHOD(call)) {
-
 
119
            case IPC_M_PHONE_HUNGUP:
-
 
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;
199
    async_manager();
127
                } else {
-
 
128
                    /*FIXME: No such connection */
-
 
129
                }
-
 
130
                break;
-
 
131
            case IPC_M_CONNECT_ME_TO:
-
 
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
               
-
 
143
                retval = 0;
-
 
144
                break;
-
 
145
            case KBD_PUSHCHAR:
-
 
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 */
-
 
150
                retval = 0;
-
 
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
                }
-
 
157
               
-
 
158
                keybuffer_push(&(connections[active_client].keybuffer), i);
-
 
159
               
-
 
160
                break;
-
 
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;
-
 
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
 
200
 
194
    return 0;  
201
    return 0;  
195
}
202
}