Ignore:
File:
1 edited

Legend:

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

    r5a6cc679 ra35b458  
    5151#include <fibril_synch.h>
    5252#include <stdlib.h>
     53#include <str.h>
    5354#include "console.h"
    5455
     
    6162        atomic_t refcnt;      /**< Connection reference count */
    6263        prodcons_t input_pc;  /**< Incoming keyboard events */
    63        
     64
    6465        /**
    6566         * Not yet sent bytes of last char event.
     
    6768        char char_remains[UTF8_CHAR_BUFFER_SIZE];
    6869        size_t char_remains_len;  /**< Number of not yet sent bytes. */
    69        
     70
    7071        fibril_mutex_t mtx;  /**< Lock protecting mutable fields */
    71        
     72
    7273        size_t index;           /**< Console index */
    7374        service_id_t dsid;      /**< Service handle */
    74        
     75
    7576        sysarg_t cols;         /**< Number of columns */
    7677        sysarg_t rows;         /**< Number of rows */
    7778        console_caps_t ccaps;  /**< Console capabilities */
    78        
     79
    7980        chargrid_t *frontbuf;    /**< Front buffer */
    8081        frontbuf_handle_t fbid;  /**< Front buffer handle */
     
    161162        fibril_mutex_lock(&switch_mtx);
    162163        fibril_mutex_lock(&cons->mtx);
    163        
     164
    164165        if ((active) && (cons == active_console)) {
    165166                output_update(output_sess, cons->fbid);
    166167                output_cursor_update(output_sess, cons->fbid);
    167168        }
    168        
     169
    169170        fibril_mutex_unlock(&cons->mtx);
    170171        fibril_mutex_unlock(&switch_mtx);
     
    175176        fibril_mutex_lock(&switch_mtx);
    176177        fibril_mutex_lock(&cons->mtx);
    177        
     178
    178179        if ((active) && (cons == active_console))
    179180                output_cursor_update(output_sess, cons->fbid);
    180        
     181
    181182        fibril_mutex_unlock(&cons->mtx);
    182183        fibril_mutex_unlock(&switch_mtx);
     
    187188        fibril_mutex_lock(&switch_mtx);
    188189        fibril_mutex_lock(&cons->mtx);
    189        
     190
    190191        if ((active) && (cons == active_console)) {
    191192                output_damage(output_sess, cons->fbid, 0, 0, cons->cols,
     
    193194                output_cursor_update(output_sess, cons->fbid);
    194195        }
    195        
     196
    196197        fibril_mutex_unlock(&cons->mtx);
    197198        fibril_mutex_unlock(&switch_mtx);
     
    207208                if (console_kcon())
    208209                        active = false;
    209                
     210
    210211                return;
    211212        }
    212        
     213
    213214        if (index > CONSOLE_COUNT)
    214215                return;
    215        
     216
    216217        console_t *cons = &consoles[index];
    217        
     218
    218219        fibril_mutex_lock(&switch_mtx);
    219        
     220
    220221        if (cons == active_console) {
    221222                fibril_mutex_unlock(&switch_mtx);
    222223                return;
    223224        }
    224        
     225
    225226        active_console = cons;
    226        
     227
    227228        fibril_mutex_unlock(&switch_mtx);
    228        
     229
    229230        cons_damage(cons);
    230231}
     
    235236        output_claim(output_sess);
    236237        cons_damage(active_console);
    237        
     238
    238239        return EOK;
    239240}
     
    243244        active = false;
    244245        output_yield(output_sess);
    245        
     246
    246247        return EOK;
    247248}
     
    260261                        return ENOMEM;
    261262                }
    262                
     263
    263264                link_initialize(&event->link);
    264265                event->type = type;
     
    266267                event->mods = mods;
    267268                event->c = c;
    268                
     269
    269270                prodcons_produce(&active_console->input_pc,
    270271                    &event->link);
    271272        }
    272        
     273
    273274        return EOK;
    274275}
     
    294295{
    295296        sysarg_t updated = 0;
    296        
    297         fibril_mutex_lock(&cons->mtx);
    298        
     297
     298        fibril_mutex_lock(&cons->mtx);
     299
    299300        switch (ch) {
    300301        case '\n':
     
    312313                updated = chargrid_putchar(cons->frontbuf, ch, true);
    313314        }
    314        
    315         fibril_mutex_unlock(&cons->mtx);
    316        
     315
     316        fibril_mutex_unlock(&cons->mtx);
     317
    317318        if (updated > 1)
    318319                cons_update(cons);
     
    324325        chargrid_set_cursor_visibility(cons->frontbuf, visible);
    325326        fibril_mutex_unlock(&cons->mtx);
    326        
     327
    327328        cons_update_cursor(cons);
    328329}
     
    343344        console_t *cons = srv_to_console(srv);
    344345        size_t pos = 0;
    345        
     346
    346347        /*
    347348         * Read input from keyboard and copy it to the buffer.
     
    354355                        bbuf[pos] = cons->char_remains[0];
    355356                        pos++;
    356                        
     357
    357358                        /* Unshift the array. */
    358359                        for (size_t i = 1; i < cons->char_remains_len; i++)
    359360                                cons->char_remains[i - 1] = cons->char_remains[i];
    360                        
     361
    361362                        cons->char_remains_len--;
    362363                }
    363                
     364
    364365                /* Still not enough? Then get another key from the queue. */
    365366                if (pos < size) {
    366367                        link_t *link = prodcons_consume(&cons->input_pc);
    367368                        kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
    368                        
     369
    369370                        /* Accept key presses of printable chars only. */
    370371                        if ((event->type == KEY_PRESS) && (event->c != 0)) {
     
    373374                                cons->char_remains_len = str_size(cons->char_remains);
    374375                        }
    375                        
     376
    376377                        free(event);
    377378                }
    378379        }
    379        
     380
    380381        *nread = size;
    381382        return EOK;
     
    389390        while (off < size)
    390391                cons_write_char(cons, str_decode(data, &off, size));
    391        
     392
    392393        *nwritten = size;
    393394        return EOK;
     
    397398{
    398399        console_t *cons = srv_to_console(srv);
    399        
     400
    400401        cons_update(cons);
    401402}
     
    404405{
    405406        console_t *cons = srv_to_console(srv);
    406        
     407
    407408        fibril_mutex_lock(&cons->mtx);
    408409        chargrid_clear(cons->frontbuf);
    409410        fibril_mutex_unlock(&cons->mtx);
    410        
     411
    411412        cons_update(cons);
    412413}
     
    415416{
    416417        console_t *cons = srv_to_console(srv);
    417        
     418
    418419        fibril_mutex_lock(&cons->mtx);
    419420        chargrid_set_cursor(cons->frontbuf, col, row);
    420421        fibril_mutex_unlock(&cons->mtx);
    421        
     422
    422423        cons_update_cursor(cons);
    423424}
     
    426427{
    427428        console_t *cons = srv_to_console(srv);
    428        
     429
    429430        fibril_mutex_lock(&cons->mtx);
    430431        chargrid_get_cursor(cons->frontbuf, col, row);
    431432        fibril_mutex_unlock(&cons->mtx);
    432        
     433
    433434        return EOK;
    434435}
     
    437438{
    438439        console_t *cons = srv_to_console(srv);
    439        
     440
    440441        fibril_mutex_lock(&cons->mtx);
    441442        *cols = cons->cols;
    442443        *rows = cons->rows;
    443444        fibril_mutex_unlock(&cons->mtx);
    444        
     445
    445446        return EOK;
    446447}
     
    449450{
    450451        console_t *cons = srv_to_console(srv);
    451        
     452
    452453        fibril_mutex_lock(&cons->mtx);
    453454        *ccaps = cons->ccaps;
    454455        fibril_mutex_unlock(&cons->mtx);
    455        
     456
    456457        return EOK;
    457458}
     
    460461{
    461462        console_t *cons = srv_to_console(srv);
    462        
     463
    463464        fibril_mutex_lock(&cons->mtx);
    464465        chargrid_set_style(cons->frontbuf, style);
     
    470471{
    471472        console_t *cons = srv_to_console(srv);
    472        
     473
    473474        fibril_mutex_lock(&cons->mtx);
    474475        chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr);
     
    480481{
    481482        console_t *cons = srv_to_console(srv);
    482        
     483
    483484        fibril_mutex_lock(&cons->mtx);
    484485        chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);
     
    489490{
    490491        console_t *cons = srv_to_console(srv);
    491        
     492
    492493        cons_set_cursor_vis(cons, visible);
    493494}
     
    498499        link_t *link = prodcons_consume(&cons->input_pc);
    499500        kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link);
    500        
     501
    501502        event->type = CEV_KEY;
    502503        event->ev.key = *kevent;
    503        
     504
    504505        free(kevent);
    505506        return EOK;
     
    509510{
    510511        console_t *cons = NULL;
    511        
     512
    512513        for (size_t i = 0; i < CONSOLE_COUNT; i++) {
    513514                if (consoles[i].dsid == (service_id_t) IPC_GET_ARG2(*icall)) {
     
    516517                }
    517518        }
    518        
     519
    519520        if (cons == NULL) {
    520521                async_answer_0(iid, ENOENT);
    521522                return;
    522523        }
    523        
     524
    524525        if (atomic_postinc(&cons->refcnt) == 0)
    525526                cons_set_cursor_vis(cons, true);
    526        
     527
    527528        con_conn(iid, icall, &cons->srvs);
    528529}
     
    532533        async_sess_t *sess;
    533534        service_id_t dsid;
    534        
     535
    535536        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    536537        if (rc != EOK) {
     
    545546                return EIO;
    546547        }
    547        
     548
    548549        rc = input_open(sess, &input_ev_ops, NULL, &input);
    549550        if (rc != EOK) {
     
    553554                return rc;
    554555        }
    555        
     556
    556557        return EOK;
    557558}
     
    561562        async_sess_t *sess;
    562563        service_id_t dsid;
    563        
     564
    564565        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    565566        if (rc == EOK) {
     
    572573        } else
    573574                return NULL;
    574        
     575
    575576        return sess;
    576577}
     
    582583        if (rc != EOK)
    583584                return false;
    584        
     585
    585586        /* Connect to output service */
    586587        output_sess = output_connect(output_svc);
    587588        if (output_sess == NULL)
    588589                return false;
    589        
     590
    590591        /* Register server */
    591592        async_set_fallback_port_handler(client_connection, NULL);
     
    596597                return false;
    597598        }
    598        
     599
    599600        output_get_dimensions(output_sess, &cols, &rows);
    600601        output_set_style(output_sess, STYLE_NORMAL);
    601        
     602
    602603        console_caps_t ccaps;
    603604        output_get_caps(output_sess, &ccaps);
    604        
     605
    605606        /*
    606607         * Inititalize consoles only if there are
     
    614615                        prodcons_initialize(&consoles[i].input_pc);
    615616                        consoles[i].char_remains_len = 0;
    616                        
     617
    617618                        consoles[i].cols = cols;
    618619                        consoles[i].rows = rows;
     
    620621                        consoles[i].frontbuf =
    621622                            chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
    622                        
     623
    623624                        if (consoles[i].frontbuf == NULL) {
    624625                                printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
    625626                                return false;
    626627                        }
    627                        
     628
    628629                        consoles[i].fbid = output_frontbuf_create(output_sess,
    629630                            consoles[i].frontbuf);
     
    632633                                return false;
    633634                        }
    634                        
     635
    635636                        con_srvs_init(&consoles[i].srvs);
    636637                        consoles[i].srvs.ops = &con_ops;
    637638                        consoles[i].srvs.sarg = &consoles[i];
    638                        
     639
    639640                        char vc[LOC_NAME_MAXLEN + 1];
    640641                        snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
    641                        
     642
    642643                        if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
    643644                                printf("%s: Unable to register device %s\n", NAME, vc);
     
    645646                        }
    646647                }
    647                
     648
    648649                input_activate(input);
    649650        }
    650        
     651
    651652        return true;
    652653}
     
    663664                return -1;
    664665        }
    665        
     666
    666667        printf("%s: HelenOS Console service\n", NAME);
    667        
     668
    668669        if (!console_srv_init(argv[1], argv[2]))
    669670                return -1;
    670        
     671
    671672        printf("%s: Accepting connections\n", NAME);
    672673        task_retval(0);
    673674        async_manager();
    674        
     675
    675676        /* Never reached */
    676677        return 0;
Note: See TracChangeset for help on using the changeset viewer.