Changeset eaf34f7 in mainline


Ignore:
Timestamp:
2006-05-30T18:01:51Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1029d3d3
Parents:
44c6d88d
Message:

Modified console to use new async framework.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • console/console.c

    r44c6d88d reaf34f7  
    3636#include <key_buffer.h>
    3737#include <console.h>
     38#include <unistd.h>
     39#include <async.h>
    3840
    3941//#define CONSOLE_COUNT VFB_CONNECTIONS
     
    4143
    4244#define NAME "CONSOLE"
     45
     46int active_client = 0;
     47
    4348
    4449typedef struct {
     
    7782}
    7883
     84/* Handler for keyboard */
     85static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
     86{
     87        ipc_callid_t callid;
     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 */
     124void client_connection(ipc_callid_t iid, ipc_call_t *icall)
     125{
     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
    79165int main(int argc, char *argv[])
    80166{
    81         ipcarg_t phonead;
    82         ipc_call_t call;
    83         ipc_callid_t callid;
     167        ipcarg_t phonehash;
    84168        int kbd_phone, fb_phone;
    85169        ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
    86170        int i;
    87         int active_client = 0;
    88171       
    89172        /* Connect to keyboard driver */
    90173
    91174        while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
     175                usleep(10000);
    92176        };
    93177       
    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) {
    95179                return -1;
    96180        };
     181        async_new_connection(phonehash, 0, NULL, keyboard_events);
    97182
    98183        /* Connect to framebuffer driver */
     
    104189                while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
    105190                               
    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);
    107192                }
    108193        }
    109194       
    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) {
    113196                return -1;
    114197        };
    115198       
    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;
    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         }
     199        async_manager();
    193200
    194201        return 0;       
  • init/init.c

    r44c6d88d reaf34f7  
    435435//      test_kbd();
    436436//      test_time();
    437         test_async_kbd();
     437//      test_async_kbd();
    438438//      test_fb();
    439439
  • libc/generic/async.c

    r44c6d88d reaf34f7  
    270270}
    271271
    272 /** Function that gets created on interrupt receival
     272/** Function that gets called on interrupt receival
    273273 *
    274274 * This function is defined as a weak symbol - to be redefined in
     
    343343        conn->ptid = psthread_create(connection_thread, conn);
    344344        conn->callid = callid;
    345         conn->call = *call;
     345        if (call)
     346                conn->call = *call;
    346347        conn->active = 1; /* We will activate it asap */
    347348        conn->cthread = cthread;
  • libc/generic/time.c

    r44c6d88d reaf34f7  
    9898}
    9999
    100 /** Wait unconditionally for specified miliseconds */
     100/** Wait unconditionally for specified microseconds */
    101101void usleep(unsigned long usec)
    102102{
Note: See TracChangeset for help on using the changeset viewer.