Ignore:
Timestamp:
2011-09-24T14:20:29Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5bf76c1
Parents:
867e2555 (diff), 1ab4aca (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/drv/bus/usb/usbhid/multimedia/multimedia.c

    r867e2555 r925a21e  
    4747#include <errno.h>
    4848#include <async.h>
    49 #include <async_obsolete.h>
    5049#include <str_error.h>
    5150
     
    5352#include <io/console.h>
    5453
    55 // FIXME: remove this header
    56 #include <kernel/ipc/ipc_methods.h>
    57 
    58 #define NAME "multimedia-keys"
     54#define NAME  "multimedia-keys"
    5955
    6056/*----------------------------------------------------------------------------*/
     
    6965        /** Count of stored keys (i.e. number of keys in the report). */
    7066        //size_t key_count;     
    71         /** IPC phone to the console device (for sending key events). */
    72         int console_phone;
     67        /** IPC session to the console device (for sending key events). */
     68        async_sess_t *console_sess;
    7369} usb_multimedia_t;
    7470
     
    7975 *
    8076 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it
    81  * assumes the caller is the console and thus it stores IPC phone to it for
     77 * assumes the caller is the console and thus it stores IPC session to it for
    8278 * later use by the driver to notify about key events.
    8379 *
     
    9187        usb_log_debug(NAME " default_connection_handler()\n");
    9288       
    93         sysarg_t method = IPC_GET_IMETHOD(*icall);
    94        
    9589        usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    9690       
     
    9993                return;
    10094        }
    101 
    102         if (method == IPC_M_CONNECT_TO_ME) {
    103                 int callback = IPC_GET_ARG5(*icall);
    104 
    105                 if (multim_dev->console_phone != -1) {
     95       
     96        async_sess_t *sess =
     97            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     98        if (sess != NULL) {
     99                if (multim_dev->console_sess == NULL) {
     100                        multim_dev->console_sess = sess;
     101                        usb_log_debug(NAME " Saved session to console: %p\n",
     102                            sess);
     103                        async_answer_0(icallid, EOK);
     104                } else
    106105                        async_answer_0(icallid, ELIMIT);
    107                         return;
    108                 }
    109 
    110                 multim_dev->console_phone = callback;
    111                 usb_log_debug(NAME " Saved phone to console: %d\n", callback);
    112                 async_answer_0(icallid, EOK);
    113                 return;
    114         }
    115        
    116         async_answer_0(icallid, EINVAL);
     106        } else
     107                async_answer_0(icallid, EINVAL);
    117108}
    118109
     
    155146
    156147        usb_log_debug2(NAME " Sending key %d to the console\n", ev.key);
    157         if (multim_dev->console_phone < 0) {
     148        if (multim_dev->console_sess == NULL) {
    158149                usb_log_warning(
    159150                    "Connection to console not ready, key discarded.\n");
     
    161152        }
    162153       
    163         async_obsolete_msg_4(multim_dev->console_phone, KBDEV_EVENT, ev.type, ev.key,
    164             ev.mods, ev.c);
    165 }
    166 
    167 /*----------------------------------------------------------------------------*/
    168 
    169 static void usb_multimedia_free(usb_multimedia_t **multim_dev)
    170 {
    171         if (multim_dev == NULL || *multim_dev == NULL) {
    172                 return;
    173         }
    174        
    175         // hangup phone to the console
    176         async_obsolete_hangup((*multim_dev)->console_phone);
    177 
    178         free(*multim_dev);
    179         *multim_dev = NULL;
     154        async_exch_t *exch = async_exchange_begin(multim_dev->console_sess);
     155        async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
     156        async_exchange_end(exch);
    180157}
    181158
     
    185162    usb_multimedia_t *multim_dev)
    186163{
    187         /* Create the function exposed under /dev/devices. */
     164        /* Create the exposed function. */
    188165        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    189166            NAME);
     
    205182        }
    206183       
    207         usb_log_debug("%s function created (jandle: %" PRIun ").\n",
     184        usb_log_debug("%s function created (handle: %" PRIun ").\n",
    208185            NAME, fun->handle);
    209186       
    210         rc = ddf_fun_add_to_class(fun, "keyboard");
     187        rc = ddf_fun_add_to_category(fun, "keyboard");
    211188        if (rc != EOK) {
    212189                usb_log_error(
    213                     "Could not add DDF function to class 'keyboard': %s.\n",
     190                    "Could not add DDF function to category 'keyboard': %s.\n",
    214191                    str_error(rc));
    215192                // TODO: Can / should I destroy the DDF function?
     
    237214        }
    238215       
    239         multim_dev->console_phone = -1;
     216        multim_dev->console_sess = NULL;
    240217       
    241218        /*! @todo Autorepeat */
     
    247224       
    248225        int rc = usb_multimedia_create_function(hid_dev, multim_dev);
    249         if (rc != EOK) {
    250                 usb_multimedia_free(&multim_dev);
     226        if (rc != EOK)
    251227                return rc;
    252         }
    253228       
    254229        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
     
    267242        if (data != NULL) {
    268243                usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    269                 usb_multimedia_free(&multim_dev);
     244                // hangup session to the console
     245                async_hangup(multim_dev->console_sess);
    270246        }
    271247}
Note: See TracChangeset for help on using the changeset viewer.