Ignore:
File:
1 edited

Legend:

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

    ra35b458 r5a6cc679  
    5151#include <fibril_synch.h>
    5252#include <stdlib.h>
    53 #include <str.h>
    5453#include "console.h"
    5554
     
    6261        atomic_t refcnt;      /**< Connection reference count */
    6362        prodcons_t input_pc;  /**< Incoming keyboard events */
    64 
     63       
    6564        /**
    6665         * Not yet sent bytes of last char event.
     
    6867        char char_remains[UTF8_CHAR_BUFFER_SIZE];
    6968        size_t char_remains_len;  /**< Number of not yet sent bytes. */
    70 
     69       
    7170        fibril_mutex_t mtx;  /**< Lock protecting mutable fields */
    72 
     71       
    7372        size_t index;           /**< Console index */
    7473        service_id_t dsid;      /**< Service handle */
    75 
     74       
    7675        sysarg_t cols;         /**< Number of columns */
    7776        sysarg_t rows;         /**< Number of rows */
    7877        console_caps_t ccaps;  /**< Console capabilities */
    79 
     78       
    8079        chargrid_t *frontbuf;    /**< Front buffer */
    8180        frontbuf_handle_t fbid;  /**< Front buffer handle */
     
    162161        fibril_mutex_lock(&switch_mtx);
    163162        fibril_mutex_lock(&cons->mtx);
    164 
     163       
    165164        if ((active) && (cons == active_console)) {
    166165                output_update(output_sess, cons->fbid);
    167166                output_cursor_update(output_sess, cons->fbid);
    168167        }
    169 
     168       
    170169        fibril_mutex_unlock(&cons->mtx);
    171170        fibril_mutex_unlock(&switch_mtx);
     
    176175        fibril_mutex_lock(&switch_mtx);
    177176        fibril_mutex_lock(&cons->mtx);
    178 
     177       
    179178        if ((active) && (cons == active_console))
    180179                output_cursor_update(output_sess, cons->fbid);
    181 
     180       
    182181        fibril_mutex_unlock(&cons->mtx);
    183182        fibril_mutex_unlock(&switch_mtx);
     
    188187        fibril_mutex_lock(&switch_mtx);
    189188        fibril_mutex_lock(&cons->mtx);
    190 
     189       
    191190        if ((active) && (cons == active_console)) {
    192191                output_damage(output_sess, cons->fbid, 0, 0, cons->cols,
     
    194193                output_cursor_update(output_sess, cons->fbid);
    195194        }
    196 
     195       
    197196        fibril_mutex_unlock(&cons->mtx);
    198197        fibril_mutex_unlock(&switch_mtx);
     
    208207                if (console_kcon())
    209208                        active = false;
    210 
     209               
    211210                return;
    212211        }
    213 
     212       
    214213        if (index > CONSOLE_COUNT)
    215214                return;
    216 
     215       
    217216        console_t *cons = &consoles[index];
    218 
     217       
    219218        fibril_mutex_lock(&switch_mtx);
    220 
     219       
    221220        if (cons == active_console) {
    222221                fibril_mutex_unlock(&switch_mtx);
    223222                return;
    224223        }
    225 
     224       
    226225        active_console = cons;
    227 
     226       
    228227        fibril_mutex_unlock(&switch_mtx);
    229 
     228       
    230229        cons_damage(cons);
    231230}
     
    236235        output_claim(output_sess);
    237236        cons_damage(active_console);
    238 
     237       
    239238        return EOK;
    240239}
     
    244243        active = false;
    245244        output_yield(output_sess);
    246 
     245       
    247246        return EOK;
    248247}
     
    261260                        return ENOMEM;
    262261                }
    263 
     262               
    264263                link_initialize(&event->link);
    265264                event->type = type;
     
    267266                event->mods = mods;
    268267                event->c = c;
    269 
     268               
    270269                prodcons_produce(&active_console->input_pc,
    271270                    &event->link);
    272271        }
    273 
     272       
    274273        return EOK;
    275274}
     
    295294{
    296295        sysarg_t updated = 0;
    297 
    298         fibril_mutex_lock(&cons->mtx);
    299 
     296       
     297        fibril_mutex_lock(&cons->mtx);
     298       
    300299        switch (ch) {
    301300        case '\n':
     
    313312                updated = chargrid_putchar(cons->frontbuf, ch, true);
    314313        }
    315 
    316         fibril_mutex_unlock(&cons->mtx);
    317 
     314       
     315        fibril_mutex_unlock(&cons->mtx);
     316       
    318317        if (updated > 1)
    319318                cons_update(cons);
     
    325324        chargrid_set_cursor_visibility(cons->frontbuf, visible);
    326325        fibril_mutex_unlock(&cons->mtx);
    327 
     326       
    328327        cons_update_cursor(cons);
    329328}
     
    344343        console_t *cons = srv_to_console(srv);
    345344        size_t pos = 0;
    346 
     345       
    347346        /*
    348347         * Read input from keyboard and copy it to the buffer.
     
    355354                        bbuf[pos] = cons->char_remains[0];
    356355                        pos++;
    357 
     356                       
    358357                        /* Unshift the array. */
    359358                        for (size_t i = 1; i < cons->char_remains_len; i++)
    360359                                cons->char_remains[i - 1] = cons->char_remains[i];
    361 
     360                       
    362361                        cons->char_remains_len--;
    363362                }
    364 
     363               
    365364                /* Still not enough? Then get another key from the queue. */
    366365                if (pos < size) {
    367366                        link_t *link = prodcons_consume(&cons->input_pc);
    368367                        kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
    369 
     368                       
    370369                        /* Accept key presses of printable chars only. */
    371370                        if ((event->type == KEY_PRESS) && (event->c != 0)) {
     
    374373                                cons->char_remains_len = str_size(cons->char_remains);
    375374                        }
    376 
     375                       
    377376                        free(event);
    378377                }
    379378        }
    380 
     379       
    381380        *nread = size;
    382381        return EOK;
     
    390389        while (off < size)
    391390                cons_write_char(cons, str_decode(data, &off, size));
    392 
     391       
    393392        *nwritten = size;
    394393        return EOK;
     
    398397{
    399398        console_t *cons = srv_to_console(srv);
    400 
     399       
    401400        cons_update(cons);
    402401}
     
    405404{
    406405        console_t *cons = srv_to_console(srv);
    407 
     406       
    408407        fibril_mutex_lock(&cons->mtx);
    409408        chargrid_clear(cons->frontbuf);
    410409        fibril_mutex_unlock(&cons->mtx);
    411 
     410       
    412411        cons_update(cons);
    413412}
     
    416415{
    417416        console_t *cons = srv_to_console(srv);
    418 
     417       
    419418        fibril_mutex_lock(&cons->mtx);
    420419        chargrid_set_cursor(cons->frontbuf, col, row);
    421420        fibril_mutex_unlock(&cons->mtx);
    422 
     421       
    423422        cons_update_cursor(cons);
    424423}
     
    427426{
    428427        console_t *cons = srv_to_console(srv);
    429 
     428       
    430429        fibril_mutex_lock(&cons->mtx);
    431430        chargrid_get_cursor(cons->frontbuf, col, row);
    432431        fibril_mutex_unlock(&cons->mtx);
    433 
     432       
    434433        return EOK;
    435434}
     
    438437{
    439438        console_t *cons = srv_to_console(srv);
    440 
     439       
    441440        fibril_mutex_lock(&cons->mtx);
    442441        *cols = cons->cols;
    443442        *rows = cons->rows;
    444443        fibril_mutex_unlock(&cons->mtx);
    445 
     444       
    446445        return EOK;
    447446}
     
    450449{
    451450        console_t *cons = srv_to_console(srv);
    452 
     451       
    453452        fibril_mutex_lock(&cons->mtx);
    454453        *ccaps = cons->ccaps;
    455454        fibril_mutex_unlock(&cons->mtx);
    456 
     455       
    457456        return EOK;
    458457}
     
    461460{
    462461        console_t *cons = srv_to_console(srv);
    463 
     462       
    464463        fibril_mutex_lock(&cons->mtx);
    465464        chargrid_set_style(cons->frontbuf, style);
     
    471470{
    472471        console_t *cons = srv_to_console(srv);
    473 
     472       
    474473        fibril_mutex_lock(&cons->mtx);
    475474        chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr);
     
    481480{
    482481        console_t *cons = srv_to_console(srv);
    483 
     482       
    484483        fibril_mutex_lock(&cons->mtx);
    485484        chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);
     
    490489{
    491490        console_t *cons = srv_to_console(srv);
    492 
     491       
    493492        cons_set_cursor_vis(cons, visible);
    494493}
     
    499498        link_t *link = prodcons_consume(&cons->input_pc);
    500499        kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link);
    501 
     500       
    502501        event->type = CEV_KEY;
    503502        event->ev.key = *kevent;
    504 
     503       
    505504        free(kevent);
    506505        return EOK;
     
    510509{
    511510        console_t *cons = NULL;
    512 
     511       
    513512        for (size_t i = 0; i < CONSOLE_COUNT; i++) {
    514513                if (consoles[i].dsid == (service_id_t) IPC_GET_ARG2(*icall)) {
     
    517516                }
    518517        }
    519 
     518       
    520519        if (cons == NULL) {
    521520                async_answer_0(iid, ENOENT);
    522521                return;
    523522        }
    524 
     523       
    525524        if (atomic_postinc(&cons->refcnt) == 0)
    526525                cons_set_cursor_vis(cons, true);
    527 
     526       
    528527        con_conn(iid, icall, &cons->srvs);
    529528}
     
    533532        async_sess_t *sess;
    534533        service_id_t dsid;
    535 
     534       
    536535        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    537536        if (rc != EOK) {
     
    546545                return EIO;
    547546        }
    548 
     547       
    549548        rc = input_open(sess, &input_ev_ops, NULL, &input);
    550549        if (rc != EOK) {
     
    554553                return rc;
    555554        }
    556 
     555       
    557556        return EOK;
    558557}
     
    562561        async_sess_t *sess;
    563562        service_id_t dsid;
    564 
     563       
    565564        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    566565        if (rc == EOK) {
     
    573572        } else
    574573                return NULL;
    575 
     574       
    576575        return sess;
    577576}
     
    583582        if (rc != EOK)
    584583                return false;
    585 
     584       
    586585        /* Connect to output service */
    587586        output_sess = output_connect(output_svc);
    588587        if (output_sess == NULL)
    589588                return false;
    590 
     589       
    591590        /* Register server */
    592591        async_set_fallback_port_handler(client_connection, NULL);
     
    597596                return false;
    598597        }
    599 
     598       
    600599        output_get_dimensions(output_sess, &cols, &rows);
    601600        output_set_style(output_sess, STYLE_NORMAL);
    602 
     601       
    603602        console_caps_t ccaps;
    604603        output_get_caps(output_sess, &ccaps);
    605 
     604       
    606605        /*
    607606         * Inititalize consoles only if there are
     
    615614                        prodcons_initialize(&consoles[i].input_pc);
    616615                        consoles[i].char_remains_len = 0;
    617 
     616                       
    618617                        consoles[i].cols = cols;
    619618                        consoles[i].rows = rows;
     
    621620                        consoles[i].frontbuf =
    622621                            chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
    623 
     622                       
    624623                        if (consoles[i].frontbuf == NULL) {
    625624                                printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
    626625                                return false;
    627626                        }
    628 
     627                       
    629628                        consoles[i].fbid = output_frontbuf_create(output_sess,
    630629                            consoles[i].frontbuf);
     
    633632                                return false;
    634633                        }
    635 
     634                       
    636635                        con_srvs_init(&consoles[i].srvs);
    637636                        consoles[i].srvs.ops = &con_ops;
    638637                        consoles[i].srvs.sarg = &consoles[i];
    639 
     638                       
    640639                        char vc[LOC_NAME_MAXLEN + 1];
    641640                        snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
    642 
     641                       
    643642                        if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
    644643                                printf("%s: Unable to register device %s\n", NAME, vc);
     
    646645                        }
    647646                }
    648 
     647               
    649648                input_activate(input);
    650649        }
    651 
     650       
    652651        return true;
    653652}
     
    664663                return -1;
    665664        }
    666 
     665       
    667666        printf("%s: HelenOS Console service\n", NAME);
    668 
     667       
    669668        if (!console_srv_init(argv[1], argv[2]))
    670669                return -1;
    671 
     670       
    672671        printf("%s: Accepting connections\n", NAME);
    673672        task_retval(0);
    674673        async_manager();
    675 
     674       
    676675        /* Never reached */
    677676        return 0;
Note: See TracChangeset for help on using the changeset viewer.