src/joystick/darwin/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 27 Aug 2008 15:10:03 +0000
changeset 2735 204be4fc2726
parent 2713 0906692aa6a4
child 2776 caf3d5b2153f
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga
slouken@172
     1
/*
slouken@172
     2
	SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@172
     4
slouken@172
     5
	This library is free software; you can redistribute it and/or
slouken@172
     6
	modify it under the terms of the GNU Library General Public
slouken@172
     7
	License as published by the Free Software Foundation; either
slouken@172
     8
	version 2 of the License, or (at your option) any later version.
slouken@172
     9
slouken@172
    10
	This library is distributed in the hope that it will be useful,
slouken@172
    11
	but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@172
    12
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@172
    13
	Library General Public License for more details.
slouken@172
    14
slouken@172
    15
	You should have received a copy of the GNU Library General Public
slouken@172
    16
	License along with this library; if not, write to the Free
slouken@172
    17
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@172
    18
slouken@172
    19
	Sam Lantinga
slouken@252
    20
	slouken@libsdl.org
slouken@172
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@172
    23
slouken@1635
    24
#ifdef SDL_JOYSTICK_IOKIT
slouken@1635
    25
slouken@1621
    26
/* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */
slouken@172
    27
/* Written 2001 by Max Horn */
slouken@172
    28
slouken@172
    29
#include <unistd.h>
slouken@172
    30
#include <ctype.h>
slouken@172
    31
#include <sysexits.h>
slouken@172
    32
#include <mach/mach.h>
slouken@172
    33
#include <mach/mach_error.h>
slouken@172
    34
#include <IOKit/IOKitLib.h>
slouken@172
    35
#include <IOKit/IOCFPlugIn.h>
slouken@209
    36
#ifdef MACOS_10_0_4
slouken@209
    37
#include <IOKit/hidsystem/IOHIDUsageTables.h>
slouken@209
    38
#else
slouken@1621
    39
/* The header was moved here in Mac OS X 10.1 */
slouken@208
    40
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
slouken@209
    41
#endif
slouken@2110
    42
#if MAC_OS_X_VERSION_MIN_REQUIRED == 1030
slouken@2110
    43
#include "10.3.9-FIX/IOHIDLib.h"
slouken@2110
    44
#else
slouken@172
    45
#include <IOKit/hid/IOHIDLib.h>
slouken@2110
    46
#endif
slouken@172
    47
#include <IOKit/hid/IOHIDKeys.h>
slouken@172
    48
#include <CoreFoundation/CoreFoundation.h>
slouken@1895
    49
#include <Carbon/Carbon.h>      /* for NewPtrClear, DisposePtr */
slouken@172
    50
slouken@2713
    51
/* For force feedback testing. */
slouken@2713
    52
#include <ForceFeedback/ForceFeedback.h>
slouken@2713
    53
#include <ForceFeedback/ForceFeedbackConstants.h>
slouken@2713
    54
slouken@172
    55
#include "SDL_joystick.h"
slouken@1361
    56
#include "../SDL_sysjoystick.h"
slouken@1361
    57
#include "../SDL_joystick_c.h"
slouken@2713
    58
#include "SDL_sysjoystick_c.h"
slouken@172
    59
slouken@172
    60
slouken@172
    61
/* Linked list of all available devices */
slouken@172
    62
static recDevice *gpDeviceList = NULL;
slouken@172
    63
slouken@172
    64
slouken@1895
    65
static void
slouken@1895
    66
HIDReportErrorNum(char *strError, long numError)
slouken@172
    67
{
slouken@1895
    68
    SDL_SetError(strError);
slouken@172
    69
}
slouken@172
    70
slouken@1895
    71
static void HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
    72
                                     recDevice * pDevice);
slouken@172
    73
slouken@172
    74
/* returns current value for element, polling element
slouken@172
    75
 * will return 0 on error conditions which should be accounted for by application
slouken@172
    76
 */
slouken@172
    77
slouken@1895
    78
static SInt32
slouken@1895
    79
HIDGetElementValue(recDevice * pDevice, recElement * pElement)
slouken@172
    80
{
slouken@1895
    81
    IOReturn result = kIOReturnSuccess;
slouken@1895
    82
    IOHIDEventStruct hidEvent;
slouken@1895
    83
    hidEvent.value = 0;
slouken@172
    84
slouken@1895
    85
    if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) {
slouken@1895
    86
        result =
slouken@1895
    87
            (*(pDevice->interface))->getElementValue(pDevice->interface,
slouken@1895
    88
                                                     pElement->cookie,
slouken@1895
    89
                                                     &hidEvent);
slouken@1895
    90
        if (kIOReturnSuccess == result) {
slouken@1895
    91
            /* record min and max for auto calibration */
slouken@1895
    92
            if (hidEvent.value < pElement->minReport)
slouken@1895
    93
                pElement->minReport = hidEvent.value;
slouken@1895
    94
            if (hidEvent.value > pElement->maxReport)
slouken@1895
    95
                pElement->maxReport = hidEvent.value;
slouken@1895
    96
        }
slouken@1895
    97
    }
slouken@1895
    98
slouken@1895
    99
    /* auto user scale */
slouken@1895
   100
    return hidEvent.value;
slouken@172
   101
}
slouken@172
   102
slouken@1895
   103
static SInt32
slouken@1895
   104
HIDScaledCalibratedValue(recDevice * pDevice, recElement * pElement,
slouken@1895
   105
                         long min, long max)
