Changeset 8351 for code/trunk/src/external/ois/mac
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (14 years ago)
- Location:
- code/trunk/src/external/ois/mac
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/ois/mac/CMakeLists.txt
r5929 r8351 3 3 MacHIDManager.h 4 4 MacInputManager.h 5 MacJoyStick.h 5 6 MacKeyboard.h 6 7 MacMouse.h 7 8 MacPrereqs.h 8 9 9 COMPILATION_BEGIN OISMacCompilation.cpp10 #COMPILATION_BEGIN OISMacCompilation.cpp 10 11 MacHelpers.cpp 11 12 MacHIDManager.cpp 12 13 MacInputManager.cpp 14 MacJoyStick.cpp 13 15 MacKeyboard.cpp 14 16 MacMouse.cpp 15 COMPILATION_END17 #COMPILATION_END 16 18 ) -
code/trunk/src/external/ois/mac/MacHIDManager.cpp
r5781 r8351 20 20 21 21 3. This notice may not be removed or altered from any source distribution. 22 */22 */ 23 23 #include "mac/MacHIDManager.h" 24 #include "mac/MacJoyStick.h" 24 25 #include "OISException.h" 25 26 #include "OISObject.h" … … 42 43 { 43 44 CFTypeRef temp = CFDictionaryGetValue(dict, OIS_CFString(keyName)); 44 45 45 46 if(temp && CFGetTypeID(temp) == CFArrayGetTypeID()) 46 47 return (CFArrayRef)temp; … … 53 54 { 54 55 CFTypeRef temp = CFDictionaryGetValue(dict, OIS_CFString(keyName)); 55 56 56 57 if(temp && CFGetTypeID(temp) == CFStringGetTypeID()) 57 58 return (CFStringRef)temp; … … 64 65 { 65 66 CFTypeRef temp = CFDictionaryGetValue(dict, OIS_CFString(keyName)); 66 67 67 68 if(temp && CFGetTypeID(temp) == CFNumberGetTypeID()) 68 69 return (CFNumberRef)temp; … … 83 84 { 84 85 CFTypeRef temp = CFArrayGetValueAtIndex(array, idx); 85 86 86 87 if(temp && CFGetTypeID(temp) == CFDictionaryGetTypeID()) 87 88 return (CFDictionaryRef)temp; … … 93 94 int getInt32(CFNumberRef ref) 94 95 { 95 96 97 98 96 int r = 0; 97 if (r) 98 CFNumberGetValue(ref, kCFNumberIntType, &r); 99 return r; 99 100 } 100 101 … … 111 112 //------------------------------------------------------------------------------------------------------// 112 113 void MacHIDManager::initialize() 114 { 115 //Make the search more specific by adding usage flags 116 int usage = kHIDUsage_GD_Joystick; 117 int page = kHIDPage_GenericDesktop; 118 119 io_iterator_t iterator = lookUpDevices(usage, page); 120 121 if(iterator) 122 iterateAndOpenDevices(iterator); 123 124 //Doesn't support multiple usage flags, iterate twice 125 usage = kHIDUsage_GD_GamePad; 126 iterator = lookUpDevices(usage, page); 127 128 if(iterator) 129 iterateAndOpenDevices(iterator); 130 } 131 132 //------------------------------------------------------------------------------------------------------// 133 io_iterator_t MacHIDManager::lookUpDevices(int usage, int page) 113 134 { 114 135 CFMutableDictionaryRef deviceLookupMap = IOServiceMatching(kIOHIDDeviceKey); 115 136 if(!deviceLookupMap) 116 137 OIS_EXCEPT(E_General, "Could not setup HID device search parameters"); 117 118 //Make the search more specific by adding usage flags 119 int usage = kHIDUsage_GD_GamePad | kHIDUsage_GD_Joystick, 120 page = kHIDPage_GenericDesktop; 121 122 CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage), 123 pageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); 124 138 139 CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); 140 CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); 141 125 142 CFDictionarySetValue(deviceLookupMap, CFSTR(kIOHIDPrimaryUsageKey), usageRef); 126 143 CFDictionarySetValue(deviceLookupMap, CFSTR(kIOHIDPrimaryUsagePageKey), pageRef); 127 144 128 145 //IOServiceGetMatchingServices consumes the map so we do not have to release it ourself 129 146 io_iterator_t iterator = 0; 130 147 IOReturn result = IOServiceGetMatchingServices(kIOMasterPortDefault, deviceLookupMap, &iterator); 131 if (result == kIOReturnSuccess && iterator) 132 { 133 io_object_t hidDevice = 0; 134 while ((hidDevice = IOIteratorNext(iterator)) !=0) 148 149 CFRelease(usageRef); 150 CFRelease(pageRef); 151 152 if(result == kIOReturnSuccess) 153 { 154 return iterator; 155 } 156 //TODO: Throw exception instead? 157 else 158 { 159 return 0; 160 } 161 } 162 163 //------------------------------------------------------------------------------------------------------// 164 void MacHIDManager::iterateAndOpenDevices(io_iterator_t iterator) 165 { 166 io_object_t hidDevice = 0; 167 while ((hidDevice = IOIteratorNext(iterator)) !=0) 168 { 169 //Get the current registry items property map 170 CFMutableDictionaryRef propertyMap = 0; 171 if (IORegistryEntryCreateCFProperties(hidDevice, &propertyMap, kCFAllocatorDefault, kNilOptions) == KERN_SUCCESS && propertyMap) 135 172 { 136 //Get the current registry items property map 137 CFMutableDictionaryRef propertyMap = 0; 138 if (IORegistryEntryCreateCFProperties(hidDevice, &propertyMap, kCFAllocatorDefault, kNilOptions) == KERN_SUCCESS && propertyMap) 173 //Go through device to find all needed info 174 HidInfo* hid = enumerateDeviceProperties(propertyMap); 175 176 if(hid) 139 177 { 140 //Go through device to find all needed info141 HidInfo* hid = enumerateDeviceProperties(propertyMap);142 if(hid)143 mDeviceList.push_back(hid);144 145 178 //todo - we need to hold an open interface so we do not have to enumerate again later 146 179 //should be able to watch for device removals also 147 148 /// Testing opening / closing interface 149 //IOCFPlugInInterface **pluginInterface = NULL; 150 //SInt32 score = 0; 151 //if (IOCreatePlugInInterfaceForService(hidDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &pluginInterface, &score) == kIOReturnSuccess) 152 //{ 153 // IOHIDDeviceInterface **interface; 154 // HRESULT pluginResult = (*pluginInterface)->QueryInterface(pluginInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void **)&(interface)); 155 // if(pluginResult == S_OK) 156 // cout << "Successfully created plugin interface for device\n"; 157 // else 158 // cout << "Not able to create plugin interface\n"; 159 160 // IODestroyPlugInInterface(pluginInterface); 161 162 // if ((*interface)->open(interface, 0) == KERN_SUCCESS) 163 // cout << "Opened interface.\n"; 164 // else 165 // cout << "Failed to open\n"; 166 167 // (*interface)->close(interface); 168 //} 169 // 180 181 // Testing opening / closing interface 182 IOCFPlugInInterface **pluginInterface = NULL; 183 SInt32 score = 0; 184 if (IOCreatePlugInInterfaceForService(hidDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &pluginInterface, &score) == kIOReturnSuccess) 185 { 186 IOHIDDeviceInterface **interface; 187 188 HRESULT pluginResult = (*pluginInterface)->QueryInterface(pluginInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void **)&(interface)); 189 190 if(pluginResult != S_OK) 191 OIS_EXCEPT(E_General, "Not able to create plugin interface"); 192 193 IODestroyPlugInInterface(pluginInterface); 194 195 hid->interface = interface; 196 197 //Check for duplicates - some devices have multiple usage 198 if(std::find(mDeviceList.begin(), mDeviceList.end(), hid) == mDeviceList.end()) 199 mDeviceList.push_back(hid); 200 } 170 201 } 171 202 } 172 173 IOObjectRelease(iterator); 174 } 175 176 CFRelease(usageRef); 177 CFRelease(pageRef); 203 } 204 205 IOObjectRelease(iterator); 178 206 } 179 207 … … 188 216 if (str) 189 217 info->vendor = CFStringGetCStringPtr(str, CFStringGetSystemEncoding()); 190 218 191 219 str = getDictionaryItemAsRef<CFStringRef>(propertyMap, kIOHIDProductKey); 192 220 if (str) 193 221 info->productKey = CFStringGetCStringPtr(str, CFStringGetSystemEncoding()); 194 222 195 223 info->combinedKey = info->vendor + " " + info->productKey; 196 224 197 225 //Go through all items in this device (i.e. buttons, hats, sticks, axes, etc) 198 226 CFArrayRef array = getDictionaryItemAsRef<CFArrayRef>(propertyMap, kIOHIDElementKey); … … 200 228 for (int i = 0; i < CFArrayGetCount(array); i++) 201 229 parseDeviceProperties(getArrayItemAsRef<CFDictionaryRef>(array, i)); 202 230 203 231 return info; 204 232 } … … 209 237 if(!properties) 210 238 return; 211 239 212 240 CFArrayRef array = getDictionaryItemAsRef<CFArrayRef>(properties, kIOHIDElementKey); 213 241 if (array) … … 227 255 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsagePageKey))) 228 256 { 229 case kHIDPage_GenericDesktop:230 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsageKey)))257 case kHIDPage_GenericDesktop: 258 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsageKey))) 231 259 { 232 case kHIDUsage_GD_Pointer: 233 cout << "\tkHIDUsage_GD_Pointer\n"; 234 parseDevicePropertiesGroup(element); 260 case kHIDUsage_GD_Pointer: 261 cout << "\tkHIDUsage_GD_Pointer\n"; 262 parseDevicePropertiesGroup(element); 263 break; 264 case kHIDUsage_GD_X: 265 case kHIDUsage_GD_Y: 266 case kHIDUsage_GD_Z: 267 case kHIDUsage_GD_Rx: 268 case kHIDUsage_GD_Ry: 269 case kHIDUsage_GD_Rz: 270 cout << "\tAxis\n"; 271 break; 272 case kHIDUsage_GD_Slider: 273 case kHIDUsage_GD_Dial: 274 case kHIDUsage_GD_Wheel: 275 cout << "\tUnsupported kHIDUsage_GD_Wheel\n"; 276 break; 277 case kHIDUsage_GD_Hatswitch: 278 cout << "\tUnsupported - kHIDUsage_GD_Hatswitch\n"; 279 break; 280 } 235 281 break; 236 case kHIDUsage_GD_X: 237 case kHIDUsage_GD_Y: 238 case kHIDUsage_GD_Z: 239 case kHIDUsage_GD_Rx: 240 case kHIDUsage_GD_Ry: 241 case kHIDUsage_GD_Rz: 242 cout << "\tAxis\n"; 282 case kHIDPage_Button: 283 cout << "\tkHIDPage_Button\n"; 243 284 break; 244 case kHIDUsage_GD_Slider:245 case kHIDUsage_GD_Dial:246 case kHIDUsage_GD_Wheel:247 cout << "\tUnsupported kHIDUsage_GD_Wheel\n";248 break;249 case kHIDUsage_GD_Hatswitch:250 cout << "\tUnsupported - kHIDUsage_GD_Hatswitch\n";251 break;252 }253 break;254 case kHIDPage_Button:255 cout << "\tkHIDPage_Button\n";256 break;257 285 } 258 286 } … … 267 295 if(!properties) 268 296 return; 269 297 270 298 CFArrayRef array = getDictionaryItemAsRef<CFArrayRef>(properties, kIOHIDElementKey); 271 299 if(array) … … 278 306 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsagePageKey))) 279 307 { 280 case kHIDPage_GenericDesktop:281 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsageKey)))308 case kHIDPage_GenericDesktop: 309 switch(getInt32(getDictionaryItemAsRef<CFNumberRef>(element, kIOHIDElementUsageKey))) 282 310 { 283 case kHIDUsage_GD_X: 284 case kHIDUsage_GD_Y: 285 case kHIDUsage_GD_Z: 286 case kHIDUsage_GD_Rx: 287 case kHIDUsage_GD_Ry: 288 case kHIDUsage_GD_Rz: 289 cout << "\t\tAxis\n"; 311 case kHIDUsage_GD_X: 312 case kHIDUsage_GD_Y: 313 case kHIDUsage_GD_Z: 314 case kHIDUsage_GD_Rx: 315 case kHIDUsage_GD_Ry: 316 case kHIDUsage_GD_Rz: 317 cout << "\t\tAxis\n"; 318 break; 319 case kHIDUsage_GD_Slider: 320 case kHIDUsage_GD_Dial: 321 case kHIDUsage_GD_Wheel: 322 cout << "\tUnsupported - kHIDUsage_GD_Wheel\n"; 323 break; 324 case kHIDUsage_GD_Hatswitch: 325 cout << "\tUnsupported - kHIDUsage_GD_Hatswitch\n"; 326 break; 327 } 290 328 break; 291 case kHIDUsage_GD_Slider: 292 case kHIDUsage_GD_Dial: 293 case kHIDUsage_GD_Wheel: 294 cout << "\tUnsupported - kHIDUsage_GD_Wheel\n"; 329 case kHIDPage_Button: 295 330 break; 296 case kHIDUsage_GD_Hatswitch:297 cout << "\tUnsupported - kHIDUsage_GD_Hatswitch\n";298 break;299 }300 break;301 case kHIDPage_Button:302 break;303 331 } 304 332 } … … 317 345 ret.insert(std::make_pair((*it)->type, (*it)->combinedKey)); 318 346 } 319 347 320 348 return ret; 321 349 } … … 326 354 int ret = 0; 327 355 HidInfoList::iterator it = mDeviceList.begin(), end = mDeviceList.end(); 328 356 329 357 for(; it != end; ++it) 330 358 { … … 341 369 int ret = 0; 342 370 HidInfoList::iterator it = mDeviceList.begin(), end = mDeviceList.end(); 343 371 344 372 for(; it != end; ++it) 345 373 { … … 347 375 ret++; 348 376 } 349 377 350 378 return ret; 351 379 } … … 355 383 { 356 384 HidInfoList::iterator it = mDeviceList.begin(), end = mDeviceList.end(); 357 385 358 386 for(; it != end; ++it) 359 387 { … … 367 395 //--------------------------------------------------------------------------------// 368 396 Object* MacHIDManager::createObject(InputManager* creator, Type iType, bool bufferMode, 369 397 const std::string & vendor) 370 398 { 371 399 Object *obj = 0; 372 400 373 401 HidInfoList::iterator it = mDeviceList.begin(), end = mDeviceList.end(); 374 402 for(; it != end; ++it) … … 376 404 if((*it)->inUse == false && (*it)->type == iType && (vendor == "" || (*it)->combinedKey == vendor)) 377 405 { 378 //create device 406 switch(iType) 407 { 408 case OISJoyStick: 409 { 410 int totalDevs = totalDevices(iType); 411 int freeDevs = freeDevices(iType); 412 int devID = totalDevs - freeDevs; 413 414 obj = new MacJoyStick((*it)->combinedKey, bufferMode, *it, creator, devID); 415 (*it)->inUse = true; 416 return obj; 417 } 418 case OISTablet: 419 //Create MacTablet 420 break; 421 default: 422 break; 423 } 379 424 } 380 425 } 381 382 if( obj == 0 ) 383 OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type."); 384 426 385 427 return obj; 386 428 } -
code/trunk/src/external/ois/mac/MacHIDManager.h
r5781 r8351 70 70 71 71 void initialize(); 72 73 void iterateAndOpenDevices(io_iterator_t iterator); 74 io_iterator_t lookUpDevices(int usage, int page); 72 75 73 76 //FactoryCreator Overrides -
code/trunk/src/external/ois/mac/MacInputManager.cpp
r5781 r8351 188 188 } 189 189 default: 190 { 191 obj = mHIDManager->createObject(creator, iType, bufferMode, vendor); 190 192 break; 193 } 191 194 } 192 195 -
code/trunk/src/external/ois/mac/MacKeyboard.cpp
r5781 r8351 199 199 char macChar; 200 200 201 // TODO clean this up202 201 if (mTextMode == Unicode) 203 202 { 204 203 //get string size 205 204 UInt32 stringsize; 206 //status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, 0, &stringsize, NULL);207 //status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, sizeof(UniChar)*10, NULL, &text );208 205 status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, sizeof(UniChar) * 10, &stringsize, &text ); 209 std::cout << "String length: " << stringsize << std::endl;210 211 //wstring unitext;212 //for (int i=0;i<10;i++) unitext += (wchar_t)text[i];213 //wcout << "Unicode out: " << unitext << endl;214 206 215 207 if(stringsize > 0)
Note: See TracChangeset
for help on using the changeset viewer.