There are hundreds of methods in OSHI leveraging JNA. Port one of them!
It's easier than you might think!
You will need to be using JDK 19. Because the FFM API is a preview API, you must compile and run the code with preview features enabled, i.e., javac --release 19 --enable-preview ... and java --enable-preview. Most IDEs will enable you to add these arguments. (In Eclipse I clicked a checkbox to enable preview features and added --enable-native-access=ooo.oshi to my VM arguments in run configurations... done!)
If you start a tutorial that has you use jlink, stop. It won't be helpful for you here. You need to use the basic method invoking and memory functions described in JEP 424. These largely have a direct correspondence to the existing JNA implementations. Some code is already committed for macOS process listings that gives a good feel for all the possibilities.
For methods and structures, check out the SystemLibrary class for macOS and usages in SysctlUtil, MacOperatingSystem and MacOSProcess. There should be enough examples there to hint you toward modeling new data structures. In summary:
- For methods, copy the corresponding JNA interface method, and wrap the call to the MethodHandle in a try/catch. Then make a corresponding private method implementing the mapping. You'll need to tweak non-primitive arguments.
- For structures, the GroupLayout examples at the bottom of the SystemLibrary class, and the access in the MacOSProcess class are good examples.
There's probably going to be a need for a generic IntByReference and LongByReference equivalent at some point...
Priority:
-
Anything you can contribute. If it's your first time doing a FFM function, pick an easy one. Any help is appreciated. Truly. Don't know where to put it in the API? Don't worry! Just submit a standalone class with the implementation and we'll move it to where it's needed!
-
Util classes covering multiple fetches (performance counters, sysctl, WMI).
-
Hot Path: Process listing (macOS is done, other OS's need it) or CPU ticks listing
There are hundreds of methods in OSHI leveraging JNA. Port one of them!
It's easier than you might think!
You will need to be using JDK 19. Because the FFM API is a preview API, you must compile and run the code with preview features enabled, i.e.,
javac --release 19 --enable-preview... andjava --enable-preview. Most IDEs will enable you to add these arguments. (In Eclipse I clicked a checkbox to enable preview features and added--enable-native-access=ooo.oshito my VM arguments in run configurations... done!)If you start a tutorial that has you use
jlink, stop. It won't be helpful for you here. You need to use the basic method invoking and memory functions described in JEP 424. These largely have a direct correspondence to the existing JNA implementations. Some code is already committed for macOS process listings that gives a good feel for all the possibilities.For methods and structures, check out the
SystemLibraryclass for macOS and usages inSysctlUtil,MacOperatingSystemandMacOSProcess. There should be enough examples there to hint you toward modeling new data structures. In summary:There's probably going to be a need for a generic IntByReference and LongByReference equivalent at some point...
Priority:
Anything you can contribute. If it's your first time doing a FFM function, pick an easy one. Any help is appreciated. Truly. Don't know where to put it in the API? Don't worry! Just submit a standalone class with the implementation and we'll move it to where it's needed!
Util classes covering multiple fetches (performance counters, sysctl, WMI).
Hot Path: Process listing (macOS is done, other OS's need it) or CPU ticks listing