Completed the general data structures.

This commit is contained in:
Klaus Reimer 2011-01-22 18:42:37 +01:00
parent 5d7ae9ba1c
commit 1b2b7daf9e
12 changed files with 318 additions and 331 deletions

View File

@ -8,5 +8,8 @@ libusb4java_la_SOURCES = \
USB_Device.c \
USB_Device_Descriptor.c \
USB_Config_Descriptor.c \
USB_Handle.c
USB_Dev_Handle.c \
USB_Interface.c \
USB_Interface_Descriptor.c \
USB_Endpoint_Descriptor.c

View File

@ -1,5 +1,4 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
@ -14,139 +13,100 @@
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
#include "USB_Bus.h"
#include "USB_Device.h"
#include "USB_Handle.h"
#include "USB_Dev_Handle.h"
/**
* Initialize libusb.
*
* Just like the name implies, usb_init sets up some internal structures.
* usb_init must be called before any other libusb functions.
* void usb_init()
*/
JNIEXPORT void JNICALL Java_de_ailis_usb4java_jni_USB_usb_1init(
JNIEnv *env, jobject jobj)
JNIEXPORT void JNICALL METHOD_NAME(USB, usb_1init)
(
JNIEnv *env, jclass class
)
{
usb_init();
}
/**
* Finds all USB busses on system.
*
* usb_find_busses will find all of the busses on the system. Returns the
* number of changes since previous call to this function (total of new
* busses and busses removed).
*
* @return The number of of changes since previous call.
* int usb_find_busses()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1find_1busses(
JNIEnv *env, jobject jobj)
JNIEXPORT jint JNICALL METHOD_NAME(USB, usb_1find_1busses)
(
JNIEnv *env, jclass class
)
{
return usb_find_busses();
}
/**
* Find all devices on all USB devices.
*
* usb_find_devices will find all of the devices on each bus. This should be
* called after usb_find_busses. Returns the number of changes since the
* previous call to this function (total of new device and devices removed).
*
* @return The number of changes since previous call.
* int usb_find_devices()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1find_1devices(
JNIEnv *env, jobject jobj)
JNIEXPORT jint JNICALL METHOD_NAME(USB, usb_1find_1devices)
(
JNIEnv *env, jclass class
)
{
return usb_find_devices();
}
/**
* Return the list of USB busses found
*
* usb_get_busses simply returns the value of the global variable
* usb_busses. This was implemented for those languages that support C
* calling convention and can use shared libraries, but don't support C
* global variables (like Delphi).
*
* @return The list of USB busses found.
* USB_Bus usb_get_busses()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USB_usb_1get_1busses(
JNIEnv *env, jclass jcls)
JNIEXPORT jobject JNICALL METHOD_NAME(USB, usb_1get_1busses)
(
JNIEnv *env, jclass class
)
{
return wrap_usb_bus(env, usb_get_busses());
}
/**
* Opens a USB device.
*
* usb_open is to be used to open up a device for use. usb_open must be
* called before attempting to perform any operations to the device. Returns
* a handle used in future communication with the device.
*
* @param device
* The USB device.
* @return The USB device handle.
* USB_Handle usb_open(USB_Device)
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USB_usb_1open(
JNIEnv *env, jclass jcls, jobject device)
JNIEXPORT jobject JNICALL METHOD_NAME(USB, usb_1open)
(
JNIEnv *env, jclass class, jobject device
)
{
return wrap_usb_dev_handle(env, usb_open(unwrap_usb_device(env, device)));
}
/**
* Closes a USB device.
*
* usb_close closes a device opened with usb_open. No further operations may
* be performed on the handle after usb_close is called. Returns 0 on
* success or < 0 on error.
*
* @param handle
* The USB device handle.
* @return 0 on success or < 0 on error.
* int usb_close(USB_Handle)
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1close(
JNIEnv *env, jclass jcls, jobject handle)
JNIEXPORT jint JNICALL METHOD_NAME(USB, usb_1close)
(
JNIEnv *env, jclass class, jobject handle
)
{
return usb_close(unwrap_usb_dev_handle(env, handle));
}
/**
* Retrieves a string descriptor from a device using the first language.
*
* usb_get_string_simple is a wrapper around usb_get_string that retrieves
* the string description specified by index in the first language for the
* descriptor and converts it into C style ASCII. Returns number of bytes
* returned in buf or < 0 on error.
* @param handle
* The USB device handle.
* @param index
* The string description index.
* @param langid
* The language id.
* @param buffer
* The buffer to write the string to.
* @param buflen
* The maximum number of bytes to read.
* @return The number of bytes read or < 0 on error.
* int usb_get_string(USB_Handle handle, int index, int langid, byte[] buffer,
* int buflen)
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1get_1string(
JNIEnv *env, jclass cls, jobject handle, jint index, jint langid,
jbyteArray buffer, jint buflen)
JNIEXPORT jint JNICALL METHOD_NAME(USB, usb_1get_1string)
(
JNIEnv *env, jclass class, jobject handle, jint index, jint langid,
jbyteArray buffer, jint buflen
)
{
char *buf = (char*) malloc(buflen);
int result = usb_get_string(unwrap_usb_dev_handle(env, handle),
@ -162,27 +122,15 @@ JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1get_1string(
/**
* Retrieves a string descriptor from a device using the first language.
*
* usb_get_string_simple is a wrapper around usb_get_string that retrieves
* the string description specified by index in the first language for the
* descriptor and converts it into C style ASCII. Returns number of bytes
* returned in buf or < 0 on error.
*
* @param handle
* The USB device handle.
* @param index
* The string description index.
* @param buffer
* The buffer to write the string to.
* @param buflen
* The maximum number of bytes to read.
* @return The number of bytes read or < 0 on error.
* int usb_get_simple_string(USB_Handle handle, int index, byte[] buffer,
* int buflen)
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USB_usb_1get_1string_1simple(
JNIEnv *env, jclass cls, jobject handle, jint index, jbyteArray buffer,
jint buflen)
JNIEXPORT jint JNICALL METHOD_NAME(USB, usb_1get_1string_1simple)
(
JNIEnv *env, jclass class, jobject handle, jint index, jbyteArray buffer,
jint buflen
)
{
char *buf = (char*) malloc(buflen);
int result = usb_get_string_simple(unwrap_usb_dev_handle(env, handle),

View File

@ -1,20 +1,19 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
/**
* @name USBBus
* @name USB_Bus
*
* Native methods for the USBBus class.
* Native methods for the USB_Bus class.
*
* @author Klaus Reimer <k@ailis.de>
* @version 0.1
*/
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
#include "USB_Device.h"
@ -31,7 +30,7 @@
jobject wrap_usb_bus(JNIEnv *env, struct usb_bus *bus)
{
if (!bus) return NULL;
jclass cls = (*env)->FindClass(env, "de/ailis/libusb/jni/USBBus");
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Bus");
if (cls == NULL) return NULL;
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
if (constructor == NULL) return NULL;
@ -58,79 +57,78 @@ struct usb_bus *unwrap_usb_bus(JNIEnv *env, jobject obj)
/**
* Returns the usb bus dirname.
*
* @return The usb bus dirname.
* string dirname()
*/
JNIEXPORT jstring JNICALL Java_de_ailis_usb4java_jni_USBBus_dirname(
JNIEnv *env, jobject this)
JNIEXPORT jstring JNICALL METHOD_NAME(USB_1Bus, dirname)
(
JNIEnv *env, jobject this
)
{
return (*env)->NewStringUTF(env, unwrap_usb_bus(env, this)->dirname);
}
/**
* Returns the next usb bus.
*
* @return The next usb bus.
* USB_Bus next()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBBus_next(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Bus, next)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_bus(env, unwrap_usb_bus(env, this)->next);
}
/**
* Returns the previous usb bus.
*
* @return The previous usb bus.
* USB_Bus prev()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBBus_prev(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Bus, prev)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_bus(env, unwrap_usb_bus(env, this)->prev);
}
/**
* Returns the usb bus location.
*
* @return The usb bus location.
* long location()
*/
JNIEXPORT jlong JNICALL Java_de_ailis_usb4java_jni_USBBus_location(
JNIEnv *env, jobject this)
JNIEXPORT jlong JNICALL METHOD_NAME(USB_1Bus, location)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_bus(env, this)->location;
}
/**
* Returns the usb devices.
*
* @return The usb devices.
* USB_Device devices()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBBus_devices(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Bus, devices)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_device(env, unwrap_usb_bus(env, this)->devices);
}
/**
* Returns the usb root device.
*
* @return The usb root device.
* USB_Device root_dev()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBBus_root_1dev(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Bus, root_1dev)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_device(env, unwrap_usb_bus(env, this)->root_dev);
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#ifndef USB_BUS_H
#define USB_BUS_H

View File

@ -1,21 +1,20 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
/**
* @name USBConfigDescriptor
* @name USB_Config_Descriptor
*
* Native methods for the USBConfigDescriptor class.
* Native methods for the USB_Config_Descriptor class.
*
* @author Klaus Reimer <k@ailis.de>
* @version 0.1
*/
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
#include "USB_Interface.h"
/**
* Creates and returns a new USB config descriptor wrapper object.
@ -32,7 +31,7 @@ jobject wrap_usb_config_descriptor(JNIEnv *env,
{
if (!descriptor) return NULL;
jclass cls = (*env)->FindClass(env,
"de/ailis/libusb/jni/USBConfigDescriptor");
PACKAGE_DIR"/USB_Config_Descriptor");
if (cls == NULL) return NULL;
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
if (constructor == NULL) return NULL;
@ -62,130 +61,130 @@ struct usb_config_descriptor *unwrap_usb_config_descriptor(JNIEnv *env,
/**
* Returns the bLength.
*
* @return The bLength.
* short bLength()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_bLength(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bLength)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->bLength;
}
/**
* Returns the bDescriptorType.
*
* @return The bDescriptorType.
* short bDescriptorType()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_bDescriptorType(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bDescriptorType)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->bDescriptorType;
}
/**
* Returns the wTotalLength.
*
* @return The wTotalLength.
* int wTotalLength()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_wTotalLength(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Config_1Descriptor, wTotalLength)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->wTotalLength;
}
/**
* Returns the bNumInterfaces.
*
* @return The bNumInterfaces.
* short bNumInterfaces()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_bNumInterfaces(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bNumInterfaces)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->bNumInterfaces;
}
/**
* Returns the bConfigurationValue.
*
* @return The bConfigurationValue.
* short bConfigurationValue()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_bConfigurationValue(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bConfigurationValue)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->bConfigurationValue;
}
/**
* Returns the iConfiguration.
*
* @return The iConfiguration.
* short iConfiguration()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_iConfiguration(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, iConfiguration)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->iConfiguration;
}
/**
* Returns the bmAttributes.
*
* @return The bmAttributes.
* short bmAttributes()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_bmAttributes(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bmAttributes)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->bmAttributes;
}
/**
* Returns the MaxPower.
*
* @return The MaxPower.
* short bMaxPower()
*/
JNIEXPORT jbyte JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_MaxPower(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Config_1Descriptor, bMaxPower)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->MaxPower;
}
/**
* Returns the extralen.
*
* @return The idProduct.
* int extralen()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_extralen(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Config_1Descriptor, extralen)
(
JNIEnv *env, jobject this
)
{
return unwrap_usb_config_descriptor(env, this)->extralen;
}
/**
* Returns the extra descriptors.
*
* @return The extra descriptors.
* byte[] extra()
*/
JNIEXPORT jbyteArray JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_extra(
JNIEnv *env, jobject this)
JNIEXPORT jbyteArray 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);
@ -193,3 +192,19 @@ JNIEXPORT jbyteArray JNICALL Java_de_ailis_usb4java_jni_USBConfigDescriptor_extr
(const jbyte *) descriptor->extra);
return array;
}
/**
* USB_Interface[] iface()
*/
JNIEXPORT jobjectArray JNICALL METHOD_NAME(USB_1Config_1Descriptor, iface)
(
JNIEnv *env, jobject this
)
{
struct usb_config_descriptor *descriptor = unwrap_usb_config_descriptor(
env, this);
return wrap_usb_interfaces(env, descriptor->bNumInterfaces,
descriptor->interface);
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#ifndef USB_CONFIG_DESCRIPTOR_H
#define USB_CONFIG_DESCRIPTOR_H

View File

@ -1,20 +1,19 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
/**
* @name USBDevHandle
* @name USB_Dev_Handle
*
* Native methods for the USBDevHandle class.
* Native methods for the USB_Dev_Handle class.
*
* @author Klaus Reimer <k@ailis.de>
* @version 0.1
*/
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
/**
@ -30,7 +29,7 @@
jobject wrap_usb_dev_handle(JNIEnv *env, struct usb_dev_handle *device)
{
if (!device) return NULL;
jclass cls = (*env)->FindClass(env, "de/ailis/libusb/jni/USBDevHandle");
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Dev_Handle");
if (cls == NULL) return NULL;
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
if (constructor == NULL) return NULL;

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#ifndef USB_DEV_HANDLE_H
#define USB_DEV_HANDLE_H

View File

@ -1,20 +1,19 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
/**
* @name USBDevice
* @name USB_Device
*
* Native methods for the USBDevice class.
* Native methods for the USB_Device class.
*
* @author Klaus Reimer <k@ailis.de>
* @version 0.1
*/
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
#include "USB_Bus.h"
#include "USB_Device_Descriptor.h"
#include "USB_Config_Descriptor.h"
@ -33,7 +32,7 @@
jobject wrap_usb_device(JNIEnv *env, struct usb_device *device)
{
if (!device) return NULL;
jclass cls = (*env)->FindClass(env, "de/ailis/libusb/jni/USBDevice");
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Device");
if (cls == NULL) return NULL;
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
if (constructor == NULL) return NULL;
@ -54,16 +53,16 @@ jobject wrap_usb_device(JNIEnv *env, struct usb_device *device)
* @return The array with the USB device wrappers.
*/
static jobjectArray wrap_usb_devices(JNIEnv *env, uint8_t num_children,
struct usb_device **children)
static jobjectArray wrap_usb_devices(JNIEnv *env, uint8_t num_devices,
struct usb_device **devices)
{
int i;
jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env, num_children,
(*env)->FindClass(env, "de/ailis/libusb/jni/USBDevice"), NULL);
for (i = 0; i < num_children; i++)
jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env, num_devices,
(*env)->FindClass(env, PACKAGE_DIR"/USB_Device"), NULL);
for (i = 0; i < num_devices; i++)
(*env)->SetObjectArrayElement(env, array, i,
wrap_usb_device(env, children[i]));
wrap_usb_device(env, devices[i]));
return array;
}
@ -87,91 +86,91 @@ struct usb_device *unwrap_usb_device(JNIEnv *env, jobject obj)
/**
* Returns the usb device filename.
*
* @return The usb device filename.
* string filename()
*/
JNIEXPORT jstring JNICALL Java_de_ailis_usb4java_jni_USBDevice_filename(
JNIEnv *env, jobject this)
JNIEXPORT jstring JNICALL METHOD_NAME(USB_1Device, filename)
(
JNIEnv *env, jobject this
)
{
return (*env)->NewStringUTF(env, unwrap_usb_device(env, this)->filename);
}
/**
* Returns the next usb device.
*
* @return The next usb device.
* USB_Device next()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_next(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Device, next)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_device(env, unwrap_usb_device(env, this)->next);
}
/**
* Returns the previous usb device.
*
* @return The previous usb device.
* USB_Device prev()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_prev(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Device, prev)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_device(env, unwrap_usb_device(env, this)->prev);
}
/**
* Returns the USB bus.
*
* @return The USB bus.
* USB_Bus bus().
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_bus(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Device, bus)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_bus(env, unwrap_usb_device(env, this)->bus);
}
/**
* Returns the device number.
*
* @return The device number.
* short devnum()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDevice_devnum(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device, devnum)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device(env, this)->devnum;
}
/**
* Returns the number of child devices.
*
* @return The number of child devices..
* short num_children()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDevice_num_1children(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device, num_1children)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device(env, this)->num_children;
}
/**
* Returns the child devices.
*
* @return The child devices.
* USB_Device children()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_children(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Device, children)
(
JNIEnv *env, jobject this
)
{
struct usb_device *device = unwrap_usb_device(env, this);
return wrap_usb_devices(env, device->num_children, device->children);
@ -179,20 +178,20 @@ JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_children(
/**
* Returns the configuration descriptors.
*
* @return The configuration descriptors.
* USB_Config_Descriptor[] config()
*/
JNIEXPORT jobjectArray JNICALL Java_de_ailis_usb4java_jni_USBDevice_config(
JNIEnv *env, jobject this)
JNIEXPORT jobjectArray JNICALL METHOD_NAME(USB_1Device, config)
(
JNIEnv *env, jobject this
)
{
int i;
struct usb_device *device = unwrap_usb_device(env, this);
struct usb_config_descriptor *descriptors = device->config;
unsigned char config_count = device->descriptor.bNumConfigurations;
jclass cls = (*env)->FindClass(env, "de/ailis/libusb/jni/USBConfigDescriptor");
jclass cls = (*env)->FindClass(env, PACKAGE_DIR"/USB_Config_Descriptor");
jobjectArray configs = (*env)->NewObjectArray(env, config_count, cls, 0);
for (i = 0; i < config_count; i++)
{
@ -204,16 +203,14 @@ JNIEXPORT jobjectArray JNICALL Java_de_ailis_usb4java_jni_USBDevice_config(
/**
* Returns the USB device descriptor.
*
* @return The USB device descriptor.
* USB_Device_Descriptor descriptor()
*/
JNIEXPORT jobject JNICALL Java_de_ailis_usb4java_jni_USBDevice_descriptor(
JNIEnv *env, jobject this)
JNIEXPORT jobject JNICALL METHOD_NAME(USB_1Device, descriptor)
(
JNIEnv *env, jobject this
)
{
return wrap_usb_device_descriptor(env, &(unwrap_usb_device(env,
this)->descriptor));
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#ifndef USB_DEVICE_H
#define USB_DEVICE_H
@ -5,6 +10,8 @@
#include <usb.h>
extern jobject wrap_usb_device(JNIEnv *env, struct usb_device *device);
extern jobjectArray wrap_usb_devices(JNIEnv *env, uint8_t num_devices,
struct usb_device **devices);
extern struct usb_device *unwrap_usb_device(JNIEnv *env, jobject obj);
#endif

View File

@ -1,20 +1,19 @@
/*
* $Id$
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
/**
* @name USBDeviceDescriptor
* @name USB_Device_Descriptor
*
* Native methods for the USBDeviceDescriptor class.
* Native methods for the USB_Device_Descriptor class.
*
* @author Klaus Reimer <k@ailis.de>
* @version 0.1
*/
#include <jni.h>
#include <usb.h>
#include "usb4java.h"
#include "USB_Bus.h"
@ -23,7 +22,7 @@
*
* @param env
* The JNI environment.
* @param device
* @param descriptor
* The USB device descriptor.
* @return The USB device descriptor wrapper object.
*/
@ -33,7 +32,7 @@ jobject wrap_usb_device_descriptor(JNIEnv *env,
{
if (!descriptor) return NULL;
jclass cls = (*env)->FindClass(env,
"de/ailis/libusb/jni/USBDeviceDescriptor");
PACKAGE_DIR"/USB_Device_Descriptor");
if (cls == NULL) return NULL;
jmethodID constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
if (constructor == NULL) return NULL;
@ -63,181 +62,182 @@ struct usb_device_descriptor *unwrap_usb_device_descriptor(JNIEnv *env,
/**
* Returns the bLength.
*
* @return The bLength.
* short bLength()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bLength(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bLength)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bLength;
}
/**
* Returns the bDescriptorType.
*
* @return The bDescriptorType.
* short bDescriptorType()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bDescriptorType(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDescriptorType)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bDescriptorType;
}
/**
* Returns the bcdUSB.
*
* @return The bcdUSB.
* int bcdUSB()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bcdUSB(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, bcdUSB)
(
JNIEnv *env, jobject this
)
{
return (jint) unwrap_usb_device_descriptor(env, this)->bcdUSB;
}
/**
* Returns the bDeviceClass.
*
* @return The bDeviceClass.
* short bDeviceClass()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bDeviceClass(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceClass)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceClass;
}
/**
* Returns the bDeviceSubClass.
*
* @return The bDeviceSubClass.
* short bDeviceSubClass()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bDeviceSubClass(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceSubClass)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceSubClass;
}
/**
* Returns the bDeviceProtocol.
*
* @return The bDeviceProtocol.
* short bDeviceProtocol()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bDeviceProtocol(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bDeviceProtocol)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bDeviceProtocol;
}
/**
* Returns the bMaxPacketSize0.
*
* @return The bMaxPacketSize0.
* short bMaxPacketSize0()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bMaxPacketSize0(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bMaxPacketSize0)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bMaxPacketSize0;
}
/**
* Returns the idVendor.
*
* @return The idVendor.
* int idVendor()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_idVendor(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, idVendor)
(
JNIEnv *env, jobject this
)
{
return (jint) unwrap_usb_device_descriptor(env, this)->idVendor;
}
/**
* Returns the idProduct.
*
* @return The idProduct.
* int idProduct()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_idProduct(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, idProduct)
(
JNIEnv *env, jobject this
)
{
return (jint) unwrap_usb_device_descriptor(env, this)->idProduct;
}
/**
* Returns the bcdDevice.
*
* @return The bcdDevice.
* int bcdDevice()
*/
JNIEXPORT jint JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bcdDevice(
JNIEnv *env, jobject this)
JNIEXPORT jint JNICALL METHOD_NAME(USB_1Device_1Descriptor, bcdDevice)
(
JNIEnv *env, jobject this
)
{
return (jint) unwrap_usb_device_descriptor(env, this)->bcdDevice;
}
/**
* Returns the iManufacturer.
*
* @return The iManufacturer.
* short iManufacturer()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_iManufacturer(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iManufacturer)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->iManufacturer;
}
/**
* Returns the iProduct.
*
* @return The iProduct.
* short iProduct()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_iProduct(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iProduct)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->iProduct;
}
/**
* Returns the iSerialNumber.
*
* @return The iSerialNumber.
* short iSerialNumber()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_iSerialNumber(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, iSerialNumber)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->iSerialNumber;
}
/**
* Returns the bNumConfigurations.
*
* @return The bNumConfigurations.
* short bNumConfigurations()
*/
JNIEXPORT jshort JNICALL Java_de_ailis_usb4java_jni_USBDeviceDescriptor_bNumConfigurations(
JNIEnv *env, jobject this)
JNIEXPORT jshort JNICALL METHOD_NAME(USB_1Device_1Descriptor, bNumConfigurations)
(
JNIEnv *env, jobject this
)
{
return (jshort) unwrap_usb_device_descriptor(env, this)->bNumConfigurations;
}

View File

@ -1,3 +1,8 @@
/*
* Copyright (C) 2011 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#ifndef USB_DEVICE_DESCRIPTOR_H
#define USB_DEVICE_DESCRIPTOR_H