[haiku-commits] Re: r42860 - haiku/trunk/src/add-ons/kernel/drivers/ports/usb_serial

Dear François,

Am 17.10.2011 17:24, schrieb François Revol:
Le 16/10/2011 13:46, pulkomandy@xxxxxxxxxxxxxxxxx a écrit :
The switch/case for VID/PID identification is getting quite long. Isn't there a
better way to do it ?

Indeed it's ugly.

Plus we register the driver without any list to the usb bus manager, and
we try to create a device (ACM by default) on any newly inserted thing...

A cleaner way would be a list of structs that would also contain the
description (the compiler should be intelligent enough to atomize
identical strings). We can even add a static factory method to the
device classes that can be pointed to from the list entries.

The only problem is the usb bus manager wants an array of
usb_support_descriptor, which doesn't leave any room for description or
other thing, so either we'd have to maintain two lists, or we will need
some cpp tricks to parse it twice to generate both.

Looks like nobody is checking my commits anymore. ;-)

To solve mentioned problem I did the following during last refactoring of usb_asix:

1) Declare the DeviceInfo struct: http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/drivers/network/usb_asix/ASIXDevice.h#L23 containing IDs, hardware type enumeration and description; 2) Statically initialized the array of DeviceInfo structs (gSupportedDevices) for every supported hardware entry: http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/drivers/network/usb_asix/Driver.cpp#L37 ; 3) Compose the array of usb_support_descriptor structures in the init_driver: http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/drivers/network/usb_asix/Driver.cpp#L225 to provide with it the USB stack; 4) Implemented the lookup_and_create_device function (http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/drivers/network/usb_asix/Driver.cpp#L67) that uses binary search through gSupportedDevices array and creates new device object correspondently it's type;

The key point of this technique is that gSupportedDevices array must be sorted to let the search procedure do the lookup.

Thank you for attention. I hope it helps.

---
Kind Regards,
  S.Zharski


Other related posts: