Hi,

On 03/27/2013 05:22 PM, Ludovic Rousseau wrote:
> 2013/3/25 Hans de Goede <hdego...@redhat.com>:
>> Hi,
>>
>>
>> On 03/23/2013 12:05 PM, Ludovic Rousseau wrote:
>>>
>>> 2013/3/23 Hans de Goede <hdego...@redhat.com>:
>>>>
>>>> We all seem to agree on that, which is good :)  So it would be helpful
>>>> to get some feedback on my proposed API for the opting in before I
>>>> actually start coding this. Let me quote my own API proposal from
>>>> another mail:
>>>>
>>>> Assuming all platforms will do auto-detach on interface claim (which
>>>> makes sense given that drivers are usually per interface), we could
>>>> make this a device_handle property, so then an app would do something
>>>> like:
>>>>
>>>> libusb_device_handle *handle;
>>>>
>>>> libusb_open(dev, &handle);
>>>> libusb_set_auto_detach(handle, 1);
>>>> libusb_claim_interface(handle, x);
>>>>
>>>> With:
>>>> void libusb_set_auto_detach(libusb_device_handle *dev, int auto_detach);
>>>
>>>
>>> I propose to rename the function in libusb_set_auto_detach_kernel_driver()
>>
>>
>> Ack.
>>
>>
>>>
>>> I also propose to give a symbolic name to the parameter value instead
>>> of using 1.
>>> Something like LIBUSB_AUTO_DETACH_KERNEL_DRIVER_ENABLE
>>>
>>> I don't know if we also need a LIBUSB_AUTO_DETACH_KERNEL_DRIVER_DISABLE
>>> If not maybe the parameter can be removed.
>>> Or maybe the function can be named:
>>> libusb_set_parameter(handle, LIBUSB_AUTO_DETACH_KERNEL_DRIVER_ENABLE)
>>
>>
>> I've been thinking about something more generic, ie:
>> int libusb_set_parameter(libusb_device_handle *dev, int parameter,
>>                           int value);
>>
>> But it seems better to me to just add per parameter set functions, these
>> kind of multiplex functions are needlessly hard to use, and need demultiplex
>> code in the implementation, which as ioctl code in the kernel shows, is
>> easy at first but gets hard pretty quickly.
>>
>> Thinking more about this I propose to simply add a:
>>
>> void libusb_enable_auto_detach_kernel_driver(libusb_device_handle *dev);
>>
>> Function, this solves the whole needing defines for the argument problem,
>> and the name makes it clear at once what the function does.
>
> The problem with a new function for each new parameter is that it is
> hard to use in a program. If you want to support different (older)
> versions of libusbx you will have to use something like:
>
> #ifdef HAVE_LIBUSB_ENABLE_AUTO_DETACH_KERNEL_DRIVER
> libusb_enable_auto_detach_kernel_driver(device);
> #else
> libusb_enable_detach_kernel_driver(device);
> #endif
>
> And add the corresponding test in configure.ac
>
> Maybe it is simpler to just always and only use
> libusb_enable_detach_kernel_driver()
>
> For each new function added to libusbx the API and ABI version needs
> to be increased. A program compiled with version N of the library
> cannot be used with a previous version of the library (unless the
> library is linked statically but that not the way to use on Linux).

Right, how I usually solve this in my usbredir code is simply bump the
minimum version required in the pkg-config check in configure.ac,
iow if people want to use the latest usbredir code, they need the
latest libusb

As for the ABI issue:
1) We should really start using symbol versioning on Linux for this
2) It is unusual to run with an older lib then an app was compiled
against.

> On the contrary, a generic function libusb_set_parameter() would
> always be available and just return LIBUSB_ERROR_NOT_SUPPORTED for
> unknown parameter. No more #ifdef dance and ABI issue.

Well if the app sees the  LIBUSB_ERROR_NOT_SUPPORTED for the auto-detach
stuff and it knows it needs detach, it will need to fallback to doing detach
the old way, so you're just replacing a #ifdef dance with a runtime dance...

Which is exactly why I just bump the minimum version needed to build
usually :)

Regards,

Hans

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to