Changeset 79460ae in mainline for console/console.c
- Timestamp:
- 2006-05-30T10:40:17Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44c6d88d
- Parents:
- f25b73d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
console/console.c
rf25b73d6 r79460ae 29 29 30 30 #include <kbd.h> 31 #include <fb.h> 31 32 #include <ipc/ipc.h> 33 #include <ipc/fb.h> 32 34 #include <ipc/services.h> 33 #include <stdio.h>34 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 42 #define NAME "CONSOLE" 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 } 37 78 38 79 int main(int argc, char *argv[]) … … 41 82 ipc_call_t call; 42 83 ipc_callid_t callid; 43 int phone_kbd, phone_fb;84 int kbd_phone, fb_phone; 44 85 ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; 45 46 printf("Uspace console service started.\n"); 47 86 int i; 87 int active_client = 0; 48 88 49 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) { 55 printf("%s: Error: Registering at naming service failed.\n", NAME); 94 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) { 56 95 return -1; 57 96 }; … … 59 98 /* Connect to framebuffer driver */ 60 99 61 while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 62 }; 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 } 63 109 110 64 111 65 /* Register service at nameserver */66 printf("%s: Registering at naming service.\n", NAME);67 68 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 113 return -1; 71 114 }; … … 75 118 switch (IPC_GET_METHOD(call)) { 76 119 case IPC_M_PHONE_HUNGUP: 77 printf("%s: Phone hung up.\n", NAME); 78 retval = 0; 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 } 79 130 break; 80 131 case IPC_M_CONNECT_ME_TO: 81 printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call)); 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 82 143 retval = 0; 83 144 break; 84 145 case KBD_PUSHCHAR: 85 printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call)); 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 */ 86 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); 87 159 88 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; 89 184 default: 90 printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));91 185 retval = ENOENT; 92 186 break;
Note:
See TracChangeset
for help on using the changeset viewer.