aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-06-10 03:12:42 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-06-10 03:12:42 +0000
commitfc0ab5a8127cffc9659b1eba88a23748a4513ae1 (patch)
tree3a7f088b04be4c19820dc2f8a6aed5462210ad56
parent5d7db8de8563948f774ee37a8a9a260a01a6723e (diff)
This commit was generated by cvs2svn to compensate for changes in r3157,
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/hcs/hid/; revision=3158
-rwxr-xr-xHID Utilities Source/HID_APIs.h150
-rwxr-xr-xHID Utilities Source/HID_CFM.c321
-rwxr-xr-xHID Utilities Source/HID_Utilities_CFM.h17
-rwxr-xr-xHID Utilities Source/HID_Utilities_External.h166
-rwxr-xr-xHID Utilities Source/ImmrHIDUtilAddOn.c95
-rwxr-xr-xHID Utilities Source/ImmrHIDUtilAddOn.h11
6 files changed, 451 insertions, 309 deletions
diff --git a/HID Utilities Source/HID_APIs.h b/HID Utilities Source/HID_APIs.h
new file mode 100755
index 0000000..d281340
--- /dev/null
+++ b/HID Utilities Source/HID_APIs.h
@@ -0,0 +1,150 @@
+
+/*
+ File: HID_APIs.h
+
+ Contains: Definition of the HID Utilities exported API's
+
+ DRI: George Warner
+
+ Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved
+
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
+ ("Apple") in consideration of your agreement to the following terms, and your
+ use, installation, modification or redistribution of this Apple software
+ constitutes acceptance of these terms. If you do not agree with these terms,
+ please do not use, install, modify or redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and subject
+ to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
+ copyrights in this original Apple software (the "Apple Software"), to use,
+ reproduce, modify and redistribute the Apple Software, with or without
+ modifications, in source and/or binary forms; provided that if you redistribute
+ the Apple Software in its entirety and without modifications, you must retain
+ this notice and the following text and disclaimers in all such redistributions of
+ the Apple Software. Neither the name, trademarks, service marks or logos of
+ Apple Computer, Inc. may be used to endorse or promote products derived from the
+ Apple Software without specific prior written permission from Apple. Except as
+ expressly stated in this notice, no other rights or licenses, express or implied,
+ are granted by Apple herein, including but not limited to any patent rights that
+ may be infringed by your derivative works or by other works in which the Apple
+ Software may be incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
+ WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
+ COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
+ OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+ (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+// ----------------------------------------------------------------
+// The DO_API micro takes four parameters:
+// #define DO_API(r,n,p,a)
+// r - what the API Returns
+// n - the Name of the API
+// p - the Parameters to the API
+// a - the Arguments passed by the API
+//
+// DO_APIr is used when an API returns a value.
+// DO_API is used when an API doesn't return a value.
+//
+// For example:
+//
+// if you have a routine that doesn't return a value:
+//
+// void MyFunction(const UInt32 pSelector, void* pPtr);
+//
+// It's macro would look like this:
+//
+// DO_API(
+// void, // this is what the function returns
+// MyFunction, // this is its Name
+// (const UInt32 pSelector, void* pPtr), // these are its parameters
+// (pSelector, pPtr)) // and these are just the arguments (no type info)
+//
+// If it returns a value like this
+//
+// OSStatus MyFunction2(const UInt32 pSelector, void* pPtr);
+//
+// It's macro would look like this:
+//
+// DO_APIr(
+// OSStatus, // this is what the function returns
+// MyFunction2, // this is its Name
+// (const UInt32 pSelector, void* pPtr), // these are its parameters
+// (pSelector, pPtr)) // and these are just the arguments (no type info)
+//
+
+#ifndef DO_API // if this isn't definedÉ
+ #define DO_API // É then don't do anything.
+#endif
+
+#ifndef DO_APIr // if this isn't definedÉ
+ #define DO_APIr DO_API // É then do the same as DO_API
+#endif
+
+DO_APIr(Boolean, HIDBuildDeviceList, (UInt32 usagePage, UInt32 usage), (usagePage, usage))
+DO_APIr(Boolean, HIDFindActionDeviceAndElement, (const pRecDevice pSearchDevice, const pRecElement pSearchElement,pRecDevice *ppFoundDevice, pRecElement *ppFoundElement), (pSearchDevice, pSearchElement,ppFoundDevice, ppFoundElement))
+DO_APIr(Boolean, HIDFindDevice, (const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice), (pSearchDevice, ppFoundDevice))
+DO_APIr(Boolean, HIDFindSubElement, (const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement), (pStartElement, pSearchElement, ppFoundElement))
+DO_APIr(Boolean, HIDGetElementNameFromVendorProductCookie, (const long vendorID, const long productID, const long cookie, char * pName), (vendorID, productID, cookie, pName))
+DO_APIr(Boolean, HIDGetElementNameFromVendorProductUsage, (const long vendorID, const long productID, const long pUsagePage, const long pUsage, char * pName), (vendorID, productID, pUsagePage, pUsage, pName))
+DO_APIr(Boolean, HIDHaveDeviceList, (void), ())
+DO_APIr(Boolean, HIDIsValidDevice, (const pRecDevice pSearchDevice), (pSearchDevice))
+DO_APIr(Boolean, HIDIsValidElement, (const pRecDevice pSearchDevice, const pRecElement pSearchElement), (pSearchDevice, pSearchElement))
+DO_APIr(Boolean, HIDRestoreElementPref, (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement), (keyCFStringRef, appCFStringRef, ppDevice, ppElement))
+DO_APIr(Boolean, HIDSaveElementPref, (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement), (keyCFStringRef, appCFStringRef, pDevice, pElement))
+DO_APIr(Boolean, HIDTransactionHasElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+DO_APIr(HIDElementTypeMask, HIDConvertElementTypeToMask, (const long type), (type))
+DO_APIr(int, HIDPrintElement, (const pRecElement pElement), (pElement))
+DO_APIr(long, HIDGetElementValue, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+//DO_APIr(long, HIDGetReport, (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, unsigned long* reportBufferSize), (pDevice,reportType, reportID, reportBuffer, reportBufferSize))
+DO_APIr(long, HIDRestoreElementConfig, (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement), (fileRef, ppDevice, ppElement))
+DO_APIr(long, HIDSetElementValue, (pRecDevice pDevice, pRecElement pElement,void* pIOHIDEvent), (pDevice, pElement,pIOHIDEvent))
+DO_APIr(long, HIDSetQueueCallback, (pRecDevice pDevice, IOHIDCallbackFunction callback,void* callbackTarget, void* callbackRefcon), (pDevice, callback,callbackTarget, callbackRefcon))
+//DO_APIr(long, HIDSetReport, (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, const unsigned long reportBufferSize),(pDevice,reportType, reportID, reportBuffer, reportBufferSize))
+DO_APIr(pRecDevice, HIDGetFirstDevice, (void), ())
+DO_APIr(pRecDevice, HIDGetNextDevice, (pRecDevice pDevice), (pDevice))
+DO_APIr(pRecElement, HIDGetFirstDeviceElement, (pRecDevice pDevice, HIDElementTypeMask typeMask), (pDevice, typeMask))
+DO_APIr(pRecElement, HIDGetNextDeviceElement, (pRecElement pElement, HIDElementTypeMask typeMask), (pElement, typeMask))
+DO_APIr(pRecElement, HIDGetPreviousDeviceElement, (pRecElement pElement, HIDElementTypeMask typeMask), (pElement, typeMask))
+DO_APIr(SInt32, HIDCalibrateValue, (SInt32 value, pRecElement pElement), (value, pElement))
+DO_APIr(SInt32, HIDScaleValue, (SInt32 value, pRecElement pElement), (value, pElement))
+DO_APIr(UInt32, HIDCountDeviceElements, (pRecDevice pDevice, HIDElementTypeMask typeMask), (pDevice, typeMask))
+DO_APIr(UInt32, HIDCountDevices, (void), ())
+DO_APIr(unsigned char, HIDConfigureAction, (pRecDevice * ppDevice, pRecElement * ppElement, float timeout), (ppDevice, ppElement, timeout))
+DO_APIr(unsigned char, HIDGetEvent, (pRecDevice pDevice, void * pHIDEvent), (pDevice, pHIDEvent))
+DO_APIr(unsigned long, HIDQueueElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+DO_APIr(unsigned long, HIDCloseReleaseInterface, (pRecDevice pDevice), (pDevice))
+DO_APIr(unsigned long, HIDCreateOpenDeviceInterface, (UInt32 hidDevice, pRecDevice pDevice), (hidDevice, pDevice))
+DO_APIr(unsigned long, HIDDequeueDevice, (pRecDevice pDevice), (pDevice))
+DO_APIr(unsigned long, HIDDequeueElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+DO_APIr(unsigned long, HIDQueueDevice, (pRecDevice pDevice), (pDevice))
+DO_APIr(unsigned long, HIDReleaseAllDeviceQueues, (void), ())
+
+DO_APIr(unsigned long, HIDTransactionAddElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+DO_APIr(unsigned long, HIDTransactionClear, (pRecDevice pDevice), (pDevice))
+DO_APIr(unsigned long, HIDTransactionCommit, (pRecDevice pDevice), (pDevice))
+DO_APIr(unsigned long, HIDTransactionGetElementDefault, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent))
+DO_APIr(unsigned long, HIDTransactionGetElementValue, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent))
+DO_APIr(unsigned long, HIDTransactionRemoveElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement))
+DO_APIr(unsigned long, HIDTransactionSetElementDefault, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent))
+DO_APIr(unsigned long, HIDTransactionSetElementValue, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent))
+
+DO_API(void, HIDGetTypeName, (IOHIDElementType theType, char * cstrName), (theType, cstrName))
+DO_API(void, HIDGetUsageName, (long valueUsagePage, long valueUsage, char * cstrName), (valueUsagePage, valueUsage, cstrName))
+DO_API(void, HIDReleaseDeviceList, (void), ())
+DO_API(void, HIDSaveElementConfig, (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie), (fileRef, pDevice, pElement, actionCookie))
+
+DO_APIr(io_object_t, AllocateHIDObjectFromRecDevice,(pRecDevice pDevice),(pDevice))
+DO_APIr(Boolean, FreeHIDObject,(io_object_t hidDevice), (hidDevice))
+
+#undef DO_API
+#undef DO_APIr
+
diff --git a/HID Utilities Source/HID_CFM.c b/HID Utilities Source/HID_CFM.c
index 0e7f1e4..ab00e0b 100755
--- a/HID Utilities Source/HID_CFM.c
+++ b/HID Utilities Source/HID_CFM.c
@@ -41,72 +41,78 @@
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
*/
-//includes
-
-#include "HID_Utilities_CFM.h"
-
+// Note: All the HID API's are defined externally in the file "HID_APIs.h".
+// How they are used in this file is defined via one or two macros:
+//
+// The DO_API micro takes four parameters:
+// #define DO_API(r,n,p,a)
+// r - what the API Returns
+// n - the Name of the API
+// p - the Parameters to the API
+// a - the Arguments passed by the API
+//
+// DO_APIr is used when an API returns a value.
+// DO_API is used when an API doesn't return a value.
+//
+// For example:
+//
+// if you have a routine that doesn't return a value:
+//
+// void MyFunction(const UInt32 pSelector, void* pPtr);
+//
+// It's macro would look like this:
+//
+// DO_API(
+// void, // this is what the function returns
+// MyFunction, // this is its Name
+// (const UInt32 pSelector, void* pPtr), // these are its parameters
+// (pSelector, pPtr)) // and these are just the arguments (no type info)
+//
+// If it returns a value like this
+//
+// OSStatus MyFunction2(const UInt32 pSelector, void* pPtr);
+//
+// It's macro would look like this:
+//
+// DO_APIr(
+// OSStatus, // this is what the function returns
+// MyFunction2, // this is its Name
+// (const UInt32 pSelector, void* pPtr), // these are its parameters
+// (pSelector, pPtr)) // and these are just the arguments (no type info)
+//
// ==================================
+// includes
+// ==================================
+#include "HID_Utilities_CFM.h"
-// types
-
-typedef unsigned char (*fpHIDBuildDeviceListtype) (unsigned long usagePage, unsigned long usage);
-typedef void (*fpHIDReleaseDeviceListtype) (void);
-typedef unsigned char (*fpHIDHaveDeviceListtype) (void);
-typedef unsigned long (*fpHIDCountDevicestype) (void);
-typedef unsigned long (*fpHIDCountDeviceElementstype) (pRecDevice pDevice, HIDElementTypeMask typeMask);
-typedef pRecDevice (*fpHIDGetFirstDevicetype) (void);
-typedef pRecDevice (*fpHIDGetNextDevicetype) (pRecDevice pDevice);
-typedef pRecElement (*fpHIDGetFirstDeviceElementtype) (pRecDevice pDevice, HIDElementTypeMask typeMask);
-typedef pRecElement (*fpHIDGetNextDeviceElementtype) (pRecElement pElement, HIDElementTypeMask typeMask);
-typedef pRecElement (*fpHIDGetPreviousDeviceElementtype) (pRecElement pElement, HIDElementTypeMask typeMask);
-typedef void (*fpHIDGetTypeNametype) (unsigned long type, char * cstrName);
-typedef void (*fpHIDGetUsageNametype) (long valueUsagePage, long valueUsage, char * cstrName);
-typedef unsigned long (*fpHIDQueueElementtype) (pRecDevice pDevice, pRecElement pElement);
-typedef unsigned long (*fpHIDQueueDevicetype) (pRecDevice pDevice);
-typedef unsigned long (*fpHIDDequeueElementtype) (pRecDevice pDevice, pRecElement pElement);
-typedef unsigned long (*fpHIDDequeueDevicetype) (pRecDevice pDevice);
-typedef unsigned char (*fpHIDGetEventtype) (pRecDevice pDevice, void * pHIDEvent);
-typedef long (*fpHIDGetElementValuetype) (pRecDevice pDevice, pRecElement pElement);
-typedef long (*fpHIDCalibrateValuetype) (long value, pRecElement pElement);
-typedef long (*fpHIDScaleValuetype) (long value, pRecElement pElement);
-typedef unsigned char (*fpHIDConfigureActiontype) (pRecDevice * ppDevice, pRecElement * ppElement, float timeout);
-typedef void (*fpHIDSaveElementConfigtype) (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie);
-typedef long (*fpHIDRestoreElementConfigtype) (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement);
+typedef OSStatus HRESULT;
+typedef UInt32 IOByteCount;
+typedef unsigned int io_service_t;
+typedef unsigned int io_object_t;
+#define S_OK ((HRESULT)0x00000000L)
-// function pointers
-fpHIDBuildDeviceListtype fpHIDBuildDeviceList = NULL;
-fpHIDReleaseDeviceListtype fpHIDReleaseDeviceList = NULL;
-fpHIDHaveDeviceListtype fpHIDHaveDeviceList = NULL;
-fpHIDCountDevicestype fpHIDCountDevices = NULL;
-fpHIDCountDeviceElementstype fpHIDCountDeviceElements = NULL;
-fpHIDGetFirstDevicetype fpHIDGetFirstDevice = NULL;
-fpHIDGetNextDevicetype fpHIDGetNextDevice = NULL;
-fpHIDGetFirstDeviceElementtype fpHIDGetFirstDeviceElement = NULL;
-fpHIDGetNextDeviceElementtype fpHIDGetNextDeviceElement = NULL;
-fpHIDGetPreviousDeviceElementtype fpHIDGetPreviousDeviceElement = NULL;
-fpHIDGetTypeNametype fpHIDGetTypeName = NULL;
-fpHIDGetUsageNametype fpHIDGetUsageName = NULL;
-fpHIDQueueElementtype fpHIDQueueElement = NULL;
-fpHIDQueueDevicetype fpHIDQueueDevice = NULL;
-fpHIDDequeueElementtype fpHIDDequeueElement = NULL;
-fpHIDDequeueDevicetype fpHIDDequeueDevice = NULL;
-fpHIDGetEventtype fpHIDGetEvent = NULL;
-fpHIDGetElementValuetype fpHIDGetElementValue = NULL;
-fpHIDCalibrateValuetype fpHIDCalibrateValue = NULL;
-fpHIDScaleValuetype fpHIDScaleValue = NULL;
-fpHIDConfigureActiontype fpHIDConfigureAction = NULL;
-fpHIDSaveElementConfigtype fpHIDSaveElementConfig = NULL;
-fpHIDRestoreElementConfigtype fpHIDRestoreElementConfig = NULL;
+// ==================================
+// define a ProcPtr type for each API
+#define DO_API(r,n,p,a) typedef r (*fp##n##Type)##p;
+#include "HID_APIs.h"
-//globals
+// ==================================
+// declare storage for each API's function pointers
+#define DO_API(r,n,p,a) static fp##n##Type fp##n = NULL;
+#include "HID_APIs.h"
+// ==================================
+// globals
+// ==================================
CFURLRef gBundleURL = NULL;
CFBundleRef gBundle = NULL;
// ==================================
-
+// setup the CFM to MachO (HID) connection
+// ==================================
OSStatus SetupHIDCFM (void)
{
Boolean didLoad = false; // Flag that indicates the status returned when attempting to load a bundle's executable code.
@@ -121,6 +127,7 @@ OSStatus SetupHIDCFM (void)
DebugStr ("\pCould open main bundle");
return paramErr;
}
+
// create a URL to the app bundle
refMainBundleURL = CFBundleCopyBundleURL (refMainBundle);
if (!refMainBundleURL)
@@ -128,8 +135,9 @@ OSStatus SetupHIDCFM (void)
DebugStr ("\pCould not copy main bundle URL");
return paramErr;
}
+#if 0 // This should only be true if the app is bundled
// create a URL that points to the app's directory
- refPathBundleURL = CFURLCreateCopyDeletingLastPathComponent (NULL, refMainBundleURL);
+ refPathBundleURL = CFURLCreateCopyDeletingLastPathComponent (kCFAllocatorDefault, refMainBundleURL);
if (!refPathBundleURL)
{
DebugStr ("\pCould not create new parent URL deleting last path component");
@@ -137,8 +145,13 @@ OSStatus SetupHIDCFM (void)
CFRelease (refMainBundleURL);
return paramErr;
}
+#else
+ refPathBundleURL = refMainBundleURL;
+ refMainBundleURL = NULL;
+#endif
+
// create a URL to the HID library bundle
- gBundleURL = CFURLCreateCopyAppendingPathComponent (NULL, refPathBundleURL, CFSTR("HID.bundle"), true);
+ gBundleURL = CFURLCreateCopyAppendingPathComponent (kCFAllocatorDefault, refPathBundleURL, CFSTR("HID.bundle"), true);
// release created URLs
if (refMainBundleURL != NULL)
CFRelease (refMainBundleURL);
@@ -147,74 +160,41 @@ OSStatus SetupHIDCFM (void)
// did we actaully get a bundle URL
if (!gBundleURL)
{
- DebugStr ("\pCould create HID bundle URL");
+ DebugStr ("\pCould not create HID bundle URL");
return paramErr;
}
// get the actual bundle for the HID library
- gBundle = CFBundleCreate (NULL, gBundleURL);
+ gBundle = CFBundleCreate (kCFAllocatorDefault, gBundleURL);
if (!gBundle)
{
DebugStr ("\pCould not create HID MachO library bundle");
+ CFShow(gBundleURL);
return paramErr;
}
+
if (!CFBundleLoadExecutable (gBundle)) // If the code was successfully loaded, look for our function.
{
DebugStr ("\pCould not load MachO executable");
return paramErr;
}
- // Now that the code is loaded, search for the function we want by name.
- fpHIDBuildDeviceList = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDBuildDeviceList"));
- fpHIDReleaseDeviceList = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDReleaseDeviceList"));
- fpHIDHaveDeviceList = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDHaveDeviceList"));
- fpHIDCountDevices = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDCountDevices"));
- fpHIDCountDeviceElements = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDCountDeviceElements"));
- fpHIDGetFirstDevice = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetFirstDevice"));
- fpHIDGetNextDevice = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetNextDevice"));
- fpHIDGetFirstDeviceElement = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetFirstDeviceElement"));
- fpHIDGetNextDeviceElement = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetNextDeviceElement"));
- fpHIDGetPreviousDeviceElement = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetPreviousDeviceElement"));
- fpHIDGetTypeName = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetTypeName"));
- fpHIDGetUsageName = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetUsageName"));
- fpHIDQueueElement = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDQueueElement"));
- fpHIDQueueDevice = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDQueueDevice"));
- fpHIDDequeueElement = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDDequeueElement"));
- fpHIDDequeueDevice = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDDequeueDevice"));
- fpHIDGetEvent = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetEvent"));
- fpHIDGetElementValue = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDGetElementValue"));
- fpHIDCalibrateValue = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDCalibrateValue"));
- fpHIDScaleValue = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDScaleValue"));
- fpHIDConfigureAction = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDConfigureAction"));
- fpHIDSaveElementConfig = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDSaveElementConfig"));
- fpHIDRestoreElementConfig = (void *) CFBundleGetFunctionPointerForName (gBundle, CFSTR("HIDRestoreElementConfig"));
+
+ // Now that the code is loaded, search for the functions we want by name.
+ // for each API, look up it's function pointer and store it the local ProcPtr.
+
+#define DO_API(r,n,p,a) fp##n = (fp##n##Type) CFBundleGetFunctionPointerForName (gBundle, CFSTR(#n));;
+#include "HID_APIs.h"
+
return noErr;
}
-
+// ==================================
+// tear down the CFM to MachO (HID) connection
+// ==================================
void TearDownHIDCFM (void)
{
- // disassociate function pointers
- fpHIDBuildDeviceList = NULL;
- fpHIDReleaseDeviceList = NULL;
- fpHIDHaveDeviceList = NULL;
- fpHIDCountDevices = NULL;
- fpHIDCountDeviceElements = NULL;
- fpHIDGetFirstDevice = NULL;
- fpHIDGetNextDevice = NULL;
- fpHIDGetFirstDeviceElement = NULL;
- fpHIDGetNextDeviceElement = NULL;
- fpHIDGetPreviousDeviceElement = NULL;
- fpHIDGetTypeName = NULL;
- fpHIDGetUsageName = NULL;
- fpHIDQueueElement = NULL;
- fpHIDQueueDevice = NULL;
- fpHIDDequeueElement = NULL;
- fpHIDDequeueDevice = NULL;
- fpHIDGetEvent = NULL;
- fpHIDGetElementValue = NULL;
- fpHIDCalibrateValue = NULL;
- fpHIDScaleValue = NULL;
- fpHIDConfigureAction = NULL;
- fpHIDSaveElementConfig = NULL;
- fpHIDRestoreElementConfig = NULL;
+ // disassociate function pointers (assign null to each one)
+#define DO_API(r,n,p,a) fp##n = NULL;
+#include "HID_APIs.h"
+
if (gBundle != NULL)
{
CFBundleUnloadExecutable (gBundle); // Unload the bundle's executable code.
@@ -224,125 +204,10 @@ void TearDownHIDCFM (void)
}
}
-unsigned char HIDBuildDeviceList (unsigned long usagePage, unsigned long usage)
-{
- return (*fpHIDBuildDeviceList) (usagePage, usage);
-}
-
-void HIDReleaseDeviceList (void)
-{
- (*fpHIDReleaseDeviceList) ();
-}
-
-unsigned char HIDHaveDeviceList (void)
-{
- return (*fpHIDHaveDeviceList) ();
-}
-
-unsigned long HIDCountDevices (void)
-{
- return (*fpHIDCountDevices) ();
-}
-
-unsigned long HIDCountDeviceElements (pRecDevice pDevice, HIDElementTypeMask typeMask)
-{
- return (*fpHIDCountDeviceElements) (pDevice, typeMask);
-}
-
-pRecDevice HIDGetFirstDevice (void)
-{
- return (*fpHIDGetFirstDevice) ();
-}
-
-pRecDevice HIDGetNextDevice (pRecDevice pDevice)
-{
- return (*fpHIDGetNextDevice) (pDevice);
-}
-
-pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeMask typeMask)
-{
- return (*fpHIDGetFirstDeviceElement) (pDevice, typeMask);
-}
-
-pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask)
-{
- return (*fpHIDGetNextDeviceElement) (pElement, typeMask);
-}
-
-pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask)
-{
- return (*fpHIDGetPreviousDeviceElement) (pElement, typeMask);
-}
-
-void HIDGetTypeName (unsigned long type, char * cstrName)
-{
- (*fpHIDGetTypeName) (type, cstrName);
-}
-
-void HIDGetUsageName (long valueUsagePage, long valueUsage, char * cstrName)
-{
- (*fpHIDGetUsageName) (valueUsagePage, valueUsage, cstrName);
-}
+// Now for each API declare a (CFM) routine that calls thru the local ProcPtr to the MachO glue.
+// Note: we use two different macros here: with & without a return value.
+#define DO_API(r,n,p,a) void n##p { (*fp##n)##a;}
+#define DO_APIr(r,n,p,a) r n##p { return (r) (*fp##n)##a;}
+#include "HID_APIs.h"
// ==================================
-
-// Element Event Queue and Value Interfaces
-
-unsigned long HIDQueueElement (pRecDevice pDevice, pRecElement pElement)
-{
- return (*fpHIDQueueElement) (pDevice, pElement);
-}
-
-unsigned long HIDQueueDevice (pRecDevice pDevice)
-{
- return (*fpHIDQueueDevice) (pDevice);
-}
-
-unsigned long HIDDequeueElement (pRecDevice pDevice, pRecElement pElement)
-{
- return (*fpHIDDequeueElement) (pDevice, pElement);
-}
-
-unsigned long HIDDequeueDevice (pRecDevice pDevice)
-{
- return (*fpHIDDequeueDevice) (pDevice);
-}
-
-unsigned char HIDGetEvent (pRecDevice pDevice, void * pHIDEvent)
-{
- return (*fpHIDGetEvent) (pDevice, pHIDEvent);
-}
-
-long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement)
-{
- return (*fpHIDGetElementValue) (pDevice, pElement);
-}
-
-long HIDCalibrateValue (long value, pRecElement pElement)
-{
- return (*fpHIDCalibrateValue) (value, pElement);
-}
-
-long HIDScaleValue (long value, pRecElement pElement)
-{
- return (*fpHIDScaleValue) (value, pElement);
-}
-
-// ==================================
-
-// Conguration and Save Interfaces
-
-unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout)
-{
- return (*fpHIDConfigureAction) (ppDevice, ppElement, timeout);
-}
-
-void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie)
-{
- (*fpHIDSaveElementConfig) (fileRef, pDevice, pElement, actionCookie);
-}
-
-long HIDRestoreElementConfig (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement)
-{
- return (*fpHIDRestoreElementConfig) (fileRef, ppDevice, ppElement);
-}
diff --git a/HID Utilities Source/HID_Utilities_CFM.h b/HID Utilities Source/HID_Utilities_CFM.h
index 3983b87..305916a 100755
--- a/HID Utilities Source/HID_Utilities_CFM.h
+++ b/HID Utilities Source/HID_Utilities_CFM.h
@@ -41,6 +41,7 @@
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
*/
#ifndef _HID_Utilities_CFM_h_
@@ -58,22 +59,6 @@ extern "C" {
#include "HID_Utilities_External.h"
-// from IOHIDKeys.h (IOKit)
-// this can't be included since the roginal file has framework includes
-// developers may need to add definitions here
-
-enum IOHIDElementType
-{
- kIOHIDElementTypeInput_Misc = 1,
- kIOHIDElementTypeInput_Button = 2,
- kIOHIDElementTypeInput_Axis = 3,
- kIOHIDElementTypeInput_ScanCodes = 4,
- kIOHIDElementTypeOutput = 129,
- kIOHIDElementTypeFeature = 257,
- kIOHIDElementTypeCollection = 513
-};
-typedef enum IOHIDElementType IOHIDElementType;
-
// ==================================
// sets up CFM function pointers. Required to be called prior using an HID Utility function from CFM
diff --git a/HID Utilities Source/HID_Utilities_External.h b/HID Utilities Source/HID_Utilities_External.h
index f364354..62a52ec 100755
--- a/HID Utilities Source/HID_Utilities_External.h
+++ b/HID Utilities Source/HID_Utilities_External.h
@@ -2,8 +2,10 @@
File: HID_Utilities_External.h
Contains: Definition of the HID Utilities exported functions
-
- DRI: George Warner
+ External interface for HID Utilities, can be used with either library or source
+ Check notes below for usage. Some type casting is required so library is framework and carbon free
+
+ DRI: George Warner
Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved
@@ -41,34 +43,66 @@
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
*/
#ifndef _HID_Utilities_External_h_
#define _HID_Utilities_External_h_
+// ==================================
+#if PRAGMA_ONCE
+#pragma once
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if PRAGMA_IMPORT
+#pragma import on
+#endif
+
+#pragma options align=mac68k
// ==================================
//includes
#if TARGET_RT_MAC_CFM
- typedef void (*IOHIDCallbackFunction)(void * target, unsigned long result, void* refcon, void * sender);
+// from IOHIDKeys.h (IOKit)
+// this can't be included since the orginal file has framework includes
+// developers may need to add definitions here
+enum IOHIDElementType
+{
+ kIOHIDElementTypeInput_Misc = 1,
+ kIOHIDElementTypeInput_Button = 2,
+ kIOHIDElementTypeInput_Axis = 3,
+ kIOHIDElementTypeInput_ScanCodes = 4,
+ kIOHIDElementTypeOutput = 129,
+ kIOHIDElementTypeFeature = 257,
+ kIOHIDElementTypeCollection = 513
+};
+typedef enum IOHIDElementType IOHIDElementType;
+
+enum IOHIDReportType
+{
+ kIOHIDReportTypeInput = 0,
+ kIOHIDReportTypeOutput,
+ kIOHIDReportTypeFeature,
+ kIOHIDReportTypeCount
+};
+typedef enum IOHIDReportType IOHIDReportType;
+typedef void (*IOHIDCallbackFunction)(void * target, unsigned long result, void* refcon, void * sender);
+typedef void* IOHIDEventStruct;
#else
#include <IOKit/hid/IOHIDLib.h>
#endif TARGET_RT_MAC_CFM
-#include <stdio.h>
-
#if 0
#include <IOKit/hid/IOHIDUsageTables.h>
-#include "PID.h" // NOTE: These are now in <IOHIDUsageTables.h>
-#include "IOHIDPowerUsage.h" // NOTE: These are now in <IOHIDUsageTables.h>
+#include "PID.h" // NOTE: These are now in <IOKit/hid/IOHIDUsageTables.h>
+#include "IOHIDPowerUsage.h" // NOTE: These are now in <IOKit/hid/IOHIDUsageTables.h>
#endif
-// ==================================
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <stdio.h>
// ==================================
// Device and Element Interfaces
@@ -104,8 +138,10 @@ struct recElement
char name[256]; // name of element (c string)
// runtime variables
- long calMin; // min returned value
- long calMax; // max returned value (calibrate call)
+ long initialCenter; // center value at start up
+ unsigned char hasCenter; // whether or not to use center for calibration
+ long minReport; // min returned value
+ long maxReport; // max returned value (calibrate call)
long userMin; // user set value to scale to (scale call)
long userMax;
@@ -163,8 +199,22 @@ extern unsigned long HIDCreateOpenDeviceInterface (UInt32 hidDevice, pRecDevice
// list is allcoated internally within HID Utilites and can be accessed via accessor functions
// structures within list are considered flat and user accessable, butnot user modifiable
// can be called again to rebuild list to account for new devices (will do the right thing in case of disposing existing list)
+// usagePage, usage are each a numDeviceTypes sized array of matching usage and usage pages
+// returns true if succesful
+
+extern Boolean HIDBuildMultiDeviceList (UInt32 *pUsagePage, UInt32 *pUsage, UInt32 numDeviceTypes);
+
+// same as above but this uses a single usagePage and usage
+
extern Boolean HIDBuildDeviceList (UInt32 usagePage, UInt32 usage);
+// updates the current device list for any new/removed devices
+// if this is called before HIDBuildDeviceList the it functions like HIDBuildMultiDeviceList
+// usagePage, usage are each a numDeviceTypes sized array of matching usage and usage pages
+// returns true if successful which means if any device were added or removed (the device config changed)
+
+extern Boolean HIDUpdateDeviceList (UInt32 *pUsagePage, UInt32 *pUsage, UInt32 numDeviceTypes);
+
// release list built by above function
// MUST be called prior to application exit to properly release devices
// if not called (or app crashes) devices can be recovered by pluging into different location in USB chain
@@ -205,12 +255,15 @@ extern pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeM
extern pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask);
// get previous element of given device in list given current element as parameter
-// this wlaks directly up the tree to the top element and does not search at each level
+// this walks directly up the tree to the top element and does not search at each level
// returns NULL if beginning of list
// uses mask of HIDElementTypeMask to restrict element found
// use kHIDElementTypeIO to get non-collection elements
extern pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask);
+// ==================================
+// Name Lookup Interfaces
+
// returns C string type name given a type enumeration passed in as parameter (see IOHIDKeys.h)
// returns empty string for invlid types
extern void HIDGetTypeName (IOHIDElementType theType, char * cstrName);
@@ -225,14 +278,6 @@ extern Boolean HIDGetElementNameFromVendorProductUsage (const long vendorID, con
// returns usage page and usage values in string form for unknown values
extern void HIDGetUsageName (long valueUsagePage, long valueUsage, char * cstrName);
-// returns calibrated value given raw value passed in
-// calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values
-extern SInt32 HIDCalibrateValue (SInt32 value, pRecElement pElement);
-
-// returns scaled value given raw value passed in
-// scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values
-extern SInt32 HIDScaleValue (SInt32 value, pRecElement pElement);
-
// ---------------------------------
// convert an element type to a mask
extern HIDElementTypeMask HIDConvertElementTypeToMask (const long type);
@@ -311,61 +356,26 @@ extern long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement);
extern long HIDSetElementValue (pRecDevice pDevice, pRecElement pElement,void* pIOHIDEvent);
// Set a callback to be called when a queue goes from empty to non-empty
-extern long HIDSetQueueCallback (pRecDevice pDevice, IOHIDCallbackFunction callback);
+extern long HIDSetQueueCallback (pRecDevice pDevice, IOHIDCallbackFunction callback,void* callbackTarget, void* callbackRefcon);
-#if 0
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
// Get a report from a device
extern long HIDGetReport (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, unsigned long* reportBufferSize);
// Send a report to a device
extern long HIDSetReport (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, const unsigned long reportBufferSize);
-#endif
+#endif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
// ==================================
// HUD utilities interfaces
// returns calibrated value given raw value passed in
// calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values
-extern long HIDCalibrateValue (long value, pRecElement pElement);
+extern SInt32 HIDCalibrateValue (SInt32 value, pRecElement pElement);
// returns scaled value given raw value passed in
// scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values
-extern long HIDScaleValue (long value, pRecElement pElement);
-
-// convert an element type to a mask
-extern HIDElementTypeMask HIDConvertElementTypeToMask (const long type);
-
-// find this device
-extern Boolean HIDFindDevice(const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice);
-
-// find the device and element for this action
-// Device: serial, vendorID, productID, location, usagePage, usage
-// Element: cookie, usagePage, usage,
-extern Boolean HIDFindActionDeviceAndElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement,
- pRecDevice *ppFoundDevice, pRecElement *ppFoundElement);
-// find the device and element for this action
-// Device: serial, vendorID, productID, location, usagePage, usage
-// Element: cookie, usagePage, usage,
-
-extern Boolean HIDFindSubElement(const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement);
-
-// print out all of an elements information
-extern int HIDPrintElement(const pRecElement pElement);
-
-// return true if this is a valid device pointer
-extern Boolean HIDIsValidDevice(const pRecDevice pSearchDevice);
-
-// return true if this is a valid element pointer for this device
-extern Boolean HIDIsValidElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement);
-
-// ==================================
-// Name Lookup Interfaces
-
-// set name from vendor id/product id look up (using cookies)
-extern Boolean HIDGetElementNameFromVendorProductCookie (const long vendorID, const long productID, const long cookie, char * pName);
-
-// set name from vendor id/product id look up (using usage page & usage)
-extern Boolean HIDGetElementNameFromVendorProductUsage (const long vendorID, const long productID, const long pUsagePage, const long pUsage, char * pName);
+extern SInt32 HIDScaleValue (SInt32 value, pRecElement pElement);
// ==================================
// Conguration and Save Interfaces
@@ -396,14 +406,19 @@ typedef struct recSaveHID
// returns false and NULL for both parameters if not found
extern unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout);
+// -- These are routines to use if the applcation wants HID Utilities to do the file handling --
+// Note: the FILE* is a MachO posix FILE and will not work with the MW MSL FILE* type.
+
// take input records, save required info
// assume file is open and at correct position.
-extern void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie);
+extern void HIDSaveElementConfig (FILE* fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie);
// take file, read one record (assume file position is correct and file is open)
// search for matching device
// return pDevice, pElement and cookie for action
-extern long HIDRestoreElementConfig (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement);
+extern long HIDRestoreElementConfig (FILE* fileRef, pRecDevice * ppDevice, pRecElement * ppElement);
+
+// -- These routines use the CFPreferences API's.
// Save the device & element values into the specified key in the specified applications preferences
extern Boolean HIDSaveElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement);
@@ -414,6 +429,19 @@ extern Boolean HIDSaveElementPref (CFStringRef keyCFStringRef, CFStringRef appCF
extern Boolean HIDRestoreElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement);
+// -- These are routines to use if the client wants to use their own file handling --
+
+// Set up a config record for saving
+// takes an input records, returns record user can save as they want
+// Note: the save rec must be pre-allocated by the calling app and will be filled out
+extern void HIDSetElementConfig (pRecSaveHID pConfigRec, pRecDevice pDevice, pRecElement pElement, long actionCookie);
+
+// Get matching element from config record
+// takes a pre-allocated and filled out config record
+// search for matching device
+// return pDevice, pElement and cookie for action
+extern long HIDGetElementConfig (pRecSaveHID pConfigRec, pRecDevice * ppDevice, pRecElement * ppElement);
+
// ==================================
// Output Transaction interface
@@ -465,9 +493,17 @@ extern unsigned long HIDTransactionCommit(pRecDevice pDevice);
extern unsigned long HIDTransactionClear(pRecDevice pDevice);
// ==================================
+#pragma options align=reset
+
+#ifdef PRAGMA_IMPORT_OFF
+#pragma import off
+#elif PRAGMA_IMPORT
+#pragma import reset
+#endif
#ifdef __cplusplus
}
#endif
+// ==================================
#endif // _HID_Utilities_External_h_
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 <mach/mach.h>
+#include <mach/mach_error.h>
+
+#include <IOKit/IOKitLib.h>
+#include <IOKit/IOCFPlugIn.h>
+#include <IOKit/hid/IOHIDLib.h>
+#include <IOKit/hid/IOHIDUsageTables.h>
+
+#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
diff --git a/HID Utilities Source/ImmrHIDUtilAddOn.h b/HID Utilities Source/ImmrHIDUtilAddOn.h
new file mode 100755
index 0000000..2f3ea24
--- /dev/null
+++ b/HID Utilities Source/ImmrHIDUtilAddOn.h
@@ -0,0 +1,11 @@
+/*
+ * ImmrHIDUtilAddOn.h
+ * UseFFAPIFromHIDUtilities
+ *
+ * Created by rlacroix on Wed Oct 16 2002.
+ * Copyright (c) 2002 Immersion Corporation. All rights reserved.
+ *
+ */
+
+extern io_object_t AllocateHIDObjectFromRecDevice( pRecDevice pDevice );
+extern Boolean FreeHIDObject( io_object_t hidDevice ); \ No newline at end of file