Changeset 79460ae in mainline for console/console.c


Ignore:
Timestamp:
2006-05-30T10:40:17Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44c6d88d
Parents:
f25b73d6
Message:

Basic support for console driver.
Does not provide separate screens yet.
TODO fix many unhandled states.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • console/console.c

    rf25b73d6 r79460ae  
    2929
    3030#include <kbd.h>
     31#include <fb.h>
    3132#include <ipc/ipc.h>
     33#include <ipc/fb.h>
    3234#include <ipc/services.h>
    33 #include <stdio.h>
    3435#include <errno.h>
     36#include <key_buffer.h>
     37#include <console.h>
     38
     39//#define CONSOLE_COUNT VFB_CONNECTIONS
     40#define CONSOLE_COUNT 6
    3541
    3642#define NAME "CONSOLE"
     43
     44typedef 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
     52connection_t connections[CONSOLE_COUNT];
     53
     54static 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
     67static 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}
    3778
    3879int main(int argc, char *argv[])
     
    4182        ipc_call_t call;
    4283        ipc_callid_t callid;
    43         int phone_kbd, phone_fb;
     84        int kbd_phone, fb_phone;
    4485        ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
    45        
    46         printf("Uspace console service started.\n");
    47        
     86        int i;
     87        int active_client = 0;
    4888       
    4989        /* Connect to keyboard driver */
    5090
    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) {
    5292        };
    5393       
    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) {
    5695                return -1;
    5796        };
     
    5998        /* Connect to framebuffer driver */
    6099       
    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                               
     106ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL);
     107                }
     108        }
    63109       
     110
    64111       
    65         /* Register service at nameserver */
    66         printf("%s: Registering at naming service.\n", NAME);
    67 
    68112        if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
    69                 printf("%s: Error: Registering at naming service failed.\n", NAME);
    70113                return -1;
    71114        };
     
    75118                switch (IPC_GET_METHOD(call)) {
    76119                        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                                }
    79130                                break;
    80131                        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                               
    82143                                retval = 0;
    83144                                break;
    84145                        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 */
    86150                                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);
    87159                               
    88160                                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;
    89184                        default:
    90                                 printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
    91185                                retval = ENOENT;
    92186                                break;
Note: See TracChangeset for help on using the changeset viewer.