slouken@172
   106
{
slouken@1895
   107
    float deviceScale = max - min;
slouken@1895
   108
    float readScale = pElement->maxReport - pElement->minReport;
slouken@1895
   109
    SInt32 value = HIDGetElementValue(pDevice, pElement);
slouken@1895
   110
    if (readScale == 0)
slouken@1895
   111
        return value;           /* no scaling at all */
slouken@1895
   112
    else
slouken@1895
   113
        return ((value - pElement->minReport) * deviceScale / readScale) +
slouken@1895
   114
            min;
slouken@172
   115
}
slouken@172
   116
slouken@858
   117
slouken@1895
   118
static void
slouken@1895
   119
HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
slouken@858
   120
{
slouken@1895
   121
    recDevice *device = (recDevice *) refcon;
slouken@1895
   122
    device->removed = 1;
slouken@1895
   123
    device->uncentered = 1;
slouken@858
   124
}
slouken@858
   125
slouken@858
   126
slouken@858
   127
slouken@172
   128
/* Create and open an interface to device, required prior to extracting values or building queues.
slouken@172
   129
 * Note: appliction now owns the device and must close and release it prior to exiting
slouken@172
   130
 */
slouken@172
   131
slouken@1895
   132
static IOReturn
slouken@1895
   133
HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
slouken@172
   134
{
slouken@1895
   135
    IOReturn result = kIOReturnSuccess;
slouken@1895
   136
    HRESULT plugInResult = S_OK;
slouken@1895
   137
    SInt32 score = 0;
slouken@1895
   138
    IOCFPlugInInterface **ppPlugInInterface = NULL;
slouken@858
   139
slouken@1895
   140
    if (NULL == pDevice->interface) {
slouken@1895
   141
        result =
slouken@1895
   142
            IOCreatePlugInInterfaceForService(hidDevice,
slouken@1895
   143
                                              kIOHIDDeviceUserClientTypeID,
slouken@1895
   144
                                              kIOCFPlugInInterfaceID,
slouken@1895
   145
                                              &ppPlugInInterface, &score);
slouken@1895
   146
        if (kIOReturnSuccess == result) {
slouken@1895
   147
            /* Call a method of the intermediate plug-in to create the device interface */
slouken@1895
   148
            plugInResult =
slouken@1895
   149
                (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
slouken@1895
   150
                                                     CFUUIDGetUUIDBytes
slouken@1895
   151
                                                     (kIOHIDDeviceInterfaceID),
slouken@2735
   152
                                                     (void *)
slouken@2735
   153
                                                     &(pDevice->interface));
slouken@1895
   154
            if (S_OK != plugInResult)
slouken@1895
   155
                HIDReportErrorNum
slouken@1895
   156
                    ("CouldnŐt query HID class device interface from plugInInterface",
slouken@1895
   157
                     plugInResult);
slouken@1895
   158
            (*ppPlugInInterface)->Release(ppPlugInInterface);
slouken@1895
   159
        } else
slouken@1895
   160
            HIDReportErrorNum
slouken@1895
   161
                ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.",
slouken@1895
   162
                 result);
slouken@1895
   163
    }
slouken@1895
   164
    if (NULL != pDevice->interface) {
slouken@1895
   165
        result = (*(pDevice->interface))->open(pDevice->interface, 0);
slouken@1895
   166
        if (kIOReturnSuccess != result)
slouken@1895
   167
            HIDReportErrorNum
slouken@1895
   168
                ("Failed to open pDevice->interface via open.", result);
slouken@1895
   169
        else
slouken@1895
   170
            (*(pDevice->interface))->setRemovalCallback(pDevice->interface,
slouken@1895
   171
                                                        HIDRemovalCallback,
slouken@1895
   172
                                                        pDevice, pDevice);
slouken@1895
   173
slouken@1895
   174
    }
slouken@1895
   175
    return result;
slouken@172
   176
}
slouken@172
   177
slouken@172
   178
/* Closes and releases interface to device, should be done prior to exting application
slouken@172
   179
 * Note: will have no affect if device or interface do not exist
slouken@172
   180
 * application will "own" the device if interface is not closed
slouken@172
   181
 * (device may have to be plug and re-plugged in different location to get it working again without a restart)
slouken@172
   182
 */
slouken@172
   183
slouken@1895
   184
static IOReturn
slouken@1895
   185
HIDCloseReleaseInterface(recDevice * pDevice)
slouken@172
   186
{
slouken@1895
   187
    IOReturn result = kIOReturnSuccess;
slouken@1895
   188
slouken@1895
   189
    if ((NULL != pDevice) && (NULL != pDevice->interface)) {
slouken@1895
   190
        /* close the interface */
slouken@1895
   191
        result = (*(pDevice->interface))->close(pDevice->interface);
slouken@1895
   192
        if (kIOReturnNotOpen == result) {
slouken@1895
   193
            /* do nothing as device was not opened, thus can't be closed */
slouken@1895
   194
        } else if (kIOReturnSuccess != result)
slouken@1895
   195
            HIDReportErrorNum("Failed to close IOHIDDeviceInterface.",
slouken@1895
   196
                              result);
slouken@1895
   197
        /* release the interface */
slouken@1895
   198
        result = (*(pDevice->interface))->Release(pDevice->interface);
slouken@1895
   199
        if (kIOReturnSuccess != result)
slouken@1895
   200
            HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
slouken@1895
   201
                              result);
slouken@1895
   202
        pDevice->interface = NULL;
slouken@1895
   203
    }
slouken@1895
   204
    return result;
slouken@172
   205
}
slouken@172
   206
slouken@172
   207
/* extracts actual specific element information from each element CF dictionary entry */
slouken@172
   208
slouken@1895
   209
static void
slouken@1895
   210
HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
slouken@172
   211
{
slouken@1895
   212
    long number;
slouken@1895
   213
    CFTypeRef refType;
slouken@172
   214
slouken@1895
   215
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
slouken@1895
   216
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
slouken@1895
   217
        pElement->cookie = (IOHIDElementCookie) number;
slouken@1895
   218
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
slouken@1895
   219
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   220
        pElement->minReport = pElement->min = number;
slouken@1895
   221
    pElement->maxReport = pElement->min;
slouken@1895
   222
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
slouken@1895
   223
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   224
        pElement->maxReport = pElement->max = number;
slouken@172
   225
/*
slouken@172
   226
	TODO: maybe should handle the following stuff somehow?
slouken@172
   227
slouken@172
   228
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
slouken@172
   229
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   230
		pElement->scaledMin = number;
slouken@172
   231
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
slouken@172
   232
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   233
		pElement->scaledMax = number;
slouken@172
   234
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
slouken@172
   235
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   236
		pElement->size = number;
slouken@172
   237
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
slouken@172
   238
	if (refType)
slouken@172
   239
		pElement->relative = CFBooleanGetValue (refType);
slouken@172
   240
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
slouken@172
   241
	if (refType)
slouken@172
   242
		pElement->wrapping = CFBooleanGetValue (refType);
slouken@172
   243
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
slouken@172
   244
	if (refType)
slouken@172
   245
		pElement->nonLinear = CFBooleanGetValue (refType);
slouken@172
   246
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
slouken@172
   247
	if (refType)
slouken@172
   248
		pElement->preferredState = CFBooleanGetValue (refType);
slouken@172
   249
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
slouken@172
   250
	if (refType)
slouken@172
   251
		pElement->nullState = CFBooleanGetValue (refType);
slouken@172
   252
*/
slouken@1895
   253
}
slouken@172
   254
slouken@172
   255
/* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements
slouken@172
   256
 * if element of interest allocate storage, add to list and retrieve element specific info
slouken@172
   257
 * if collection then pass on to deconstruction collection into additional individual elements
slouken@172
   258
 */
slouken@172
   259
slouken@1895
   260
static void
slouken@1895
   261
HIDAddElement(CFTypeRef refElement, recDevice * pDevice)
slouken@172
   262
{
slouken@1895
   263
    recElement *element = NULL;
slouken@1895
   264
    recElement **headElement = NULL;
slouken@1895
   265
    long elementType, usagePage, usage;
slouken@1895
   266
    CFTypeRef refElementType =
slouken@1895
   267
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
slouken@1895
   268
    CFTypeRef refUsagePage =
slouken@1895
   269
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   270
    CFTypeRef refUsage =
slouken@1895
   271
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
slouken@172
   272
slouken@172
   273
slouken@1895
   274
    if ((refElementType)
slouken@1895
   275
        &&
slouken@1895
   276
        (CFNumberGetValue(refElementType, kCFNumberLongType, &elementType))) {
slouken@1895
   277
        /* look at types of interest */
slouken@1895
   278
        if ((elementType == kIOHIDElementTypeInput_Misc)
slouken@1895
   279
            || (elementType == kIOHIDElementTypeInput_Button)
slouken@1895
   280
            || (elementType == kIOHIDElementTypeInput_Axis)) {
slouken@1895
   281
            if (refUsagePage
slouken@1895
   282
                && CFNumberGetValue(refUsagePage, kCFNumberLongType,
slouken@1895
   283
                                    &usagePage) && refUsage
slouken@1895
   284
                && CFNumberGetValue(refUsage, kCFNumberLongType, &usage)) {
slouken@1895
   285
                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
slouken@1895
   286
                case kHIDPage_GenericDesktop:
slouken@1895
   287
                    {
slouken@1895
   288
                        switch (usage) {        /* look at usage to determine function */
slouken@1895
   289
                        case kHIDUsage_GD_X:
slouken@1895
   290
                        case kHIDUsage_GD_Y:
slouken@1895
   291
                        case kHIDUsage_GD_Z:
slouken@1895
   292
                        case kHIDUsage_GD_Rx:
slouken@1895
   293
                        case kHIDUsage_GD_Ry:
slouken@1895
   294
                        case kHIDUsage_GD_Rz:
slouken@1895
   295
                        case kHIDUsage_GD_Slider:
slouken@1895
   296
                        case kHIDUsage_GD_Dial:
slouken@1895
   297
                        case kHIDUsage_GD_Wheel:
slouken@1895
   298
                            element = (recElement *)
slouken@1895
   299
                                NewPtrClear(sizeof(recElement));
slouken@1895
   300
                            if (element) {
slouken@1895
   301
                                pDevice->axes++;
slouken@1895
   302
                                headElement = &(pDevice->firstAxis);
slouken@1895
   303
                            }
slouken@1895
   304
                            break;
slouken@1895
   305
                        case kHIDUsage_GD_Hatswitch:
slouken@1895
   306
                            element = (recElement *)
slouken@1895
   307
                                NewPtrClear(sizeof(recElement));
slouken@1895
   308
                            if (element) {
slouken@1895
   309
                                pDevice->hats++;
slouken@1895
   310
                                headElement = &(pDevice->firstHat);
slouken@1895
   311
                            }
slouken@1895
   312
                            break;
slouken@1895
   313
                        }
slouken@1895
   314
                    }
slouken@1895
   315
                    break;
slouken@1895
   316
                case kHIDPage_Button:
slouken@1895
   317
                    element = (recElement *)
slouken@1895
   318
                        NewPtrClear(sizeof(recElement));
slouken@1895
   319
                    if (element) {
slouken@1895
   320
                        pDevice->buttons++;
slouken@1895
   321
                        headElement = &(pDevice->firstButton);
slouken@1895
   322
                    }
slouken@1895
   323
                    break;
slouken@1895
   324
                default:
slouken@1895
   325
                    break;
slouken@1895
   326
                }
slouken@1895
   327
            }
slouken@1895
   328
        } else if (kIOHIDElementTypeCollection == elementType)
slouken@1895
   329
            HIDGetCollectionElements((CFMutableDictionaryRef) refElement,
slouken@1895
   330
                                     pDevice);
slouken@1895
   331
    }
