Ignore:
File:
1 edited

Legend:

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

    r5a6cc679 ra35b458  
    5454#include <stdio.h>
    5555#include <stdlib.h>
     56#include <str.h>
    5657#include <str_error.h>
    5758
     
    7778        /** Link into the list of clients */
    7879        link_t link;
    79        
     80
    8081        /** Indicate whether the client is active */
    8182        bool active;
    82        
     83
    8384        /** Client callback session */
    8485        async_sess_t *sess;
     
    111112        if (client == NULL)
    112113                return NULL;
    113        
     114
    114115        link_initialize(&client->link);
    115116        client->active = false;
    116117        client->sess = NULL;
    117        
     118
    118119        list_append(&client->link, &clients);
    119        
     120
    120121        return client;
    121122}
     
    124125{
    125126        client_t *client = (client_t *) data;
    126        
     127
    127128        list_remove(&client->link);
    128129        free(client);
     
    143144        kbd_event_t ev;
    144145        unsigned int mod_mask;
    145        
     146
    146147        switch (key) {
    147148        case KC_LCTRL:
     
    166167                mod_mask = 0;
    167168        }
    168        
     169
    169170        if (mod_mask != 0) {
    170171                if (type == KEY_PRESS)
     
    173174                        kdev->mods = kdev->mods & ~mod_mask;
    174175        }
    175        
     176
    176177        switch (key) {
    177178        case KC_CAPS_LOCK:
     
    187188                mod_mask = 0;
    188189        }
    189        
     190
    190191        if (mod_mask != 0) {
    191192                if (type == KEY_PRESS) {
     
    197198                        kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys);
    198199                        kdev->lock_keys = kdev->lock_keys | mod_mask;
    199                        
     200
    200201                        /* Update keyboard lock indicator lights. */
    201202                        (*kdev->ctl_ops->set_ind)(kdev, kdev->mods);
     
    204205                }
    205206        }
    206        
     207
    207208        // TODO: More elegant layout switching
    208        
     209
    209210        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    210211            (key == KC_F1)) {
     
    213214                return;
    214215        }
    215        
     216
    216217        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    217218            (key == KC_F2)) {
     
    220221                return;
    221222        }
    222        
     223
    223224        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    224225            (key == KC_F3)) {
     
    227228                return;
    228229        }
    229        
     230
    230231        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    231232            (key == KC_F4)) {
     
    234235                return;
    235236        }
    236        
     237
    237238        ev.type = type;
    238239        ev.key = key;
    239240        ev.mods = kdev->mods;
    240        
     241
    241242        ev.c = layout_parse_ev(kdev->active_layout, &ev);
    242        
     243
    243244        list_foreach(clients, link, client_t, client) {
    244245                if (client->active) {
     
    256257                if (client->active) {
    257258                        async_exch_t *exch = async_exchange_begin(client->sess);
    258                        
     259
    259260                        if ((dx) || (dy))
    260261                                async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
    261                        
     262
    262263                        if (dz) {
    263264                                // TODO: Implement proper wheel support
    264265                                keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
    265                                
     266
    266267                                for (unsigned int i = 0; i < 3; i++)
    267268                                        async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
    268                                
     269
    269270                                async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
    270271                        }
    271                        
     272
    272273                        async_exchange_end(exch);
    273274                }
     
    308309        list_foreach(clients, link, client_t, client)
    309310                client->active = ((active) && (client == active_client));
    310        
     311
    311312        /* Notify clients about the arbitration */
    312313        list_foreach(clients, link, client_t, client) {
     
    326327                return;
    327328        }
    328        
     329
    329330        async_answer_0(iid, EOK);
    330        
     331
    331332        while (true) {
    332333                ipc_call_t call;
    333334                ipc_callid_t callid = async_get_call(&call);
    334                
     335
    335336                if (!IPC_GET_IMETHOD(call)) {
    336337                        if (client->sess != NULL) {
     
    338339                                client->sess = NULL;
    339340                        }
    340                        
     341
    341342                        async_answer_0(callid, EOK);
    342343                        return;
    343344                }
    344                
     345
    345346                async_sess_t *sess =
    346347                    async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
     
    374375                active = true;
    375376        }
    376        
     377
    377378        client_arbitration();
    378379}
     
    386387                return NULL;
    387388        }
    388        
     389
    389390        link_initialize(&kdev->link);
    390        
     391
    391392        kdev->mods = KM_NUM_LOCK;
    392393        kdev->lock_keys = 0;
    393394        kdev->active_layout = layout_create(layout[0]);
    394        
     395
    395396        return kdev;
    396397}
     
    404405                return NULL;
    405406        }
    406        
     407
    407408        link_initialize(&mdev->link);
    408        
     409
    409410        return mdev;
    410411}
     
    418419                return NULL;
    419420        }
    420        
     421
    421422        sdev->kdev = kbd_dev_new();
    422423        if (sdev->kdev == NULL) {
     
    426427
    427428        link_initialize(&sdev->link);
    428        
     429
    429430        return sdev;
    430431}
     
    436437        if (kdev == NULL)
    437438                return;
    438        
     439
    439440        kdev->port_ops = port;
    440441        kdev->ctl_ops = ctl;
    441442        kdev->svc_id = 0;
    442        
     443
    443444        /* Initialize port driver. */
    444445        if ((*kdev->port_ops->init)(kdev) != 0)
    445446                goto fail;
    446        
     447
    447448        /* Initialize controller driver. */
    448449        if ((*kdev->ctl_ops->init)(kdev) != 0) {
     
    450451                goto fail;
    451452        }
    452        
     453
    453454        list_append(&kdev->link, &kbd_devs);
    454455        return;
    455        
     456
    456457fail:
    457458        free(kdev);
     
    468469        if (kdev == NULL)
    469470                return -1;
    470        
     471
    471472        kdev->svc_id = service_id;
    472473        kdev->port_ops = NULL;
    473474        kdev->ctl_ops = &kbdev_ctl;
    474        
     475
    475476        errno_t rc = loc_service_get_name(service_id, &kdev->svc_name);
    476477        if (rc != EOK) {
     
    478479                goto fail;
    479480        }
    480        
     481
    481482        /* Initialize controller driver. */
    482483        if ((*kdev->ctl_ops->init)(kdev) != 0) {
    483484                goto fail;
    484485        }
    485        
     486
    486487        list_append(&kdev->link, &kbd_devs);
    487488        *kdevp = kdev;
    488489        return 0;
    489        
     490
    490491fail:
    491492        if (kdev->svc_name != NULL)
     
    505506        if (mdev == NULL)
    506507                return -1;
    507        
     508
    508509        mdev->svc_id = service_id;
    509510        mdev->port_ops = NULL;
    510511        mdev->proto_ops = &mousedev_proto;
    511        
     512
    512513        errno_t rc = loc_service_get_name(service_id, &mdev->svc_name);
    513514        if (rc != EOK) {
     
    515516                goto fail;
    516517        }
    517        
     518
    518519        /* Initialize controller driver. */
    519520        if ((*mdev->proto_ops->init)(mdev) != 0) {
    520521                goto fail;
    521522        }
    522        
     523
    523524        list_append(&mdev->link, &mouse_devs);
    524525        *mdevp = mdev;
    525526        return 0;
    526        
     527
    527528fail:
    528529        free(mdev);
     
    559560        if (sdev == NULL)
    560561                return -1;
    561        
     562
    562563        sdev->kdev->svc_id = service_id;
    563        
     564
    564565        rc = loc_service_get_name(service_id, &sdev->kdev->svc_name);
    565566        if (rc != EOK)
     
    597598                fibril_add_ready(fid);
    598599        }
    599        
     600
    600601        *sdevp = sdev;
    601602        return 0;
    602        
     603
    603604fail:
    604605        if (sdev->kdev->svc_name != NULL)
     
    640641        bool already_known;
    641642        errno_t rc;
    642        
     643
    643644        rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
    644645        if (rc != EOK) {
     
    646647                return ENOENT;
    647648        }
    648        
     649
    649650        /*
    650651         * Check for new keyboard devices
     
    659660        for (i = 0; i < count; i++) {
    660661                already_known = false;
    661                
     662
    662663                /* Determine whether we already know this device. */
    663664                list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
     
    667668                        }
    668669                }
    669                
     670
    670671                if (!already_known) {
    671672                        kbd_dev_t *kdev;
     
    676677                }
    677678        }
    678        
     679
    679680        free(svcs);
    680        
     681
    681682        /* XXX Handle device removal */
    682        
     683
    683684        return EOK;
    684685}
     
    691692        bool already_known;
    692693        errno_t rc;
    693        
     694
    694695        rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
    695696        if (rc != EOK) {
     
    697698                return ENOENT;
    698699        }
    699        
     700
    700701        /*
    701702         * Check for new mouse devices
     
    707708                return EIO;
    708709        }
    709        
     710
    710711        for (i = 0; i < count; i++) {
    711712                already_known = false;
    712                
     713
    713714                /* Determine whether we already know this device. */
    714715                list_foreach(mouse_devs, link, mouse_dev_t, mdev) {
     
    718719                        }
    719720                }
    720                
     721
    721722                if (!already_known) {
    722723                        mouse_dev_t *mdev;
     
    727728                }
    728729        }
    729        
     730
    730731        free(svcs);
    731        
     732
    732733        /* XXX Handle device removal */
    733        
     734
    734735        return EOK;
    735736}
     
    742743        bool already_known;
    743744        errno_t rc;
    744        
     745
    745746        rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING);
    746747        if (rc != EOK) {
     
    748749                return ENOENT;
    749750        }
    750        
     751
    751752        /*
    752753         * Check for new serial devices
     
    761762        for (i = 0; i < count; i++) {
    762763                already_known = false;
    763                
     764
    764765                /* Determine whether we already know this device. */
    765766                list_foreach(serial_devs, link, serial_dev_t, sdev) {
     
    769770                        }
    770771                }
    771                
     772
    772773                if (!already_known) {
    773774                        serial_dev_t *sdev;
     
    778779                }
    779780        }
    780        
     781
    781782        free(svcs);
    782        
     783
    783784        /* XXX Handle device removal */
    784        
     785
    785786        return EOK;
    786787}
     
    789790{
    790791        errno_t rc;
    791        
     792
    792793        fibril_mutex_lock(&discovery_lock);
    793        
     794
    794795        if (!serial_console) {
    795796                rc = dev_check_new_kbdevs();
     
    798799                        return rc;
    799800                }
    800        
     801
    801802                rc = dev_check_new_mousedevs();
    802803                if (rc != EOK) {
     
    811812                }
    812813        }
    813        
     814
    814815        fibril_mutex_unlock(&discovery_lock);
    815        
     816
    816817        return EOK;
    817818}
     
    831832                return rc;
    832833        }
    833        
     834
    834835        return dev_check_new();
    835836}
     
    848849                return 1;
    849850        }
    850        
     851
    851852        printf("%s: HelenOS input service\n", NAME);
    852        
     853
    853854        list_initialize(&clients);
    854855        list_initialize(&kbd_devs);
    855856        list_initialize(&mouse_devs);
    856857        list_initialize(&serial_devs);
    857        
     858
    858859        serial_console = config_get_value("console");
    859        
     860
    860861        /* Add legacy keyboard devices. */
    861862        kbd_add_legacy_devs();
    862        
     863
    863864        /* Register driver */
    864865        async_set_client_data_constructor(client_data_create);
    865866        async_set_client_data_destructor(client_data_destroy);
    866867        async_set_fallback_port_handler(client_connection, NULL);
    867        
     868
    868869        rc = loc_server_register(NAME);
    869870        if (rc != EOK) {
     
    871872                return rc;
    872873        }
    873        
     874
    874875        service_id_t service_id;
    875876        rc = loc_service_register(argv[1], &service_id);
     
    878879                return rc;
    879880        }
    880        
     881
    881882        /* Receive kernel notifications */
    882883        rc = async_event_subscribe(EVENT_KCONSOLE, kconsole_event_handler, NULL);
     
    884885                printf("%s: Failed to register kconsole notifications (%s)\n",
    885886                    NAME, str_error(rc));
    886        
     887
    887888        /* Start looking for new input devices */
    888889        input_start_dev_discovery();
    889        
     890
    890891        printf("%s: Accepting connections\n", NAME);
    891892        task_retval(0);
    892893        async_manager();
    893        
     894
    894895        /* Not reached. */
    895896        return 0;
Note: See TracChangeset for help on using the changeset viewer.