IOHIDDeviceClass.h [plain text]
#ifndef _IOKIT_IOHIDDeviceClass_H
#define _IOKIT_IOHIDDeviceClass_H
#include "IOHIDLib.h"
#include "IOHIDIUnknown.h"
class IOHIDQueueClass;
struct IOHIDElementStruct
{
unsigned long cookie;
long type;
long min;
long max;
long usage;
long usagePage;
long bytes;
unsigned long valueLocation;
CFDictionaryRef elementDictionaryRef;
};
typedef struct IOHIDElementStruct IOHIDElementStruct;
class IOHIDDeviceClass : public IOHIDIUnknown
{
typedef struct MyPrivateData {
io_object_t notification;
IOHIDDeviceClass * self;
} MyPrivateData;
private:
friend class IOHIDQueueClass;
friend class IOHIDOutputTransactionClass;
IOHIDDeviceClass(IOHIDDeviceClass &src);
void operator =(IOHIDDeviceClass &src);
protected:
IOHIDDeviceClass();
virtual ~IOHIDDeviceClass();
static IOCFPlugInInterface sIOCFPlugInInterfaceV1;
static IOHIDDeviceInterface122 sHIDDeviceInterfaceV122;
struct InterfaceMap fHIDDevice;
io_service_t fService;
io_connect_t fConnection;
IONotificationPortRef fAsyncPort;
CFRunLoopRef fRunLoop;
IONotificationPortRef fNotifyPort;
CFRunLoopSourceRef fCFSource;
CFRunLoopSourceRef fNotifyCFSource;
bool fIsOpen;
bool fIsLUNZero;
bool fIsTerminated;
bool fIsSeized;
bool fAsyncPortSetupDone;
UInt32 fCachedFlags;
MyPrivateData * fAsyncPrivateDataRef;
MyPrivateData * fNotifyPrivateDataRef;
IOHIDCallbackFunction fRemovalCallback;
void * fRemovalTarget;
void * fRemovalRefcon;
CFMutableSetRef fQueues;
CFMutableArrayRef fDeviceElements;
vm_address_t fCurrentValuesMappedMemory;
vm_size_t fCurrentValuesMappedMemorySize;
long fElementCount;
IOHIDElementStruct * fElements;
long fReportHandlerElementCount;
IOHIDElementStruct * fReportHandlerElements;
IOHIDQueueClass * fReportHandlerQueue;
IOHIDReportCallbackFunction fInputReportCallback;
void * fInputReportTarget;
void * fInputReportRefcon;
void * fInputReportBuffer;
UInt32 fInputReportBufferSize;
HRESULT queryInterfaceQueue (void **ppv);
HRESULT queryInterfaceOutputTransaction (void **ppv);
IOReturn fillElementValue(IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent);
void convertByteToWord( const UInt8 * src,
UInt32 * dst,
UInt32 bitsToCopy);
void convertWordToByte( const UInt32 * src,
UInt8 * dst,
UInt32 bitsToCopy);
IOReturn finishAsyncPortSetup();
IOReturn finishReportHandlerQueueSetup();
IOHIDQueueClass * createQueue(bool reportHandler=false);
static void _cfmachPortCallback(CFMachPortRef cfPort, mach_msg_header_t *msg, CFIndex size, void *info);
static void _hidReportCallback(void *refcon, IOReturn result, UInt32 bufferSize);
static void _deviceNotification( void *refCon,
io_service_t service,
natural_t messageType,
void *messageArgument );
static void _hidReportHandlerCallback(void * target, IOReturn result, void * refcon, void * sender);
public:
HRESULT attachQueue (IOHIDQueueClass * iohidQueue, bool reportHandler = false);
HRESULT detachQueue (IOHIDQueueClass * iohidQueue);
HRESULT attachOutputTransaction (IOHIDOutputTransactionClass * iohidOutputTrans);
HRESULT detachOutputTransaction (IOHIDOutputTransactionClass * iohidOutputTrans);
bool getElement(IOHIDElementCookie elementCookie, IOHIDElementStruct *element);
IOHIDElementType getElementType (IOHIDElementCookie elementCookie);
UInt32 getElementByteSize (IOHIDElementCookie elementCookie);
static IOCFPlugInInterface **alloc();
virtual HRESULT queryInterface(REFIID iid, void **ppv);
virtual IOReturn probe(CFDictionaryRef propertyTable,
io_service_t service, SInt32 *order);
virtual IOReturn start(CFDictionaryRef propertyTable,
io_service_t service);
virtual IOReturn createAsyncEventSource(CFRunLoopSourceRef *source);
virtual CFRunLoopSourceRef getAsyncEventSource();
virtual IOReturn createAsyncPort(mach_port_t *port);
virtual mach_port_t getAsyncPort();
virtual IOReturn open(UInt32 flags);
virtual IOReturn close();
virtual IOReturn setRemovalCallback(
IOHIDCallbackFunction removalCallback,
void * removalTarget,
void * removalRefcon);
virtual IOReturn getElementValue( IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent);
virtual IOReturn setElementValue(
IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent,
UInt32 timeoutMS = 0,
IOHIDElementCallbackFunction callback = NULL,
void * callbackTargetm = NULL,
void * callbackRefcon = NULL,
bool pushToDevice = false);
virtual IOReturn queryElementValue(
IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent,
UInt32 timeoutMS,
IOHIDElementCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
virtual IOReturn startAllQueues(bool deviceInitiated = false);
virtual IOReturn stopAllQueues(bool deviceInitiated = false);
virtual IOHIDQueueInterface ** allocQueue();
virtual IOHIDOutputTransactionInterface ** allocOutputTransaction();
virtual IOReturn setReport (IOHIDReportType reportType,
UInt32 reportID,
void * reportBuffer,
UInt32 reportBufferSize,
UInt32 timeoutMS,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
virtual IOReturn getReport (IOHIDReportType reportType,
UInt32 reportID,
void * reportBuffer,
UInt32 * reportBufferSize,
UInt32 timeoutMS,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
virtual IOReturn copyMatchingElements(
CFDictionaryRef matchingDict,
CFArrayRef * elements);
virtual IOReturn setInterruptReportHandlerCallback(
void * reportBuffer,
UInt32 reportBufferSize,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
protected:
static inline IOHIDDeviceClass *getThis(void *self)
{ return (IOHIDDeviceClass *) ((InterfaceMap *) self)->obj; };
static IOReturn deviceProbe(void *self,
CFDictionaryRef propertyTable,
io_service_t service, SInt32 *order);
static IOReturn deviceStart(void *self,
CFDictionaryRef propertyTable,
io_service_t service);
static IOReturn deviceStop(void *self);
static IOReturn deviceCreateAsyncEventSource(void *self,
CFRunLoopSourceRef *source);
static CFRunLoopSourceRef deviceGetAsyncEventSource(void *self);
static IOReturn deviceCreateAsyncPort(void *self, mach_port_t *port);
static mach_port_t deviceGetAsyncPort(void *self);
static IOReturn deviceOpen(void *self, UInt32 flags);
static IOReturn deviceClose(void *self);
static IOReturn deviceSetRemovalCallback(void * self,
IOHIDCallbackFunction removalCallback,
void * removalTarget,
void * removalRefcon);
static IOReturn deviceGetElementValue(void * self,
IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent);
static IOReturn deviceSetElementValue(void * self,
IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent,
UInt32 timeoutMS,
IOHIDElementCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
static IOReturn deviceQueryElementValue(void * self,
IOHIDElementCookie elementCookie,
IOHIDEventStruct * valueEvent,
UInt32 timeoutMS,
IOHIDElementCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
static IOReturn deviceStartAllQueues(void * self);
static IOReturn deviceStopAllQueues(void * self);
static IOHIDQueueInterface ** deviceAllocQueue(void *self);
static IOHIDOutputTransactionInterface ** deviceAllocOutputTransaction (void *self);
static IOReturn deviceSetReport (void * self,
IOHIDReportType reportType,
UInt32 reportID,
void * reportBuffer,
UInt32 reportBufferSize,
UInt32 timeoutMS,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
static IOReturn deviceGetReport (void * self,
IOHIDReportType reportType,
UInt32 reportID,
void * reportBuffer,
UInt32 * reportBufferSize,
UInt32 timeoutMS,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
static IOReturn deviceCopyMatchingElements(void * self,
CFDictionaryRef matchingDict,
CFArrayRef * elements);
static IOReturn deviceSetInterruptReportHandlerCallback(void * self,
void * reportBuffer,
UInt32 reportBufferSize,
IOHIDReportCallbackFunction callback,
void * callbackTarget,
void * callbackRefcon);
static void StaticCountElements (const void * value, void * parameter);
static void StaticCreateLeafElements (const void * value, void * parameter);
kern_return_t BuildElements (CFDictionaryRef properties, CFMutableArrayRef set);
long CountElements (CFDictionaryRef properties, CFTypeRef element, CFStringRef key);
kern_return_t CreateLeafElements (CFDictionaryRef properties,
CFMutableArrayRef array,
CFTypeRef element,
long * allocatedElementCount,
CFStringRef key,
IOHIDElementStruct *elements);
kern_return_t FindReportHandlers(CFDictionaryRef properties);
};
#endif