| 599 | } |
| 600 | |
| 601 | static void read_callback(struct libusb_transfer *transfer) |
| 602 | { |
| 603 | hid_device *dev = transfer->user_data; |
| 604 | int res; |
| 605 | |
| 606 | if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { |
| 607 | |
| 608 | struct input_report *rpt = malloc(sizeof(*rpt)); |
| 609 | rpt->data = malloc(transfer->actual_length); |
| 610 | memcpy(rpt->data, transfer->buffer, transfer->actual_length); |
| 611 | rpt->len = transfer->actual_length; |
| 612 | rpt->next = NULL; |
| 613 | |
| 614 | //pthread_mutex_lock(&dev->mutex); |
| 615 | |
| 616 | /* Attach the new report object to the end of the list. */ |
| 617 | if (dev->input_reports == NULL) { |
| 618 | /* The list is empty. Put it at the root. */ |
| 619 | dev->input_reports = rpt; |
| 620 | //pthread_cond_signal(&dev->condition); |
| 621 | } |
| 622 | else { |
| 623 | /* Find the end of the list and attach. */ |
| 624 | struct input_report *cur = dev->input_reports; |
| 625 | int num_queued = 0; |
| 626 | while (cur->next != NULL) { |
| 627 | cur = cur->next; |
| 628 | num_queued++; |
| 629 | } |
| 630 | cur->next = rpt; |
| 631 | |
| 632 | /* Pop one off if we've reached 30 in the queue. This |
| 633 | way we don't grow forever if the user never reads |
| 634 | anything from the device. */ |
| 635 | if (num_queued > 30) { |
| 636 | return_data(dev, NULL, 0); |
| 637 | } |
| 638 | } |
| 639 | //pthread_mutex_unlock(&dev->mutex); |
| 640 | } |
| 641 | else if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { |
| 642 | dev->shutdown_thread = 1; |
| 643 | dev->cancelled = 1; |
| 644 | return; |
| 645 | } |
| 646 | else if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) { |
| 647 | dev->shutdown_thread = 1; |
| 648 | dev->cancelled = 1; |
| 649 | return; |
| 650 | } |
| 651 | else if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT) { |
| 652 | //LOG("Timeout (normal)\n"); |
| 653 | } |
| 654 | else { |
| 655 | LOG("Unknown transfer code: %d\n", transfer->status); |
| 656 | } |
| 657 | |
| 658 | /* Re-submit the transfer object. */ |
nothing calls this directly
no test coverage detected