slouken@172
   332
slouken@1895
   333
    if (element && headElement) {       /* add to list */
slouken@1895
   334
        pDevice->elements++;
slouken@1895
   335
        if (NULL == *headElement)
slouken@1895
   336
            *headElement = element;
slouken@1895
   337
        else {
slouken@1895
   338
            recElement *elementPrevious, *elementCurrent;
slouken@1895
   339
            elementCurrent = *headElement;
slouken@1895
   340
            while (elementCurrent) {
slouken@1895
   341
                elementPrevious = elementCurrent;
slouken@1895
   342
                elementCurrent = elementPrevious->pNext;
slouken@1895
   343
            }
slouken@1895
   344
            elementPrevious->pNext = element;
slouken@1895
   345
        }
slouken@1895
   346
        element->pNext = NULL;
slouken@1895
   347
        HIDGetElementInfo(refElement, element);
slouken@1895
   348
    }
slouken@172
   349
}
slouken@172
   350
slouken@172
   351
/* collects information from each array member in device element list (each array memeber = element) */
slouken@172
   352
slouken@1895
   353
static void
slouken@1895
   354
HIDGetElementsCFArrayHandler(const void *value, void *parameter)
slouken@172
   355
{
slouken@1895
   356
    if (CFGetTypeID(value) == CFDictionaryGetTypeID())
slouken@1895
   357
        HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
slouken@172
   358
}
slouken@172
   359
slouken@172
   360
/* handles retrieval of element information from arrays of elements in device IO registry information */
slouken@172
   361
slouken@1895
   362
static void
slouken@1895
   363
HIDGetElements(CFTypeRef refElementCurrent, recDevice * pDevice)
slouken@172
   364
{
slouken@1895
   365
    CFTypeID type = CFGetTypeID(refElementCurrent);
slouken@1895
   366
    if (type == CFArrayGetTypeID()) {   /* if element is an array */
slouken@1895
   367
        CFRange range = { 0, CFArrayGetCount(refElementCurrent) };
slouken@1895
   368
        /* CountElementsCFArrayHandler called for each array member */
slouken@1895
   369
        CFArrayApplyFunction(refElementCurrent, range,
slouken@1895
   370
                             HIDGetElementsCFArrayHandler, pDevice);
slouken@1895
   371
    }
slouken@1895
   372
}
slouken@172
   373
slouken@172
   374
/* handles extracting element information from element collection CF types
slouken@172
   375
 * used from top level element decoding and hierarchy deconstruction to flatten device element list
slouken@172
   376
 */
slouken@172
   377
slouken@1895
   378
static void
slouken@1895
   379
HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
   380
                         recDevice * pDevice)
slouken@172
   381
{
slouken@1895
   382
    CFTypeRef refElementTop =
slouken@1895
   383
        CFDictionaryGetValue(deviceProperties, CFSTR(kIOHIDElementKey));
slouken@1895
   384
    if (refElementTop)
slouken@1895
   385
        HIDGetElements(refElementTop, pDevice);
slouken@172
   386
}
slouken@172
   387
slouken@172
   388
/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
slouken@172
   389
slouken@1895
   390
static void
slouken@1895
   391
HIDTopLevelElementHandler(const void *value, void *parameter)
slouken@172
   392
{
slouken@1895
   393
    CFTypeRef refCF = 0;
slouken@1895
   394
    if (CFGetTypeID(value) != CFDictionaryGetTypeID())
slouken@1895
   395
        return;
slouken@1895
   396
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   397
    if (!CFNumberGetValue
slouken@1895
   398
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
slouken@1895
   399
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   400
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsageKey));
slouken@1895
   401
    if (!CFNumberGetValue
slouken@1895
   402
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
slouken@1895
   403
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
slouken@172
   404
}
slouken@172
   405
slouken@172
   406
/* extracts device info from CF dictionary records in IO registry */
slouken@172
   407
slouken@1895
   408
static void
slouken@1895
   409
HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
slouken@1895
   410
                 recDevice * pDevice)
