Allow subclasses to refuse particular (vid, pid) pairs.
This commit is contained in:
@@ -47,20 +47,25 @@ bool HIDDevice::Open( io_object_t device )
|
|||||||
|
|
||||||
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) );
|
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() )
|
if( object && CFGetTypeID(object) == CFStringGetTypeID() )
|
||||||
m_sDescription = CFStringGetCStringPtr( CFStringRef(object), CFStringGetSystemEncoding() );
|
m_sDescription = CFStringGetCStringPtr( CFStringRef(object), CFStringGetSystemEncoding() );
|
||||||
if( m_sDescription == "" )
|
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 );
|
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 )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user