Allow subclasses to refuse particular (vid, pid) pairs.

This commit is contained in:
Steve Checkoway
2006-02-24 10:47:33 +00:00
parent 19bb34974e
commit b760e127a8
2 changed files with 20 additions and 10 deletions
+10 -5
View File
@@ -47,10 +47,6 @@ bool HIDDevice::Open( io_object_t device )
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) ); object = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) );
if( object && CFGetTypeID(object) == CFStringGetTypeID() )
m_sDescription = CFStringGetCStringPtr( CFStringRef(object), CFStringGetSystemEncoding() );
if( m_sDescription == "" )
{
CFTypeRef vidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) ); CFTypeRef vidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) );
CFTypeRef pidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) ); CFTypeRef pidRef = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) );
int vid, pid; int vid, pid;
@@ -59,9 +55,18 @@ bool HIDDevice::Open( io_object_t device )
vid = 0; vid = 0;
if( pidRef && !IntValue(pidRef, pid) ) if( pidRef && !IntValue(pidRef, pid) )
pid = 0; pid = 0;
m_sDescription = ssprintf( "%04x:%04x", vid, pid );
if( !SupportsVidPid(vid, pid) )
{
CFRelease( properties );
return false;
} }
if( object && CFGetTypeID(object) == CFStringGetTypeID() )
m_sDescription = CFStringGetCStringPtr( CFStringRef(object), CFStringGetSystemEncoding() );
if( m_sDescription == "" )
m_sDescription = ssprintf( "%04x:%04x", vid, pid );
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) ); object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) );
if ( !object || CFGetTypeID(object) != CFArrayGetTypeID() ) if ( !object || CFGetTypeID(object) != CFArrayGetTypeID() )
{ {
@@ -72,6 +72,11 @@ protected:
*/ */
virtual void Open() = 0; 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. // This adds the element with the given cookie to the queue to be notified of state changes.
inline void AddElementToQueue( int cookie ) inline void AddElementToQueue( int cookie )
{ {