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_IOHIDUPSClass_H 25#define _IOKIT_IOHIDUPSClass_H 26 27 28#include <IOKit/ps/IOUPSPlugIn.h> 29#include <IOKit/hid/IOHIDLib.h> 30#include "IOHIDIUnknown.h" 31 32//--------------------------------------------------------------------------- 33// UPSElementStruct 34//--------------------------------------------------------------------------- 35struct UPSHIDElement { 36 SInt32 currentValue; 37 SInt32 usagePage; 38 SInt32 usage; 39 SInt32 unit; 40 SInt8 unitExponent; 41 bool isCommand; 42 bool isDesiredCollection; 43 bool isDesiredType; 44 bool shouldPoll; 45 double multiplier; 46 IOHIDElementType type; 47 IOHIDElementCookie cookie; 48 IOReturn lastReturn; 49}; 50 51#define kIOHIDUnitVolt 0xf0d121 52#define kIOHIDUnitAmp 0x100001 53 54#define kIOHIDUnitExponentVolt 7 55#define kIOHIDUnitExponentAmp -2 56 57class IOHIDUPSClass : public IOHIDIUnknown 58{ 59private: 60 // Disable copy constructors 61 IOHIDUPSClass(IOHIDUPSClass &src); 62 void operator =(IOHIDUPSClass &src); 63 64protected: 65 IOHIDUPSClass(); 66 virtual ~IOHIDUPSClass(); 67 68 static IOCFPlugInInterface sIOCFPlugInInterfaceV1; 69 static IOUPSPlugInInterface_v140 sUPSPlugInInterface_v140; 70 71 struct InterfaceMap _upsDevice; 72 io_service_t _service; 73 74 CFTypeRef _asyncEventSource; 75 76 IOHIDDeviceInterface122 ** _hidDeviceInterface; 77 IOHIDQueueInterface ** _hidQueueInterface; 78 IOHIDOutputTransactionInterface ** _hidTransactionInterface; 79 80 CFMutableDictionaryRef _hidProperties; 81 CFMutableDictionaryRef _hidElements; 82 CFMutableDictionaryRef _upsElements; 83 84 CFMutableDictionaryRef _upsEvent; 85 CFMutableDictionaryRef _upsProperties; 86 CFSetRef _upsCapabilities; 87 88 IOUPSEventCallbackFunction _eventCallback; 89 void * _eventTarget; 90 void * _eventRefcon; 91 92 bool _isACPresent; 93 94 95 static inline IOHIDUPSClass *getThis(void *self) 96 { return (IOHIDUPSClass *) ((InterfaceMap *) self)->obj; }; 97 98 // IOCFPlugInInterface methods 99 static IOReturn _probe(void *self, 100 CFDictionaryRef propertyTable, 101 io_service_t service, SInt32 *order); 102 103 static IOReturn _start(void *self, 104 CFDictionaryRef propertyTable, 105 io_service_t service); 106 107 static IOReturn _stop(void *self); 108 109 // IOUPSPlugInInterface methods 110 static IOReturn _getProperties( 111 void * self, 112 CFDictionaryRef * properties); 113 114 static IOReturn _getCapabilities( 115 void * self, 116 CFSetRef * capabilities); 117 118 static IOReturn _getEvent( 119 void * self, 120 CFDictionaryRef * event); 121 122 static IOReturn _setEventCallback( 123 void * self, 124 IOUPSEventCallbackFunction callback, 125 void * target, 126 void * refcon); 127 128 static IOReturn _sendCommand( 129 void * self, 130 CFDictionaryRef command); 131 132 static IOReturn _createAsyncEventSource( 133 void * self, 134 CFTypeRef * eventSource); 135 136 static void _queueCallbackFunction( 137 void * target, 138 IOReturn result, 139 void * refcon, 140 void * sender); 141 142 static void _timerCallbackFunction( 143 CFRunLoopTimerRef timer, 144 void * refCon); 145 146 bool findElements(); 147 148 void storeUPSElement(CFStringRef psKey, UPSHIDElement * newElementRef); 149 150 bool updateElementValue(UPSHIDElement * tempHIDElement, IOReturn * error); 151 152 bool setupQueue(); 153 154 bool processEvent(UPSHIDElement * hidElement); 155 156public: 157 // IOCFPlugin stuff 158 static IOCFPlugInInterface **alloc(); 159 160 virtual HRESULT queryInterface(REFIID iid, void **ppv); 161 162 virtual IOReturn probe( 163 CFDictionaryRef propertyTable, 164 io_service_t service, 165 SInt32 * order); 166 167 virtual IOReturn start( 168 CFDictionaryRef propertyTable, 169 io_service_t service); 170 171 virtual IOReturn stop(); 172 173 virtual IOReturn getProperties( 174 CFDictionaryRef * properties); 175 176 virtual IOReturn getCapabilities( 177 CFSetRef * capabilities); 178 179 virtual IOReturn getEvent( 180 CFDictionaryRef * event, 181 bool * changed = NULL); 182 183 virtual void getEventProcess( 184 UPSHIDElement * elementRef, 185 CFStringRef psKey, 186 bool * changed); 187 188 virtual IOReturn setEventCallback( 189 IOUPSEventCallbackFunction callback, 190 void * target, 191 void * refcon); 192 193 virtual IOReturn sendCommand( 194 CFDictionaryRef command); 195 196 virtual void sendCommandProcess( 197 UPSHIDElement * elementRef, 198 SInt32 value); 199 200 virtual IOReturn createAsyncEventSource( 201 CFTypeRef * eventSource); 202 203}; 204 205#endif /* !_IOKIT_IOHIDUPSClass_H */ 206