summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-09-05 18:19:23 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-09-05 18:19:23 +0000
commit40a6aef0c3fe9da2ba51b23404d9caed269afe7e (patch)
treee1c91f8d56a6e2918249570416f1e8df2ed21a88 /rbutil
parentc196da2ceeddfc03a42e6a620aa08e3f583c8f0d (diff)
Implement USB VID / PID retrieval using IOKit on OS X.
Instead of using libusb as wrapper query the USB IDs via IOKit. Since libusb is only used for that this means that it's no longer necessary on OS X. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28001 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/base/system.cpp82
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro6
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 @@
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <CoreServices/CoreServices.h>
+#include <IOKit/IOKitLib.h>
+#include <IOKit/usb/IOUSBLib.h>
#endif
#include "utils.h"
@@ -227,7 +229,7 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
QMap<uint32_t, QString> usbids;
// usb pid detection
qDebug() << "[System] Searching for USB devices";
-#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
+#if defined(Q_OS_LINUX)
#if defined(LIBUSB1)
libusb_device **devs;
int res;
@@ -313,6 +315,84 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
#endif
#endif
+#if defined(Q_OS_MACX)
+ kern_return_t result = KERN_FAILURE;
+ CFMutableDictionaryRef usb_matching_dictionary;
+ io_iterator_t usb_iterator = IO_OBJECT_NULL;
+ usb_matching_dictionary = IOServiceMatching(kIOUSBDeviceClassName);
+ result = IOServiceGetMatchingServices(kIOMasterPortDefault, usb_matching_dictionary,
+ &usb_iterator);
+ if(result) {
+ qDebug() << "[System] USB: IOKit: Could not get matching services.";
+ return usbids;
+ }
+
+ io_object_t usbCurrentObj;
+ while((usbCurrentObj = IOIteratorNext(usb_iterator))) {
+ uint32_t id;
+ QString name;
+ /* get vendor ID */
+ CFTypeRef vidref = NULL;
+ int vid = 0;
+ vidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idVendor"),
+ kCFAllocatorDefault, 0);
+ CFNumberGetValue((CFNumberRef)vidref, kCFNumberIntType, &vid);
+ CFRelease(vidref);
+
+ /* get product ID */
+ CFTypeRef pidref = NULL;
+ int pid = 0;
+ pidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idProduct"),
+ kCFAllocatorDefault, 0);
+ CFNumberGetValue((CFNumberRef)pidref, kCFNumberIntType, &pid);
+ CFRelease(pidref);
+ id = vid << 16 | pid;
+
+ /* get product vendor */
+ char vendor_buf[256];
+ CFIndex vendor_buflen = 256;
+ CFTypeRef vendor_name_ref = NULL;
+
+ vendor_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
+ kIOServicePlane, CFSTR("USB Vendor Name"),
+ kCFAllocatorDefault, 0);
+ if(vendor_name_ref != NULL) {
+ CFStringGetCString((CFStringRef)vendor_name_ref, vendor_buf, vendor_buflen,
+ kCFStringEncodingUTF8);
+ name += QString::fromUtf8(vendor_buf) + " ";
+ CFRelease(vendor_name_ref);
+ }
+ else {
+ name += QObject::tr("(unknown vendor name) ");
+ }
+
+ /* get product name */
+ char product_buf[256];
+ CFIndex product_buflen = 256;
+ CFTypeRef product_name_ref = NULL;
+
+ product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
+ kIOServicePlane, CFSTR("USB Product Name"),
+ kCFAllocatorDefault, 0);
+ if(product_name_ref != NULL) {
+ CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen,
+ kCFStringEncodingUTF8);
+ name += QString::fromUtf8(product_buf);
+ CFRelease(product_name_ref);
+ }
+ else {
+ name += QObject::tr("(unknown product name)");
+ }
+
+ if(id) {
+ usbids.insert(id, name);
+ qDebug() << "[System] USB:" << QString("0x%1").arg(id, 8, 16) << name;
+ }
+
+ }
+ IOObjectRelease(usb_iterator);
+#endif
+
#if defined(Q_OS_WIN32)
HDEVINFO deviceInfo;
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
win32 {
LIBS += -lsetupapi -lnetapi32
}
-unix:!static:!libusb1 {
+unix:!static:!libusb1:!macx {
LIBS += -lusb
}
-unix:!static:libusb1 {
+unix:!static:libusb1:!macx {
DEFINES += LIBUSB1
LIBS += -lusb-1.0
}
@@ -144,7 +144,7 @@ unix {
LIBS += -lz
}
-unix:static {
+unix:!macx:static {
# force statically linking of libusb. Libraries that are appended
# later will get linked dynamically again.
LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic