Remove dynamic load of libusb on Windows

It wasn't adding any value and caused problems
with static build targets and using libusb functions
in other parts of the code (e.g. EzUsb).
This commit is contained in:
Mark Liversedge
2011-12-17 22:21:51 +00:00
parent a570081488
commit e028faf0ac
3 changed files with 15 additions and 93 deletions

View File

@@ -29,70 +29,25 @@
LibUsb::LibUsb(int type) : type(type)
{
// dynamic load of libusb on Windows, it is statically linked in Linux
// this is to avoid dll conflicts where the lib has already been installed
#ifdef WIN32
QLibrary libusb0("libusb0");
usb_set_debug = (VoidIntProto) libusb0.resolve("usb_set_debug");
usb_strerror = (CharVoidProto) libusb0.resolve("usb_strerror");
usb_init = (IntVoidProto) libusb0.resolve("usb_init");
usb_find_busses = (IntVoidProto) libusb0.resolve("usb_find_busses");
usb_find_devices = (IntVoidProto) libusb0.resolve("usb_find_devices");
usb_clear_halt = (IntUsb_dev_handleUintProto) libusb0.resolve("usb_clear_halt");
usb_release_interface = (IntUsb_dev_handleIntProto) libusb0.resolve("usb_release_interface");
usb_close = (IntUsb_dev_handleProto) libusb0.resolve("usb_close");
usb_bulk_read = (IntUsb_dev_handleIntCharIntIntProto) libusb0.resolve("usb_bulk_read");
usb_interrupt_write = (IntUsb_dev_handleIntCharIntIntProto) libusb0.resolve("usb_interrupt_write");
usb_get_busses = (Usb_busVoidProto) libusb0.resolve("usb_get_busses");
usb_open = (Usb_dev_handleUsb_deviceProto) libusb0.resolve("usb_open");
usb_set_configuration = (IntUsb_dev_handleIntProto) libusb0.resolve("usb_set_configuration");
usb_claim_interface = (IntUsb_dev_handleIntProto) libusb0.resolve("usb_claim_interface");
usb_set_altinterface = (IntUsb_dev_handleIntProto) libusb0.resolve("usb_set_altinterface");
if (!(isDllLoaded = libusb0.isLoaded()))
{
qWarning("libusb0.dll was not loaded");
return;
}
#endif
intf = NULL;
readBufIndex = 0;
readBufSize = 0;
// Initialize the library.
usb_init();
usb_set_debug(0);
if (OperatingSystem != WINDOWS) {
// Initialize the library.
usb_init();
// Find all busses.
usb_find_busses();
// Find all connected devices.
usb_find_devices();
}
usb_find_busses();
usb_find_devices();
}
int LibUsb::open()
{
if (OperatingSystem == WINDOWS) {
// Find all busses.
usb_find_busses();
if (!isDllLoaded) return -1;
} else {
// Initialize the library.
usb_init();
// Find all busses.
usb_find_busses();
// Find all connected devices.
usb_find_devices();
}
// Find all connected devices.
usb_find_devices();
readBufSize = 0;
readBufIndex = 0;
@@ -135,8 +90,6 @@ int LibUsb::read(char *buf, int bytes)
// check it isn't closed already
if (!device) return -1;
if (OperatingSystem == WINDOWS && !isDllLoaded) return -1;
// The USB2 stick really doesn't like you reading 1 byte when more are available
// so we use a local buffered read
int bufRemain = readBufSize - readBufIndex;
@@ -191,8 +144,6 @@ int LibUsb::write(char *buf, int bytes)
// check it isn't closed
if (!device) return -1;
if (OperatingSystem == WINDOWS && !isDllLoaded) return -1;
int rc;
if (OperatingSystem == WINDOWS) {
rc = usb_interrupt_write(device, writeEndpoint, buf, bytes, 1000);
@@ -253,8 +204,10 @@ struct usb_dev_handle* LibUsb::OpenFortius()
//
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == FORTIUS_VID && dev->descriptor.idProduct == FORTIUS_INIT_PID) {
if ((udev = usb_open(dev))) {

View File

@@ -59,39 +59,6 @@ public:
int write(char *buf, int bytes);
private:
#ifdef WIN32 // we only do dynamic loading on Windows
/*************************************************************************
* Functions to load from libusb0.dll
*/
typedef void (*VoidIntProto)(int);
typedef void (*VoidProto)();
typedef int (*IntVoidProto)();
typedef char * (*CharVoidProto)();
typedef int (*IntUsb_dev_handleUintProto)(usb_dev_handle *dev, unsigned int);
typedef int (*IntUsb_dev_handleIntProto)(usb_dev_handle *, int);
typedef int (*IntUsb_dev_handleProto)(usb_dev_handle *);
typedef int (*IntUsb_dev_handleIntCharIntIntProto)(usb_dev_handle *, int, char *, int, int);
typedef struct usb_bus * (*Usb_busVoidProto)();
typedef struct usb_dev_handle * (*Usb_dev_handleUsb_deviceProto)(struct usb_device *);
VoidIntProto usb_set_debug;
CharVoidProto usb_strerror;
IntVoidProto usb_init;
IntVoidProto usb_find_busses;
IntVoidProto usb_find_devices;
IntUsb_dev_handleUintProto usb_clear_halt;
IntUsb_dev_handleIntProto usb_release_interface;
IntUsb_dev_handleProto usb_close;
IntUsb_dev_handleIntCharIntIntProto usb_bulk_read;
IntUsb_dev_handleIntCharIntIntProto usb_interrupt_write;
Usb_busVoidProto usb_get_busses;
Usb_dev_handleUsb_deviceProto usb_open;
IntUsb_dev_handleIntProto usb_set_configuration;
IntUsb_dev_handleIntProto usb_claim_interface;
IntUsb_dev_handleIntProto usb_set_altinterface;
/************************************************************************/
#endif
struct usb_dev_handle* OpenAntStick();
struct usb_dev_handle* OpenFortius();
struct usb_interface_descriptor* usb_find_interface(struct usb_config_descriptor* config_descriptor);
@@ -106,7 +73,6 @@ private:
int readBufIndex;
int readBufSize;
bool isDllLoaded;
int type;
};
#endif

View File

@@ -85,15 +85,18 @@ qwt3d {
# are we supporting USB2 devices
!isEmpty( LIBUSB_INSTALL ) {
INCLUDEPATH += $${LIBUSB_INSTALL}/include
DEFINES += GC_HAVE_LIBUSB
INCLUDEPATH += $${LIBUSB_INSTALL}/include
SOURCES += LibUsb.cpp EzUsb.c Fortius.cpp FortiusController.cpp
HEADERS += LibUsb.h EzUsb.h Fortius.cpp FortiusController.h
unix {
# for linux and mac
LIBS += $${LIBUSB_INSTALL}/lib/libusb.a
}
win32 {
LIBS += $${LIBUSB_INSTALL}/lib/gcc/libusb.a
}
}
# are we supporting video playback?