Changeset 26e7d6d in mainline for uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
- Timestamp:
- 2011-09-19T16:31:00Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a347a11
- Parents:
- 3842a955 (diff), 086290d (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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
r3842a955 r26e7d6d 47 47 #include <errno.h> 48 48 #include <async.h> 49 #include <async_obsolete.h>50 49 #include <str_error.h> 51 50 … … 53 52 #include <io/console.h> 54 53 55 // FIXME: remove this header 56 #include <kernel/ipc/ipc_methods.h> 57 58 #define NAME "multimedia-keys" 54 #define NAME "multimedia-keys" 59 55 60 56 /*----------------------------------------------------------------------------*/ … … 69 65 /** Count of stored keys (i.e. number of keys in the report). */ 70 66 //size_t key_count; 71 /** IPC phoneto 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; 73 69 } usb_multimedia_t; 74 70 … … 79 75 * 80 76 * 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 for77 * assumes the caller is the console and thus it stores IPC session to it for 82 78 * later use by the driver to notify about key events. 83 79 * … … 91 87 usb_log_debug(NAME " default_connection_handler()\n"); 92 88 93 sysarg_t method = IPC_GET_IMETHOD(*icall);94 95 89 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 96 90 … … 99 93 return; 100 94 } 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 106 105 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); 117 108 } 118 109 … … 155 146 156 147 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) { 158 149 usb_log_warning( 159 150 "Connection to console not ready, key discarded.\n"); … … 161 152 } 162 153 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); 180 157 } 181 158 … … 185 162 usb_multimedia_t *multim_dev) 186 163 { 187 /* Create the function exposed under /dev/devices. */164 /* Create the exposed function. */ 188 165 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 189 166 NAME); … … 205 182 } 206 183 207 usb_log_debug("%s function created ( jandle: %" PRIun ").\n",184 usb_log_debug("%s function created (handle: %" PRIun ").\n", 208 185 NAME, fun->handle); 209 186 210 rc = ddf_fun_add_to_c lass(fun, "keyboard");187 rc = ddf_fun_add_to_category(fun, "keyboard"); 211 188 if (rc != EOK) { 212 189 usb_log_error( 213 "Could not add DDF function to c lass'keyboard': %s.\n",190 "Could not add DDF function to category 'keyboard': %s.\n", 214 191 str_error(rc)); 215 192 // TODO: Can / should I destroy the DDF function? … … 237 214 } 238 215 239 multim_dev->console_ phone = -1;216 multim_dev->console_sess = NULL; 240 217 241 218 /*! @todo Autorepeat */ … … 247 224 248 225 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 249 if (rc != EOK) { 250 usb_multimedia_free(&multim_dev); 226 if (rc != EOK) 251 227 return rc; 252 }253 228 254 229 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); … … 267 242 if (data != NULL) { 268 243 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); 270 246 } 271 247 }
Note:
See TracChangeset
for help on using the changeset viewer.