diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2015-06-12 02:55:15 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2015-06-12 03:00:26 +0200 |
commit | 32eee8cad4fd7bf38b98e5c8db0455bed75e03bc (patch) | |
tree | 7e87005cd086363688f1d24f9ea3d7dedf752e72 /kcontrol | |
parent | 5c031202ddedf63416cf20cb4ad4618a00fe5a25 (diff) | |
download | tdebase-32eee8cad4fd7bf38b98e5c8db0455bed75e03bc.tar.gz tdebase-32eee8cad4fd7bf38b98e5c8db0455bed75e03bc.zip |
Fix build with libusb 2.0 on freebsd
[taken from FreeBSD kdebase3 patches]
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit e1d8ccc637042d5ab84b0d532590f4cf8ef8e567)
Diffstat (limited to 'kcontrol')
-rw-r--r-- | kcontrol/ConfigureChecks.cmake | 6 | ||||
-rw-r--r-- | kcontrol/usbview/CMakeLists.txt | 4 | ||||
-rw-r--r-- | kcontrol/usbview/usbdevices.cpp | 124 | ||||
-rw-r--r-- | kcontrol/usbview/usbdevices.h | 7 |
4 files changed, 61 insertions, 80 deletions
diff --git a/kcontrol/ConfigureChecks.cmake b/kcontrol/ConfigureChecks.cmake index 9676dbab3..3f017390c 100644 --- a/kcontrol/ConfigureChecks.cmake +++ b/kcontrol/ConfigureChecks.cmake @@ -47,12 +47,12 @@ endif( ) ##### check for libusb ########################## -if( WITH_LIBUSB ) - pkg_search_module( LIBUSB libusb ) +if( WITH_LIBUSB OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) + pkg_search_module( LIBUSB libusb libusb-2.0 ) if( LIBUSB_FOUND ) set( HAVE_LIBUSB 1 CACHE INTERNAL "" FORCE ) else( ) - tde_message_fatal( "libusb are requested, but not found on your system" ) + tde_message_fatal( "libusb is required, but not found on your system" ) endif( ) endif( ) diff --git a/kcontrol/usbview/CMakeLists.txt b/kcontrol/usbview/CMakeLists.txt index a55aacbd7..1584d0699 100644 --- a/kcontrol/usbview/CMakeLists.txt +++ b/kcontrol/usbview/CMakeLists.txt @@ -40,3 +40,7 @@ tde_add_kpart( kcm_usb AUTOMOC LINK tdeui-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) + +if( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) + target_link_libraries( kcm_usb-module ${LIBUSB_LIBRARIES} ) +endif( ) diff --git a/kcontrol/usbview/usbdevices.cpp b/kcontrol/usbview/usbdevices.cpp index ac7f1ce9c..d8322612a 100644 --- a/kcontrol/usbview/usbdevices.cpp +++ b/kcontrol/usbview/usbdevices.cpp @@ -230,9 +230,9 @@ TQString USBDevice::dump() if ( _devnodes.count() > 1 ) for ( TQStringList::Iterator it = _devnodes.at(1); it != _devnodes.end(); ++it ) r += "<tr><td></td><td>" + *it + "</td></tr>"; -#else +#else r += i18n("<tr><td><i>Max. Packet Size</i></td><td>%1</td></tr>").arg(_maxPacketSize); -#endif +#endif r += "<tr><td></td></tr>"; if (_hasBW) @@ -318,18 +318,26 @@ bool USBDevice::parseSys(TQString dname) /* * FreeBSD support by Markus Brueffer <markus@brueffer.de> + * libusb20 support by Hans Petter Selasky <hselasky@freebsd.org> * * Basic idea and some code fragments were taken from FreeBSD's usbdevs(8), * originally developed for NetBSD, so this code should work with no or * only little modification on NetBSD. */ -void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent) +void USBDevice::collectData(struct libusb20_backend *pbe, + struct libusb20_device *pdev) { + char tempbuf[32]; + struct usb_device_info di; + + if (libusb20_dev_get_info(pdev, &di)) + memset(&di, 0, sizeof(di)); + // determine data for this device - _level = level; - _parent = parent; - + _level = 0; + _parent = 0; + _bus = di.udi_bus; _device = di.udi_addr; _product = TQString::fromLatin1(di.udi_product); @@ -343,89 +351,57 @@ void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent) _prot = di.udi_protocol; _power = di.udi_power; _channels = di.udi_nports; - + // determine the speed -#if __FreeBSD_version > 490102 switch (di.udi_speed) { - case USB_SPEED_LOW: _speed = 1.5; break; - case USB_SPEED_FULL: _speed = 12.0; break; - case USB_SPEED_HIGH: _speed = 480.0; break; + case LIBUSB20_SPEED_LOW: _speed = 1.5; break; + case LIBUSB20_SPEED_FULL: _speed = 12.0; break; + case LIBUSB20_SPEED_HIGH: _speed = 480.0; break; + case LIBUSB20_SPEED_VARIABLE: _speed = 480.0; break; + case LIBUSB20_SPEED_SUPER: _speed = 4800.0; break; + default: _speed = 480.0; break; } -#else - _speed = di.udi_lowspeed ? 1.5 : 12.0; -#endif // Get all attached devicenodes - for ( int i = 0; i < USB_MAX_DEVNAMES; ++i ) - if ( di.udi_devnames[i][0] ) - _devnodes << di.udi_devnames[i]; + for (int i = 0; i < 32; ++i) { + if (libusb20_dev_get_iface_desc(pdev, i, tempbuf, sizeof(tempbuf)) == 0) { + _devnodes << tempbuf; + } else { + break; + } + } // For compatibility, split the revision number sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor ); - // Cycle through the attached devices if there are any - for ( int p = 0; p < di.udi_nports; ++p ) { - // Get data for device - struct usb_device_info di2; - - di2.udi_addr = di.udi_ports[p]; - - if ( di2.udi_addr >= USB_MAX_DEVICES ) - continue; - - if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 ) - continue; - - // Only add the device if we didn't detect it, yet - if (!find( di2.udi_bus, di2.udi_addr ) ) - { - USBDevice *device = new USBDevice(); - device->collectData( fd, level + 1, di2, di.udi_addr ); - } - } } - - bool USBDevice::parse(TQString fname) { - static bool showErrorMessage = true; - bool error = false; + struct libusb20_backend *pbe; + struct libusb20_device *pdev; + _devices.clear(); - - TQFile controller("/dev/usb0"); - int i = 1; - while ( controller.exists() ) - { - // If the devicenode exists, continue with further inspection - if ( controller.open(IO_ReadOnly) ) - { - for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) - { - struct usb_device_info di; - - di.udi_addr = addr; - if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 ) - { - if (!find( di.udi_bus, di.udi_addr ) ) - { - USBDevice *device = new USBDevice(); - device->collectData( controller.handle(), 0, di, 0); - } - } - } - controller.close(); - } else { - error = true; - } - controller.setName( TQString::fromLocal8Bit("/dev/usb%1").arg(i++) ); - } - - if ( showErrorMessage && error ) { - showErrorMessage = false; - KMessageBox::error( 0, i18n("Could not open one or more USB controller. Make sure, you have read access to all USB controllers that should be listed here.")); + + pbe = libusb20_be_alloc_default(); + if (pbe == NULL) + return (false); + + pdev = NULL; + + while ((pdev = libusb20_be_device_foreach(pbe, pdev))) { + USBDevice *device = new USBDevice(); + device->collectData(pbe, pdev); } - + + libusb20_be_free(pbe); + return true; } + +bool USBDevice::parseSys(TQString) +{ + // sysfs is not available on FreeBSD + return 0; +} #endif diff --git a/kcontrol/usbview/usbdevices.h b/kcontrol/usbview/usbdevices.h index 23717ee65..d7a62fbfa 100644 --- a/kcontrol/usbview/usbdevices.h +++ b/kcontrol/usbview/usbdevices.h @@ -17,7 +17,8 @@ #include <tqptrlist.h> #ifdef Q_OS_FREEBSD -#include <dev/usb/usb.h> +#include <libusb20.h> +#include <dev/usb/usb_ioctl.h> #endif class USBDB; @@ -26,7 +27,7 @@ class USBDB; class USBDevice { public: - + USBDevice(); void parseLine(TQString line); @@ -66,7 +67,7 @@ private: unsigned int _vendorID, _prodID, _revMajor, _revMinor; #ifdef Q_OS_FREEBSD - void collectData( int fd, int level, usb_device_info &di, int parent ); + void collectData(struct libusb20_backend *, struct libusb20_device *); TQStringList _devnodes; #endif }; |