slouken@172
   411
{
slouken@1895
   412
    CFMutableDictionaryRef usbProperties = 0;
slouken@1895
   413
    io_registry_entry_t parent1, parent2;
slouken@172
   414
slouken@1895
   415
    /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
slouken@1895
   416
     * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
slouken@1895
   417
     */
slouken@1895
   418
    if ((KERN_SUCCESS ==
slouken@1895
   419
         IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1))
slouken@1895
   420
        && (KERN_SUCCESS ==
slouken@1895
   421
            IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
slouken@1895
   422
        && (KERN_SUCCESS ==
slouken@1895
   423
            IORegistryEntryCreateCFProperties(parent2, &usbProperties,
slouken@1895
   424
                                              kCFAllocatorDefault,
slouken@1895
   425
                                              kNilOptions))) {
slouken@1895
   426
        if (usbProperties) {
slouken@1895
   427
            CFTypeRef refCF = 0;
slouken@1895
   428
            /* get device info
slouken@1895
   429
             * try hid dictionary first, if fail then go to usb dictionary
slouken@1895
   430
             */
slouken@172
   431
slouken@172
   432
slouken@1895
   433
            /* get product name */
slouken@1895
   434
            refCF =
slouken@1895
   435
                CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
slouken@1895
   436
            if (!refCF)
slouken@1895
   437
                refCF =
slouken@1895
   438
                    CFDictionaryGetValue(usbProperties,
slouken@1895
   439
                                         CFSTR("USB Product Name"));
slouken@1895
   440
            if (refCF) {
slouken@1895
   441
                if (!CFStringGetCString
slouken@1895
   442
                    (refCF, pDevice->product, 256,
slouken@1895
   443
                     CFStringGetSystemEncoding()))
slouken@1895
   444
                    SDL_SetError
slouken@1895
   445
                        ("CFStringGetCString error retrieving pDevice->product.");
slouken@1895
   446
            }
slouken@1895
   447
slouken@1895
   448
            /* get usage page and usage */
slouken@1895
   449
            refCF =
slouken@1895
   450
                CFDictionaryGetValue(hidProperties,
slouken@1895
   451
                                     CFSTR(kIOHIDPrimaryUsagePageKey));
slouken@1895
   452
            if (refCF) {
slouken@1895
   453
                if (!CFNumberGetValue
slouken@1895
   454
                    (refCF, kCFNumberLongType, &pDevice->usagePage))
slouken@1895
   455
                    SDL_SetError
slouken@1895
   456
                        ("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   457
                refCF =
slouken@1895
   458
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   459
                                         CFSTR(kIOHIDPrimaryUsageKey));
slouken@1895
   460
                if (refCF)
slouken@1895
   461
                    if (!CFNumberGetValue
slouken@1895
   462
                        (refCF, kCFNumberLongType, &pDevice->usage))
slouken@1895
   463
                        SDL_SetError
slouken@1895
   464
                            ("CFNumberGetValue error retrieving pDevice->usage.");
slouken@1895
   465
            }
slouken@1895
   466
slouken@1895
   467
            if (NULL == refCF) {        /* get top level element HID usage page or usage */
slouken@1895
   468
                /* use top level element instead */
slouken@1895
   469
                CFTypeRef refCFTopElement = 0;
slouken@1895
   470
                refCFTopElement =
slouken@1895
   471
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   472
                                         CFSTR(kIOHIDElementKey));
slouken@1895
   473
                {
slouken@1895
   474
                    /* refCFTopElement points to an array of element dictionaries */
slouken@1895
   475
                    CFRange range = { 0, CFArrayGetCount(refCFTopElement) };
slouken@1895
   476
                    CFArrayApplyFunction(refCFTopElement, range,
slouken@1895
   477
                                         HIDTopLevelElementHandler, pDevice);
slouken@1895
   478
                }
slouken@1895
   479
            }
slouken@1895
   480
slouken@1895
   481
            CFRelease(usbProperties);
slouken@1895
   482
        } else
slouken@1895
   483
            SDL_SetError
slouken@1895
   484
                ("IORegistryEntryCreateCFProperties failed to create usbProperties.");
slouken@1895
   485
slouken@1895
   486
        if (kIOReturnSuccess != IOObjectRelease(parent2))
slouken@1895
   487
            SDL_SetError("IOObjectRelease error with parent2.");
slouken@1895
   488
        if (kIOReturnSuccess != IOObjectRelease(parent1))
slouken@1895
   489
            SDL_SetError("IOObjectRelease error with parent1.");
slouken@1895
   490
    }
slouken@172
   491
}
slouken@172
   492
slouken@172
   493
slouken@1895
   494
static recDevice *
slouken@1895
   495
HIDBuildDevice(io_object_t hidDevice)
slouken@172
   496
{
slouken@1895
   497
    recDevice *pDevice = (recDevice *) NewPtrClear(sizeof(recDevice));
slouken@1895
   498
    if (pDevice) {
slouken@1895
   499
        /* get dictionary for HID properties */
slouken@1895
   500
        CFMutableDictionaryRef hidProperties = 0;
slouken@1895
   501
        kern_return_t result =
slouken@1895
   502
            IORegistryEntryCreateCFProperties(hidDevice, &hidProperties,
slouken@1895
   503
                                              kCFAllocatorDefault,
slouken@1895
   504
                                              kNilOptions);
slouken@1895
   505
        if ((result == KERN_SUCCESS) && hidProperties) {
slouken@1895
   506
            /* create device interface */
slouken@1895
   507
            result = HIDCreateOpenDeviceInterface(hidDevice, pDevice);
slouken@1895
   508
            if (kIOReturnSuccess == result) {
slouken@1895
   509
                HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
slouken@1895
   510
                HIDGetCollectionElements(hidProperties, pDevice);
slouken@1895
   511
            } else {
slouken@1895
   512
                DisposePtr((Ptr) pDevice);
slouken@1895
   513
                pDevice = NULL;
slouken@1895
   514
            }
slouken@1895
   515
            CFRelease(hidProperties);
slouken@1895
   516
        } else {
slouken@1895
   517
            DisposePtr((Ptr) pDevice);
slouken@1895
   518
            pDevice = NULL;
slouken@1895
   519
        }
slouken@1895
   520
    }
slouken@1895
   521
    return pDevice;
slouken@172
   522
}
slouken@172
   523
slouken@172
   524
/* disposes of the element list associated with a device and the memory associated with the list
slouken@172
   525
 */
