1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dominik Riebeling 2010-09-05 18:19:23 +00:00
parent c196da2cee
commit 40a6aef0c3
2 changed files with 84 additions and 4 deletions

View file

@ -64,6 +64,8 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h> #include <SystemConfiguration/SystemConfiguration.h>
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
#endif #endif
#include "utils.h" #include "utils.h"
@ -227,7 +229,7 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
QMap<uint32_t, QString> usbids; QMap<uint32_t, QString> usbids;
// usb pid detection // usb pid detection
qDebug() << "[System] Searching for USB devices"; qDebug() << "[System] Searching for USB devices";
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) #if defined(Q_OS_LINUX)
#if defined(LIBUSB1) #if defined(LIBUSB1)
libusb_device **devs; libusb_device **devs;
int res; int res;
@ -313,6 +315,84 @@ QMap<uint32_t, QString> System::listUsbDevices(void)
#endif #endif
#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) #if defined(Q_OS_WIN32)
HDEVINFO deviceInfo; HDEVINFO deviceInfo;
SP_DEVINFO_DATA infoData; SP_DEVINFO_DATA infoData;

View file

@ -132,10 +132,10 @@ DEFINES += RBUTIL _LARGEFILE64_SOURCE
win32 { win32 {
LIBS += -lsetupapi -lnetapi32 LIBS += -lsetupapi -lnetapi32
} }
unix:!static:!libusb1 { unix:!static:!libusb1:!macx {
LIBS += -lusb LIBS += -lusb
} }
unix:!static:libusb1 { unix:!static:libusb1:!macx {
DEFINES += LIBUSB1 DEFINES += LIBUSB1
LIBS += -lusb-1.0 LIBS += -lusb-1.0
} }
@ -144,7 +144,7 @@ unix {
LIBS += -lz LIBS += -lz
} }
unix:static { unix:!macx:static {
# force statically linking of libusb. Libraries that are appended # force statically linking of libusb. Libraries that are appended
# later will get linked dynamically again. # later will get linked dynamically again.
LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic LIBS += -Wl,-Bstatic -lusb -Wl,-Bdynamic