Changeset 15d0046 in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2014-09-12T13:22:33Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b20126
Parents:
8db09e4 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r8db09e4 r15d0046  
    4141#include <str_error.h>
    4242#include <loc.h>
    43 #include <event.h>
    4443#include <io/con_srv.h>
    4544#include <io/kbd_event.h>
     
    8483/** Input server proxy */
    8584static input_t *input;
     85static bool active = false;
    8686
    8787/** Session to the output server */
     
    9898static FIBRIL_MUTEX_INITIALIZE(switch_mtx);
    9999
    100 static console_t *prev_console = &consoles[0];
    101100static console_t *active_console = &consoles[0];
    102 static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
    103 
     101
     102static int input_ev_active(input_t *);
     103static int input_ev_deactive(input_t *);
    104104static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
    105105static int input_ev_move(input_t *, int, int);
     
    108108
    109109static input_ev_ops_t input_ev_ops = {
     110        .active = input_ev_active,
     111        .deactive = input_ev_deactive,
    110112        .key = input_ev_key,
    111113        .move = input_ev_move,
     
    159161        fibril_mutex_lock(&cons->mtx);
    160162       
    161         if ((cons == active_console) && (active_console != kernel_console)) {
     163        if ((active) && (cons == active_console)) {
    162164                output_update(output_sess, cons->fbid);
    163165                output_cursor_update(output_sess, cons->fbid);
     
    173175        fibril_mutex_lock(&cons->mtx);
    174176       
    175         if ((cons == active_console) && (active_console != kernel_console))
     177        if ((active) && (cons == active_console))
    176178                output_cursor_update(output_sess, cons->fbid);
    177179       
     
    185187        fibril_mutex_lock(&cons->mtx);
    186188       
    187         if ((cons == active_console) && (active_console != kernel_console)) {
     189        if ((active) && (cons == active_console)) {
    188190                output_damage(output_sess, cons->fbid, 0, 0, cons->cols,
    189191                    cons->rows);
     
    195197}
    196198
    197 static void cons_switch(console_t *cons)
    198 {
     199static void cons_switch(unsigned int index)
     200{
     201        /*
     202         * The first undefined index is reserved
     203         * for switching to the kernel console.
     204         */
     205        if (index == CONSOLE_COUNT) {
     206                if (console_kcon())
     207                        active = false;
     208               
     209                return;
     210        }
     211       
     212        if (index > CONSOLE_COUNT)
     213                return;
     214       
     215        console_t *cons = &consoles[index];
     216       
    199217        fibril_mutex_lock(&switch_mtx);
    200218       
     
    204222        }
    205223       
    206         if (cons == kernel_console) {
    207                 output_yield(output_sess);
    208                 if (!console_kcon()) {
    209                         output_claim(output_sess);
    210                         fibril_mutex_unlock(&switch_mtx);
    211                         return;
    212                 }
    213         }
    214        
    215         if (active_console == kernel_console)
    216                 output_claim(output_sess);
    217        
    218         prev_console = active_console;
    219224        active_console = cons;
    220225       
     
    224229}
    225230
    226 static console_t *cons_get_active_uspace(void)
    227 {
    228         fibril_mutex_lock(&switch_mtx);
    229        
    230         console_t *active_uspace = active_console;
    231         if (active_uspace == kernel_console)
    232                 active_uspace = prev_console;
    233        
    234         assert(active_uspace != kernel_console);
    235        
    236         fibril_mutex_unlock(&switch_mtx);
    237        
    238         return active_uspace;
     231static int input_ev_active(input_t *input)
     232{
     233        active = true;
     234        output_claim(output_sess);
     235        cons_damage(active_console);
     236       
     237        return EOK;
     238}
     239
     240static int input_ev_deactive(input_t *input)
     241{
     242        active = false;
     243        output_yield(output_sess);
     244       
     245        return EOK;
    239246}
    240247
     
    242249    keymod_t mods, wchar_t c)
    243250{
    244         if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
     251        if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) &&
    245252            ((mods & KM_CTRL) == 0)) {
    246                 cons_switch(&consoles[key - KC_F1]);
     253                cons_switch(key - KC_F1);
    247254        } else {
    248255                /* Got key press/release event */
     
    259266                event->c = c;
    260267               
    261                 /*
    262                  * Kernel console does not read events
    263                  * from us, so we will redirect them
    264                  * to the (last) active userspace console
    265                  * if necessary.
    266                  */
    267                 console_t *target_console = cons_get_active_uspace();
    268                
    269                 prodcons_produce(&target_console->input_pc,
     268                prodcons_produce(&active_console->input_pc,
    270269                    &event->link);
    271270        }
     
    377376                }
    378377        }
    379 
     378       
    380379        return size;
    381380}
     
    388387        while (off < size)
    389388                cons_write_char(cons, str_decode(data, &off, size));
     389       
    390390        return size;
    391391}
     
    498498        event->type = CEV_KEY;
    499499        event->ev.key = *kevent;
     500       
    500501        free(kevent);
    501502        return EOK;
     
    507508       
    508509        for (size_t i = 0; i < CONSOLE_COUNT; i++) {
    509                 if (i == KERNEL_CONSOLE)
    510                         continue;
    511                
    512510                if (consoles[i].dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
    513511                        cons = &consoles[i];
     
    526524        con_conn(iid, icall, &cons->srvs);
    527525}
    528 
    529526
    530527static int input_connect(const char *svc)
     
    555552       
    556553        return EOK;
    557 }
    558 
    559 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    560 {
    561         cons_switch(prev_console);
    562554}
    563555
     
    583575static bool console_srv_init(char *input_svc, char *output_svc)
    584576{
    585         int rc;
    586        
    587577        /* Connect to input service */
    588         rc = input_connect(input_svc);
     578        int rc = input_connect(input_svc);
    589579        if (rc != EOK)
    590580                return false;
     
    610600        output_get_caps(output_sess, &ccaps);
    611601       
    612         /* Inititalize consoles */
    613         for (size_t i = 0; i < CONSOLE_COUNT; i++) {
    614                 consoles[i].index = i;
    615                 atomic_set(&consoles[i].refcnt, 0);
    616                 fibril_mutex_initialize(&consoles[i].mtx);
    617                 prodcons_initialize(&consoles[i].input_pc);
    618                 consoles[i].char_remains_len = 0;
    619                
    620                 if (i == KERNEL_CONSOLE)
    621                         continue;
    622                
    623                 consoles[i].cols = cols;
    624                 consoles[i].rows = rows;
    625                 consoles[i].ccaps = ccaps;
    626                 consoles[i].frontbuf =
    627                     chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
    628                
    629                 if (consoles[i].frontbuf == NULL) {
    630                         printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
    631                         return false;
     602        /*
     603         * Inititalize consoles only if there are
     604         * actually some output devices.
     605         */
     606        if (ccaps != 0) {
     607                for (size_t i = 0; i < CONSOLE_COUNT; i++) {
     608                        consoles[i].index = i;
     609                        atomic_set(&consoles[i].refcnt, 0);
     610                        fibril_mutex_initialize(&consoles[i].mtx);
     611                        prodcons_initialize(&consoles[i].input_pc);
     612                        consoles[i].char_remains_len = 0;
     613                       
     614                        consoles[i].cols = cols;
     615                        consoles[i].rows = rows;
     616                        consoles[i].ccaps = ccaps;
     617                        consoles[i].frontbuf =
     618                            chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
     619                       
     620                        if (consoles[i].frontbuf == NULL) {
     621                                printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
     622                                return false;
     623                        }
     624                       
     625                        consoles[i].fbid = output_frontbuf_create(output_sess,
     626                            consoles[i].frontbuf);
     627                        if (consoles[i].fbid == 0) {
     628                                printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
     629                                return false;
     630                        }
     631                       
     632                        con_srvs_init(&consoles[i].srvs);
     633                        consoles[i].srvs.ops = &con_ops;
     634                        consoles[i].srvs.sarg = &consoles[i];
     635                       
     636                        char vc[LOC_NAME_MAXLEN + 1];
     637                        snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
     638                       
     639                        if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
     640                                printf("%s: Unable to register device %s\n", NAME, vc);
     641                                return false;
     642                        }
    632643                }
    633644               
    634                 consoles[i].fbid = output_frontbuf_create(output_sess,
    635                     consoles[i].frontbuf);
    636                 if (consoles[i].fbid == 0) {
    637                         printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
    638                         return false;
    639                 }
    640                
    641                 con_srvs_init(&consoles[i].srvs);
    642                 consoles[i].srvs.ops = &con_ops;
    643                 consoles[i].srvs.sarg = &consoles[i];
    644                
    645                 char vc[LOC_NAME_MAXLEN + 1];
    646                 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
    647                
    648                 if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
    649                         printf("%s: Unable to register device %s\n", NAME, vc);
    650                         return false;
    651                 }
    652         }
    653        
    654         cons_damage(active_console);
    655        
    656         /* Receive kernel notifications */
    657         async_set_interrupt_received(interrupt_received);
    658         rc = event_subscribe(EVENT_KCONSOLE, 0);
    659         if (rc != EOK)
    660                 printf("%s: Failed to register kconsole notifications (%s)\n",
    661                     NAME, str_error(rc));
     645                input_activate(input);
     646        }
    662647       
    663648        return true;
Note: See TracChangeset for help on using the changeset viewer.