device filtering support

Vitali Lovich vlovich at gmail.com
Tue Jan 31 01:06:39 EST 2012


https://github.com/vlovich/libusb/tree/filter_support feature rebase on top of rc3

Request for review.  Verified works on Linux.  Pretty sure that it works on OSX & Windows as those code paths are even simpler.  I'm planning for this to go into the first forked release of libusbx (i.e. not 1.0.9).  This can have significant benefit in terms of CPU usage since it avoids unnecessary allocations & usb querying if the device is of no interest to upper layers.  It also simplifies a lot of user code since they typically will filter for a specific vid/pid from the list anyways.

libusb_filter_vid_pid(libusb_context *ctx, int *vids, int *pids, int nfilters);

vids - an array of vids to allow (-1 indicates that all vids match this entry)
pids - an array of pids to allow (-1 indicates that all pids match this entry)

if -1 is specified for both vid/pid in any entry, obviously the filter will do nothing.

Usage:
libusb_filter_vid_pid(NULL, { 0xabcd }, { -1}, 1);

-Vitali


More information about the libusbx mailing list