From faa02ea1a208dccdc0df2c9ba567c09ca6c2e957 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 30 Nov 2006 05:47:56 +0000 Subject: moved over sources from externals/hcs/hid/HID Utilities Source. This is not just a straight download of the .sit package, it includes some necessary updates that were posted to the Apple lists. See the history in externals/hcs/hid/HID Utilities Source for more info. svn path=/trunk/externals/io/hidio/; revision=6532 --- HID Utilities Source/ImmrHIDUtilAddOn.c | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 HID Utilities Source/ImmrHIDUtilAddOn.c (limited to 'HID Utilities Source/ImmrHIDUtilAddOn.c') diff --git a/HID Utilities Source/ImmrHIDUtilAddOn.c b/HID Utilities Source/ImmrHIDUtilAddOn.c new file mode 100755 index 0000000..6d2cbaf --- /dev/null +++ b/HID Utilities Source/ImmrHIDUtilAddOn.c @@ -0,0 +1,95 @@ +/* + * ImmrHIDUtilAddOn.c + * UseFFAPIFromHIDUtilities + * + * Created by rlacroix on Wed Oct 16 2002. + * Copyright (c) 2002 Immersion Corporation. All rights reserved. + * + */ + +#include +#include + +#include +#include +#include +#include + +#include "HID_Utilities_External.h" +#include "ImmrHIDUtilAddOn.h" + +//--------------------------------------------------------------------------------- +// +// AllocateHIDObjectFromRecDevice() +// +// returns: +// NULL, or acceptable io_object_t +// +//--------------------------------------------------------------------------------- +io_service_t AllocateHIDObjectFromRecDevice( pRecDevice pDevice ) +{ + CFMutableDictionaryRef matchingDict; + UInt32 locationID = pDevice->locID; + CFNumberRef refUsage = NULL; + mach_port_t masterPort = NULL; + IOReturn result = kIOReturnSuccess; + io_service_t hidDevice = NULL; + + do // while( 0 ) + { + result = IOMasterPort (bootstrap_port, &masterPort); + if( result != kIOReturnSuccess ) + { + break; + } + + // Set up the matching criteria for the devices we're interested in. + // We are interested in instances of class IOHIDDevice. + // matchingDict is consumed below (in IOServiceGetMatchingService) + // so we have no leak here. + // + matchingDict = IOServiceMatching(kIOHIDDeviceKey); + if (!matchingDict) + { + break; + } + + // Add a key for locationID to our matching dictionary. This works for matching to + // IOHIDDevices, so we will only look for a device attached to that particular port + // on the machine. + // + refUsage = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &locationID); + CFDictionaryAddValue( matchingDict, + CFSTR(kIOHIDLocationIDKey), + refUsage); + CFRelease(refUsage); + + // IOServiceGetMatchingService assumes that we already know that there is only one device + // that matches. This way we don't have to do the whole iteration dance to look at each + // device that matches. This is a new API in 10.2 + // + hidDevice = IOServiceGetMatchingService( masterPort, matchingDict); + } + while( 0 ); + + // Free master port if we created one. + // + if (masterPort) + mach_port_deallocate(mach_task_self(), masterPort); + + return hidDevice; +} + +//--------------------------------------------------------------------------------- +// +// FreeHIDObject() +// +//--------------------------------------------------------------------------------- +bool FreeHIDObject( io_service_t hidDevice ) +{ + kern_return_t kr; + + kr = IOObjectRelease(hidDevice); + + return( kIOReturnSuccess == kr ); +} \ No newline at end of file -- cgit v1.2.1