oculus1
view libovr/Src/osx/OVR_OSX_HIDDevice.cpp @ 23:0c76f70fb7e9
merged
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Sep 2013 04:13:33 +0300 |
parents | |
children |
line source
1 /************************************************************************************
2 Filename : OVR_OSX_HIDDevice.cpp
3 Content : OSX HID device implementation.
4 Created : February 26, 2013
5 Authors : Lee Cooper
7 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
9 Use of this software is subject to the terms of the Oculus license
10 agreement provided at the time of installation or download, or which
11 otherwise accompanies this software in either electronic or hard copy form.
13 *************************************************************************************/
15 #include "OVR_OSX_HIDDevice.h"
17 #include <IOKit/usb/IOUSBLib.h>
19 namespace OVR { namespace OSX {
21 static const UInt32 MAX_QUEUED_INPUT_REPORTS = 5;
23 //-------------------------------------------------------------------------------------
24 // **** OSX::DeviceManager
26 HIDDeviceManager::HIDDeviceManager(DeviceManager* manager)
27 : DevManager(manager)
28 {
29 HIDManager = NULL;
30 }
32 HIDDeviceManager::~HIDDeviceManager()
33 {
34 }
36 CFRunLoopRef HIDDeviceManager::getRunLoop()
37 {
38 if (DevManager != NULL)
39 {
40 return DevManager->pThread->GetRunLoop();
41 }
43 return CFRunLoopGetCurrent();
44 }
46 bool HIDDeviceManager::initializeManager()
47 {
48 if (HIDManager != NULL)
49 {
50 return true;
51 }
53 HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
55 if (!HIDManager)
56 {
57 return false;
58 }
60 // Create a Matching Dictionary
61 CFMutableDictionaryRef matchDict =
62 CFDictionaryCreateMutable(kCFAllocatorDefault,
63 2,
64 &kCFTypeDictionaryKeyCallBacks,
65 &kCFTypeDictionaryValueCallBacks);
67 // Specify a device manufacturer in the Matching Dictionary
68 UInt32 vendorId = Oculus_VendorId;
69 CFNumberRef vendorIdRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vendorId);
70 CFDictionarySetValue(matchDict,
71 CFSTR(kIOHIDVendorIDKey),
72 vendorIdRef);
73 // Register the Matching Dictionary to the HID Manager
74 IOHIDManagerSetDeviceMatching(HIDManager, matchDict);
75 CFRelease(vendorIdRef);
76 CFRelease(matchDict);
78 // Register a callback for USB device detection with the HID Manager
79 IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, &staticDeviceMatchingCallback, this);
81 IOHIDManagerScheduleWithRunLoop(HIDManager, getRunLoop(), kCFRunLoopDefaultMode);
83 return true;
84 }
86 bool HIDDeviceManager::Initialize()
87 {
88 return initializeManager();
89 }
91 void HIDDeviceManager::Shutdown()
92 {
93 OVR_ASSERT_LOG(HIDManager, ("Should have called 'Initialize' before 'Shutdown'."));
94 CFRelease(HIDManager);
96 LogText("OVR::OSX::HIDDeviceManager - shutting down.\n");
97 }
99 bool HIDDeviceManager::getIntProperty(IOHIDDeviceRef device, CFStringRef propertyName, SInt32* pResult)
100 {
102 CFTypeRef ref = IOHIDDeviceGetProperty(device, propertyName);
104 if (!ref)
105 {
106 return false;
107 }
109 if (CFGetTypeID(ref) != CFNumberGetTypeID())
110 {
111 return false;
112 }
114 CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, pResult);
116 return true;
117 }
119 bool HIDDeviceManager::initVendorProductVersion(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc)
120 {
122 if (!getVendorId(device, &(pDevDesc->VendorId)))
123 {
124 return false;
125 }
127 if (!getProductId(device, &(pDevDesc->ProductId)))
128 {
129 return false;
130 }
132 return true;
133 }
135 bool HIDDeviceManager::initUsage(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc)
136 {
138 SInt32 result;
140 if (!getIntProperty(device, CFSTR(kIOHIDPrimaryUsagePageKey), &result))
141 {
142 return false;
143 }
145 pDevDesc->UsagePage = result;
148 if (!getIntProperty(device, CFSTR(kIOHIDPrimaryUsageKey), &result))
149 {
150 return false;
151 }
153 pDevDesc->Usage = result;
155 return true;
156 }
158 bool HIDDeviceManager::initSerialNumber(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc)
159 {
160 return getSerialNumberString(device, &(pDevDesc->SerialNumber));
161 }
163 bool HIDDeviceManager::initStrings(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc)
164 {
166 // Regardless of whether they fail we'll try and get the remaining.
167 getStringProperty(device, CFSTR(kIOHIDManufacturerKey), &(pDevDesc->Manufacturer));
168 getStringProperty(device, CFSTR(kIOHIDProductKey), &(pDevDesc->Product));
170 return true;
171 }
173 bool HIDDeviceManager::getStringProperty(IOHIDDeviceRef device,
174 CFStringRef propertyName,
175 String* pResult)
176 {
178 CFStringRef str = (CFStringRef) IOHIDDeviceGetProperty(device, propertyName);
180 if (!str)
181 {
182 return false;
183 }
185 CFIndex length = CFStringGetLength(str);
186 CFRange range = CFRangeMake(0, length);
188 // Test the conversion first to get required buffer size.
189 CFIndex bufferLength;
190 CFIndex numberOfChars = CFStringGetBytes(str,
191 range,
192 kCFStringEncodingUTF8,
193 (char) '?',
194 FALSE,
195 NULL,
196 0,
197 &bufferLength);
199 if (numberOfChars == 0)
200 {
201 return false;
202 }
204 // Now allocate buffer.
205 char* buffer = new char[bufferLength+1];
207 numberOfChars = CFStringGetBytes(str,
208 range,
209 kCFStringEncodingUTF8,
210 (char) '?',
211 FALSE,
212 (UInt8*) buffer,
213 bufferLength,
214 NULL);
215 OVR_ASSERT_LOG(numberOfChars != 0, ("CFStringGetBytes failed."));
217 buffer[bufferLength] = '\0';
218 *pResult = String(buffer);
220 return true;
221 }
223 bool HIDDeviceManager::getVendorId(IOHIDDeviceRef device, UInt16* pResult)
224 {
225 SInt32 result;
227 if (!getIntProperty(device, CFSTR(kIOHIDVendorIDKey), &result))
228 {
229 return false;
230 }
232 *pResult = result;
234 return true;
235 }
237 bool HIDDeviceManager::getProductId(IOHIDDeviceRef device, UInt16* pResult)
238 {
239 SInt32 result;
241 if (!getIntProperty(device, CFSTR(kIOHIDProductIDKey), &result))
242 {
243 return false;
244 }
246 *pResult = result;
248 return true;
249 }
251 bool HIDDeviceManager::getLocationId(IOHIDDeviceRef device, SInt32* pResult)
252 {
253 SInt32 result;
255 if (!getIntProperty(device, CFSTR(kIOHIDLocationIDKey), &result))
256 {
257 return false;
258 }
260 *pResult = result;
262 return true;
263 }
265 bool HIDDeviceManager::getSerialNumberString(IOHIDDeviceRef device, String* pResult)
266 {
268 if (!getStringProperty(device, CFSTR(kIOHIDSerialNumberKey), pResult))
269 {
270 return false;
271 }
273 return true;
274 }
276 bool HIDDeviceManager::getPath(IOHIDDeviceRef device, String* pPath)
277 {
279 String transport;
280 if (!getStringProperty(device, CFSTR(kIOHIDTransportKey), &transport))
281 {
282 return false;
283 }
285 UInt16 vendorId;
286 if (!getVendorId(device, &vendorId))
287 {
288 return false;
289 }
291 UInt16 productId;
292 if (!getProductId(device, &productId))
293 {
294 return false;
295 }
297 String serialNumber;
298 if (!getSerialNumberString(device, &serialNumber))
299 {
300 return false;
301 }
304 StringBuffer buffer;
305 buffer.AppendFormat("%s:vid=%04hx:pid=%04hx:ser=%s",
306 transport.ToCStr(),
307 vendorId,
308 productId,
309 serialNumber.ToCStr());
311 *pPath = String(buffer);
313 return true;
314 }
316 bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor)
317 {
318 if (!initializeManager())
319 {
320 return false;
321 }
324 CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager);
325 if (!deviceSet)
326 return false;
328 CFIndex deviceCount = CFSetGetCount(deviceSet);
330 // Allocate a block of memory and read the set into it.
331 IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount);
332 CFSetGetValues(deviceSet, (const void **) devices);
335 // Iterate over devices.
336 for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
337 {
338 IOHIDDeviceRef hidDev = devices[deviceIndex];
340 if (!hidDev)
341 {
342 continue;
343 }
345 HIDDeviceDesc devDesc;
347 if (getPath(hidDev, &(devDesc.Path)) &&
348 initVendorProductVersion(hidDev, &devDesc) &&
349 enumVisitor->MatchVendorProduct(devDesc.VendorId, devDesc.ProductId) &&
350 initUsage(hidDev, &devDesc))
351 {
352 initStrings(hidDev, &devDesc);
353 initSerialNumber(hidDev, &devDesc);
355 // Look for the device to check if it is already opened.
356 Ptr<DeviceCreateDesc> existingDevice = DevManager->FindHIDDevice(devDesc);
357 // if device exists and it is opened then most likely the CreateHIDFile
358 // will fail; therefore, we just set Enumerated to 'true' and continue.
359 if (existingDevice && existingDevice->pDevice)
360 {
361 existingDevice->Enumerated = true;
362 continue;
363 }
365 // Construct minimal device that the visitor callback can get feature reports from.
366 OSX::HIDDevice device(this, hidDev);
368 enumVisitor->Visit(device, devDesc);
369 }
370 }
372 OVR_FREE(devices);
373 CFRelease(deviceSet);
375 return true;
376 }
378 OVR::HIDDevice* HIDDeviceManager::Open(const String& path)
379 {
381 Ptr<OSX::HIDDevice> device = *new OSX::HIDDevice(this);
383 if (!device->HIDInitialize(path))
384 {
385 return NULL;
386 }
388 device->AddRef();
390 return device;
391 }
393 bool HIDDeviceManager::getFullDesc(IOHIDDeviceRef device, HIDDeviceDesc* desc)
394 {
396 if (!initVendorProductVersion(device, desc))
397 {
398 return false;
399 }
401 if (!initUsage(device, desc))
402 {
403 return false;
404 }
406 if (!initSerialNumber(device, desc))
407 {
408 return false;
409 }
411 initStrings(device, desc);
413 return true;
414 }
416 // New USB device specified in the matching dictionary has been added (callback function)
417 void HIDDeviceManager::staticDeviceMatchingCallback(void *inContext,
418 IOReturn inResult,
419 void *inSender,
420 IOHIDDeviceRef inIOHIDDeviceRef)
421 {
422 HIDDeviceManager* hidMgr = static_cast<HIDDeviceManager*>(inContext);
423 HIDDeviceDesc hidDevDesc;
424 hidMgr->getPath(inIOHIDDeviceRef, &hidDevDesc.Path);
425 hidMgr->getFullDesc(inIOHIDDeviceRef, &hidDevDesc);
427 hidMgr->DevManager->DetectHIDDevice(hidDevDesc);
428 }
430 //-------------------------------------------------------------------------------------
431 // **** OSX::HIDDevice
433 HIDDevice::HIDDevice(HIDDeviceManager* manager)
434 : HIDManager(manager), InMinimalMode(false)
435 {
436 Device = NULL;
437 RepluggedNotificationPort = 0;
438 }
440 // This is a minimal constructor used during enumeration for us to pass
441 // a HIDDevice to the visit function (so that it can query feature reports).
442 HIDDevice::HIDDevice(HIDDeviceManager* manager, IOHIDDeviceRef device)
443 : HIDManager(manager), Device(device), InMinimalMode(true)
444 {
445 RepluggedNotificationPort = 0;
446 }
448 HIDDevice::~HIDDevice()
449 {
450 if (!InMinimalMode)
451 {
452 HIDShutdown();
453 }
454 }
456 bool HIDDevice::HIDInitialize(const String& path)
457 {
459 DevDesc.Path = path;
461 if (!openDevice())
462 {
463 LogText("OVR::OSX::HIDDevice - Failed to open HIDDevice: %s", path.ToCStr());
464 return false;
465 }
467 // Setup notification for when a device is unplugged and plugged back in.
468 if (!setupDevicePluggedInNotification())
469 {
470 LogText("OVR::OSX::HIDDevice - Failed to setup notification for when device plugged back in.");
471 closeDevice(false);
472 return false;
473 }
475 HIDManager->DevManager->pThread->AddTicksNotifier(this);
478 LogText("OVR::OSX::HIDDevice - Opened '%s'\n"
479 " Manufacturer:'%s' Product:'%s' Serial#:'%s'\n",
480 DevDesc.Path.ToCStr(),
481 DevDesc.Manufacturer.ToCStr(), DevDesc.Product.ToCStr(),
482 DevDesc.SerialNumber.ToCStr());
484 return true;
485 }
487 bool HIDDevice::initInfo()
488 {
489 // Device must have been successfully opened.
490 OVR_ASSERT(Device);
493 // Get report lengths.
494 SInt32 bufferLength;
495 bool getResult = HIDManager->getIntProperty(Device, CFSTR(kIOHIDMaxInputReportSizeKey), &bufferLength);
496 OVR_ASSERT(getResult);
497 InputReportBufferLength = (UInt16) bufferLength;
499 getResult = HIDManager->getIntProperty(Device, CFSTR(kIOHIDMaxOutputReportSizeKey), &bufferLength);
500 OVR_ASSERT(getResult);
501 OutputReportBufferLength = (UInt16) bufferLength;
503 getResult = HIDManager->getIntProperty(Device, CFSTR(kIOHIDMaxFeatureReportSizeKey), &bufferLength);
504 OVR_ASSERT(getResult);
505 FeatureReportBufferLength = (UInt16) bufferLength;
508 if (ReadBufferSize < InputReportBufferLength)
509 {
510 OVR_ASSERT_LOG(false, ("Input report buffer length is bigger than read buffer."));
511 return false;
512 }
514 // Get device desc.
515 if (!HIDManager->getFullDesc(Device, &DevDesc))
516 {
517 OVR_ASSERT_LOG(false, ("Failed to get device desc while initializing device."));
518 return false;
519 }
521 return true;
522 }
524 void HIDDevice::staticDeviceAddedCallback(void* pContext, io_iterator_t iterator)
525 {
526 HIDDevice* pDevice = (HIDDevice*) pContext;
527 pDevice->deviceAddedCallback(iterator);
528 }
530 void HIDDevice::deviceAddedCallback(io_iterator_t iterator)
531 {
533 if (Device == NULL)
534 {
535 if (openDevice())
536 {
537 LogText("OVR::OSX::HIDDevice - Reopened device : %s", DevDesc.Path.ToCStr());
539 Ptr<DeviceCreateDesc> existingHIDDev = HIDManager->DevManager->FindHIDDevice(DevDesc);
540 if (existingHIDDev && existingHIDDev->pDevice)
541 {
542 HIDManager->DevManager->CallOnDeviceAdded(existingHIDDev);
543 }
544 }
545 }
547 // Reset callback.
548 while (IOIteratorNext(iterator))
549 ;
550 }
552 bool HIDDevice::openDevice()
553 {
555 // Have to iterate through devices again to generate paths.
556 CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager->HIDManager);
557 CFIndex deviceCount = CFSetGetCount(deviceSet);
559 // Allocate a block of memory and read the set into it.
560 IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount);
561 CFSetGetValues(deviceSet, (const void **) devices);
564 // Iterate over devices.
565 IOHIDDeviceRef device = NULL;
567 for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
568 {
569 IOHIDDeviceRef tmpDevice = devices[deviceIndex];
571 if (!tmpDevice)
572 {
573 continue;
574 }
576 String path;
577 if (!HIDManager->getPath(tmpDevice, &path))
578 {
579 continue;
580 }
582 if (path == DevDesc.Path)
583 {
584 device = tmpDevice;
585 break;
586 }
587 }
590 OVR_FREE(devices);
592 if (!device)
593 {
594 CFRelease(deviceSet);
595 return false;
596 }
598 // Attempt to open device.
599 if (IOHIDDeviceOpen(device, kIOHIDOptionsTypeSeizeDevice)
600 != kIOReturnSuccess)
601 {
602 CFRelease(deviceSet);
603 return false;
604 }
606 // Retain the device before we release the set.
607 CFRetain(device);
608 CFRelease(deviceSet);
611 Device = device;
614 if (!initInfo())
615 {
616 IOHIDDeviceClose(Device, kIOHIDOptionsTypeSeizeDevice);
617 CFRelease(Device);
618 Device = NULL;
619 return false;
620 }
623 // Setup the Run Loop and callbacks.
624 IOHIDDeviceScheduleWithRunLoop(Device,
625 HIDManager->getRunLoop(),
626 kCFRunLoopDefaultMode);
628 IOHIDDeviceRegisterInputReportCallback(Device,
629 ReadBuffer,
630 ReadBufferSize,
631 staticHIDReportCallback,
632 this);
634 IOHIDDeviceRegisterRemovalCallback(Device,
635 staticDeviceRemovedCallback,
636 this);
638 return true;
639 }
641 void HIDDevice::HIDShutdown()
642 {
644 HIDManager->DevManager->pThread->RemoveTicksNotifier(this);
646 if (Device != NULL) // Device may already have been closed if unplugged.
647 {
648 closeDevice(false);
649 }
651 IOObjectRelease(RepluggedNotification);
652 if (RepluggedNotificationPort)
653 IONotificationPortDestroy(RepluggedNotificationPort);
655 LogText("OVR::OSX::HIDDevice - HIDShutdown '%s'\n", DevDesc.Path.ToCStr());
656 }
658 bool HIDDevice::setupDevicePluggedInNotification()
659 {
661 // Setup notification when devices are plugged in.
662 RepluggedNotificationPort = IONotificationPortCreate(kIOMasterPortDefault);
664 CFRunLoopSourceRef notificationRunLoopSource =
665 IONotificationPortGetRunLoopSource(RepluggedNotificationPort);
667 CFRunLoopAddSource(HIDManager->getRunLoop(),
668 notificationRunLoopSource,
669 kCFRunLoopDefaultMode);
671 CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
673 // Have to specify vendorId and productId. Doesn't seem to accept additional
674 // things like serial number.
675 SInt32 vendorId = DevDesc.VendorId;
676 CFNumberRef numberRef = CFNumberCreate(kCFAllocatorDefault,
677 kCFNumberSInt32Type,
678 &vendorId);
679 CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), numberRef);
680 CFRelease(numberRef);
682 SInt32 deviceProductId = DevDesc.ProductId;
683 numberRef = CFNumberCreate(kCFAllocatorDefault,
684 kCFNumberSInt32Type,
685 &deviceProductId);
686 CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID), numberRef);
687 CFRelease(numberRef);
689 kern_return_t result =
690 IOServiceAddMatchingNotification(RepluggedNotificationPort,
691 kIOMatchedNotification,
692 matchingDict,
693 staticDeviceAddedCallback,
694 this,
695 &RepluggedNotification);
697 if (result != KERN_SUCCESS)
698 {
699 CFRelease(RepluggedNotificationPort);
700 RepluggedNotificationPort = 0;
701 return false;
702 }
704 // Iterate through to arm.
705 while (IOIteratorNext(RepluggedNotification))
706 {
707 }
709 return true;
710 }
712 void HIDDevice::closeDevice(bool wasUnplugged)
713 {
714 OVR_ASSERT(Device != NULL);
716 if (!wasUnplugged)
717 {
718 // Clear the registered callbacks.
719 IOHIDDeviceRegisterInputReportCallback(Device,
720 ReadBuffer,
721 InputReportBufferLength,
722 NULL,
723 this);
725 IOHIDDeviceRegisterRemovalCallback(Device, NULL, this);
727 IOHIDDeviceUnscheduleFromRunLoop(Device,
728 HIDManager->getRunLoop(),
729 kCFRunLoopDefaultMode);
730 IOHIDDeviceClose(Device, kIOHIDOptionsTypeNone);
731 }
733 CFRelease(Device);
734 Device = NULL;
736 LogText("OVR::OSX::HIDDevice - HID Device Closed '%s'\n", DevDesc.Path.ToCStr());
737 }
739 void HIDDevice::staticHIDReportCallback(void* pContext,
740 IOReturn result,
741 void* pSender,
742 IOHIDReportType reportType,
743 uint32_t reportId,
744 uint8_t* pReport,
745 CFIndex reportLength)
746 {
747 HIDDevice* pDevice = (HIDDevice*) pContext;
748 return pDevice->hidReportCallback(pReport, (UInt32)reportLength);
749 }
751 void HIDDevice::hidReportCallback(UByte* pData, UInt32 length)
752 {
754 // We got data.
755 if (Handler)
756 {
757 Handler->OnInputReport(pData, length);
758 }
759 }
761 void HIDDevice::staticDeviceRemovedCallback(void* pContext, IOReturn result, void* pSender)
762 {
763 HIDDevice* pDevice = (HIDDevice*) pContext;
764 pDevice->deviceRemovedCallback();
765 }
767 void HIDDevice::deviceRemovedCallback()
768 {
769 Ptr<HIDDevice> _this(this); // prevent from release
771 Ptr<DeviceCreateDesc> existingHIDDev = HIDManager->DevManager->FindHIDDevice(DevDesc);
772 if (existingHIDDev && existingHIDDev->pDevice)
773 {
774 HIDManager->DevManager->CallOnDeviceRemoved(existingHIDDev);
775 }
776 closeDevice(true);
777 }
779 CFStringRef HIDDevice::generateRunLoopModeString(IOHIDDeviceRef device)
780 {
781 const UInt32 safeBuffSize = 256;
782 char nameBuff[safeBuffSize];
783 OVR_sprintf(nameBuff, safeBuffSize, "%016lX", device);
785 return CFStringCreateWithCString(NULL, nameBuff, kCFStringEncodingASCII);
786 }
788 bool HIDDevice::SetFeatureReport(UByte* data, UInt32 length)
789 {
791 if (!Device)
792 return false;
794 UByte reportID = data[0];
796 if (reportID == 0)
797 {
798 // Not using reports so remove from data packet.
799 data++;
800 length--;
801 }
803 IOReturn result = IOHIDDeviceSetReport( Device,
804 kIOHIDReportTypeFeature,
805 reportID,
806 data,
807 length);
809 return (result == kIOReturnSuccess);
810 }
812 bool HIDDevice::GetFeatureReport(UByte* data, UInt32 length)
813 {
814 if (!Device)
815 return false;
817 CFIndex bufferLength = length;
819 // Report id is in first byte of the buffer.
820 IOReturn result = IOHIDDeviceGetReport(Device, kIOHIDReportTypeFeature, data[0], data, &bufferLength);
822 return (result == kIOReturnSuccess);
823 }
825 UInt64 HIDDevice::OnTicks(UInt64 ticksMks)
826 {
828 if (Handler)
829 {
830 return Handler->OnTicks(ticksMks);
831 }
833 return DeviceManagerThread::Notifier::OnTicks(ticksMks);
834 }
836 HIDDeviceManager* HIDDeviceManager::CreateInternal(OSX::DeviceManager* devManager)
837 {
839 if (!System::IsInitialized())
840 {
841 // Use custom message, since Log is not yet installed.
842 OVR_DEBUG_STATEMENT(Log::GetDefaultLog()->
843 LogMessage(Log_Debug, "HIDDeviceManager::Create failed - OVR::System not initialized"); );
844 return 0;
845 }
847 Ptr<OSX::HIDDeviceManager> manager = *new OSX::HIDDeviceManager(devManager);
849 if (manager)
850 {
851 if (manager->Initialize())
852 {
853 manager->AddRef();
854 }
855 else
856 {
857 manager.Clear();
858 }
859 }
861 return manager.GetPtr();
862 }
864 } // namespace OSX
866 //-------------------------------------------------------------------------------------
867 // ***** Creation
869 // Creates a new HIDDeviceManager and initializes OVR.
870 HIDDeviceManager* HIDDeviceManager::Create()
871 {
872 OVR_ASSERT_LOG(false, ("Standalone mode not implemented yet."));
874 if (!System::IsInitialized())
875 {
876 // Use custom message, since Log is not yet installed.
877 OVR_DEBUG_STATEMENT(Log::GetDefaultLog()->
878 LogMessage(Log_Debug, "HIDDeviceManager::Create failed - OVR::System not initialized"); );
879 return 0;
880 }
882 Ptr<OSX::HIDDeviceManager> manager = *new OSX::HIDDeviceManager(NULL);
884 if (manager)
885 {
886 if (manager->Initialize())
887 {
888 manager->AddRef();
889 }
890 else
891 {
892 manager.Clear();
893 }
894 }
896 return manager.GetPtr();
897 }
899 } // namespace OVR