diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/base/system.cpp | 82 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.pro | 6 |
2 files changed, 84 insertions, 4 deletions
diff --git a/rbutil/rbutilqt/base/system.cpp b/rbutil/rbutilqt/base/system.cpp index 229becc40c..748bc60766 100644 --- a/rbutil/rbutilqt/base/system.cpp +++ b/rbutil/rbutilqt/base/system.cpp | |||
@@ -64,6 +64,8 @@ | |||
64 | #include <CoreFoundation/CoreFoundation.h> | 64 | #include <CoreFoundation/CoreFoundation.h> |
65 | #include <SystemConfiguration/SystemConfiguration.h> | 65 | #include <SystemConfiguration/SystemConfiguration.h> |
66 | #include <CoreServices/CoreServices.h> | 66 | #include <CoreServices/CoreServices.h> |
67 | #include <IOKit/IOKitLib.h> | ||
68 | #include <IOKit/usb/IOUSBLib.h> | ||
67 | #endif | 69 | #endif |
68 | 70 | ||
69 | #include "utils.h" | 71 | #include "utils.h" |
@@ -227,7 +229,7 @@ QMap<uint32_t, QString> System::listUsbDevices(void) | |||
227 | QMap<uint32_t, QString> usbids; | 229 | QMap<uint32_t, QString> usbids; |
228 | // usb pid detection | 230 | // usb pid detection |
229 | qDebug() << "[System] Searching for USB devices"; | 231 | qDebug() << "[System] Searching for USB devices"; |
230 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | 232 | #if defined(Q_OS_LINUX) |
231 | #if defined(LIBUSB1) | 233 | #if defined(LIBUSB1) |
232 | libusb_device **devs; | 234 | libusb_device **devs; |
233 | int res; | 235 | int res; |
@@ -313,6 +315,84 @@ QMap<uint32_t, QString> System::listUsbDevices(void) | |||
313 | #endif | 315 | #endif |
314 | #endif | 316 | #endif |
315 | 317 | ||
318 | #if defined(Q_OS_MACX) | ||
319 | kern_return_t result = KERN_FAILURE; | ||
320 | CFMutableDictionaryRef usb_matching_dictionary; | ||
321 | io_iterator_t usb_iterator = IO_OBJECT_NULL; | ||
322 | usb_matching_dictionary = IOServiceMatching(kIOUSBDeviceClassName); | ||
323 | result = IOServiceGetMatchingServices(kIOMasterPortDefault, usb_matching_dictionary, | ||
324 | &usb_iterator); | ||
325 | if(result) { | ||
326 | qDebug() << "[System] USB: IOKit: Could not get matching services."; | ||
327 | return usbids; | ||
328 | } | ||
329 | |||
330 | io_object_t usbCurrentObj; | ||
331 | while((usbCurrentObj = IOIteratorNext(usb_iterator))) { | ||
332 | uint32_t id; | ||
333 | QString name; | ||
334 | /* get vendor ID */ | ||
335 | CFTypeRef vidref = NULL; | ||
336 | int vid = 0; | ||
337 | vidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idVendor"), | ||
338 | kCFAllocatorDefault, 0); | ||
339 | CFNumberGetValue((CFNumberRef)vidref, kCFNumberIntType, &vid); | ||
340 | CFRelease(vidref); | ||
341 | |||
342 | /* get product ID */ | ||
343 | CFTypeRef pidref = NULL; | ||
344 | int pid = 0; | ||
345 | pidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idProduct"), | ||
346 | kCFAllocatorDefault, 0); | ||
347 | CFNumberGetValue((CFNumberRef)pidref, kCFNumberIntType, &pid); | ||
348 | CFRelease(pidref); | ||
349 | id = vid << 16 | pid; | ||
350 | |||
351 | /* get product vendor */ | ||
352 | char vendor_buf[256]; | ||
353 | CFIndex vendor_buflen = 256; | ||
354 | CFTypeRef vendor_name_ref = NULL; | ||
355 | |||
356 | vendor_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj, | ||
357 | kIOServicePlane, CFSTR("USB Vendor Name"), | ||
358 | kCFAllocatorDefault, 0); | ||
359 | if(vendor_name_ref != NULL) { | ||
360 | CFStringGetCString((CFStringRef)vendor_name_ref, vendor_buf, vendor_buflen, | ||
361 | kCFStringEncodingUTF8); | ||
362 | name += QString::fromUtf8(vendor_buf) + " "; | ||
363 | CFRelease(vendor_name_ref); | ||
364 | } | ||
365 | else { | ||
366 | name += QObject::tr("(unknown vendor name) "); | ||
367 | } | ||
368 | |||
369 | /* get product name */ | ||
370 | char product_buf[256]; | ||
371 | CFIndex product_buflen = 256; | ||
372 | CFTypeRef product_name_ref = NULL; | ||
373 | |||
374 | product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj, | ||
375 | kIOServicePlane, CFSTR("USB Product Name"), | ||
376 | kCFAllocatorDefault, 0); | ||
377 | if(product_name_ref != NULL) { | ||
378 | CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen, | ||
379 | kCFStringEncodingUTF8); | ||
380 | name += QString::fromUtf8(product_buf); | ||
381 | CFRelease(product_name_ref); | ||
382 | } | ||
383 | else { | ||
384 | name += QObject::tr("(unknown product name)"); | ||
385 | } | ||
386 | |||
387 | if(id) { | ||
388 | usbids.insert(id, name); | ||
389 | qDebug() << "[System] USB:" << QString("0x%1").arg(id, 8, 16) << name; | ||
390 | } | ||
391 | |||
392 | } | ||
393 | IOObjectRelease(usb_iterator); | ||
394 | #endif | ||
395 | |||
316 | #if defined(Q_OS_WIN32) | 396 | #if defined(Q_OS_WIN32) |
317 | HDEVINFO deviceInfo; | 397 | HDEVINFO deviceInfo; |
318 | SP_DEVINFO_DATA infoData; | 398 | SP_DEVINFO_DATA infoData; |
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index ec440ab199..099a8ef7ab 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro | |||
@@ -132,10 +132,10 @@ DEFINES += RBUTIL _LARGEFILE64_SOURCE | |||
132 | win32 { | 132 | win32 { |
133 | LIBS += -lsetupapi -lnetapi32 | 133 | LIBS += -lsetupapi -lnetapi32 |
134 | } | 134 | } |
135 | unix:!static:!libusb1 { | 135 | unix:!static:!libusb1:!macx { |
136 | LIBS += -lusb | 136 | LIBS += -lusb |
137 | } | 137 | } |
138 | unix:!static:libusb1 { | 138 | unix:!static:libusb1:!macx { |
139 | DEFINES += LIBUSB1 | 139 | DEFINES += LIBUSB1 |
140 | LIBS += -lusb-1.0 | 140 | LIBS += -lusb-1.0 |
141 | } | 141 | } |
@@ -144,7 +144,7 @@ unix { | |||
144 | LIBS += -lz | 144 | LIBS += -lz |
145 | } | 145 | } |
146 | 146 | ||
147 | unix:static { | 147 | unix:!macx:static { |
148 | # force statically linking of libusb. Libraries that are appended | 148 | # force statically linking of libusb. Libraries that are appended |
149 | # later will get linked dynamically again. | 149 | # later will get linked dynamically again. |
150 | LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic | 150 | LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic |