Subversion Repositories HelenOS-historic

Rev

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

Rev 1447 Rev 1451
Line 26... Line 26...
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
 
29
 
30
#include <kbd.h>
30
#include <kbd.h>
-
 
31
#include <fb.h>
31
#include <ipc/ipc.h>
32
#include <ipc/ipc.h>
-
 
33
#include <ipc/fb.h>
32
#include <ipc/services.h>
34
#include <ipc/services.h>
33
#include <stdio.h>
-
 
34
#include <errno.h>
35
#include <errno.h>
-
 
36
#include <key_buffer.h>
-
 
37
#include <console.h>
-
 
38
 
-
 
39
//#define CONSOLE_COUNT VFB_CONNECTIONS
-
 
40
#define CONSOLE_COUNT 6
35
 
41
 
36
#define NAME "CONSOLE"
42
#define NAME "CONSOLE"
37
 
43
 
-
 
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
 
38
int main(int argc, char *argv[])
79
int main(int argc, char *argv[])
39
{
80
{
40
    ipcarg_t phonead;
81
    ipcarg_t phonead;
41
    ipc_call_t call;
82
    ipc_call_t call;
42
    ipc_callid_t callid;
83
    ipc_callid_t callid;
43
    int phone_kbd, phone_fb;
84
    int kbd_phone, fb_phone;
44
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
85
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
45
   
86
    int i;
46
    printf("Uspace console service started.\n");
87
    int active_client = 0;
47
   
-
 
48
   
88
   
49
    /* Connect to keyboard driver */
89
    /* Connect to keyboard driver */
50
 
90
 
51
    while ((phone_kbd = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
91
    while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
52
    };
92
    };
53
   
93
   
54
    if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) {
94
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) {
55
        printf("%s: Error: Registering at naming service failed.\n", NAME);
-
 
56
        return -1;
95
        return -1;
57
    };
96
    };
58
 
97
 
59
    /* Connect to framebuffer driver */
98
    /* Connect to framebuffer driver */
60
   
99
   
-
 
100
    for (i = 0; i < CONSOLE_COUNT; i++) {
-
 
101
        connections[i].used = 0;
-
 
102
        keybuffer_init(&(connections[i].keybuffer));
-
 
103
        /* TODO: init key_buffer */
61
    while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
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);
62
    };
107
        }
63
   
108
    }
64
   
109
   
65
    /* Register service at nameserver */
-
 
66
    printf("%s: Registering at naming service.\n", NAME);
-
 
67
 
110
 
-
 
111
   
68
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
112
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
69
        printf("%s: Error: Registering at naming service failed.\n", NAME);
-
 
70
        return -1;
113
        return -1;
71
    };
114
    };
72
   
115
   
73
    while (1) {
116
    while (1) {
74
        callid = ipc_wait_for_call(&call);
117
        callid = ipc_wait_for_call(&call);
75
        switch (IPC_GET_METHOD(call)) {
118
        switch (IPC_GET_METHOD(call)) {
76
            case IPC_M_PHONE_HUNGUP:
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; */
77
                printf("%s: Phone hung up.\n", NAME);
125
                    /* FIXME: active_connection hungup */
78
                retval = 0;
126
                    retval = 0;
-
 
127
                } else {
-
 
128
                    /*FIXME: No such connection */
-
 
129
                }
79
                break;
130
                break;
80
            case IPC_M_CONNECT_ME_TO:
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;
81
                printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
141
                connections[i].client_phone = IPC_GET_ARG3(call);
-
 
142
               
82
                retval = 0;
143
                retval = 0;
83
                break;
144
                break;
84
            case KBD_PUSHCHAR:
145
            case KBD_PUSHCHAR:
-
 
146
                /* got key from keyboard driver */
-
 
147
                /* find active console */
85
                printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call));
148
                /* if client is awaiting key, send it */
-
 
149
                /*FIXME: else store key to its buffer */
86
                retval = 0;
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);
87
               
174
               
88
                break;
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;
89
            default:
184
            default:
90
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
-
 
91
                retval = ENOENT;
185
                retval = ENOENT;
92
                break;
186
                break;
93
        }
187
        }
94
 
188
 
95
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
189
        if (! (callid & IPC_CALLID_NOTIFICATION)) {