]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/corefoundation/hid.cpp
guard against errors like in wxStringBase::AllocBeforeWrite code (1123226)
[wxWidgets.git] / src / mac / corefoundation / hid.cpp
index 735895bbf5f8787ddad40d6b47cf93170004237f..16c956b2077fb47163a885a74a7967541db7264d 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/mac/corefoundation/hid.h"
 #include "wx/string.h"
 #include "wx/log.h"
+#include "wx/mac/corefoundation/cfstring.h"
 
 
 // ---------------------------------------------------------------------------
@@ -118,7 +119,7 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev)
        //Now get the maching services
        io_iterator_t pIterator;
        wxIOCHECK(IOServiceGetMatchingServices(m_pPort, pDictionary, &pIterator), "No Matching HID Services");
-       wxASSERT(pIterator != 0);
+       wxASSERT_MSG(pIterator != 0, wxT("No devices found!"));
 
        //Now we iterate through them
        io_object_t pObject;
@@ -133,11 +134,40 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev)
                //Just for sanity :)
                wxASSERT(CFGetTypeID(CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey))) == CFStringGetTypeID());
                        
+/*
+        kIOHIDTransportKey;
+        kIOHIDVendorIDKey;
+        kIOHIDProductIDKey;
+        kIOHIDVersionNumberKey;
+        kIOHIDManufacturerKey;
+        kIOHIDSerialNumberKey;
+        if !kIOHIDLocationIDKey
+            kUSBDevicePropertyLocationID
+        kIOHIDPrimaryUsageKey
+kIOHIDPrimaryUsagePageKey
+idProduct
+idVendor
+USB Product Name
+*/
                //Get [product] name
-               m_szName = CFStringGetCStringPtr        (
-                                               (CFStringRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey)), 
-                                               CFStringGetSystemEncoding()
-                                                                               );
+               m_szProductName = wxMacCFStringHolder( (CFStringRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey)), false ).AsString();
+        
+        CFNumberRef nref = (CFNumberRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductIDKey));
+        
+        if (nref)
+        CFNumberGetValue(
+                               nref,   
+                               kCFNumberIntType,
+                &m_nProductId
+                               );
+
+        nref = (CFNumberRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDVendorIDKey));
+        if (nref)
+       CFNumberGetValue(
+                               nref,   
+                               kCFNumberIntType,
+                &m_nManufacturerId
+                               );
 
                //Create the interface (good grief - long function names!)
                SInt32 nScore;
@@ -164,8 +194,6 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev)
                //
                wxCFArray CookieArray = CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDElementKey));
                BuildCookies(CookieArray);
-               if (m_ppQueue != NULL)
-                       wxVERIFY((*m_ppQueue)->start(m_ppQueue) == S_OK);
 
                //cleanup
                CFRelease(pDictionary);
@@ -215,7 +243,9 @@ int wxHIDDevice::GetCount (int nClass, int nType)
        //Now get the maching services
        io_iterator_t pIterator;
        wxIOCHECK(IOServiceGetMatchingServices(m_pPort, pDictionary, &pIterator), "No Matching HID Services");
-       wxASSERT(pIterator != 0);
+       
+    if(pIterator == NULL)
+        return 0;
 
        //Now we iterate through them
        io_object_t pObject;