Skip to content

Commit 312ae8a

Browse files
committed
Native monitoring example
1 parent a856746 commit 312ae8a

7 files changed

Lines changed: 978 additions & 0 deletions

File tree

examples/monitor_native/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Device Monitoring (Native)
2+
3+
This example project demonstrates how to build a native application that
4+
monitors USB devices using [GraalVM](https://www.graalvm.org/) and
5+
this _Java Does USB_ library.
6+
7+
## Build and Run
8+
9+
### Prerequisites
10+
11+
- [GraalVM](https://www.graalvm.org/) 25 or higher
12+
- [Maven](https://maven.apache.org/) 3.9 or higher
13+
14+
15+
### Preparation
16+
17+
GraalVM needs help to learn about the Java FFM downcall and upcall descriptors,
18+
and it needs some help to include all required methods. The relevant items
19+
differ from operating system to operating system. When building the native image,
20+
the operating system must be selected by changing the path in the file
21+
`native-image.properties` in the directory
22+
`src/main/resources/META-INF/native-image/net.codecrete.usb.examples/monitor_native`.
23+
24+
```properties
25+
Args = --enable-native-access=ALL-UNNAMED -H:ConfigurationFileDirectories=config/macos
26+
```
27+
28+
Note the last word of the line. In this case, it is `macos`. Change this to
29+
`linux` or `windows` if needed.
30+
31+
In your own Maven project, you might also need to move the file or rather rename
32+
directory. It must be named according to the pattern
33+
`src/main/resources/META-INF/native-image/<groupId>/<artifactId>`.
34+
35+
Also check that the environment variable `JAVA_HOME` points to the GraalVM directory.
36+
37+
38+
### Building
39+
40+
```shell
41+
mvn -Pnative package
42+
```
43+
44+
45+
### Running
46+
47+
```shell
48+
./target/monitor-native
49+
```
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"foreign": {
3+
"downcalls": [
4+
{
5+
"returnType": "jint",
6+
"parameterTypes": [
7+
"void*",
8+
"void*"
9+
]
10+
},
11+
{
12+
"returnType": "jint",
13+
"parameterTypes": [
14+
"void*",
15+
"void*",
16+
"void*"
17+
]
18+
},
19+
{
20+
"returnType": "jint",
21+
"parameterTypes": [
22+
"jint",
23+
"jlong",
24+
"void*"
25+
],
26+
"options": {
27+
"captureCallState": true,
28+
"firstVariadicArg": 2
29+
}
30+
},
31+
{
32+
"returnType": "jint",
33+
"parameterTypes": [
34+
"jint"
35+
]
36+
},
37+
{
38+
"returnType": "void*",
39+
"parameterTypes": [
40+
"void*"
41+
]
42+
},
43+
{
44+
"returnType": "jint",
45+
"parameterTypes": [
46+
"jint",
47+
"void*",
48+
"jint",
49+
"jint"
50+
],
51+
"options": {
52+
"captureCallState": true
53+
}
54+
},
55+
{
56+
"returnType": "void*",
57+
"parameterTypes": []
58+
},
59+
{
60+
"returnType": "jint",
61+
"parameterTypes": [
62+
"jint"
63+
],
64+
"options": {
65+
"captureCallState": true
66+
}
67+
},
68+
{
69+
"returnType": "jint",
70+
"parameterTypes": [
71+
"void*",
72+
"jint"
73+
],
74+
"options": {
75+
"captureCallState": true
76+
}
77+
},
78+
{
79+
"returnType": "void*",
80+
"parameterTypes": [
81+
"void*",
82+
"void*"
83+
]
84+
},
85+
{
86+
"returnType": "void*",
87+
"parameterTypes": [
88+
"jint"
89+
]
90+
},
91+
{
92+
"returnType": "jint",
93+
"parameterTypes": [
94+
"void*"
95+
]
96+
},
97+
{
98+
"returnType": "jint",
99+
"parameterTypes": [
100+
"jint",
101+
"jint",
102+
"jint",
103+
"void*"
104+
],
105+
"options": {
106+
"captureCallState": true
107+
}
108+
}
109+
]
110+
}
111+
}

0 commit comments

Comments
 (0)