IGN:Allow drivers to perform arbitrary post id match checks to detect devices

This commit is contained in:
Kovid Goyal 2009-01-10 17:01:11 -08:00
parent 399b6bbcb0
commit 719926222e
2 changed files with 18 additions and 2 deletions

View File

@ -41,6 +41,20 @@ class Device(object):
'''Return the FDI description of this device for HAL on linux.'''
return ''
@classmethod
def can_handle(cls, device_info):
'''
Optional method to perform further checks on a device to see if this driver
is capable of handling it. If it is not it should return False. This method
is only called after the vendor, product ids and the bcd have matched, so
it can do some relatively time intensive checks. The default implementation
returns True.
:param device_info: On windows a device ID string. On Unix a tuple of
``(vendor_id, product_id, bcd)``.
'''
return True
def open(self):
'''
Perform any device specific initialization. Called after the device is

View File

@ -63,12 +63,14 @@ class DeviceScanner(object):
for device_id in self.devices:
if vid in device_id and pid in device_id:
if self.test_bcd_windows(device_id, getattr(device, 'BCD', None)):
return True
if device.can_handle(device_id):
return True
else:
for vendor, product, bcdDevice in self.devices:
if device.VENDOR_ID == vendor and device.PRODUCT_ID == product:
if self.test_bcd(bcdDevice, getattr(device, 'BCD', None)):
return True
if device.can_handle((vendor, product, bcdDevice)):
return True
return False