Mercurial > sdl-ios-xcode
view src/joystick/darwin/10.3.9-FIX/IOHIDLib.h @ 4157:baf615f9f2a0 SDL-1.2
Date: Thu, 16 Oct 2008 20:27:34 +0400
From: "Ilya Kasnacheev" <ilya.kasnacheev@gmail.com>
To: sdl@lists.libsdl.org
Subject: [SDL] SDL for Windows CE: a few GAPI patches
Hi *!
I've just ported a POWDER roguelike ( http://www.zincland.com/powder/ ) to
Windows CE (PDAs, Windows Mobile/Pocket PC). To do that, I had to get libsdl
working. Thanks for the awesome project files, it built without a hitch.
Nevertheless, I've found quite a few bugs in Windows CE (GAPI) SDL
implementation, which I've solved and now present as a serie of patches.
I'll try carefully annotate them. Please annotate them so I can work
toward accepting
them into the main source tree since without them SDL isn't really working on
Windows CE (I wonder why nobody fixed them before, btw: why isn't SDL popular as
a way to develop Windows CE games? Where are no ports?)
These changes can't be considered flawless, but they can be considered working
because I've yet to hear complains about things I fixed and POWDER build for
Windows CE is now considered stable.
Note: my comments start with !!, delete them before applying.
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.c
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.c 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c 2008-10-16
20:02:11.000000000 +0400
@@ -643,6 +643,7 @@
}
gapi->userOrientation = SDL_ORIENTATION_UP;
+ gapi->systemOrientation = SDL_ORIENTATION_UP;
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports
fullscreen only */
/* GAPI or VGA? */
@@ -661,18 +662,21 @@
}
/* detect user landscape mode */
- if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) <
GetSystemMetrics(SM_CYSCREEN)))
+ if( (width > height) && (gapi->gxProperties.cxWidth <
gapi->gxProperties.cyHeight))
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
+ if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
+ gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
+
/* shall we apply hires fix? for example when we do not use
hires resource */
gapi->hiresFix = 0;
- if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )
+ if( gapi->systemOrientation == gapi->userOrientation )
{
- if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+ if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
gapi->hiresFix = 1;
} else
- if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
- if( !((width == GetSystemMetrics(SM_CYSCREEN))
&& (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait,
device landscape
+ if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+// if( !((width == gapi->gxProperties.cyHeight)
&& (height == gapi->gxProperties.cxWidth))) // user portrait, device
landscape
gapi->hiresFix = 1;
switch( gapi->userOrientation )
!! It used to query system metrics which return dimensions according to screen
!! orientation, which can really be portrait, left landscape or right landscape.
!! This is presumably incorrect because we couldn't care less about user mode
!! dimensions - all we want are the GAPI framebuffer dimensions, which
only match
!! user dimensions in one of possible orientations.
!! There's a fair dose of cargo cult programming involved in this fix, but it
!! used to work only in one orientation (portrait for PDAs, where frame-buffer
!! have same orientation as user screen), and now it works on all orientations.
@@ -742,21 +746,30 @@
WIN_FlushMessageQueue();
/* Open GAPI display */
- if( !gapi->useVga && this->hidden->useGXOpenDisplay )
+ if( !gapi->useVga && this->hidden->useGXOpenDisplay &&
!this->hidden->alreadyGXOpened )
+ {
+ this->hidden->alreadyGXOpened = 1;
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
return(NULL);
}
+ }
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
printf("display width: %d\n", gapi->gxProperties.cxWidth);
printf("display height: %d\n", gapi->gxProperties.cyHeight);
+ printf("system display width: %d\n", GetSystemMetrics(SM_CXSCREEN));
+ printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
+ printf("user orientation: %d\n", gapi->userOrientation);
+ printf("system orientation: %d\n", gapi->userOrientation);
+ printf("gapi orientation: %d\n", gapi->gapiOrientation);
+
if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
{
!! Previous version used to call gapi->gxFunc.GXOpenDisplay each time the video
!! mode would be changed. You shouldn't, because this call has a
meaning "Lock the
!! GAPI framebuffer, designate it as busy", so the second call will fail (it is
!! already locked/busy).
!! Testing might not find that because most programs set up the video mode only
!! once, but POWDER does this once in a while, so it crashed when in
320x240 mode
!! (640x480 mode doesn't use that code, it worked fine).
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.h
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.h 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h 2008-10-16
20:02:11.000000000 +0400
@@ -132,12 +132,17 @@
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
+ // The orientation of the video mode user wants to get
+ // Probably restricted to UP and RIGHT
enum SDL_ScreenOrientation userOrientation;
int invert;
char hiresFix; // using hires mode without defining hires resource
// --------------
int useGXOpenDisplay; /* use GXOpenDispplay */
+ int alreadyGXOpened;
int w, h;
+ // The orientation of GAPI framebuffer.
+ // Never changes on the same device.
enum SDL_ScreenOrientation gapiOrientation;
void *buffer; // may be 8, 16, 24, 32 bpp
@@ -153,6 +158,10 @@
int startOffset; // in bytes
int useVga;
int suspended; // do not pu anything into video memory
+ // The orientation of the system, as defined by SM_CXSCREEN
and SM_CYSCREEN
+ // User can change it by using 'screen layout' in system options
+ // Restricted to UP or RIGHT
+ enum SDL_ScreenOrientation systemOrientation;
};
!! This is a flag variable, see the previous comment
!! And yet another orientation: now we have to keep three of them in mind.
diff -bru SDL-1.2.13/src/video/wincommon/SDL_sysevents.c
SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c
--- SDL-1.2.13/src/video/wincommon/SDL_sysevents.c 2007-12-31
07:48:02.000000000 +0300
+++ SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c 2008-10-16
20:02:12.000000000 +0400
@@ -160,10 +160,22 @@
#endif */
}
break;
+ // FIXME: Older version used just SDL_VideoSurface->(w, h)
+ // w and h are "clipped" while x and y are "raw", which caused
+ // x in former and y in latter case to be clipped in a
wrong direction,
+ // thus offsetting the coordinate on 2 x clip pixels
+ // (like, 128 for 640 -> 512 clipping).
+ // We will now try to extract and use raw values.
+ // The way to do that RIGHT is do
(orientation-dependent) clipping before
+ // doing this transform, but it's hardly possible.
+
+ // SEE SDL_mouse.c /ClipOffset to understand these calculations.
case SDL_ORIENTATION_RIGHT:
if (!SDL_VideoSurface)
break;
- rotatedX = SDL_VideoSurface->w - *y;
+ rotatedX = (2 *
((SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
+ SDL_VideoSurface->format->BytesPerPixel))
+ + SDL_VideoSurface->w - *y;
rotatedY = *x;
*x = rotatedX;
*y = rotatedY;
@@ -172,7 +184,8 @@
if (!SDL_VideoSurface)
break;
rotatedX = *y;
- rotatedY = SDL_VideoSurface->h - *x;
+ rotatedY = (2 *
(SDL_VideoSurface->offset/SDL_VideoSurface->pitch))
+ + SDL_VideoSurface->h - *x;
*x = rotatedX;
*y = rotatedY;
break;
!! That's the trickest part, hence the long comment.
!! GAPI would really support only 320x240 or 640x480 mode, if application
!! requested the different screen size (as POWDER did, wishing
256x192), then SDL
!! is going to grab the first mode that fits the requested, and pad the screen
!! with black bars (as they do with wide-screen films).
!! It would also get, say, 240x320 mode, and to turn it into 256x192 it would
!! need to rotate mouse clicks.
!! It worked, but one bug slipped through: it would receive mouse clicks
!! unpadded, then rotate them, and then pad the black bars. The
problem is: rotate
!! is done by GAPI driver while padding is done by SDL core. SDL core
doesn't know
!! anything about rotating, so it would pad one of dimensions incorrectly.
I understand that some of my claims (or code) might seem unbacked, but you can
always grab the POWDER binary, compile your own libsdl with one or more of
those fixes turned off, and see how weird it would misbehave. I can even supply
you with those custom builds of libsdl if you don't want to set up the build
environment for windows ce, you'll just need a PDA or a smartphone with it.
I plan to take care of SDL on Windows CE as long as I maintain the POWDER port.
POWDER is good for that because it:
Employs both padded (with centered image, black bars) and unpadded
(image occupies full screen) graphics; initializes video more than
once; uses both 320x240 and 640x480 video; uses both stylus and
buttons.
There's still a list of unresolved issues which I'm planning to fix:
1) Arrow buttons on PDA return weird scancodes compared to PC, this
caused the game to misbehave before I've fixed that. You can see it on
those diagrams:
http://wrar.name/upload/powder-htc.png
http://wrar.name/upload/powder-pda.png
2) SDL (or underlying windows) doesn't care to rotate arrow presses
when we're in a low-res GAPI mode, but it will rotate them in VGA mode
(because of different screen orientations, the same arrow buttons can
suddently mean different directions). Solution: we should stick to
GAPI user orientation (the orientation the program supposedly wants)
and rotate the keys on our own.
_______________________________________________
SDL mailing list
SDL@lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 07 Nov 2008 04:15:36 +0000 |
parents | e3945f84427f |
children |
line wrap: on
line source
/* *INDENT-OFF* */ /* * * @APPLE_LICENSE_HEADER_START@ * * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #ifndef _IOKIT_HID_IOHIDLIB_H_ #define _IOKIT_HID_IOHIDLIB_H_ #include <sys/cdefs.h> __BEGIN_DECLS #include <CoreFoundation/CoreFoundation.h> #if COREFOUNDATION_CFPLUGINCOM_SEPARATE #include <CoreFoundation/CFPlugInCOM.h> #endif #include <IOKit/IOTypes.h> #include <IOKit/IOReturn.h> #include <IOKit/hid/IOHIDKeys.h> struct IOHIDEventStruct { IOHIDElementType type; IOHIDElementCookie elementCookie; SInt32 value; AbsoluteTime timestamp; UInt32 longValueSize; void * longValue; }; typedef struct IOHIDEventStruct IOHIDEventStruct; /* FA12FA38-6F1A-11D4-BA0C-0005028F18D5 */ #define kIOHIDDeviceUserClientTypeID CFUUIDGetConstantUUIDWithBytes(NULL, \ 0xFA, 0x12, 0xFA, 0x38, 0x6F, 0x1A, 0x11, 0xD4, \ 0xBA, 0x0C, 0x00, 0x05, 0x02, 0x8F, 0x18, 0xD5) /* 13AA9C44-6F1B-11D4-907C-0005028F18D5 */ #define kIOHIDDeviceFactoryID CFUUIDGetConstantUUIDWithBytes(NULL, \ 0x13, 0xAA, 0x9C, 0x44, 0x6F, 0x1B, 0x11, 0xD4, \ 0x90, 0x7C, 0x00, 0x05, 0x02, 0x8F, 0x18, 0xD5) /* 78BD420C-6F14-11D4-9474-0005028F18D5 */ /*! @defined kIOHIDDeviceInterfaceID @discussion Interface ID for the IOHIDDeviceInterface. Corresponds to an available HID device. */ #define kIOHIDDeviceInterfaceID CFUUIDGetConstantUUIDWithBytes(NULL, \ 0x78, 0xBD, 0x42, 0x0C, 0x6F, 0x14, 0x11, 0xD4, \ 0x94, 0x74, 0x00, 0x05, 0x02, 0x8F, 0x18, 0xD5) /* 7D0B510E-16D5-11D7-9E9B-000393992E38 */ /*! @defined kIOHIDDeviceInterfaceID121 @discussion Interface ID for the IOHIDDeviceInterface121. Corresponds to an available HID device that includes methods from IOHIDDeviceInterface. This interface is available on IOHIDLib 1.2.1 and Mac OS X 10.2.3 or later.*/ #define kIOHIDDeviceInterfaceID121 CFUUIDGetConstantUUIDWithBytes(NULL, \ 0x7d, 0xb, 0x51, 0xe, 0x16, 0xd5, 0x11, 0xd7, \ 0x9e, 0x9b, 0x0, 0x3, 0x93, 0x99, 0x2e, 0x38) /* B70ABF31-16D5-11D7-AB35-000393992E38 */ /*! @defined kIOHIDDeviceInterfaceID122 @discussion Interface ID for the IOHIDDeviceInterface122. Corresponds to an available HID device that includes methods from IOHIDDeviceInterface and IOHIDDeviceInterface121. This interface is available on IOHIDLib 1.2.2 and Mac OS X 10.3 or later.*/ #define kIOHIDDeviceInterfaceID122 CFUUIDGetConstantUUIDWithBytes(NULL, \ 0xb7, 0xa, 0xbf, 0x31, 0x16, 0xd5, 0x11, 0xd7, \ 0xab, 0x35, 0x0, 0x3, 0x93, 0x99, 0x2e, 0x38) /* 8138629E-6F14-11D4-970E-0005028F18D5 */ /*! @defined kIOHIDQueueInterfaceID @discussion Interface ID for the kIOHIDQueueInterfaceID. Corresponds to a queue for a specific HID device. */ #define kIOHIDQueueInterfaceID CFUUIDGetConstantUUIDWithBytes(NULL, \ 0x81, 0x38, 0x62, 0x9E, 0x6F, 0x14, 0x11, 0xD4, \ 0x97, 0x0E, 0x00, 0x05, 0x02, 0x8F, 0x18, 0xD5) /* 80CDCC00-755D-11D4-8E0F-0005028F18D5 */ /*! @defined kIOHIDOutputTransactionInterfaceID @discussion Interface ID for the kIOHIDOutputTransactionInterfaceID. Corresponds to an output transaction for one or more report IDs on a specific device. */ #define kIOHIDOutputTransactionInterfaceID CFUUIDGetConstantUUIDWithBytes(NULL,\ 0x80, 0xCD, 0xCC, 0x00, 0x75, 0x5D, 0x11, 0xD4, \ 0x80, 0xEF, 0x00, 0x05, 0x02, 0x8F, 0x18, 0xD5) /*! @typedef IOHIDCallbackFunction @discussion Type and arguments of callout C function that is used when a completion routine is called, see IOHIDLib.h:setRemovalCallback(). @param target void * pointer to your data, often a pointer to an object. @param result Completion result of desired operation. @param refcon void * pointer to more data. @param sender Interface instance sending the completion routine. */ typedef void (*IOHIDCallbackFunction) (void * target, IOReturn result, void * refcon, void * sender); /*! @typedef IOHIDElementCallbackFunction @discussion Type and arguments of callout C function that is used when a completion routine is called, see IOHIDLib.h:setElementValue(). @param target void * pointer to your data, often a pointer to an object. @param result Completion result of desired operation. @param refcon void * pointer to more data. @param sender Interface instance sending the completion routine. @param elementCookie Element within interface instance sending completion. */ typedef void (*IOHIDElementCallbackFunction) (void * target, IOReturn result, void * refcon, void * sender, IOHIDElementCookie elementCookie); /*! @typedef IOHIDReportCallbackFunction @discussion Type and arguments of callout C function that is used when a completion routine is called, see IOHIDLib.h:setReport(). @param target void * pointer to your data, often a pointer to an object. @param result Completion result of desired operation. @param refcon void * pointer to more data. @param sender Interface instance sending the completion routine. @param bufferSize Size of the buffer received upon completion. */ typedef void (*IOHIDReportCallbackFunction) (void * target, IOReturn result, void * refcon, void * sender, UInt32 bufferSize); /* Forward declarations of the queue and output transaction interfaces */ struct IOHIDQueueInterface; struct IOHIDOutputTransactionInterface; typedef struct IOHIDQueueInterface IOHIDQueueInterface; typedef struct IOHIDOutputTransactionInterface IOHIDOutputTransactionInterface; // // IOHIDDeviceInterface Functions available in version 1.0 (10.0) and higher of Mac OS X // #define IOHIDDEVICEINTERFACE_FUNCS_100 \ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); \ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); \ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); \ mach_port_t (*getAsyncPort)(void * self); \ IOReturn (*open)(void * self, UInt32 flags); \ IOReturn (*close)(void * self); \ IOReturn (*setRemovalCallback)(void * self, IOHIDCallbackFunction removalCallback, \ void * removalTarget, void * removalRefcon); \ IOReturn (*getElementValue)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * valueEvent); \ IOReturn (*setElementValue)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * valueEvent, UInt32 timeoutMS, \ IOHIDElementCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon); \ IOReturn (*queryElementValue)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * valueEvent, UInt32 timeoutMS, \ IOHIDElementCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon); \ IOReturn (*startAllQueues)(void * self); \ IOReturn (*stopAllQueues)(void * self); \ IOHIDQueueInterface ** (*allocQueue) (void *self); \ IOHIDOutputTransactionInterface ** (*allocOutputTransaction) (void *self) // // IOHIDDeviceInterface Functions available in version 1.2.1 (10.2.3) and higher of Mac OS X // #define IOHIDDEVICEINTERFACE_FUNCS_121 \ IOReturn (*setReport)(void * self, IOHIDReportType reportType, UInt32 reportID, \ void * reportBuffer, UInt32 reportBufferSize, \ UInt32 timeoutMS, IOHIDReportCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon); \ IOReturn (*getReport)(void * self, IOHIDReportType reportType, \ UInt32 reportID, void * reportBuffer, \ UInt32 * reportBufferSize, UInt32 timeoutMS, \ IOHIDReportCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon) // // IOHIDDeviceInterface Functions available in version 1.2.2 (10.3) and higher of Mac OS X // #define IOHIDDEVICEINTERFACE_FUNCS_122 \ IOReturn (*copyMatchingElements)(void * self, CFDictionaryRef matchingDict, \ CFArrayRef * elements); \ IOReturn (*setInterruptReportHandlerCallback)(void * self, void * reportBuffer, \ UInt32 reportBufferSize, \ IOHIDReportCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon) typedef struct IOHIDDeviceInterface { IUNKNOWN_C_GUTS; IOHIDDEVICEINTERFACE_FUNCS_100; IOHIDDEVICEINTERFACE_FUNCS_121; } IOHIDDeviceInterface; typedef struct IOHIDDeviceInterface121 { IUNKNOWN_C_GUTS; IOHIDDEVICEINTERFACE_FUNCS_100; IOHIDDEVICEINTERFACE_FUNCS_121; } IOHIDDeviceInterface121; typedef struct IOHIDDeviceInterface122 { IUNKNOWN_C_GUTS; IOHIDDEVICEINTERFACE_FUNCS_100; IOHIDDEVICEINTERFACE_FUNCS_121; IOHIDDEVICEINTERFACE_FUNCS_122; } IOHIDDeviceInterface122; // // IOHIDQueueInterface Functions available in version 1.0 (10.0) and higher of Mac OS X // #define IOHIDQUEUEINTERFACE_FUNCS_100 \ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); \ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); \ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); \ mach_port_t (*getAsyncPort)(void * self); \ IOReturn (*create)(void * self, UInt32 flags, UInt32 depth); \ IOReturn (*dispose)(void * self); \ IOReturn (*addElement)(void * self, IOHIDElementCookie elementCookie, UInt32 flags);\ IOReturn (*removeElement)(void * self, IOHIDElementCookie elementCookie); \ Boolean (*hasElement)(void * self, IOHIDElementCookie elementCookie); \ IOReturn (*start)(void * self); \ IOReturn (*stop)(void * self); \ IOReturn (*getNextEvent)(void * self, IOHIDEventStruct * event, \ AbsoluteTime maxTime, UInt32 timeoutMS); \ IOReturn (*setEventCallout)(void * self, IOHIDCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon); \ IOReturn (*getEventCallout)(void * self, IOHIDCallbackFunction * outCallback, \ void ** outCallbackTarget, void ** outCallbackRefcon) struct IOHIDQueueInterface { IUNKNOWN_C_GUTS; IOHIDQUEUEINTERFACE_FUNCS_100; }; // // IOHIDOutputTransactionInterface Functions available in version 1.2 (10.2) and higher of Mac OS X // #define IOHIDOUTPUTTRANSACTIONINTERFACE_FUNCS_120 \ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); \ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); \ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); \ mach_port_t (*getAsyncPort)(void * self); \ IOReturn (*create)(void * self); \ IOReturn (*dispose)(void * self); \ IOReturn (*addElement)(void * self, IOHIDElementCookie elementCookie); \ IOReturn (*removeElement)(void * self, IOHIDElementCookie elementCookie); \ Boolean (*hasElement)(void * self, IOHIDElementCookie elementCookie); \ IOReturn (*setElementDefault)(void *self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * valueEvent); \ IOReturn (*getElementDefault)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * outValueEvent); \ IOReturn (*setElementValue)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * valueEvent); \ IOReturn (*getElementValue)(void * self, IOHIDElementCookie elementCookie, \ IOHIDEventStruct * outValueEvent); \ IOReturn (*commit)(void * self, UInt32 timeoutMS, IOHIDCallbackFunction callback, \ void * callbackTarget, void * callbackRefcon); \ IOReturn (*clear)(void * self) struct IOHIDOutputTransactionInterface { IUNKNOWN_C_GUTS; IOHIDOUTPUTTRANSACTIONINTERFACE_FUNCS_120; }; // // BEGIN READABLE STRUCTURE DEFINITIONS // // This portion of uncompiled code provides a more reader friendly representation of // the CFPlugin methods defined above. #if 0 /*! @class IOHIDDeviceInterface @discussion CFPlugin object subclass which provides the primary interface to HID devices. */ typedef struct IOHIDDeviceInterface { IUNKNOWN_C_GUTS; /*! @function createAsyncEventSource @abstract Creates async eventsource. @discussion This method will create an async mach port, if one has not already been created. @param source Reference to CFRunLoopSourceRef that is created. @result Returns an IOReturn code. */ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); /*! @function getAsyncEventSource @abstract Gets the created async event source. @result Returns a CFRunLoopSourceRef. */ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); /*! @function createAsyncPort @abstract Creates an async port. @discussion The port must be created before any callbacks can be used. @param port Reference to mach port that is created. @result Returns an IOReturn code. */ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); /*! @function getAsyncPort @abstract Gets the current async port. @result Returns a mach_port_t. */ mach_port_t (*getAsyncPort)(void * self); /*! @function open @abstract Opens the device. @param flags Flags to be passed down to the user client. @result Returns an IOReturn code. */ IOReturn (*open)(void * self, UInt32 flags); /*! @function close @abstract Closes the device. @result Returns an IOReturn code. */ IOReturn (*close)(void * self); /*! @function setRemovalCallback @abstract Sets callback to be used when device is removed. @param removalCallback Called when the device is removed. @param removeTarget Passed to the callback. @param removalRefcon Passed to the callback. @result Returns an IOReturn code. */ IOReturn (*setRemovalCallback)(void * self, IOHIDCallbackFunction removalCallback, void * removalTarget, void * removalRefcon); /*! @function getElementValue @abstract Obtains the most recent value of an element. @discussion This call is most useful for interrupt driven elements, such as input type elements. Since feature type element values need to be polled from the device, it is recommended to use the queryElementValue method to obtain the current value. The timestamp field in the event details the last time the element value was altered. @param elementCookie The element of interest. @param valueEvent The event that will be filled. If a long value is present, it is up to the caller to deallocate it. @result Returns an IOReturn code. */ IOReturn (*getElementValue)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * valueEvent); /*! @function setElementValue @abstract Sets an element value on the device. @discussion This call is most useful for feature type elements. It is recommended to use IOOutputTransaction for output type elements. @param elementCookie The element of interest. @param valueEvent The event that will be filled. If a long value is present, it will be copied. @param timeoutMS UNSUPPORTED. @param callback UNSUPPORTED. @param callbackTarget UNSUPPORTED. @param callbackRefcon UNSUPPORTED. @result Returns an IOReturn code. */ IOReturn (*setElementValue)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * valueEvent, UInt32 timeoutMS, IOHIDElementCallbackFunction callback, void * callbackTarget, void * callbackRefcon); /*! @function queryElementValue @abstract Obtains the current value of an element. @discussion This call is most useful for feature type elements. This method will poll the device for the current element value. @param elementCookie The element of interest. @param valueEvent The event that will be filled. If a long value is present, it is up to the caller to deallocate it. @param timeoutMS UNSUPPORTED. @param callback UNSUPPORTED. @param callbackTarget UNSUPPORTED. @param callbackRefcon UNSUPPORTED. @result Returns an IOReturn code. */ IOReturn (*queryElementValue)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * valueEvent, UInt32 timeoutMS, IOHIDElementCallbackFunction callback, void * callbackTarget, void * callbackRefcon); /*! @function startAllQueues @abstract Starts data delivery on all queues for this device. @result Returns an IOReturn code. */ IOReturn (*startAllQueues)(void * self); /*! @function stopAllQueues @abstract Stops data delivery on all queues for this device. @result Returns an IOReturn code. */ IOReturn (*stopAllQueues)(void * self); /*! @function allocQueue @abstract Wrapper to return instances of the IOHIDQueueInterface. @result Returns the created IOHIDQueueInterface. */ IOHIDQueueInterface ** (*allocQueue) (void *self); /*! @function allocOutputTransaction @abstract Wrapper to return instances of the IOHIDOutputTransactionInterface. @result Returns the created IOHIDOutputTransactionInterface. */ IOHIDOutputTransactionInterface ** (*allocOutputTransaction) (void *self); } IOHIDDeviceInterface; /*! @class IOHIDDeviceInterface121 @discussion CFPlugin object subclass which provides the primary interface to HID devices. This class is a subclass of IOHIDDeviceInterface. */ typedef struct IOHIDDeviceInterface121 { IUNKNOWN_C_GUTS; IOHIDDEVICEINTERFACE_FUNCS_100; /*! @function setReport @abstract Sends a report to the device. @param reportType The report type. @param reportID The report id. @param reportBuffer Pointer to a preallocated buffer. @param reportBufferSize Size of the reportBuffer in bytes. @param timeoutMS @param callback If null, this method will behave synchronously. @param callbackTarget The callback target passed to the callback. @param callbackRefcon The callback refcon passed to the callback. @result Returns an IOReturn code. */ IOReturn (*setReport) (void * self, IOHIDReportType reportType, UInt32 reportID, void * reportBuffer, UInt32 reportBufferSize, UInt32 timeoutMS, IOHIDReportCallbackFunction callback, void * callbackTarget, void * callbackRefcon); /*! @function getReport @abstract Obtains a report from the device. @param reportType The report type. @param reportID The report ID. @param reportBuffer Pointer to a preallocated buffer. @param reportBufferSize Size of the reportBuffer in bytes. When finished, will contain the actual size of the report. @param timeoutMS @param callback If null, this method will behave synchronously. @param callbackTarget The callback target passed to the callback. @param callbackRefcon The callback refcon passed to the callback. @result Returns an IOReturn code. */ IOReturn (*getReport) (void * self, IOHIDReportType reportType, UInt32 reportID, void * reportBuffer, UInt32 * reportBufferSize, UInt32 timeoutMS, IOHIDReportCallbackFunction callback, void * callbackTarget, void * callbackRefcon); }IOHIDDeviceInterface121; /*! @class IOHIDDeviceInterface122 @discussion CFPlugin object subclass which provides the primary interface to HID devices. This class is a subclass of IOHIDDeviceInterface121. */ typedef struct IOHIDDeviceInterface122 { IUNKNOWN_C_GUTS; IOHIDDEVICEINTERFACE_FUNCS_100; IOHIDDEVICEINTERFACE_FUNCS_121; /*! @function copyMatchingElements @abstract Obtains specific elements defined by the device. @discussion Using keys defined in IOHIDKeys.h for elements, create a matching dictonary containing items that you wish to search for. A null array indicates that no elements matching that criteria were found. Each item in the array is a reference to the same dictionary item that represents each element in the I/O Registry. It is up to the caller to release the returned array of elements. @param matchingDict Dictionary containg key/value pairs to match on. Pass a null value to match on all elements. @param elements Pointer to a CFArrayRef that will be returned by this method. It is up to the caller to release it when finished. @result Returns an IOReturn code. */ IOReturn (*copyMatchingElements)(void * self, CFDictionaryRef matchingDict, CFArrayRef * elements); /*! @function setInterruptReportHandlerCallback @abstract Sets the report handler callout to be called when the data is received from the Interrupt-In pipe. @discussion In order for this to work correctly, you must call createAsyncPort and createAsyncEventSource. @param reportBuffer Pointer to a preallocated buffer. @param reportBufferSize Size of the reportBuffer in bytes. @param callback If non-NULL, is a callback to be called when data is received from the device. @param callbackTarget The callback target passed to the callback @param callbackRefcon The callback refcon passed to the callback. @result Returns an IOReturn code. */ IOReturn (*setInterruptReportHandlerCallback)( void * self, void * reportBuffer, UInt32 reportBufferSize, IOHIDReportCallbackFunction callback, void * callbackTarget, void * callbackRefcon); }IOHIDDeviceInterface122; /*! @class IOHIDQueueInterface @discussion CFPlugin object subclass which provides an interface for input queues from HID devices. Created by an IOHIDDeviceInterface object. */ typedef struct IOHIDQueueInterface { IUNKNOWN_C_GUTS; /*! @function createAsyncEventSource @abstract Creates an async event source. @discussion This will be used with setEventCallout. @param source The newly created event source. @result Returns an IOReturn code. */ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); /*! @function getAsyncEventSource @abstract Obtains the current event source. @result Returns a CFRunLoopSourceRef. */ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); /*! @function createAsyncPort @abstract Creates an async port. @discussion This will be used with createAsyncEventSource. @param port The newly created async port. @result Returns an IOReturn code. */ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); /*! @function getAsyncPort @abstract Obtains the current async port. @result Returns a mach_port_t. */ mach_port_t (*getAsyncPort)(void * self); /*! @function create @abstract Creates the current queue. @param flags @param depth The maximum number of elements in the queue before the oldest elements in the queue begin to be lost. @result Returns an IOReturn code. */ IOReturn (*create)(void * self, UInt32 flags, UInt32 depth); /*! @function create @abstract Disposes of the current queue. @result Returns an IOReturn code. */ IOReturn (*dispose)(void * self); /*! @function addElement @abstract Adds an element to the queue. @discussion If the element has already been added to queue, an error will be returned. @param elementCookie The element of interest. @param flags @result Returns an IOReturn code. */ IOReturn (*addElement)(void * self, IOHIDElementCookie elementCookie, UInt32 flags); /*! @function removeElement @abstract Removes an element from the queue. @discussion If the element has not been added to queue, an error will be returned. @param elementCookie The element of interest. @result Returns an IOReturn code. */ IOReturn (*removeElement)(void * self, IOHIDElementCookie elementCookie); /*! @function hasElement @abstract Checks whether an element has been added to the queue. @discussion Will return true if present, otherwise will return false. @param elementCookie The element of interest. @result Returns a Boolean value. */ Boolean (*hasElement)(void * self, IOHIDElementCookie elementCookie); /*! @function start @abstract Starts event delivery to the queue. @result Returns an IOReturn code. */ IOReturn (*start)(void * self); /*! @function stop @abstract Stops event delivery to the queue. @result Returns an IOReturn code. */ IOReturn (*stop)(void * self); /*! @function getNextEvent @abstract Reads next event from the queue. @param event The event that will be filled. If a long value is present, it is up to the caller to deallocate it. @param maxtime UNSUPPORTED. If non-zero, limits read events to those that occured on or before maxTime. @param timoutMS UNSUPPORTED. The timeout in milliseconds, a zero timeout will cause this call to be non-blocking (returning queue empty) if there is a NULL callback, and blocking forever until the queue is non-empty if there is a valid callback. @result Returns an IOReturn code. */ IOReturn (*getNextEvent)(void * self, IOHIDEventStruct * event, AbsoluteTime maxTime, UInt32 timeoutMS); /*! @function setEventCallout @abstract Sets the event callout to be called when the queue transitions to non-empty. @discussion In order for this to work correctly, you must call createAsyncPort and createAsyncEventSource. @param callback if non-NULL is a callback to be called when data is inserted to the queue @param callbackTarget The callback target passed to the callback @param callbackRefcon The callback refcon passed to the callback. @result Returns an IOReturn code. */ IOReturn (*setEventCallout)(void * self, IOHIDCallbackFunction callback, void * callbackTarget, void * callbackRefcon); /*! @function getEventCallout @abstract Gets the event callout. @discussion This callback will be called the queue transitions to non-empty. @param callback if non-NULL is a callback to be called when data is inserted to the queue @param callbackTarget The callback target passed to the callback @param callbackRefcon The callback refcon passed to the callback @result Returns an IOReturn code. */ IOReturn (*getEventCallout)(void * self, IOHIDCallbackFunction * outCallback, void ** outCallbackTarget, void ** outCallbackRefcon); } IOHIDQueueInterface; /*! @class IOHIDOutputTransactionInterface @discussion CFPlugin object subclass which privides interface for output transactions to HID devices. Created by a IOHIDDeviceInterface object. */ typedef struct IOHIDOutputTransactionInterface { IUNKNOWN_C_GUTS; /*! @function createAsyncEventSource @abstract Creates an async event source. @discussion This will be used with setEventCallout. @param source The newly created event source @result Returns an IOReturn code. */ IOReturn (*createAsyncEventSource)(void * self, CFRunLoopSourceRef * source); /*! @function getAsyncEventSource @abstract Obtains the current event source. @result Returns a CFRunLoopSourceRef. */ CFRunLoopSourceRef (*getAsyncEventSource)(void * self); /*! @function createAsyncPort @abstract Creates an async port. @discussion This will be used with createAsyncEventSource. @param port The newly created async port. @result Returns an IOReturn code. */ IOReturn (*createAsyncPort)(void * self, mach_port_t * port); /*! @function getAsyncPort @abstract Obtains the current async port. @result Returns a mach_port_t. */ mach_port_t (*getAsyncPort)(void * self); /*! @function create @abstract Creates the current transaction. @discussion This method will free any memory that has been allocated for this transaction. @result Returns an IOReturn code. */ IOReturn (*create)(void * self); /*! @function dispose @abstract Disposes of the current transaction. @discussion The transaction will have to be recreated, in order to perform any operations on the transaction. @result Returns an IOReturn code. */ IOReturn (*dispose)(void * self); /*! @function addElement @abstract Adds an element to the transaction. @discussion If the element has already been added to transaction, an error will be returned. @param elementCookie The element of interest. @result Returns an IOReturn code. */ IOReturn (*addElement) (void * self, IOHIDElementCookie elementCookie); /*! @function removeElement @abstract Removes an element from the transaction. @discussion If the element has not been added to transaction, an error will be returned. @param elementCookie The element of interest. @result Returns an IOReturn code. */ IOReturn (*removeElement) (void * self, IOHIDElementCookie elementCookie); /*! @function hasElement @abstract Checks whether an element has been added to the transaction. @discussion Will return true if present, otherwise will return false. @param elementCookie The element of interest. @result Returns a Boolean value. */ Boolean (*hasElement) (void * self, IOHIDElementCookie elementCookie); /*! @function setElementDefault @abstract Sets the default value of an element in a transaction. @discussion An error will be returned if the element has not been added to the transaction. @param elementCookie The element of interest. @param valueEvent The event that will be filled. If a long value is present, it will be copied. @result Returns an IOReturn code. */ IOReturn (*setElementDefault)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * valueEvent); /*! @function getElementDefault @abstract Obtains the default value of an element in a transaction. @discussion An error will be returned if the element has not been added to the transaction. @param elementCookie The element of interest. @param outValueEvent The event that will be filled. If a long value is present, it is up to the caller to deallocate it. @result Returns an IOReturn code. */ IOReturn (*getElementDefault)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * outValueEvent); /*! @function setElementValue @abstract Sets the value of an element in a transaction. @discussion An error will be returned if the element has not been added to the transaction. @param elementCookie The element of interest. @param valueEvent The event that will be filled. If a long value is present, it will be copied. @result Returns an IOReturn code. */ IOReturn (*setElementValue)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * valueEvent); /*! @function getElementValue @abstract Obtains the value of an element in a transaction. @discussion An error will be returned if the element has not been added to the transaction. @param elementCookie The element of interest. @param outValueEvent The event that will be filled. If a long value is present, it is up to the caller to deallocate it. @result Returns an IOReturn code. */ IOReturn (*getElementValue)(void * self, IOHIDElementCookie elementCookie, IOHIDEventStruct * outValueEvent); /*! @function commit @abstract Commits the transaction. @discussion Transaction element values, if set, will be sent to the device. Otherwise, the default element value will be used. If neither are set, that element will be omitted from the commit. After a transaction is committed, transaction element values will be cleared. Default values will be preserved. @param timeoutMS UNSUPPORTED @param callback UNSUPPORTED @param callbackTarget UNSUPPORTED @param callbackRefcon UNSUPPORTED @result Returns an IOReturn code. */ IOReturn (*commit)(void * self, UInt32 timeoutMS, IOHIDCallbackFunction callback, void * callbackTarget, void * callbackRefcon); /*! @function clear @abstract Clears the transaction. @discussion Transaction element values will cleared. Default values will be preserved. @result Returns an IOReturn code. */ IOReturn (*clear)(void * self); } IOHIDOutputTransactionInterface; #endif __END_DECLS #endif /* !_IOKIT_HID_IOHIDLIB_H_ */