From b760e127a81cd2d91a45921de9f4aa6c3ac239c3 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Fri, 24 Feb 2006 10:47:33 +0000 Subject: [PATCH] Allow subclasses to refuse particular (vid, pid) pairs. --- stepmania/src/archutils/Darwin/HIDDevice.cpp | 25 ++++++++++++-------- stepmania/src/archutils/Darwin/HIDDevice.h | 5 ++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/stepmania/src/archutils/Darwin/HIDDevice.cpp b/stepmania/src/archutils/Darwin/HIDDevice.cpp index 90f0c592e1..47eda46e6b 100644 --- a/stepmania/src/archutils/Darwin/HIDDevice.cpp +++ b/stepmania/src/archutils/Darwin/HIDDevice.cpp @@ -47,20 +47,25 @@ bool HIDDevice::Open( io_object_t device ) object = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) ); + CFTypeRef vidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) ); + CFTypeRef pidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) ); + int vid, pid; + + if( vidRef && !IntValue(vidRef, vid) ) + vid = 0; + if( pidRef && !IntValue(pidRef, pid) ) + pid = 0; + + if( !SupportsVidPid(vid, pid) ) + { + CFRelease( properties ); + return false; + } + if( object && CFGetTypeID(object) == CFStringGetTypeID() ) m_sDescription = CFStringGetCStringPtr( CFStringRef(object), CFStringGetSystemEncoding() ); if( m_sDescription == "" ) - { - CFTypeRef vidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) ); - CFTypeRef pidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) ); - int vid, pid; - - if( vidRef && !IntValue(vidRef, vid) ) - vid = 0; - if( pidRef && !IntValue(pidRef, pid) ) - pid = 0; m_sDescription = ssprintf( "%04x:%04x", vid, pid ); - } object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) ); if ( !object || CFGetTypeID(object) != CFArrayGetTypeID() ) diff --git a/stepmania/src/archutils/Darwin/HIDDevice.h b/stepmania/src/archutils/Darwin/HIDDevice.h index f943968b89..72038f67a3 100644 --- a/stepmania/src/archutils/Darwin/HIDDevice.h +++ b/stepmania/src/archutils/Darwin/HIDDevice.h @@ -72,6 +72,11 @@ protected: */ virtual void Open() = 0; + /* + * Optional. Subclasses can return false if they do not support the (vid, pid) pair. + */ + virtual bool SupportsVidPid( int vid, int pid ) { return true; } + // This adds the element with the given cookie to the queue to be notified of state changes. inline void AddElementToQueue( int cookie ) {