If we can't run, perform clean up right then.

This commit is contained in:
Steve Checkoway
2006-01-27 07:30:42 +00:00
parent e09e502038
commit 3cb4f5711d
2 changed files with 19 additions and 15 deletions
+17 -13
View File
@@ -13,9 +13,9 @@ HIDDevice::~HIDDevice()
CFRunLoopSourceRef runLoopSource; CFRunLoopSourceRef runLoopSource;
if( m_bRunning ) if( m_bRunning )
CALL( m_Queue, stop );
if( (runLoopSource = CALL(m_Queue, getAsyncEventSource)) )
{ {
CALL( m_Queue, stop );
runLoopSource = CALL( m_Queue, getAsyncEventSource );
mach_port_deallocate( mach_task_self(), CALL(m_Queue, getAsyncPort) ); mach_port_deallocate( mach_task_self(), CALL(m_Queue, getAsyncPort) );
CFRunLoopSourceInvalidate( runLoopSource ); CFRunLoopSourceInvalidate( runLoopSource );
CFRelease( runLoopSource ); CFRelease( runLoopSource );
@@ -47,18 +47,16 @@ bool HIDDevice::Open( io_object_t device )
CFStringRef productRef = (CFStringRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) ); CFStringRef productRef = (CFStringRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDProductKey) );
if( productRef ) if( productRef )
{
m_sDescription = CFStringGetCStringPtr( productRef, CFStringGetSystemEncoding() ); m_sDescription = CFStringGetCStringPtr( productRef, CFStringGetSystemEncoding() );
} if( m_sDescription == "" )
else
{ {
CFTypeRef vidRef = (CFTypeRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) ); CFTypeRef vidRef = (CFTypeRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDVendorIDKey) );
CFTypeRef pidRef = (CFTypeRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) ); CFTypeRef pidRef = (CFTypeRef)CFDictionaryGetValue( properties, CFSTR(kIOHIDProductIDKey) );
int vid, pid; int vid, pid;
if( vidRef && !IntValue(vidRef, &vid) ) if( vidRef && !IntValue(vidRef, vid) )
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 ); m_sDescription = ssprintf( "%04x:%04x", vid, pid );
} }
@@ -125,6 +123,8 @@ bool HIDDevice::Open( io_object_t device )
PrintIOErr( ret, "Failed to create the queue." ); PrintIOErr( ret, "Failed to create the queue." );
CALL( m_Queue, Release ); CALL( m_Queue, Release );
m_Queue = NULL; m_Queue = NULL;
CALL( m_Interface, Release );
m_Interface = NULL;
return false; return false;
} }
@@ -147,7 +147,7 @@ void HIDDevice::StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback
if( !CFRunLoopContainsSource(loopRef, runLoopSource, kCFRunLoopDefaultMode) ) if( !CFRunLoopContainsSource(loopRef, runLoopSource, kCFRunLoopDefaultMode) )
CFRunLoopAddSource( loopRef, runLoopSource, kCFRunLoopDefaultMode ); CFRunLoopAddSource( loopRef, runLoopSource, kCFRunLoopDefaultMode );
CALL( m_Queue, setEventCallout, callback, target, (void *)refCon ); ret = CALL( m_Queue, setEventCallout, callback, target, (void *)refCon );
if( ret != kIOReturnSuccess ) if( ret != kIOReturnSuccess )
{ {
@@ -160,6 +160,10 @@ void HIDDevice::StartQueue( CFRunLoopRef loopRef, IOHIDCallbackFunction callback
if( ret != kIOReturnSuccess ) if( ret != kIOReturnSuccess )
{ {
mach_port_deallocate( mach_task_self(), CALL(m_Queue, getAsyncPort) );
CFRunLoopSourceInvalidate( runLoopSource );
CFRelease( runLoopSource );
PrintIOErr( ret, "Failed to start the queue." ); PrintIOErr( ret, "Failed to start the queue." );
return; return;
} }
@@ -180,12 +184,12 @@ void HIDDevice::AddLogicalDevice( const void *value, void *context )
// Get usage page // Get usage page
object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsagePageKey) ); object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsagePageKey) );
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usagePage) ) if( !object || CFGetTypeID(object) != numID || !IntValue(object, usagePage) )
return; return;
// Get usage // Get usage
object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsageKey) ); object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsageKey) );
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usage) ) if( !object || CFGetTypeID(object) != numID || !IntValue(object, usage) )
return; return;
if( !(elements = (CFArrayRef)CFDictionaryGetValue( dict, CFSTR(kIOHIDElementKey))) ) if( !(elements = (CFArrayRef)CFDictionaryGetValue( dict, CFSTR(kIOHIDElementKey))) )
@@ -221,18 +225,18 @@ void HIDDevice::AddElement( const void *value, void *context )
// Get usage page // Get usage page
object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsagePageKey) ); object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsagePageKey) );
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usagePage) ) if( !object || CFGetTypeID(object) != numID || !IntValue(object, usagePage) )
return; return;
// Get usage // Get usage
object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsageKey) ); object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementUsageKey) );
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usage) ) if( !object || CFGetTypeID(object) != numID || !IntValue(object, usage) )
return; return;
// Get cookie // Get cookie
object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementCookieKey) ); object = CFDictionaryGetValue( dict, CFSTR(kIOHIDElementCookieKey) );
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &cookie) ) if( !object || CFGetTypeID(object) != numID || !IntValue(object, cookie) )
return; return;
This->AddElement( usagePage, usage, cookie, dict ); This->AddElement( usagePage, usage, cookie, dict );
} }
+2 -2
View File
@@ -28,9 +28,9 @@ static inline void PrintIOErr( IOReturn err, const char *s )
LOG->Warn( "%s - %s(%x,%d)", s, mach_error_string(err), err, err & 0xFFFFFF ); LOG->Warn( "%s - %s(%x,%d)", s, mach_error_string(err), err, err & 0xFFFFFF );
} }
static inline Boolean IntValue( const void *o, int *n ) static inline Boolean IntValue( const void *o, int &n )
{ {
return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, n ); return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, &n );
} }
/* /*