slouken@172
   526
slouken@1895
   527
static void
slouken@1895
   528
HIDDisposeElementList(recElement ** elementList)
slouken@172
   529
{
slouken@1895
   530
    recElement *pElement = *elementList;
slouken@1895
   531
    while (pElement) {
slouken@1895
   532
        recElement *pElementNext = pElement->pNext;
slouken@1895
   533
        DisposePtr((Ptr) pElement);
slouken@1895
   534
        pElement = pElementNext;
slouken@1895
   535
    }
slouken@1895
   536
    *elementList = NULL;
slouken@172
   537
}
slouken@172
   538
slouken@172
   539
/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
slouken@172
   540
 * all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
slouken@172
   541
 */
slouken@172
   542
slouken@1895
   543
static recDevice *
slouken@1895
   544
HIDDisposeDevice(recDevice ** ppDevice)
slouken@172
   545
{
slouken@1895
   546
    kern_return_t result = KERN_SUCCESS;
slouken@1895
   547
    recDevice *pDeviceNext = NULL;
slouken@1895
   548
    if (*ppDevice) {
slouken@1895
   549
        /* save next device prior to disposing of this device */
slouken@1895
   550
        pDeviceNext = (*ppDevice)->pNext;
slouken@1895
   551
slouken@2713
   552
        /* free posible io_service_t */
slouken@2713
   553
        if ((*ppDevice)->ffservice) {
slouken@2713
   554
            IOObjectRelease((*ppDevice)->ffservice);
slouken@2713
   555
            (*ppDevice)->ffservice = 0;
slouken@2713
   556
        }
slouken@2713
   557
slouken@1895
   558
        /* free element lists */
slouken@1895
   559
        HIDDisposeElementList(&(*ppDevice)->firstAxis);
slouken@1895
   560
        HIDDisposeElementList(&(*ppDevice)->firstButton);
slouken@1895
   561
        HIDDisposeElementList(&(*ppDevice)->firstHat);
slouken@1895
   562
slouken@1895
   563
        result = HIDCloseReleaseInterface(*ppDevice);   /* function sanity checks interface value (now application does not own device) */
slouken@1895
   564
        if (kIOReturnSuccess != result)
slouken@1895
   565
            HIDReportErrorNum
slouken@1895
   566
                ("HIDCloseReleaseInterface failed when trying to dipose device.",
slouken@1895
   567
                 result);
slouken@1895
   568
        DisposePtr((Ptr) * ppDevice);
slouken@1895
   569
        *ppDevice = NULL;
slouken@1895
   570
    }
slouken@1895
   571
    return pDeviceNext;
slouken@172
   572
}
slouken@172
   573
slouken@172
   574
slouken@172
   575
/* Function to scan the system for joysticks.
slouken@172
   576
 * Joystick 0 should be the system default joystick.
slouken@172
   577
 * This function should return the number of available joysticks, or -1
slouken@172
   578
 * on an unrecoverable fatal error.
slouken@172
   579
 */
slouken@1895
   580
int
slouken@1895
   581
SDL_SYS_JoystickInit(void)
slouken@172
   582
{
slouken@1895
   583
    IOReturn result = kIOReturnSuccess;
slouken@1895
   584
    mach_port_t masterPort = 0;
slouken@1895
   585
    io_iterator_t hidObjectIterator = 0;
slouken@1895
   586
    CFMutableDictionaryRef hidMatchDictionary = NULL;
slouken@1895
   587
    recDevice *device, *lastDevice;
slouken@1895
   588
    io_object_t ioHIDDeviceObject = 0;
slouken@172
   589
slouken@1895
   590
    SDL_numjoysticks = 0;
slouken@172
   591
slouken@1895
   592
    if (gpDeviceList) {
slouken@1895
   593
        SDL_SetError("Joystick: Device list already inited.");
slouken@1895
   594
        return -1;
slouken@1895
   595
    }
slouken@172
   596
slouken@1895
   597
    result = IOMasterPort(bootstrap_port, &masterPort);
slouken@1895
   598
    if (kIOReturnSuccess != result) {
slouken@1895
   599
        SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
slouken@1895
   600
        return -1;
slouken@1895
   601
    }
slouken@172
   602
slouken@1895
   603
    /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
slouken@1895
   604
    hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
slouken@1895
   605
    if (hidMatchDictionary) {
slouken@1895
   606
        /* Add key for device type (joystick, in this case) to refine the matching dictionary. */
slouken@172
   607
slouken@1895
   608
        /* NOTE: we now perform this filtering later
slouken@1895
   609
           UInt32 usagePage = kHIDPage_GenericDesktop;
slouken@1895
   610
           UInt32 usage = kHIDUsage_GD_Joystick;
slouken@1895
   611
           CFNumberRef refUsage = NULL, refUsagePage = NULL;
slouken@1895
   612
slouken@1895
   613
           refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
slouken@1895
   614
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
slouken@1895
   615
           refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
slouken@1895
   616
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
slouken@1895
   617
         */
slouken@1895
   618
    } else {
slouken@1895
   619
        SDL_SetError
slouken@1895
   620
            ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
slouken@1895
   621
        return -1;
slouken@1895
   622
    }
slouken@1895
   623
slouken@1895
   624
    /*/ Now search I/O Registry for matching devices. */
slouken@1895
   625
    result =
slouken@1895
   626
        IOServiceGetMatchingServices(masterPort, hidMatchDictionary,
slouken@1895
   627
                                     &hidObjectIterator);
slouken@1895
   628
    /* Check for errors */
slouken@1895
   629
    if (kIOReturnSuccess != result) {
slouken@1895
   630
        SDL_SetError("Joystick: Couldn't create a HID object iterator.");
slouken@1895
   631
        return -1;
slouken@1895
   632
    }
slouken@1895
   633
    if (!hidObjectIterator) {   /* there are no joysticks */
slouken@1895
   634
        gpDeviceList = NULL;
slouken@1895
   635
        SDL_numjoysticks = 0;
slouken@1895
   636
        return 0;
slouken@1895
   637
    }
slouken@1895
   638
    /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
slouken@1895
   639
slouken@1895
   640
    /* build flat linked list of devices from device iterator */
slouken@1895
   641
slouken@1895
   642
    gpDeviceList = lastDevice = NULL;
slouken@1895
   643
slouken@1895
   644
    while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
slouken@1895
   645
        /* build a device record */
slouken@1895
   646
        device = HIDBuildDevice(ioHIDDeviceObject);
slouken@1895
   647
        if (!device)
slouken@1895
   648
            continue;
slouken@1895
   649
slouken@1895
   650
        /* Filter device list to non-keyboard/mouse stuff */
slouken@2120
   651
        if ((device->usagePage != kHIDPage_GenericDesktop) ||
slouken@2120
   652
            ((device->usage != kHIDUsage_GD_Joystick &&
slouken@2120
   653
              device->usage != kHIDUsage_GD_GamePad &&
slouken@2120
   654
              device->usage != kHIDUsage_GD_MultiAxisController))) {
icculus@620
   655
slouken@1895
   656
            /* release memory for the device */
slouken@1895
   657
            HIDDisposeDevice(&device);
slouken@1895
   658
            DisposePtr((Ptr) device);
slouken@1895
   659
            continue;
slouken@1895
   660
        }
slouken@172
   661
slouken@2713
   662
        /* We have to do some storage of the io_service_t for
slouken@2713
   663
         * SDL_HapticOpenFromJoystick */
slouken@2713
   664
        if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
slouken@2713
   665
            device->ffservice = ioHIDDeviceObject;
slouken@2713
   666
        } else {
slouken@2713
   667
            device->ffservice = 0;
slouken@2713
   668
        }
