forked from usb4java/libusb4java
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInterface.c
53 lines (46 loc) · 1.41 KB
/
Interface.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (C) 2013 Klaus Reimer ([email protected])
* See LICENSE.md file for copying conditions
*/
#include "Interface.h"
#include "InterfaceDescriptor.h"
jobject wrapInterface(JNIEnv *env, const struct libusb_interface *iface)
{
return wrapPointer(env, iface, CLASS_PATH("Interface"),
"interfacePointer");
}
jobjectArray wrapInterfaces(JNIEnv *env, int count,
const struct libusb_interface *interfaces)
{
jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env,
count, (*env)->FindClass(env, CLASS_PATH("Interface")),
NULL);
for (int i = 0; i < count; i++)
(*env)->SetObjectArrayElement(env, array, i,
wrapInterface(env, &interfaces[i]));
return array;
}
struct libusb_interface *unwrapInterface(JNIEnv *env, jobject iface)
{
return (struct libusb_interface *) unwrapPointer(env, iface,
"interfacePointer");
}
JNIEXPORT jint JNICALL METHOD_NAME(Interface, numAltsetting)
(
JNIEnv *env, jobject this
)
{
struct libusb_interface* interface = unwrapInterface(env, this);
if (!interface) return 0;
return interface->num_altsetting;
}
JNIEXPORT jobjectArray JNICALL METHOD_NAME(Interface, altsetting)
(
JNIEnv *env, jobject this
)
{
struct libusb_interface* interface = unwrapInterface(env, this);
if (!interface) return NULL;
return wrapInterfaceDescriptors(env, interface->num_altsetting,
interface->altsetting);
}