Converted all descriptors to use NIO.
This commit is contained in:
parent
b37ab2f5f6
commit
e12e4204e8
@ -5,6 +5,9 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
|
||||
/**
|
||||
* The USB configuration descriptor describes information about a specific USB
|
||||
@ -13,18 +16,18 @@ package de.ailis.usb4java;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
public final class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pointer
|
||||
* The low-level pointer to the C structure.
|
||||
* @param data
|
||||
* The descriptor data
|
||||
*/
|
||||
|
||||
USB_Config_Descriptor(final long pointer)
|
||||
public USB_Config_Descriptor(final ByteBuffer data)
|
||||
{
|
||||
super(pointer);
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +38,11 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The total length of all configuration data (unsigned short).
|
||||
*/
|
||||
|
||||
public native int wTotalLength();
|
||||
public final int wTotalLength()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(2);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -44,7 +51,10 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The number of supported interfaces (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumInterfaces();
|
||||
public final int bNumInterfaces()
|
||||
{
|
||||
return this.data.get(4) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -54,7 +64,10 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The configuration value (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bConfigurationValue();
|
||||
public final int bConfigurationValue()
|
||||
{
|
||||
return this.data.get(5) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -64,7 +77,10 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iConfiguration();
|
||||
public final int iConfiguration()
|
||||
{
|
||||
return this.data.get(6) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -83,7 +99,10 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return A bitmap with configuration attributes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bmAttributes();
|
||||
public final int bmAttributes()
|
||||
{
|
||||
return this.data.get(7) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -94,7 +113,10 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The maximum power consumption in 2mA units (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bMaxPower();
|
||||
public final int bMaxPower()
|
||||
{
|
||||
return this.data.get(8) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -105,7 +127,7 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public short MaxPower()
|
||||
public final int MaxPower()
|
||||
{
|
||||
return bMaxPower();
|
||||
}
|
||||
@ -117,7 +139,7 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The length of the extra data block in bytes.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
public final native int extralen();
|
||||
|
||||
|
||||
/**
|
||||
@ -126,7 +148,7 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The extra data block.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
public final native ByteBuffer extra();
|
||||
|
||||
|
||||
/**
|
||||
@ -137,5 +159,5 @@ public class USB_Config_Descriptor extends USB_Descriptor_Header
|
||||
* @return The interfaces of this USB configuration.
|
||||
*/
|
||||
|
||||
public native USB_Interface[] iface();
|
||||
public final native USB_Interface[] iface();
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* All standard descriptors have the two fields bLength and bDescriptorType
|
||||
@ -15,20 +17,21 @@ package de.ailis.usb4java;
|
||||
|
||||
public abstract class USB_Descriptor_Header
|
||||
{
|
||||
/** The low-level pointer to the C structure. */
|
||||
final long pointer;
|
||||
/** The descriptor data. */
|
||||
protected final ByteBuffer data;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pointer
|
||||
* The low-level pointer to the C structure.
|
||||
* @param data
|
||||
* The descriptor data.
|
||||
*/
|
||||
|
||||
USB_Descriptor_Header(final long pointer)
|
||||
public USB_Descriptor_Header(final ByteBuffer data)
|
||||
{
|
||||
this.pointer = pointer;
|
||||
this.data = data;
|
||||
this.data.limit(bLength());
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +41,10 @@ public abstract class USB_Descriptor_Header
|
||||
* @return The size of the descriptor in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bLength();
|
||||
public final int bLength()
|
||||
{
|
||||
return this.data.get(0) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -47,5 +53,8 @@ public abstract class USB_Descriptor_Header
|
||||
* @return The interface descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDescriptorType();
|
||||
public final int bDescriptorType()
|
||||
{
|
||||
return this.data.get(1) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Klaus Reimer <k@ailis.de>
|
||||
* See LICENSE.txt for licensing information.
|
||||
*/
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* All standard descriptors have the two fields bLength and bDescriptorType
|
||||
* in common. So this base class implements them.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public abstract class USB_Descriptor_Header2
|
||||
{
|
||||
/** The descriptor data. */
|
||||
protected final ByteBuffer data;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param data
|
||||
* The descriptor data.
|
||||
*/
|
||||
|
||||
public USB_Descriptor_Header2(final ByteBuffer data)
|
||||
{
|
||||
this.data = data;
|
||||
this.data.limit(bLength());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the descriptor in bytes.
|
||||
*
|
||||
* @return The size of the descriptor in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public final int bLength()
|
||||
{
|
||||
return this.data.get(0) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the interface descriptor type.
|
||||
*
|
||||
* @return The interface descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public final int bDescriptorType()
|
||||
{
|
||||
return this.data.get(1) & 0xff;
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,9 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
|
||||
/**
|
||||
* The USB device descriptor contains global information about a USB device and
|
||||
@ -14,18 +17,18 @@ package de.ailis.usb4java;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
public final class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pointer
|
||||
* The low-level pointer to the C structure.
|
||||
* @param data
|
||||
* The descriptor data.
|
||||
*/
|
||||
|
||||
USB_Device_Descriptor(final long pointer)
|
||||
public USB_Device_Descriptor(final ByteBuffer data)
|
||||
{
|
||||
super(pointer);
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +40,11 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The USB specification release number (unsigned short).
|
||||
*/
|
||||
|
||||
public native int bcdUSB();
|
||||
public final int bcdUSB()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(2);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -56,7 +63,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The device class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceClass();
|
||||
public final int bDeviceClass()
|
||||
{
|
||||
return this.data.get(4) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -74,7 +84,11 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The device subclass code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceSubClass();
|
||||
public final int bDeviceSubClass()
|
||||
{
|
||||
return this.data.get(5) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -95,7 +109,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The device protocol code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceProtocol();
|
||||
public final int bDeviceProtocol()
|
||||
{
|
||||
return this.data.get(6) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -105,7 +122,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The maximum packet size for endpoint zero (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bMaxPacketSize0();
|
||||
public final int bMaxPacketSize0()
|
||||
{
|
||||
return this.data.get(7) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -114,7 +134,11 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The vendor ID (unsigned short).
|
||||
*/
|
||||
|
||||
public native int idVendor();
|
||||
public final int idVendor()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(8);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -123,7 +147,11 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The product ID (unsigned short).
|
||||
*/
|
||||
|
||||
public native int idProduct();
|
||||
public final int idProduct()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(10);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -132,7 +160,11 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return THe device release number (unsigned short).
|
||||
*/
|
||||
|
||||
public native int bcdDevice();
|
||||
public final int bcdDevice()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(12);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -141,7 +173,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The index of the manufacturer string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iManufacturer();
|
||||
public final int iManufacturer()
|
||||
{
|
||||
return this.data.get(14) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -150,7 +185,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The index of the product string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iProduct();
|
||||
public final int iProduct()
|
||||
{
|
||||
return this.data.get(15) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -159,7 +197,10 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The index of the serial number string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iSerialNumber();
|
||||
public final int iSerialNumber()
|
||||
{
|
||||
return this.data.get(16) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -168,5 +209,8 @@ public class USB_Device_Descriptor extends USB_Descriptor_Header
|
||||
* @return The number of configurations (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumConfigurations();
|
||||
public final int bNumConfigurations()
|
||||
{
|
||||
return this.data.get(17) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
|
||||
/**
|
||||
* This descriptor contains information about an endpoint.
|
||||
@ -12,18 +15,18 @@ package de.ailis.usb4java;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
public final class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pointer
|
||||
* The low-level pointer to the C structure.
|
||||
* @param data
|
||||
* The descriptor data.
|
||||
*/
|
||||
|
||||
USB_Endpoint_Descriptor(final long pointer)
|
||||
public USB_Endpoint_Descriptor(final ByteBuffer data)
|
||||
{
|
||||
super(pointer);
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +41,11 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The endpoint address (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bEndpointAddress();
|
||||
public final int bEndpointAddress()
|
||||
{
|
||||
return this.data.get(2) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the endpoint attributes. This is a bitmask with the following
|
||||
@ -56,7 +63,10 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The endpoint attributes bitmask (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bmAttributes();
|
||||
public final int bmAttributes()
|
||||
{
|
||||
return this.data.get(3) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -74,7 +84,11 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The maximum packet size of the endpoint (unsigned short).
|
||||
*/
|
||||
|
||||
public native int wMaxPacketSize();
|
||||
public final int wMaxPacketSize()
|
||||
{
|
||||
this.data.order(ByteOrder.LITTLE_ENDIAN).position(4);
|
||||
return this.data.asShortBuffer().get() & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -84,7 +98,10 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The interval for polling endpoint (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bInterval();
|
||||
public final int bInterval()
|
||||
{
|
||||
return this.data.get(6) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -93,7 +110,10 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The refresh information (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bRefresh();
|
||||
public final int bRefresh()
|
||||
{
|
||||
return this.data.get(7) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -102,7 +122,10 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The synch address (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bSynchAddress();
|
||||
public final int bSynchAddress()
|
||||
{
|
||||
return this.data.get(8) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -111,7 +134,7 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The extra descriptor data.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
public final native ByteBuffer extra();
|
||||
|
||||
|
||||
/**
|
||||
@ -120,5 +143,5 @@ public class USB_Endpoint_Descriptor extends USB_Descriptor_Header
|
||||
* @return The extra descriptor size.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
public final native int extralen();
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* The interface descriptor describes a specific interface of a USB
|
||||
@ -13,18 +15,18 @@ package de.ailis.usb4java;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
public final class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pointer
|
||||
* The low-level pointer to the C structure.
|
||||
* @param data
|
||||
* The descriptor data
|
||||
*/
|
||||
|
||||
USB_Interface_Descriptor(final long pointer)
|
||||
public USB_Interface_Descriptor(final ByteBuffer data)
|
||||
{
|
||||
super(pointer);
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +36,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The interface number (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceNumber();
|
||||
public final int bInterfaceNumber()
|
||||
{
|
||||
return this.data.get(0) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -44,7 +49,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The value used to select this alternate setting (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bAlternateSetting();
|
||||
public final int bAlternateSetting()
|
||||
{
|
||||
return this.data.get(2) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -53,7 +61,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The number of endpoints (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumEndpoints();
|
||||
public final int bNumEndpoints()
|
||||
{
|
||||
return this.data.get(3) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -65,7 +76,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The interface class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceClass();
|
||||
public final int bInterfaceClass()
|
||||
{
|
||||
return this.data.get(4) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -77,7 +91,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The interface sub class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceSubClass();
|
||||
public final int bInterfaceSubClass()
|
||||
{
|
||||
return this.data.get(5) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -92,7 +109,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The protocol code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceProtocol();
|
||||
public final int bInterfaceProtocol()
|
||||
{
|
||||
return this.data.get(6) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -101,7 +121,10 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The string descriptor index (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iInterface();
|
||||
public final int iInterface()
|
||||
{
|
||||
return this.data.get(7) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -110,7 +133,7 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The array with endpoints.
|
||||
*/
|
||||
|
||||
public native USB_Endpoint_Descriptor[] endpoint();
|
||||
public final native USB_Endpoint_Descriptor[] endpoint();
|
||||
|
||||
|
||||
/**
|
||||
@ -119,7 +142,7 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The extra descriptor data.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
public final native ByteBuffer extra();
|
||||
|
||||
|
||||
/**
|
||||
@ -128,5 +151,5 @@ public class USB_Interface_Descriptor extends USB_Descriptor_Header
|
||||
* @return The size of the extra data in bytes.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
public final native int extralen();
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ import java.nio.CharBuffer;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_String_Descriptor extends USB_Descriptor_Header2
|
||||
public final class USB_String_Descriptor extends USB_Descriptor_Header
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
@ -25,7 +25,7 @@ public class USB_String_Descriptor extends USB_Descriptor_Header2
|
||||
* The descriptor data.
|
||||
*/
|
||||
|
||||
USB_String_Descriptor(final ByteBuffer data)
|
||||
public USB_String_Descriptor(final ByteBuffer data)
|
||||
{
|
||||
super(data);
|
||||
}
|
||||
@ -37,7 +37,7 @@ public class USB_String_Descriptor extends USB_Descriptor_Header2
|
||||
* @return The string data.
|
||||
*/
|
||||
|
||||
public char[] wData()
|
||||
public final char[] wData()
|
||||
{
|
||||
this.data.position(2);
|
||||
final CharBuffer chars = this.data.order(ByteOrder.LITTLE_ENDIAN)
|
||||
@ -53,7 +53,7 @@ public class USB_String_Descriptor extends USB_Descriptor_Header2
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
public final String toString()
|
||||
{
|
||||
return new String(wData());
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class Dump
|
||||
indent(); System.out.format("extralen: 0x%08x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < descriptor.extralen(); i++)
|
||||
System.out.format(" %02x", descriptor.extra()[i]);
|
||||
System.out.format(" %02x", descriptor.extra().get(i));
|
||||
System.out.format("\n");
|
||||
level--;
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class Dump
|
||||
indent(); System.out.format("extralen: 0x%08x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < descriptor.extralen(); i++)
|
||||
System.out.format(" %02x", descriptor.extra()[i]);
|
||||
System.out.format(" %02x", descriptor.extra().get(i));
|
||||
System.out.format("\n");
|
||||
indent(); System.out.format("Endpoints:\n");
|
||||
level++;
|
||||
@ -180,7 +180,7 @@ public class Dump
|
||||
indent(); System.out.format("extralen: 0x%08x\n", config.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < config.extralen(); i++)
|
||||
System.out.format(" %02x", config.extra()[i]);
|
||||
System.out.format(" %02x", config.extra().get(i));
|
||||
System.out.format("\n");
|
||||
indent(); System.out.format("Interfaces:\n");
|
||||
level++;
|
||||
|
||||
@ -6,7 +6,6 @@ libusb4java_la_SOURCES = \
|
||||
USB.c \
|
||||
USB_Bus.c \
|
||||
USB_Device.c \
|
||||
USB_Descriptor_Header.c \
|
||||
USB_Device_Descriptor.c \
|
||||
USB_Config_Descriptor.c \
|
||||
USB_Dev_Handle.c \
|
||||
|
||||
@ -33,9 +33,11 @@ jobject wrap_usb_config_descriptor(JNIEnv *env,
|
||||
jclass cls = (*env)->FindClass(env,
|
||||
PACKAGE_DIR"/USB_Config_Descriptor");
|
||||
if (cls == NULL) return NULL;
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>",
|
||||
"(Ljava/nio/ByteBuffer;)V");
|
||||
if (constructor == NULL) return NULL;
|
||||
return (*env)->NewObject(env, cls, constructor, (long) descriptor);
|
||||
jobject buffer = (*env)->NewDirectByteBuffer(env, descriptor, 18);
|
||||
return (*env)->NewObject(env, cls, constructor, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -54,94 +56,18 @@ struct usb_config_descriptor *unwrap_usb_config_descriptor(JNIEnv *env,
|
||||
jobject obj)
|
||||
{
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "pointer", "J");
|
||||
return (struct usb_config_descriptor *) ((*env)->GetLongField(env,
|
||||
obj, field));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int wTotalLength()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Config_1Descriptor, wTotalLength)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->wTotalLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bNumInterfaces()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bNumInterfaces)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->bNumInterfaces;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bConfigurationValue()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bConfigurationValue)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->bConfigurationValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short iConfiguration()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, iConfiguration)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->iConfiguration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bmAttributes()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bmAttributes)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->bmAttributes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bMaxPower()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bMaxPower)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_config_descriptor(env, this)->MaxPower;
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "data",
|
||||
"Ljava/nio/ByteBuffer;");
|
||||
jobject buffer = (*env)->GetObjectField(env, obj, field);
|
||||
return (struct usb_config_descriptor *)
|
||||
(*env)->GetDirectBufferAddress(env, buffer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int extralen()
|
||||
*/
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Config_1Descriptor, extralen)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
@ -152,19 +78,17 @@ JNIEXPORT jint JNICALL METHOD_NAME(USB_1Config_1Descriptor, extralen)
|
||||
|
||||
|
||||
/**
|
||||
* byte[] extra()
|
||||
* ByteBuffer extra()
|
||||
*/
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL METHOD_NAME(USB_1Config_1Descriptor, extra)
|
||||
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Config_1Descriptor, extra)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
struct usb_config_descriptor *descriptor = unwrap_usb_config_descriptor(env, this);
|
||||
jbyteArray array = (*env)->NewByteArray(env, descriptor->extralen);
|
||||
(*env)->SetByteArrayRegion(env, array, 0, descriptor->extralen,
|
||||
(const jbyte *) descriptor->extra);
|
||||
return array;
|
||||
struct usb_config_descriptor *descriptor =
|
||||
unwrap_usb_config_descriptor(env, this);
|
||||
return (*env)->NewDirectByteBuffer(env, descriptor, descriptor->extralen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
|
||||
* See COPYING file for copying conditions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name USB_Descriptor_Header
|
||||
*
|
||||
* Native methods for the USB_Descriptor_Header class.
|
||||
*
|
||||
* @author Klaus Reimer <k@ailis.de>
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <usb.h>
|
||||
#include "usb4java.h"
|
||||
|
||||
|
||||
/**
|
||||
* Returns the wrapped USB descriptor header object from the specified
|
||||
* wrapper object.
|
||||
*
|
||||
* @param env
|
||||
* The JNI environment.
|
||||
* @param obj
|
||||
* The USB descriptor header wrapper object.
|
||||
* @return The USB descriptor header object.
|
||||
*/
|
||||
|
||||
struct usb_descriptor_header *unwrap_usb_descriptor_header(JNIEnv *env,
|
||||
jobject obj)
|
||||
{
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "pointer", "J");
|
||||
return (struct usb_descriptor_header *) ((*env)->GetLongField(env,
|
||||
obj, field));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bLength()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Descriptor_1Header, bLength)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_descriptor_header(env, this)->bLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bDescriptorType()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Descriptor_1Header, bDescriptorType)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return unwrap_usb_descriptor_header(env, this)->bDescriptorType;
|
||||
}
|
||||
@ -34,9 +34,11 @@ jobject wrap_usb_device_descriptor(JNIEnv *env,
|
||||
jclass cls = (*env)->FindClass(env,
|
||||
PACKAGE_DIR"/USB_Device_Descriptor");
|
||||
if (cls == NULL) return NULL;
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>",
|
||||
"(Ljava/nio/ByteBuffer;)V");
|
||||
if (constructor == NULL) return NULL;
|
||||
return (*env)->NewObject(env, cls, constructor, (long) descriptor);
|
||||
jobject buffer = (*env)->NewDirectByteBuffer(env, descriptor, 18);
|
||||
return (*env)->NewObject(env, cls, constructor, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -55,163 +57,9 @@ struct usb_device_descriptor *unwrap_usb_device_descriptor(JNIEnv *env,
|
||||
jobject obj)
|
||||
{
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "pointer", "J");
|
||||
return (struct usb_device_descriptor *) ((*env)->GetLongField(env,
|
||||
obj, field));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int bcdUSB()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, bcdUSB)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jint) unwrap_usb_device_descriptor(env, this)->bcdUSB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bDeviceClass()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceClass)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bDeviceSubClass()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceSubClass)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceSubClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bDeviceProtocol()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceProtocol)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceProtocol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bMaxPacketSize0()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bMaxPacketSize0)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->bMaxPacketSize0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int idVendor()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, idVendor)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jint) unwrap_usb_device_descriptor(env, this)->idVendor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int idProduct()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, idProduct)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jint) unwrap_usb_device_descriptor(env, this)->idProduct;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int bcdDevice()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, bcdDevice)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jint) unwrap_usb_device_descriptor(env, this)->bcdDevice;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short iManufacturer()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iManufacturer)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->iManufacturer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short iProduct()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iProduct)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->iProduct;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short iSerialNumber()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iSerialNumber)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->iSerialNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bNumConfigurations()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bNumConfigurations)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_device_descriptor(env, this)->bNumConfigurations;
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "data",
|
||||
"Ljava/nio/ByteBuffer;");
|
||||
jobject buffer = (*env)->GetObjectField(env, obj, field);
|
||||
return (struct usb_device_descriptor *)
|
||||
(*env)->GetDirectBufferAddress(env, buffer);
|
||||
}
|
||||
|
||||
@ -32,9 +32,11 @@ jobject wrap_usb_endpoint_descriptor(JNIEnv *env,
|
||||
if (!descriptor) return NULL;
|
||||
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Endpoint_Descriptor");
|
||||
if (cls == NULL) return NULL;
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>",
|
||||
"(Ljava/nio/ByteBuffer;)V");
|
||||
if (constructor == NULL) return NULL;
|
||||
return (*env)->NewObject(env, cls, constructor, (long) descriptor);
|
||||
jobject buffer = (*env)->NewDirectByteBuffer(env, descriptor, 18);
|
||||
return (*env)->NewObject(env, cls, constructor, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -80,87 +82,11 @@ struct usb_endpoint_descriptor *unwrap_usb_endpoint_descriptor(JNIEnv *env,
|
||||
jobject obj)
|
||||
{
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "pointer", "J");
|
||||
return (struct usb_endpoint_descriptor *) ((*env)->GetLongField(env,
|
||||
obj, field));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bEndpointAddress()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, bEndpointAddress)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->bEndpointAddress;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bmAttributes()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, bmAttributes)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->bmAttributes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* int wMaxPacketSize()
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, wMaxPacketSize)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->wMaxPacketSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bInterval()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, bInterval)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->bInterval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bRefresh()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, bRefresh)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->bRefresh;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bSynchAddress()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, bSynchAddress)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_endpoint_descriptor(env, this)->bSynchAddress;
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "data",
|
||||
"Ljava/nio/ByteBuffer;");
|
||||
jobject buffer = (*env)->GetObjectField(env, obj, field);
|
||||
return (struct usb_endpoint_descriptor *)
|
||||
(*env)->GetDirectBufferAddress(env, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -188,8 +114,6 @@ JNIEXPORT jbyteArray JNICALL METHOD_NAME(USB_1Endpoint_1Descriptor, extra)
|
||||
{
|
||||
struct usb_endpoint_descriptor *descriptor =
|
||||
unwrap_usb_endpoint_descriptor(env, this);
|
||||
jbyteArray array = (*env)->NewByteArray(env, descriptor->extralen);
|
||||
(*env)->SetByteArrayRegion(env, array, 0, descriptor->extralen,
|
||||
(const jbyte *) descriptor->extra);
|
||||
return array;
|
||||
return (*env)->NewDirectByteBuffer(env, descriptor, descriptor->extralen);
|
||||
|
||||
}
|
||||
|
||||
@ -31,11 +31,14 @@ jobject wrap_usb_interface_descriptor(JNIEnv *env,
|
||||
struct usb_interface_descriptor *descriptor)
|
||||
{
|
||||
if (!descriptor) return NULL;
|
||||
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Interface_Descriptor");
|
||||
jclass cls = (*env)->FindClass(env,
|
||||
PACKAGE_DIR"/USB_Interface_Descriptor");
|
||||
if (cls == NULL) return NULL;
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
|
||||
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>",
|
||||
"(Ljava/nio/ByteBuffer;)V");
|
||||
if (constructor == NULL) return NULL;
|
||||
return (*env)->NewObject(env, cls, constructor, (long) descriptor);
|
||||
jobject buffer = (*env)->NewDirectByteBuffer(env, descriptor, 18);
|
||||
return (*env)->NewObject(env, cls, constructor, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -81,100 +84,11 @@ struct usb_interface_descriptor *unwrap_usb_interface_descriptor(JNIEnv *env,
|
||||
jobject obj)
|
||||
{
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "pointer", "J");
|
||||
return (struct usb_interface_descriptor *) ((*env)->GetLongField(env,
|
||||
obj, field));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bInterfaceNumber()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bInterfaceNumber)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bInterfaceNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bAlternateSetting()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bAlternateSetting)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bAlternateSetting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bNumEndpoints()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bNumEndpoints)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bNumEndpoints;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bInterfaceClass()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bInterfaceClass)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bInterfaceClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bInterfaceSubClass()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bInterfaceSubClass)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bInterfaceSubClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short bInterfaceProtocol()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, bInterfaceProtocol)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->bInterfaceProtocol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* short iInterface()
|
||||
*/
|
||||
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Interface_1Descriptor, iInterface)
|
||||
(
|
||||
JNIEnv *env, jobject this
|
||||
)
|
||||
{
|
||||
return (jshort) unwrap_usb_interface_descriptor(env, this)->iInterface;
|
||||
jfieldID field = (*env)->GetFieldID(env, cls, "data",
|
||||
"Ljava/nio/ByteBuffer;");
|
||||
jobject buffer = (*env)->GetObjectField(env, obj, field);
|
||||
return (struct usb_interface_descriptor *)
|
||||
(*env)->GetDirectBufferAddress(env, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -202,10 +116,7 @@ JNIEXPORT jbyteArray JNICALL METHOD_NAME(USB_1Interface_1Descriptor, extra)
|
||||
{
|
||||
struct usb_interface_descriptor *descriptor =
|
||||
unwrap_usb_interface_descriptor(env, this);
|
||||
jbyteArray array = (*env)->NewByteArray(env, descriptor->extralen);
|
||||
(*env)->SetByteArrayRegion(env, array, 0, descriptor->extralen,
|
||||
(const jbyte *) descriptor->extra);
|
||||
return array;
|
||||
return (*env)->NewDirectByteBuffer(env, descriptor, descriptor->extralen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user