1/* 2 * 3 * @APPLE_LICENSE_HEADER_START@ 4 * 5 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 6 * 7 * This file contains Original Code and/or Modifications of Original Code 8 * as defined in and that are subject to the Apple Public Source License 9 * Version 2.0 (the 'License'). You may not use this file except in 10 * compliance with the License. Please obtain a copy of the License at 11 * http://www.opensource.apple.com/apsl/ and read it before using this 12 * file. 13 * 14 * The Original Code and all software distributed under the License are 15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 * Please see the License for the specific language governing rights and 20 * limitations under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 23 */ 24#ifndef _IOKIT_IOHIDQueueClass_H 25#define _IOKIT_IOHIDQueueClass_H 26 27#include <IOKit/IODataQueueShared.h> 28 29#include "IOHIDDeviceClass.h" 30 31class IOHIDQueueClass : public IOHIDIUnknown 32{ 33 // Disable copy constructors 34 IOHIDQueueClass(IOHIDQueueClass &src); 35 void operator =(IOHIDQueueClass &src); 36 37protected: 38 static IOHIDDeviceQueueInterface sHIDQueueInterfaceV2; 39 40 struct InterfaceMap fHIDQueue; 41 mach_port_t fAsyncPort; 42 CFMachPortRef fCFMachPort; 43 CFRunLoopSourceRef fCFSource; 44 45 // if created, how we were created 46 bool fIsCreated; 47 uint32_t fCreatedFlags; 48 uint32_t fCreatedDepth; 49 uint64_t fQueueRef; 50 51 bool fQueueEntrySizeChanged; 52 53 // ptr to shared memory for queue 54 IODataQueueMemory * fQueueMappedMemory; 55 vm_size_t fQueueMappedMemorySize; 56 57 // owming device 58 IOHIDDeviceClass * fOwningDevice; 59 60 // Related IOHIDQueue call back info 61 IOHIDCallback fEventCallback; 62 void * fEventRefcon; 63 CFMutableSetRef fElements; 64 65 static IOReturn _getAsyncEventSource(void *self, CFTypeRef *source); 66 static IOReturn _getAsyncPort(void *self, mach_port_t *port); 67 static IOReturn _setDepth(void *self, uint32_t depth, IOOptionBits options); 68 static IOReturn _getDepth(void *self, uint32_t *pDepth); 69 static IOReturn _addElement (void * self, IOHIDElementRef element, IOOptionBits options); 70 static IOReturn _removeElement (void * self, IOHIDElementRef element, IOOptionBits options); 71 static IOReturn _hasElement (void * self, IOHIDElementRef element, Boolean *pValue, IOOptionBits options); 72 static IOReturn _start (void * self, IOOptionBits options); 73 static IOReturn _stop (void * self, IOOptionBits options); 74 static IOReturn _copyNextEventValue (void * self, IOHIDValueRef * pEvent, uint32_t timeout, IOOptionBits options); 75 static IOReturn _setEventCallback ( void * self, IOHIDCallback callback, void * refcon); 76 77public: 78 IOHIDQueueClass(); 79 virtual ~IOHIDQueueClass(); 80 81 void setOwningDevice (IOHIDDeviceClass * owningDevice) { fOwningDevice = owningDevice; }; 82 void * getInterfaceMap () { return &fHIDQueue; }; 83 84 virtual HRESULT queryInterface(REFIID iid, void **ppv); 85 virtual IOReturn getAsyncEventSource(CFTypeRef *source); 86 virtual IOReturn getAsyncPort(mach_port_t *port); 87 IOReturn setAsyncPort(mach_port_t port); 88 89 virtual IOReturn create (IOOptionBits options, uint32_t depth); 90 virtual IOReturn dispose (); 91 virtual IOReturn getDepth(uint32_t * pDepth); 92 virtual IOReturn addElement (IOHIDElementRef element, IOOptionBits options = 0); 93 virtual IOReturn removeElement (IOHIDElementRef element, IOOptionBits options = 0); 94 virtual IOReturn hasElement (IOHIDElementRef element, Boolean * pValue, IOOptionBits options = 0); 95 virtual IOReturn start (IOOptionBits options = 0); 96 virtual IOReturn stop (IOOptionBits options = 0); 97 virtual IOReturn copyNextEventValue (IOHIDValueRef * pEvent, uint32_t timeout, IOOptionBits options = 0); 98 virtual IOReturn setEventCallback (IOHIDCallback callback, void * refcon); 99 100 static void queueEventSourceCallback(CFMachPortRef cfPort, mach_msg_header_t *msg, CFIndex size, void *info); 101 102 static inline IOHIDQueueClass *getThis(void *self) { return (IOHIDQueueClass *) ((InterfaceMap *) self)->obj; }; 103}; 104 105 106class IOHIDObsoleteQueueClass : public IOHIDQueueClass 107{ 108 // Disable copy constructors 109 IOHIDObsoleteQueueClass(IOHIDObsoleteQueueClass &src); 110 void operator =(IOHIDObsoleteQueueClass &src); 111 112 IOHIDCallbackFunction fCallback; 113 void * fTarget; 114 void * fRefcon; 115 116 static void _eventCallback(void * refcon, IOReturn result, void * sender); 117protected: 118 119 static IOHIDQueueInterface sHIDQueueInterface; 120 static IOReturn _createAsyncEventSource(void * self, CFRunLoopSourceRef * pSource); 121 static CFRunLoopSourceRef _getAsyncEventSource(void *self); 122 static mach_port_t _getAsyncPort(void *self); 123 static IOReturn _create(void * self, uint32_t flags, uint32_t depth); 124 static IOReturn _dispose (void * self); 125 static IOReturn _addElement (void * self, IOHIDElementCookie cookie, uint32_t flags); 126 static IOReturn _removeElement (void * self, IOHIDElementCookie cookie); 127 static Boolean _hasElement (void * self, IOHIDElementCookie cookie); 128 static IOReturn _start (void * self); 129 static IOReturn _stop (void * self); 130 static IOReturn _getNextEvent (void * self, IOHIDEventStruct * event, AbsoluteTime maxTime, uint32_t timeoutMS); 131 static IOReturn _getEventCallout (void * self, IOHIDCallbackFunction * pCallback, void ** pTarget, void ** pRefcon); 132 static IOReturn _setEventCallout (void * self, IOHIDCallbackFunction callback, void * target, void * refcon); 133 134public: 135 IOHIDObsoleteQueueClass(); 136 137 virtual HRESULT queryInterface(REFIID iid, void **ppv); 138 virtual IOReturn createAsyncEventSource(CFRunLoopSourceRef * pSource); 139 virtual IOReturn addElement (IOHIDElementCookie cookie, 140 uint32_t flags); 141 virtual IOReturn addElement (IOHIDElementRef element, 142 IOOptionBits options = 0); 143 virtual IOReturn removeElement (IOHIDElementCookie cookie); 144 virtual IOReturn removeElement (IOHIDElementRef element, 145 IOOptionBits options = 0); 146 virtual Boolean hasElement (IOHIDElementCookie cookie); 147 virtual IOReturn hasElement (IOHIDElementRef element, 148 Boolean * pValue, 149 IOOptionBits options = 0); 150 virtual IOReturn getNextEvent (IOHIDEventStruct * event, AbsoluteTime maxTime, uint32_t timeoutMS); 151 virtual IOReturn getEventCallout (IOHIDCallbackFunction * pCallback, void ** pTarget, void ** pRefcon); 152 virtual IOReturn setEventCallout (IOHIDCallbackFunction callback, void * target, void * refcon); 153 154 static inline IOHIDObsoleteQueueClass *getThis(void *self){ return (IOHIDObsoleteQueueClass *)((InterfaceMap *) self)->obj; }; 155 156}; 157 158 159#endif /* !_IOKIT_IOHIDQueueClass_H */ 160