slouken@2713
   669
slouken@1895
   670
        /* Add device to the end of the list */
slouken@1895
   671
        if (lastDevice)
slouken@1895
   672
            lastDevice->pNext = device;
slouken@1895
   673
        else
slouken@1895
   674
            gpDeviceList = device;
slouken@1895
   675
        lastDevice = device;
slouken@1895
   676
    }
slouken@1895
   677
    result = IOObjectRelease(hidObjectIterator);        /* release the iterator */
slouken@1895
   678
slouken@1895
   679
    /* Count the total number of devices we found */
slouken@1895
   680
    device = gpDeviceList;
slouken@1895
   681
    while (device) {
slouken@1895
   682
        SDL_numjoysticks++;
slouken@1895
   683
        device = device->pNext;
slouken@1895
   684
    }
slouken@1895
   685
slouken@1895
   686
    return SDL_numjoysticks;
slouken@172
   687
}
slouken@172
   688
slouken@172
   689
/* Function to get the device-dependent name of a joystick */
slouken@1895
   690
const char *
slouken@1895
   691
SDL_SYS_JoystickName(int index)
slouken@172
   692
{
slouken@1895
   693
    recDevice *device = gpDeviceList;
slouken@172
   694
slouken@1895
   695
    for (; index > 0; index--)
slouken@1895
   696
        device = device->pNext;
slouken@1895
   697
slouken@1895
   698
    return device->product;
slouken@172
   699
}
slouken@172
   700
slouken@172
   701
/* Function to open a joystick for use.
slouken@172
   702
 * The joystick to open is specified by the index field of the joystick.
slouken@172
   703
 * This should fill the nbuttons and naxes fields of the joystick structure.
slouken@172
   704
 * It returns 0, or -1 if there is an error.
slouken@172
   705
 */
slouken@1895
   706
int
slouken@1895
   707
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
slouken@172
   708
{
slouken@1895
   709
    recDevice *device = gpDeviceList;
slouken@1895
   710
    int index;
slouken@172
   711
slouken@1895
   712
    for (index = joystick->index; index > 0; index--)
slouken@1895
   713
        device = device->pNext;
slouken@172
   714
slouken@1895
   715
    joystick->hwdata = device;
slouken@1895
   716
    joystick->name = device->product;
slouken@172
   717
slouken@1895
   718
    joystick->naxes = device->axes;
slouken@1895
   719
    joystick->nhats = device->hats;
slouken@1895
   720
    joystick->nballs = 0;
slouken@1895
   721
    joystick->nbuttons = device->buttons;
slouken@1895
   722
slouken@1895
   723
    return 0;
slouken@172
   724
}
slouken@172
   725
slouken@172
   726
/* Function to update the state of a joystick - called as a device poll.
slouken@172
   727
 * This function shouldn't update the joystick structure directly,
slouken@172
   728
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@172
   729
 * and update joystick device state.
slouken@172
   730
 */
slouken@1895
   731
