Bug 221 - Only one USB device can be used at a time.
Summary: Only one USB device can be used at a time.
Alias: None
Product: libsigrok
Classification: Unclassified
Component: Common: USB handling code (show other bugs)
Version: unreleased development snapshot
Hardware: All All
: Normal major
Target Milestone: ---
Assignee: Nobody
Depends on:
Reported: 2013-12-22 00:21 CET by Martin Ling
Modified: 2014-01-20 01:10 CET (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Martin Ling 2013-12-22 00:21:56 CET
USB drivers register their event handlers against fds obtained from libusb_get_pollfds(). These fds are not device-specific however - they include fds for all devices in the context as well as perhaps some that might be shared. This gives rise to the following sequence:

Device A added - event handler A registered to its fds.
Device B added - event handler B registered to fds for both A and B.
Device B removed - fds for both A and B are removed.

We need to get away from the approach of using an fd (or similar) as the unique identifier for an event handler. There are plenty of cases in which we might need to have multiple handlers registered for the same resource.

I propose we put the existing *_source_add arguments in a struct:

struct sr_event_handler {
    int events;
    int timeout;
    sr_receive_data_callback_t cb;
    void *cb_data;

Drivers can then keep references to the event handlers they have registered, and request their removal by pointer.