Changeset 1601f3c in mainline for uspace/srv/console/console.c


Ignore:
Timestamp:
2009-05-21T15:32:42Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7d158097
Parents:
a095d20
Message:

console cleanup (no functional changes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/console/console.c

    ra095d20 r1601f3c  
    2828
    2929/** @addtogroup console
    30  * @{ 
     30 * @{
    3131 */
    3232/** @file
     
    5656#include "gcons.h"
    5757
    58 #define MAX_KEYREQUESTS_BUFFERED 32
    59 
    60 #define NAME "console"
     58#define NAME  "console"
     59
     60#define MAX_KEYREQUESTS_BUFFERED  32
     61
     62/** Size of cwrite_buf. */
     63#define CWRITE_BUF_SIZE  256
    6164
    6265/** Index of currently used virtual console.
     
    7073/** Information about framebuffer */
    7174struct {
    72         int phone;              /**< Framebuffer phone */
    73         ipcarg_t rows;          /**< Framebuffer rows */
    74         ipcarg_t cols;          /**< Framebuffer columns */
     75        int phone;      /**< Framebuffer phone */
     76        ipcarg_t rows;  /**< Framebuffer rows */
     77        ipcarg_t cols;  /**< Framebuffer columns */
    7578} fb_info;
    7679
    7780typedef struct {
    78         keybuffer_t keybuffer;          /**< Buffer for incoming keys. */
     81        keybuffer_t keybuffer;        /**< Buffer for incoming keys. */
     82       
    7983        /** Buffer for unsatisfied request for keys. */
    8084        FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
    81                 MAX_KEYREQUESTS_BUFFERED);     
    82         int keyrequest_counter;         /**< Number of requests in buffer. */
    83         int client_phone;               /**< Phone to connected client. */
    84         int used;                       /**< 1 if this virtual console is
    85                                          * connected to some client.*/
    86         screenbuffer_t screenbuffer;    /**< Screenbuffer for saving screen
    87                                          * contents and related settings. */
     85            MAX_KEYREQUESTS_BUFFERED);
     86       
     87        int keyrequest_counter;       /**< Number of requests in buffer. */
     88        int client_phone;             /**< Phone to connected client. */
     89        int used;                     /**< 1 if this virtual console is
     90                                           connected to some client. */
     91        screenbuffer_t screenbuffer;  /**< Screenbuffer for saving screen
     92                                           contents and related settings. */
    8893} connection_t;
    8994
    90 static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual
    91                                                  * consoles */
    92 static keyfield_t *interbuffer = NULL;          /**< Pointer to memory shared
    93                                                  * with framebufer used for
    94                                                  * faster virtual console
    95                                                  * switching */
     95/** Array of data for virtual consoles */
     96static connection_t connections[CONSOLE_COUNT];
     97
     98/** Pointer to memory shared with framebufer used for
     99    faster virtual console switching */
     100static keyfield_t *interbuffer = NULL;
    96101
    97102/** Information on row-span yet unsent to FB driver. */
    98103struct {
    99         int row;                /**< Row where the span lies. */
    100         int col;                /**< Leftmost column of the span. */
    101         int n;                  /**< Width of the span. */
     104        int row;  /**< Row where the span lies. */
     105        int col;  /**< Leftmost column of the span. */
     106        int cnt;  /**< Width of the span. */
    102107} fb_pending;
    103 
    104 /** Size of cwrite_buf. */
    105 #define CWRITE_BUF_SIZE 256
    106108
    107109/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
    108110static char cwrite_buf[CWRITE_BUF_SIZE];
    109 
    110 static void fb_putchar(wchar_t c, int row, int col);
    111 
    112111
    113112/** Find unused virtual console.
     
    122121                        return i;
    123122        }
     123       
    124124        return -1;
    125125}
     
    186186                set_style(attrs->a.s.style);
    187187                break;
    188 
    189188        case at_idx:
    190189                set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
    191190                    attrs->a.i.flags);
    192191                break;
    193 
    194192        case at_rgb:
    195193                set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
     
    201199static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
    202200{
    203         int i, j;
    204         int rc;
     201        int i;
     202        int j;
    205203        attrs_t *attrs;
    206204        keyfield_t *field;
    207 
     205       
    208206        if (interbuffer) {
    209207                for (j = 0; j < h; j++) {
    210208                        for (i = 0; i < w; i++) {
    211209                                interbuffer[i + j * w] =
    212                                     *get_field_at(&conn->screenbuffer,
    213                                         x + i, y + j);
     210                                    *get_field_at(&conn->screenbuffer, x + i, y + j);
    214211                        }
    215212                }
    216 
    217                 rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
     213               
     214                async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
    218215                    x, y, w, h);
    219         } else {
    220                 rc = ENOTSUP;
    221         }
    222 
    223         if (rc != 0) {
    224                 /*
    225                 attrs = &conn->screenbuffer.attrs;
    226 
    227                 for (j = 0; j < h; j++) {
    228                         for (i = 0; i < w; i++) {
    229                                 field = get_field_at(&conn->screenbuffer,
    230                                     x + i, y + j);
    231                                 if (!attrs_same(*attrs, field->attrs))
    232                                         set_attrs(&field->attrs);
    233                                 attrs = &field->attrs;
    234 
    235                                 fb_putchar(field->character, y + j, x + i);
    236                         }
    237                 }*/
    238216        }
    239217}
     
    242220static void fb_pending_flush(void)
    243221{
    244         screenbuffer_t *scr;
    245 
    246         scr = &(connections[active_console].screenbuffer);
    247 
    248         if (fb_pending.n > 0) {
     222        screenbuffer_t *scr
     223            = &(connections[active_console].screenbuffer);
     224       
     225        if (fb_pending.cnt > 0) {
    249226                fb_update_area(&connections[active_console], fb_pending.col,
    250                     fb_pending.row, fb_pending.n, 1);
    251                 fb_pending.n = 0;
     227                    fb_pending.row, fb_pending.cnt, 1);
     228                fb_pending.cnt = 0;
    252229        }
    253230}
     
    257234 * This adds the cell to the pending rowspan if possible. Otherwise
    258235 * the old span is flushed first.
     236 *
    259237 */
    260238static void cell_mark_changed(int row, int col)
    261239{
    262         if (fb_pending.n != 0) {
    263                 if (row != fb_pending.row ||
    264                     col != fb_pending.col + fb_pending.n) {
     240        if (fb_pending.cnt != 0) {
     241                if ((row != fb_pending.row)
     242                    || (col != fb_pending.col + fb_pending.cnt)) {
    265243                        fb_pending_flush();
    266244                }
    267245        }
    268 
    269         if (fb_pending.n == 0) {
     246       
     247        if (fb_pending.cnt == 0) {
    270248                fb_pending.row = row;
    271249                fb_pending.col = col;
    272250        }
    273 
    274         ++fb_pending.n;
    275 }
    276 
     251       
     252        fb_pending.cnt++;
     253}
    277254
    278255/** Print a character to the active VC with buffering. */
     
    287264        bool flush_cursor = false;
    288265        screenbuffer_t *scr = &(connections[console].screenbuffer);
    289 
     266       
    290267        switch (ch) {
    291268        case '\n':
     
    299276        case '\t':
    300277                scr->position_x += 8;
    301                 scr->position_x -= scr->position_x % 8; 
     278                scr->position_x -= scr->position_x % 8;
    302279                break;
    303280        case '\b':
     
    309286                screenbuffer_putchar(scr, ' ');
    310287                break;
    311         default:       
     288        default:
    312289                if (console == active_console)
    313290                        cell_mark_changed(scr->position_y, scr->position_x);
    314 
     291               
    315292                screenbuffer_putchar(scr, ch);
    316293                scr->position_x++;
    317294        }
    318 
     295       
    319296        if (scr->position_x >= scr->size_x) {
    320297                flush_cursor = true;
     
    330307                        async_msg_1(fb_info.phone, FB_SCROLL, 1);
    331308        }
    332 
     309       
    333310        scr->position_x = scr->position_x % scr->size_x;
    334 
     311       
    335312        if (console == active_console && flush_cursor)
    336313                curs_goto(scr->position_y, scr->position_x);
     
    341318{
    342319        connection_t *conn;
    343         int i, j, rc;
     320        int i;
     321        int j;
     322        int rc;
    344323        keyfield_t *field;
    345324        attrs_t *attrs;
     
    347326        if (newcons == active_console)
    348327                return;
    349 
     328       
    350329        fb_pending_flush();
    351 
     330       
    352331        if (newcons == KERNEL_CONSOLE) {
    353332                async_serialize_start();
     
    357336                kbd_yield();
    358337                async_serialize_end();
    359 
     338               
    360339               
    361340                if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
     
    409388                                        attrs = &field->attrs;
    410389                                        if ((field->character == ' ') &&
    411                                             (attrs_same(field->attrs,
    412                                             conn->screenbuffer.attrs)))
     390                                            (attrs_same(field->attrs, conn->screenbuffer.attrs)))
    413391                                                continue;
    414 
     392                                       
    415393                                        fb_putchar(field->character, j, i);
    416394                                }
     
    436414       
    437415        /* Ignore parameters, the connection is alread opened */
    438         while (1) {
     416        while (true) {
    439417                callid = async_get_call(&call);
    440418                switch (IPC_GET_METHOD(call)) {
     
    461439                        ev.c = IPC_GET_ARG4(call);
    462440                       
    463                         /* switch to another virtual console */
    464                        
     441                        /* Switch to another virtual console */
    465442                        conn = &connections[active_console];
    466 
     443                       
    467444                        if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
    468445                            CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
     
    474451                        }
    475452                       
    476                         /* if client is awaiting key, send it */
    477                         if (conn->keyrequest_counter > 0) {             
     453                        /* If client is awaiting key, send it */
     454                        if (conn->keyrequest_counter > 0) {
    478455                                conn->keyrequest_counter--;
    479456                                ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
     
    481458                                break;
    482459                        }
    483 
     460                       
    484461                        keybuffer_push(&conn->keybuffer, &ev);
    485462                        retval = 0;
    486 
     463                       
    487464                        break;
    488465                default:
     
    500477        wchar_t ch;
    501478        size_t off;
    502 
     479       
    503480        if (!ipc_data_write_receive(&callid, &size)) {
    504481                ipc_answer_0(callid, EINVAL);
     
    506483                return;
    507484        }
    508 
     485       
    509486        if (size > CWRITE_BUF_SIZE)
    510487                size = CWRITE_BUF_SIZE;
    511 
     488       
    512489        (void) ipc_data_write_finalize(callid, cwrite_buf, size);
    513 
     490       
    514491        async_serialize_start();
    515 
     492       
    516493        off = 0;
    517494        while (off < size) {
     
    519496                write_char(consnum, ch);
    520497        }
    521 
     498       
    522499        async_serialize_end();
    523 
     500       
    524501        gcons_notify_char(consnum);
    525502        ipc_answer_1(rid, EOK, size);
     
    553530        ipc_answer_0(iid, EOK);
    554531       
    555         while (1) {
     532        while (true) {
    556533                async_serialize_end();
    557534                callid = async_get_call(&call);
     
    562539                arg3 = 0;
    563540                arg4 = 0;
    564 
     541               
    565542                switch (IPC_GET_METHOD(call)) {
    566543                case IPC_M_PHONE_HUNGUP:
     
    609586                        if (consnum == active_console) {
    610587                                async_req_0_0(fb_info.phone, FB_FLUSH);
    611 
     588                               
    612589                                scr = &(connections[consnum].screenbuffer);
    613590                                curs_goto(scr->position_y, scr->position_x);
     
    651628                                /* buffer is empty -> store request */
    652629                                if (conn->keyrequest_counter <
    653                                         MAX_KEYREQUESTS_BUFFERED) {     
     630                                        MAX_KEYREQUESTS_BUFFERED) {
    654631                                        fifo_push(conn->keyrequests, callid);
    655632                                        conn->keyrequest_counter++;
     
    744721        }
    745722        connections[KERNEL_CONSOLE].used = 1;
    746 
     723       
    747724        /* Set up shared memory buffer. */
    748725        ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
    749726        interbuffer = as_get_mappable_page(ib_size);
    750 
    751         fb_pending.n = 0;
    752 
     727       
     728        fb_pending.cnt = 0;
     729       
    753730        if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
    754731            AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
    755732                interbuffer = NULL;
    756733        }
    757 
     734       
    758735        if (interbuffer) {
    759736                if (ipc_share_out_start(fb_info.phone, interbuffer,
     
    775752        if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
    776753                printf(NAME ": Error registering kconsole notifications\n");
    777                
     754       
    778755        async_set_interrupt_received(interrupt_received);
    779756       
Note: See TracChangeset for help on using the changeset viewer.