Ignore:
File:
1 edited

Legend:

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

    ra35b458 r5a6cc679  
    5454#include <stdio.h>
    5555#include <stdlib.h>
    56 #include <str.h>
    5756#include <str_error.h>
    5857
     
    7877        /** Link into the list of clients */
    7978        link_t link;
    80 
     79       
    8180        /** Indicate whether the client is active */
    8281        bool active;
    83 
     82       
    8483        /** Client callback session */
    8584        async_sess_t *sess;
     
    112111        if (client == NULL)
    113112                return NULL;
    114 
     113       
    115114        link_initialize(&client->link);
    116115        client->active = false;
    117116        client->sess = NULL;
    118 
     117       
    119118        list_append(&client->link, &clients);
    120 
     119       
    121120        return client;
    122121}
     
    125124{
    126125        client_t *client = (client_t *) data;
    127 
     126       
    128127        list_remove(&client->link);
    129128        free(client);
     
    144143        kbd_event_t ev;
    145144        unsigned int mod_mask;
    146 
     145       
    147146        switch (key) {
    148147        case KC_LCTRL:
     
    167166                mod_mask = 0;
    168167        }
    169 
     168       
    170169        if (mod_mask != 0) {
    171170                if (type == KEY_PRESS)
     
    174173                        kdev->mods = kdev->mods & ~mod_mask;
    175174        }
    176 
     175       
    177176        switch (key) {
    178177        case KC_CAPS_LOCK:
     
    188187                mod_mask = 0;
    189188        }
    190 
     189       
    191190        if (mod_mask != 0) {
    192191                if (type == KEY_PRESS) {
     
    198197                        kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys);
    199198                        kdev->lock_keys = kdev->lock_keys | mod_mask;
    200 
     199                       
    201200                        /* Update keyboard lock indicator lights. */
    202201                        (*kdev->ctl_ops->set_ind)(kdev, kdev->mods);
     
    205204                }
    206205        }
    207 
     206       
    208207        // TODO: More elegant layout switching
    209 
     208       
    210209        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    211210            (key == KC_F1)) {
     
    214213                return;
    215214        }
    216 
     215       
    217216        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    218217            (key == KC_F2)) {
     
    221220                return;
    222221        }
    223 
     222       
    224223        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    225224            (key == KC_F3)) {
     
    228227                return;
    229228        }
    230 
     229       
    231230        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) &&
    232231            (key == KC_F4)) {
     
    235234                return;
    236235        }
    237 
     236       
    238237        ev.type = type;
    239238        ev.key = key;
    240239        ev.mods = kdev->mods;
    241 
     240       
    242241        ev.c = layout_parse_ev(kdev->active_layout, &ev);
    243 
     242       
    244243        list_foreach(clients, link, client_t, client) {
    245244                if (client->active) {
     
    257256                if (client->active) {
    258257                        async_exch_t *exch = async_exchange_begin(client->sess);
    259 
     258                       
    260259                        if ((dx) || (dy))
    261260                                async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
    262 
     261                       
    263262                        if (dz) {
    264263                                // TODO: Implement proper wheel support
    265264                                keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
    266 
     265                               
    267266                                for (unsigned int i = 0; i < 3; i++)
    268267                                        async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
    269 
     268                               
    270269                                async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
    271270                        }
    272 
     271                       
    273272                        async_exchange_end(exch);
    274273                }
     
    309308        list_foreach(clients, link, client_t, client)
    310309                client->active = ((active) && (client == active_client));
    311 
     310       
    312311        /* Notify clients about the arbitration */
    313312        list_foreach(clients, link, client_t, client) {
     
    327326                return;
    328327        }
    329 
     328       
    330329        async_answer_0(iid, EOK);
    331 
     330       
    332331        while (true) {
    333332                ipc_call_t call;
    334333                ipc_callid_t callid = async_get_call(&call);
    335 
     334               
    336335                if (!IPC_GET_IMETHOD(call)) {
    337336                        if (client->sess != NULL) {
     
    339338                                client->sess = NULL;
    340339                        }
    341 
     340                       
    342341                        async_answer_0(callid, EOK);
    343342                        return;
    344343                }
    345 
     344               
    346345                async_sess_t *sess =
    347346                    async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
     
    375374                active = true;
    376375        }
    377 
     376       
    378377        client_arbitration();
    379378}
     
    387386                return NULL;
    388387        }
    389 
     388       
    390389        link_initialize(&kdev->link);
    391 
     390       
    392391        kdev->mods = KM_NUM_LOCK;
    393392        kdev->lock_keys = 0;
    394393        kdev->active_layout = layout_create(layout[0]);
    395 
     394       
    396395        return kdev;
    397396}
     
    405404                return NULL;
    406405        }
    407 
     406       
    408407        link_initialize(&mdev->link);
    409 
     408       
    410409        return mdev;
    411410}
     
    419418                return NULL;
    420419        }
    421 
     420       
    422421        sdev->kdev = kbd_dev_new();
    423422        if (sdev->kdev == NULL) {
     
    427426
    428427        link_initialize(&sdev->link);
    429 
     428       
    430429        return sdev;
    431430}
     
    437436        if (kdev == NULL)
    438437                return;
    439 
     438       
    440439        kdev->port_ops = port;
    441440        kdev->ctl_ops = ctl;
    442441        kdev->svc_id = 0;
    443 
     442       
    444443        /* Initialize port driver. */
    445444        if ((*kdev->port_ops->init)(kdev) != 0)
    446445                goto fail;
    447 
     446       
    448447        /* Initialize controller driver. */
    449448        if ((*kdev->ctl_ops->init)(kdev) != 0) {
     
    451450                goto fail;
    452451        }
    453 
     452       
    454453        list_append(&kdev->link, &kbd_devs);
    455454        return;
    456 
     455       
    457456fail:
    458457        free(kdev);
     
    469468        if (kdev == NULL)
    470469                return -1;
    471 
     470       
    472471        kdev->svc_id = service_id;
    473472        kdev->port_ops = NULL;
    474473        kdev->ctl_ops = &kbdev_ctl;
    475 
     474       
    476475        errno_t rc = loc_service_get_name(service_id, &kdev->svc_name);
    477476        if (rc != EOK) {
     
    479478                goto fail;
    480479        }
    481 
     480       
    482481        /* Initialize controller driver. */
    483482        if ((*kdev->ctl_ops->init)(kdev) != 0) {
    484483                goto fail;
    485484        }
    486 
     485       
    487486        list_append(&kdev->link, &kbd_devs);
    488487        *kdevp = kdev;
    489488        return 0;
    490 
     489       
    491490fail:
    492491        if (kdev->svc_name != NULL)
     
    506505        if (mdev == NULL)
    507506                return -1;
    508 
     507       
    509508        mdev->svc_id = service_id;
    510509        mdev->port_ops = NULL;
    511510        mdev->proto_ops = &mousedev_proto;
    512 
     511       
    513512        errno_t rc = loc_service_get_name(service_id, &mdev->svc_name);
    514513        if (rc != EOK) {
     
    516515                goto fail;
    517516        }
    518 
     517       
    519518        /* Initialize controller driver. */
    520519        if ((*mdev->proto_ops->init)(mdev) != 0) {
    521520                goto fail;
    522521        }
    523 
     522       
    524523        list_append(&mdev->link, &mouse_devs);
    525524        *mdevp = mdev;
    526525        return 0;
    527 
     526       
    528527fail:
    529528        free(mdev);
     
    560559        if (sdev == NULL)
    561560                return -1;
    562 
     561       
    563562        sdev->kdev->svc_id = service_id;
    564 
     563       
    565564        rc = loc_service_get_name(service_id, &sdev->kdev->svc_name);
    566565        if (rc != EOK)
     
    598597                fibril_add_ready(fid);
    599598        }
    600 
     599       
    601600        *sdevp = sdev;
    602601        return 0;
    603 
     602       
    604603fail:
    605604        if (sdev->kdev->svc_name != NULL)
     
    641640        bool already_known;
    642641        errno_t rc;
    643 
     642       
    644643        rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
    645644        if (rc != EOK) {
     
    647646                return ENOENT;
    648647        }
    649 
     648       
    650649        /*
    651650         * Check for new keyboard devices
     
    660659        for (i = 0; i < count; i++) {
    661660                already_known = false;
    662 
     661               
    663662                /* Determine whether we already know this device. */
    664663                list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
     
    668667                        }
    669668                }
    670 
     669               
    671670                if (!already_known) {
    672671                        kbd_dev_t *kdev;
     
    677676                }
    678677        }
    679 
     678       
    680679        free(svcs);
    681 
     680       
    682681        /* XXX Handle device removal */
    683 
     682       
    684683        return EOK;
    685684}
     
    692691        bool already_known;
    693692        errno_t rc;
    694 
     693       
    695694        rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
    696695        if (rc != EOK) {
     
    698697                return ENOENT;
    699698        }
    700 
     699       
    701700        /*
    702701         * Check for new mouse devices
     
    708707                return EIO;
    709708        }
    710 
     709       
    711710        for (i = 0; i < count; i++) {
    712711                already_known = false;
    713 
     712               
    714713                /* Determine whether we already know this device. */
    715714                list_foreach(mouse_devs, link, mouse_dev_t, mdev) {
     
    719718                        }
    720719                }
    721 
     720               
    722721                if (!already_known) {
    723722                        mouse_dev_t *mdev;
     
    728727                }
    729728        }
    730 
     729       
    731730        free(svcs);
    732 
     731       
    733732        /* XXX Handle device removal */
    734 
     733       
    735734        return EOK;
    736735}
     
    743742        bool already_known;
    744743        errno_t rc;
    745 
     744       
    746745        rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING);
    747746        if (rc != EOK) {
     
    749748                return ENOENT;
    750749        }
    751 
     750       
    752751        /*
    753752         * Check for new serial devices
     
    762761        for (i = 0; i < count; i++) {
    763762                already_known = false;
    764 
     763               
    765764                /* Determine whether we already know this device. */
    766765                list_foreach(serial_devs, link, serial_dev_t, sdev) {
     
    770769                        }
    771770                }
    772 
     771               
    773772                if (!already_known) {
    774773                        serial_dev_t *sdev;
     
    779778                }
    780779        }
    781 
     780       
    782781        free(svcs);
    783 
     782       
    784783        /* XXX Handle device removal */
    785 
     784       
    786785        return EOK;
    787786}
     
    790789{
    791790        errno_t rc;
    792 
     791       
    793792        fibril_mutex_lock(&discovery_lock);
    794 
     793       
    795794        if (!serial_console) {
    796795                rc = dev_check_new_kbdevs();
     
    799798                        return rc;
    800799                }
    801 
     800       
    802801                rc = dev_check_new_mousedevs();
    803802                if (rc != EOK) {
     
    812811                }
    813812        }
    814 
     813       
    815814        fibril_mutex_unlock(&discovery_lock);
    816 
     815       
    817816        return EOK;
    818817}
     
    832831                return rc;
    833832        }
    834 
     833       
    835834        return dev_check_new();
    836835}
     
    849848                return 1;
    850849        }
    851 
     850       
    852851        printf("%s: HelenOS input service\n", NAME);
    853 
     852       
    854853        list_initialize(&clients);
    855854        list_initialize(&kbd_devs);
    856855        list_initialize(&mouse_devs);
    857856        list_initialize(&serial_devs);
    858 
     857       
    859858        serial_console = config_get_value("console");
    860 
     859       
    861860        /* Add legacy keyboard devices. */
    862861        kbd_add_legacy_devs();
    863 
     862       
    864863        /* Register driver */
    865864        async_set_client_data_constructor(client_data_create);
    866865        async_set_client_data_destructor(client_data_destroy);
    867866        async_set_fallback_port_handler(client_connection, NULL);
    868 
     867       
    869868        rc = loc_server_register(NAME);
    870869        if (rc != EOK) {
     
    872871                return rc;
    873872        }
    874 
     873       
    875874        service_id_t service_id;
    876875        rc = loc_service_register(argv[1], &service_id);
     
    879878                return rc;
    880879        }
    881 
     880       
    882881        /* Receive kernel notifications */
    883882        rc = async_event_subscribe(EVENT_KCONSOLE, kconsole_event_handler, NULL);
     
    885884                printf("%s: Failed to register kconsole notifications (%s)\n",
    886885                    NAME, str_error(rc));
    887 
     886       
    888887        /* Start looking for new input devices */
    889888        input_start_dev_discovery();
    890 
     889       
    891890        printf("%s: Accepting connections\n", NAME);
    892891        task_retval(0);
    893892        async_manager();
    894 
     893       
    895894        /* Not reached. */
    896895        return 0;
Note: See TracChangeset for help on using the changeset viewer.