Changeset 26e7d6d in mainline for uspace/drv/bus/usb/usbhid/mouse/mousedev.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/mouse/mousedev.c
r3842a955 r26e7d6d 42 42 #include <errno.h> 43 43 #include <async.h> 44 #include <async_obsolete.h>45 44 #include <str_error.h> 46 #include <ipc/mouse .h>45 #include <ipc/mouseev.h> 47 46 #include <io/console.h> 48 47 … … 56 55 #define ARROWS_PER_SINGLE_WHEEL 3 57 56 58 // FIXME: remove this header 59 #include <kernel/ipc/ipc_methods.h> 60 61 #define NAME "mouse" 57 #define NAME "mouse" 62 58 63 59 /*----------------------------------------------------------------------------*/ … … 74 70 const char *HID_MOUSE_FUN_NAME = "mouse"; 75 71 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel"; 76 const char *HID_MOUSE_C LASS_NAME= "mouse";77 const char *HID_MOUSE_WHEEL_C LASS_NAME= "keyboard";72 const char *HID_MOUSE_CATEGORY = "mouse"; 73 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard"; 78 74 79 75 /** Default idle rate for mouses. */ … … 128 124 ipc_callid_t icallid, ipc_call_t *icall) 129 125 { 130 sysarg_t method = IPC_GET_IMETHOD(*icall); 131 132 usb_mouse_t *mouse_dev = (usb_mouse_t *)fun->driver_data; 126 usb_mouse_t *mouse_dev = (usb_mouse_t *) fun->driver_data; 133 127 134 128 if (mouse_dev == NULL) { … … 141 135 usb_log_debug("default_connection_handler: fun->name: %s\n", 142 136 fun->name); 143 usb_log_debug("default_connection_handler: mouse_phone: %d, wheel " 144 "phone: %d\n", mouse_dev->mouse_phone, mouse_dev->wheel_phone); 145 146 int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) 147 ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone; 148 149 if (method == IPC_M_CONNECT_TO_ME) { 150 int callback = IPC_GET_ARG5(*icall); 151 152 if (*phone != -1) { 137 usb_log_debug("default_connection_handler: mouse_sess: %p, " 138 "wheel_sess: %p\n", mouse_dev->mouse_sess, mouse_dev->wheel_sess); 139 140 async_sess_t **sess_ptr = 141 (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) ? 142 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 143 144 async_sess_t *sess = 145 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 146 if (sess != NULL) { 147 if (*sess_ptr == NULL) { 148 *sess_ptr = sess; 149 usb_log_debug("Console session to mouse set ok (%p).\n", 150 sess); 151 async_answer_0(icallid, EOK); 152 } else { 153 153 usb_log_debug("default_connection_handler: Console " 154 " phoneto mouse already set.\n");154 "session to mouse already set.\n"); 155 155 async_answer_0(icallid, ELIMIT); 156 return;157 156 } 158 159 *phone = callback; 160 usb_log_debug("Console phone to mouse set ok (%d).\n", *phone); 161 async_answer_0(icallid, EOK); 162 return; 163 } 164 165 usb_log_debug("default_connection_handler: Invalid function.\n"); 166 async_answer_0(icallid, EINVAL); 157 } else { 158 usb_log_debug("default_connection_handler: Invalid function.\n"); 159 async_answer_0(icallid, EINVAL); 160 } 167 161 } 168 162 … … 175 169 return NULL; 176 170 } 177 mouse->mouse_ phone = -1;178 mouse->wheel_ phone = -1;171 mouse->mouse_sess = NULL; 172 mouse->wheel_sess = NULL; 179 173 180 174 return mouse; … … 183 177 /*----------------------------------------------------------------------------*/ 184 178 185 static void usb_mouse_free(usb_mouse_t **mouse_dev) 186 { 187 assert(mouse_dev != NULL && *mouse_dev != NULL); 188 189 // hangup phone to the console 190 if ((*mouse_dev)->mouse_phone >= 0) { 191 async_obsolete_hangup((*mouse_dev)->mouse_phone); 192 } 193 194 if ((*mouse_dev)->wheel_phone >= 0) { 195 async_obsolete_hangup((*mouse_dev)->wheel_phone); 196 } 197 198 free(*mouse_dev); 199 *mouse_dev = NULL; 179 static void usb_mouse_destroy(usb_mouse_t *mouse_dev) 180 { 181 assert(mouse_dev != NULL); 182 183 // hangup session to the console 184 if (mouse_dev->mouse_sess != NULL) 185 async_hangup(mouse_dev->mouse_sess); 186 187 if (mouse_dev->wheel_sess != NULL) 188 async_hangup(mouse_dev->wheel_sess); 200 189 } 201 190 … … 206 195 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 207 196 208 if (mouse_dev->wheel_ phone < 0) {197 if (mouse_dev->wheel_sess == NULL) { 209 198 usb_log_warning( 210 199 "Connection to console not ready, wheel roll discarded.\n"); … … 218 207 /* Send arrow press and release. */ 219 208 usb_log_debug2("Sending key %d to the console\n", key); 220 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 221 KEY_PRESS, key, 0, 0); 222 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 223 KEY_RELEASE, key, 0, 0); 209 210 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess); 211 212 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0); 213 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0); 214 215 async_exchange_end(exch); 224 216 } 225 217 } … … 256 248 assert(mouse_dev != NULL); 257 249 258 if (mouse_dev->mouse_ phone < 0) {259 usb_log_warning(NAME " No console phone.\n");250 if (mouse_dev->mouse_sess == NULL) { 251 usb_log_warning(NAME " No console session.\n"); 260 252 return true; 261 253 } … … 269 261 270 262 if ((shift_x != 0) || (shift_y != 0)) { 271 async_obsolete_req_2_0(mouse_dev->mouse_phone, 272 MEVENT_MOVE, shift_x, shift_y); 273 } 274 275 if (wheel != 0) { 263 async_exch_t *exch = async_exchange_begin(mouse_dev->mouse_sess); 264 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 265 async_exchange_end(exch); 266 } 267 268 if (wheel != 0) 276 269 usb_mouse_send_wheel(mouse_dev, wheel); 277 }278 270 279 271 /* … … 295 287 if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0 296 288 && field->value != 0) { 297 async_obsolete_req_2_0(mouse_dev->mouse_phone, 298 MEVENT_BUTTON, field->usage, 1); 289 async_exch_t *exch = 290 async_exchange_begin(mouse_dev->mouse_sess); 291 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 1); 292 async_exchange_end(exch); 293 299 294 mouse_dev->buttons[field->usage - field->usage_minimum] 300 295 = field->value; 301 } else if ( 302 mouse_dev->buttons[field->usage - field->usage_minimum] != 0 296 } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0 303 297 && field->value == 0) { 304 async_obsolete_req_2_0(mouse_dev->mouse_phone, 305 MEVENT_BUTTON, field->usage, 0); 306 mouse_dev->buttons[field->usage - field->usage_minimum] 307 = field->value; 308 } 298 async_exch_t *exch = 299 async_exchange_begin(mouse_dev->mouse_sess); 300 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 0); 301 async_exchange_end(exch); 302 303 mouse_dev->buttons[field->usage - field->usage_minimum] = 304 field->value; 305 } 309 306 310 307 field = usb_hid_report_get_sibling( … … 326 323 assert(mouse != NULL); 327 324 328 /* Create the function exposed under /dev/devices. */325 /* Create the exposed function. */ 329 326 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); 330 327 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, … … 346 343 } 347 344 348 usb_log_debug("Adding DDF function to c lass%s...\n",349 HID_MOUSE_C LASS_NAME);350 rc = ddf_fun_add_to_c lass(fun, HID_MOUSE_CLASS_NAME);345 usb_log_debug("Adding DDF function to category %s...\n", 346 HID_MOUSE_CATEGORY); 347 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY); 351 348 if (rc != EOK) { 352 349 usb_log_error( 353 "Could not add DDF function to c lass%s: %s.\n",354 HID_MOUSE_C LASS_NAME, str_error(rc));350 "Could not add DDF function to category %s: %s.\n", 351 HID_MOUSE_CATEGORY, str_error(rc)); 355 352 ddf_fun_destroy(fun); 356 353 return rc; … … 384 381 } 385 382 386 usb_log_debug("Adding DDF function to c lass%s...\n",387 HID_MOUSE_WHEEL_C LASS_NAME);388 rc = ddf_fun_add_to_c lass(fun, HID_MOUSE_WHEEL_CLASS_NAME);383 usb_log_debug("Adding DDF function to category %s...\n", 384 HID_MOUSE_WHEEL_CATEGORY); 385 rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY); 389 386 if (rc != EOK) { 390 387 usb_log_error( 391 "Could not add DDF function to c lass%s: %s.\n",392 HID_MOUSE_WHEEL_C LASS_NAME, str_error(rc));388 "Could not add DDF function to category %s: %s.\n", 389 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 393 390 ddf_fun_destroy(fun); 394 391 return rc; … … 438 435 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 439 436 if (rc != EOK) { 440 usb_mouse_ free(&mouse_dev);437 usb_mouse_destroy(mouse_dev); 441 438 return rc; 442 439 } … … 465 462 { 466 463 if (data != NULL) { 467 usb_mouse_ free((usb_mouse_t **)&data);464 usb_mouse_destroy((usb_mouse_t *)data); 468 465 } 469 466 }
Note:
See TracChangeset
for help on using the changeset viewer.