support for 64 bit os (thanks to Jonas)

dummy root bus added to UsbView
tests updated

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@259 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
spandi
2007-09-03 19:09:49 +00:00
parent a08d70e123
commit b6d82b5754
16 changed files with 252 additions and 199 deletions

View File

@@ -27,7 +27,7 @@ public class Device {
private int idVendor, idProduct, dev_configuration, dev_interface,
dev_altinterface;
private int usbDevHandle;
private long usbDevHandle;
private boolean resetOnFirstOpen, resetDone;
@@ -181,7 +181,7 @@ public class Device {
dev = initDevice();
if (dev != null) {
int res = LibusbJava.usb_open(dev);
long res = LibusbJava.usb_open(dev);
if (res == 0) {
throw new USBException("LibusbJava.usb_open: "
+ LibusbJava.usb_strerror());
@@ -411,16 +411,17 @@ public class Device {
return writeInterrupt(out_ep_address, data, size, timeout,
false);
}
throw new USBTimeoutException("LibusbJava.usb_bulk_write: "
+ LibusbJava.usb_strerror());
throw new USBTimeoutException(
"LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror());
}
throw new USBException("LibusbJava.usb_bulk_write: "
throw new USBException("LibusbJava.usb_interrupt_write: "
+ LibusbJava.usb_strerror());
}
logger.info("length written: " + lenWritten);
if (logger.isLoggable(Level.FINEST)) {
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
StringBuffer sb = new StringBuffer("interruptwrite, ep 0x"
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
+ " Bytes sent: ");
for (int i = 0; i < lenWritten; i++) {
@@ -472,16 +473,16 @@ public class Device {
return readInterrupt(in_ep_address, data, size, timeout,
false);
}
throw new USBTimeoutException("LibusbJava.usb_bulk_read: "
throw new USBTimeoutException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror());
}
throw new USBException("LibusbJava.usb_bulk_read: "
throw new USBException("LibusbJava.usb_interrupt_read: "
+ LibusbJava.usb_strerror());
}
logger.info("length read: " + lenRead);
if (logger.isLoggable(Level.FINEST)) {
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
StringBuffer sb = new StringBuffer("interrupt, ep 0x"
+ Integer.toHexString(in_ep_address) + ": " + lenRead
+ " Bytes received: ");
for (int i = 0; i < lenRead; i++) {
@@ -582,7 +583,7 @@ public class Device {
* @throws USBException
* throws an USBException if the action fails
*/
private void claim_interface(int usb_dev_handle, int configuration,
private void claim_interface(long usb_dev_handle, int configuration,
int interface_, int altinterface) throws USBException {
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
usbDevHandle = 0;
@@ -619,7 +620,7 @@ public class Device {
* @throws USBException
* throws an USBException if the action fails
*/
private void release_interface(int dev_handle, int interface_)
private void release_interface(long dev_handle, int interface_)
throws USBException {
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
usbDevHandle = 0;

View File

@@ -102,7 +102,7 @@ public class LibusbJava {
* @return a handle used in future communication with the device. 0 if an
* error has occurred.
*/
public static native int usb_open(Usb_Device dev);
public static native long usb_open(Usb_Device dev);
/**
* <code>usb_close</code> closes a device opened with
@@ -112,7 +112,7 @@ public class LibusbJava {
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_close(int dev_handle);
public static native int usb_close(long dev_handle);
/**
* Sets the active configuration of a device
@@ -124,7 +124,7 @@ public class LibusbJava {
* bConfigurationValue.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_configuration(int dev_handle,
public static native int usb_set_configuration(long dev_handle,
int configuration);
/**
@@ -137,7 +137,7 @@ public class LibusbJava {
* bAlternateSetting.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_altinterface(int dev_handle, int alternate);
public static native int usb_set_altinterface(long dev_handle, int alternate);
/**
* Clears any halt status on an endpoint.
@@ -148,7 +148,7 @@ public class LibusbJava {
* The value specified in the descriptor field bEndpointAddress.
* @return 0 on success or < 0 on error.
*/
public static native int usb_clear_halt(int dev_handle, int ep);
public static native int usb_clear_halt(long dev_handle, int ep);
/**
* Resets a device by sending a RESET down the port it is connected to.<br>
@@ -162,7 +162,7 @@ public class LibusbJava {
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_reset(int dev_handle);
public static native int usb_reset(long dev_handle);
/**
* Claim an interface of a device.<br>
@@ -178,7 +178,7 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_claim_interface(int dev_handle, int interface_);
public static native int usb_claim_interface(long dev_handle, int interface_);
/**
* Releases a previously claimed interface
@@ -190,7 +190,7 @@ public class LibusbJava {
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_release_interface(int dev_handle,
public static native int usb_release_interface(long dev_handle,
int interface_);
// Control Transfers
@@ -209,7 +209,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written/read or < 0 on error.
*/
public static native int usb_control_msg(int dev_handle, int requesttype,
public static native int usb_control_msg(long dev_handle, int requesttype,
int request, int value, int index, byte[] bytes, int size,
int timeout);
@@ -223,7 +223,7 @@ public class LibusbJava {
* @param langid
* @return the descriptor String or null
*/
public static native String usb_get_string(int dev_handle, int index,
public static native String usb_get_string(long dev_handle, int index,
int langid);
/**
@@ -236,13 +236,13 @@ public class LibusbJava {
* @param index
* @return the descriptor String or null
*/
public static native String usb_get_string_simple(int dev_handle, int index);
public static native String usb_get_string_simple(long dev_handle, int index);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the default control pipe.<br>
* <br>
* See {@link #usb_get_descriptor_by_endpoint(int, int, byte, byte, int)}
* See {@link #usb_get_descriptor_by_endpoint(long, int, byte, byte, int)}
* for a function that allows the control endpoint to be specified.
*
* @param dev_handle
@@ -254,7 +254,7 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor(int dev_handle, byte type,
public static native String usb_get_descriptor(long dev_handle, byte type,
byte index, int size);
/**
@@ -271,7 +271,7 @@ public class LibusbJava {
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor_by_endpoint(int dev_handle,
public static native String usb_get_descriptor_by_endpoint(long dev_handle,
int ep, byte type, byte index, int size);
// Bulk Transfers
@@ -286,7 +286,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_bulk_write(int dev_handle, int ep,
public static native int usb_bulk_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
@@ -300,7 +300,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_bulk_read(int dev_handle, int ep,
public static native int usb_bulk_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
// Interrupt Transfers
@@ -315,7 +315,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_interrupt_write(int dev_handle, int ep,
public static native int usb_interrupt_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
@@ -329,7 +329,7 @@ public class LibusbJava {
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_interrupt_read(int dev_handle, int ep,
public static native int usb_interrupt_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**

View File

@@ -44,7 +44,7 @@ public class Usb_Config_Descriptor extends Usb_Descriptor {
private int extralen;
/**
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(int, int)}).
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(long, int)}).
*
* @return the value to use as an argument to select this configuration
*/

View File

@@ -53,7 +53,7 @@ public class Usb_Interface_Descriptor extends Usb_Descriptor {
}
/**
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(int, int)}).<br>
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, int)}).<br>
*
* @return the alternate setting
*/

View File

@@ -31,6 +31,8 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
private Usb_Bus rootBus;
private static final String USB_ROOT = "USB";
private JTextArea textArea;
private Vector<TreeModelListener> treeModelListeners = new Vector<TreeModelListener>();
@@ -52,14 +54,26 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
* Returns the root of the tree.
*/
public Object getRoot() {
return rootBus;
return USB_ROOT;
}
/**
* Returns the child of parent at index index in the parent's child array.
*/
public Object getChild(Object parent, int index) {
if (parent instanceof Usb_Bus) {
if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0)
{
Usb_Bus curBus = rootBus;
for (int i = 0; curBus != null; curBus = curBus.getNext(), i++)
{
if (i == index)
return curBus;
}
}
else if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0;
while (device != null) {
@@ -104,8 +118,23 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
/**
* Returns the number of children of parent.
*/
public int getChildCount(Object parent) {
if (parent instanceof Usb_Bus) {
public int getChildCount(Object parent)
{
if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0)
{
int count = 0;
Usb_Bus curBus = rootBus;
for (; curBus != null; curBus = curBus.getNext())
{
count++;
}
return count;
}
else if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0;
while (device != null) {
@@ -243,7 +272,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|| (dev.getDescriptor().getIProduct() > 0) || (dev
.getDescriptor().getISerialNumber() > 0))) {
if (tmpDevDesc.equals(devDesc)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb.append("\terror opening the device\n");
@@ -319,7 +348,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
for (int i = 0; i < tmpConfDesc.length; i++) {
if ((tmpConfDesc.equals(confDesc))
&& (confDesc.getIConfiguration() > 0)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb.append("\terror opening the device\n");
@@ -395,9 +424,9 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
Usb_Interface_Descriptor[] tmpIntDescs = ints[j]
.getAltsetting();
for (int k = 0; k < ints.length; k++) {
if (tmpIntDescs[i].equals(intDesc)
if (i < tmpIntDescs.length && tmpIntDescs[i].equals(intDesc)
&& (intDesc.getIInterface() > 0)) {
int handle = LibusbJava.usb_open(dev);
long handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n");
if (handle <= 0) {
sb