[libhid-discuss] finding multile devices

Charles Lepple clepple at ghz.cc
Sat Jan 12 22:27:59 UTC 2008

[please keep the list CC'd.]

On Jan 12, 2008, at 10:48 AM, Warren Jasper wrote:

> I think you missed my point.  When searching the bus for a match,  
> there should be a helper function that returns either:
> 1. ALL the devices that match (could be more than one)

Most people are using one device at a time. You might have an  
argument for an extra function that returns a list of opened device  
handles, though.

> 2. Subsequent calls need to return matched devices that have not  
> been open.

I understand exactly what you're looking for here, and what I was  
saying is that checking with the hid_is_opened() function can only  
prove that something in that process (or thread, really) has opened  
that interface. That won't catch the device/interface being opened by  
another library, program or thread.

That said, my suggestion about keeping a list inside your code would  
work. The custom matcher function doesn't have to match against  
serial numbers - it can also check against a list of devices that  
your code has previously opened. The reason why I am suggesting this  
before changing libhid code is that it means you don't have to wait  
for a new release of libhid to get this functionality, and you can  
test this idea to make sure there isn't something wrong with my  

> Due to the way the code is structured, the change needs to occur in  
> hid_find_usb_device().  An easy fix would be to pass an extra argument

Extra arguments break backwards compatibility.

> You check for open devices before you call
> hid_find_devices (for example in hid_get_usb _handle() which is  
> called by hid_open() which is called by ...).  You are checking for  
> that too early, and missing un-opened devices on the bus.

I'm not sure I follow the last sentence. Again, hid_is_opened() only  
checks a handle that is internal to the process calling libhid -  
there is not a one-to-one mapping to a device.

> Otherwise, I need to rewrite the entire way devices are scanned to  
> get a handle to open a device.  The way libhid is currently  
> implemented,
> you only return the first match, and there is no mechanism to get  
> other matches on the bus for multiple devices.;

See above. The way I see this working, you create an empty list of  
devices you have opened (I assume that you have such a list anyway).  
In the custom matcher function, you return "false" if you have  
already have that particular device in the list.

If we were to have that in libhid, you still stand the chance of  
getting a few devices that have been grabbed by other processes or  
kernel drivers.

Charles Lepple

More information about the libhid-discuss mailing list