void
slouken@1895
   732
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
slouken@172
   733
{
slouken@1895
   734
    recDevice *device = joystick->hwdata;
slouken@1895
   735
    recElement *element;
slouken@2287
   736
    SInt32 value, range;
slouken@1895
   737
    int i;
slouken@858
   738
slouken@1895
   739
    if (device->removed) {      /* device was unplugged; ignore it. */
slouken@1895
   740
        if (device->uncentered) {
slouken@1895
   741
            device->uncentered = 0;
slouken@858
   742
slouken@1895
   743
            /* Tell the app that everything is centered/unpressed... */
slouken@1895
   744
            for (i = 0; i < device->axes; i++)
slouken@1895
   745
                SDL_PrivateJoystickAxis(joystick, i, 0);
slouken@858
   746
slouken@1895
   747
            for (i = 0; i < device->buttons; i++)
slouken@1895
   748
                SDL_PrivateJoystickButton(joystick, i, 0);
slouken@858
   749
slouken@1895
   750
            for (i = 0; i < device->hats; i++)
slouken@1895
   751
                SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
slouken@1895
   752
        }
slouken@858
   753
slouken@1895
   754
        return;
slouken@1895
   755
    }
slouken@858
   756
slouken@1895
   757
    element = device->firstAxis;
slouken@1895
   758
    i = 0;
slouken@1895
   759
    while (element) {
slouken@1895
   760
        value = HIDScaledCalibratedValue(device, element, -32768, 32767);
slouken@1895
   761
        if (value != joystick->axes[i])
slouken@1895
   762
            SDL_PrivateJoystickAxis(joystick, i, value);
slouken@1895
   763
        element = element->pNext;
slouken@1895
   764
        ++i;
slouken@1895
   765
    }
slouken@1895
   766
slouken@1895
   767
    element = device->firstButton;
slouken@1895
   768
    i = 0;
slouken@1895
   769
    while (element) {
slouken@1895
   770
        value = HIDGetElementValue(device, element);
slouken@1895
   771
        if (value > 1)          /* handle pressure-sensitive buttons */
slouken@629
   772
            value = 1;
slouken@1895
   773
        if (value != joystick->buttons[i])
slouken@1895
   774
            SDL_PrivateJoystickButton(joystick, i, value);
slouken@1895
   775
        element = element->pNext;
slouken@1895
   776
        ++i;
slouken@1895
   777
    }
slouken@172
   778
slouken@1895
   779
    element = device->firstHat;
slouken@1895
   780
    i = 0;
slouken@1895
   781
    while (element) {
slouken@1895
   782
        Uint8 pos = 0;
slouken@1895
   783
slouken@2287
   784
        range = (element->max - element->min + 1);
slouken@2287
   785
        value = HIDGetElementValue(device, element) - element->min;
bob@2295
   786
        if (range == 4)         /* 4 position hatswitch - scale up value */
slouken@1895
   787
            value *= 2;
bob@2295
   788
        else if (range != 8)    /* Neither a 4 nor 8 positions - fall back to default position (centered) */
slouken@1895
   789
            value = -1;
slouken@1895
   790
        switch (value) {
slouken@1895
   791
        case 0:
slouken@1895
   792
            pos = SDL_HAT_UP;
slouken@1895
   793
            break;
slouken@1895
   794
        case 1:
slouken@1895
   795
            pos = SDL_HAT_RIGHTUP;
slouken@1895
   796
            break;
slouken@1895
   797
        case 2:
slouken@1895
   798
            pos = SDL_HAT_RIGHT;
slouken@1895
   799
            break;
slouken@1895
   800
        case 3:
slouken@1895
   801
            pos = SDL_HAT_RIGHTDOWN;
slouken@1895
   802
            break;
slouken@1895
   803
        case 4:
slouken@1895
   804
            pos = SDL_HAT_DOWN;
slouken@1895
   805
            break;
slouken@1895
   806
        case 5:
slouken@1895
   807
            pos = SDL_HAT_LEFTDOWN;
slouken@1895
   808
            break;
slouken@1895
   809
        case 6:
slouken@1895
   810
            pos = SDL_HAT_LEFT;
slouken@1895
   811
            break;
slouken@1895
   812
        case 7:
slouken@1895
   813
            pos = SDL_HAT_LEFTUP;
slouken@1895
   814
            break;
slouken@1895
   815
        default:
slouken@1895
   816
            /* Every other value is mapped to center. We do that because some
slouken@1895
   817
             * joysticks use 8 and some 15 for this value, and apparently
slouken@1895
   818
             * there are even more variants out there - so we try to be generous.
slouken@1895
   819
             */
slouken@1895
   820
            pos = SDL_HAT_CENTERED;
slouken@1895
   821
            break;
slouken@1895
   822
        }
slouken@1895
   823
        if (pos != joystick->hats[i])
slouken@1895
   824
            SDL_PrivateJoystickHat(joystick, i, pos);
slouken@1895
   825
        element = element->pNext;
slouken@1895
   826
        ++i;
slouken@1895
   827
    }
slouken@1895
   828
slouken@1895
   829
    return;
slouken@172
   830
}
slouken@172
   831
slouken@172
   832
/* Function to close a joystick after use */
slouken@1895
   833
void
slouken@1895
   834
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
slouken@172
   835
{
slouken@1895
   836
    /* Should we do anything here? */
slouken@1895
   837
    return;
slouken@172
   838
}
slouken@172
   839
slouken@172
   840
/* Function to perform any system-specific joystick related cleanup */
slouken@1895
   841
void
slouken@1895
   842
SDL_SYS_JoystickQuit(void)
slouken@172
   843
{
slouken@1895
   844
    while (NULL != gpDeviceList)
slouken@1895
   845
        gpDeviceList = HIDDisposeDevice(&gpDeviceList);
slouken@172
   846
}
slouken@1635
   847
slouken@1635
   848
#endif /* SDL_JOYSTICK_IOKIT */
slouken@1895
   849
/* vi: set ts=4 sw=4 expandtab: */