diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index deef007..5d88317 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -26,11 +26,11 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup Java - uses: actions/setup-java@v3 + uses: oracle-actions/setup-java@v1 with: - distribution: 'zulu' - java-version: '21' - cache: 'maven' + website: jdk.java.net + release: 22 + version: latest - name: Configure GPG key run: | echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import diff --git a/README.md b/README.md index 8a7e0b9..193708a 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,10 @@ [![javadoc](https://javadoc.io/badge2/net.codecrete.usb/java-does-usb/javadoc.svg)](https://javadoc.io/doc/net.codecrete.usb/java-does-usb) -*Java Does USB* is a Java library for working with USB devices. It allows to query information about all conntected USB devices and to communicate with USB devices using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.) +*Java Does USB* is a Java library for working with USB devices. It allows to query the conntected USB devices and to communicate with them using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.) -The library uses the [Foreign Function & Memory API](https://github.com/openjdk/panama-foreign) to access native APIs of the underlying operating system. It is written entirely in Java and does not need JNI or any native third-party library. The *Foreign Function & Memory API* (aka as project Panama) is currently in preview and will leave preview with Java 22. Currently, it can be used with Java 19, Java 20 or Java 21 (with preview features enabled). +The library uses the [Foreign Function and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html#GUID-FBE990DA-C356-46E8-9109-C75567849BA8) to access native APIs of the underlying operating system. It is written entirely in Java and does not use JNI or any native third-party library. The *Foreign Function and Memory API* has been introduced with Java 22. Preview versions were available in several earlier releases. -| Version | Main New Features | Compatibility | -| - | - | - | -| 0.7.x | New setter/getter names for improved Kotlin support; Kotlin examples | JDK 21 | -| 0.6.x | Support for JDK 21; better handling of composite devices on Windows | JDK 21 | -| 0.5.x | Support for JDK 20; high-throuput I/O streams | JDK 20 | -| 0.4.x | Early release | JDK 19 | - -*Note: The main branch and published versions ≥ 0.6.0 work with JDK 21 only. For JDK 20, use version 0.5.*. For JDK 19, use version 0.4.x. ## Features @@ -25,17 +17,8 @@ The library uses the [Foreign Function & Memory API](https://github.com/openjdk/ - Descriptive information about interfaces, settings and endpoints - High-throughput input/output streams - Support for alternate interface settings, composite devices and interface association -- Published on Maven Central - -### Planned - -- Isochronous transfer - -### Not planned +- Published on Maven Central and licensed under the permissive MIT license -- Changing configuration: The library selects the first configuration. Changing configurations is rarely used and not supported on Windows (limitation of WinUSB). -- USB 3.0 streams: Not supported on Windows (limitation of WinUSB). -- Providing information about USB buses, controllers and hubs ## Getting Started @@ -48,14 +31,14 @@ If you are using Maven, add the below dependency to your pom.xml: net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT ``` If you are using Gradle, add the below dependency to your build.gradle file: ```groovy -compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '0.7.1' +compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '1.0.0-SNAPSHOT' ``` ```java @@ -74,11 +57,14 @@ public class EnumerateDevices { ``` + ## Documentation - [Javadoc](https://javadoc.io/doc/net.codecrete.usb/java-does-usb) + + ## Examples - [Bulk Transfer](examples/bulk_transfer/) demonstrates how to find a USB device, open it and communicate using bulk transfer. @@ -88,12 +74,12 @@ public class EnumerateDevices { - [ePaper Display](examples/epaper_display) communicates with an IT8951 controller for e-Paper displays and shows an image on the display. + ## Prerequisite -- Java 21, preview features enabled (available at https://www.azul.com/downloads/?package=jdk) +- Java 22 available at [jdk.java.net](https://jdk.java.net/21/), [Azul](https://www.azul.com/downloads/?package=jdk), [Adoptium](https://adoptium.net/temurin/releases/) or with your favorite package manager. - Windows (x86 64-bit), macOS (x86 64-bit, ARM 64-bit) or Linux 64 bit (x86 64-bit, ARM 64-bit) -For JDK 20, use the latest published version 0.5.x. For JDK 19, use the latest published version 0.4.x. ## Platform-specific Considerations @@ -101,16 +87,16 @@ For JDK 20, use the latest published version 0.5.x. For JDK 19, use the latest p ### macOS -No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation-system drivers can be unloaded if the application is run with root privileges. +No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation system drivers can be unloaded if the application is run with root privileges. It runs both on Macs with Apple Silicon and Intel processors. ### Linux -*libudev* is used to discover and monitor USB devices. It is closely tied to *systemd*. So the library only runs on Linux distributions with *systemd* and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfill this requirement. +*libudev* is used to discover and monitor USB devices. It is closely tied to *systemd*. So the library only runs on Linux distributions with *systemd* and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfill this requirement. It runs on both Intel and ARM64 processors. Similar to macOS, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation system drivers can be unloaded (without the need for root privileges). -Most Linux distributions by default set up user accounts without permissions to access USB devices directly. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership: +Most Linux distributions set up user accounts without permissions to access USB devices. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership: Create a file called `/etc/udev/rules.d/80-javadoesusb-udev.rules` with the below content: @@ -120,35 +106,55 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666" This adds the rule to assign permission mode 0666 to all USB devices with vendor ID `0xCAFE`. This unregistered vendor ID is used by the test devices. +Without the *udev* rule, it is still possible to enumerate and query all USB devices. + ### Windows -The Windows driver model is more rigid than the ones of macOS or Linux. It's not possible to open any USB device that is not claimed. Instead, only devices using the *WinUSB* driver can be opened. This even applies to devices with no installed driver. +The Windows driver model is rather rigid. It's not possible to open any USB device unless it uses the *WinUSB* driver. This even applies to devices with no installed driver. Enumerating and querying USB devices is possible independent of the driver. -USB devices can implement certain control requests to instruct Windows to automatically install the WinUSB driver (search for *WCID* or *Microsoft OS Compatibility Descriptors*). The WinUSB driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/). +USB devices can implement special control requests to instruct Windows to automatically install the WinUSB driver (search for *WCID* or *Microsoft OS Compatibility Descriptors*). The WinUSB driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/). The test devices implement the required control requests. So the driver is installed automatically. -The library has not been tested on Windows for ARM64. It might or might not work. +Windows for ARM64 is not yet supported. A port is probably easy, provided you have hardware to test it. -### Troubleshooting -#### `ClassFormatError` (all platforms) +## Troubleshooting -The error `java.lang.ClassFormatError: Illegal field name "" in class net/codecrete/usb/windows/WindowsUsbDeviceRegistry` is caused by a bug in JDK 21, which has been fixed in the mean-time. Please upgrade to the latest release of JDK 21 (at least 21.0.1). +### 32-bit versions +The *Foreign Function And Memory API* has not been implemented for 32-bit operating systems / JDKs (and likely never will be). -### 32-bit versions -The Foreign Function & Memory API has not been implemented for 32-bit operating systems / JDKs (and likely never will be). +## Running on older JDK versions +The *Foreign Function And Memory API* has been available as a preview feature in JDKs before 22. However, incompatible changes were made from preview to preview to release. Earlier versions can be used with specific versions of this library: +| Version | Main New Features | Compatibility | +| - | - | - | +| 1.0.x | Release for final Java API | JDK 22 | +| 0.7.x | New setter/getter names for improved Kotlin support; Kotlin examples | JDK 21 | +| 0.6.x | Support for JDK 21; better handling of composite devices on Windows | JDK 21 | +| 0.5.x | Support for JDK 20; high-throuput I/O streams | JDK 20 | +| 0.4.x | Early release | JDK 19 | -## Code generation +When using an older JDK, preview features must be enabled using the `--enable-preview` VM option. -Many bindings for the native APIs have been generated with *jextract*. See the [jextract](java-does-usb/jextract) subdirectory for more information. For functions that need to retain the error state (`errno` on Linux, `GetLastError()` on Windows), the bindings have been manually written as *jextract* does not support it. + + +## Building from source + +To build from source, run the following command: + +``` +cd java-does-usb +mvn clean install -DskipTests +``` + +The tests are skipped as they require that a special test device is connected to the computer. See the next section for more information. @@ -164,17 +170,26 @@ The test device with the *loopback-stm32* code supports all tests. If the test d Tests can be run from the command line: ``` +cd java-does-usb mvn clean test ``` -If they are run from an IDE (such as IntelliJ IDEA), you must likely configure VM options to enable preview features and allow native access: +If they are run from an IDE (such as IntelliJ IDEA), you must likely configure VM options to allow native access: ``` ---enable-preview --enable-native-access=net.codecrete.usb +--enable-native-access=net.codecrete.usb ``` Or (if modules are ignored): ``` ---enable-preview --enable-native-access=ALL-UNNAMED +--enable-native-access=ALL-UNNAMED ``` + + + +## Code generation + +Many bindings for the native APIs have been generated with *jextract*. See the [jextract](java-does-usb/jextract) subdirectory for more information. For functions that need to retain the error state (`errno` on Linux, `GetLastError()` on Windows), the bindings have been manually written as *jextract* does not support it. + +Since the code can only be generated for the current operating system, it must be generated on separate computers for Linux, Windows and macOS. Thus, the generated code is included in the repository. The generated code is compilable on all operating systems. diff --git a/examples/bulk_transfer/.mvn/wrapper/maven-wrapper.properties b/examples/bulk_transfer/.mvn/wrapper/maven-wrapper.properties index 6d3a566..f3283b0 100644 --- a/examples/bulk_transfer/.mvn/wrapper/maven-wrapper.properties +++ b/examples/bulk_transfer/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/bulk_transfer/README.md b/examples/bulk_transfer/README.md index dd25eb8..2758c3a 100644 --- a/examples/bulk_transfer/README.md +++ b/examples/bulk_transfer/README.md @@ -4,16 +4,16 @@ This sample shows how to find a device, open it and transfer data from and to bu ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) - A USB device with bulk IN and OUT endpoints (e.g. the test device, see https://github.com/manuelbl/JavaDoesUSB/tree/main/test-devices/loopback-stm32) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -39,24 +39,22 @@ $ mvn compile exec:exec [INFO] Scanning for projects... [INFO] [INFO] --------------< net.codecrete.usb.examples:bulk-transfer >-------------- -[INFO] Building bulk-transfer 0.7.1 +[INFO] Building bulk-transfer 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] -[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ bulk-transfer --- -[INFO] Using 'UTF-8' encoding to copy filtered resources. -[INFO] skip non existing resourceDirectory /Users/me/Documents/JavaDoesUSB/examples/bulk_transfer/src/main/resources +[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ bulk-transfer --- +[INFO] skip non existing resourceDirectory /home/user/Documents/JavaDoesUSB/examples/bulk_transfer/src/main/resources [INFO] -[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ bulk-transfer --- -[INFO] Changes detected - recompiling the module! -[INFO] Compiling 1 source file to /Users/me/Documents/JavaDoesUSB/examples/bulk_transfer/target/classes +[INFO] --- maven-compiler-plugin:3.12.1:compile (default-compile) @ bulk-transfer --- +[INFO] Nothing to compile - all classes are up to date. [INFO] -[INFO] --- exec-maven-plugin:3.1.0:exec (default-cli) @ bulk-transfer --- +[INFO] --- exec-maven-plugin:3.1.1:exec (default-cli) @ bulk-transfer --- 6 bytes sent. 6 bytes received. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ -[INFO] Total time: 1.259 s -[INFO] Finished at: 2023-03-23T14:10:17+01:00 +[INFO] Total time: 1.228 s +[INFO] Finished at: 2024-02-18T16:23:29+01:00 [INFO] ------------------------------------------------------------------------ ``` diff --git a/examples/bulk_transfer/mvnw.cmd b/examples/bulk_transfer/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/bulk_transfer/mvnw.cmd +++ b/examples/bulk_transfer/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/bulk_transfer/pom.xml b/examples/bulk_transfer/pom.xml index fbf1a3c..6613a04 100644 --- a/examples/bulk_transfer/pom.xml +++ b/examples/bulk_transfer/pom.xml @@ -6,86 +6,82 @@ net.codecrete.usb.examples bulk-transfer - 0.7.1 + 1.0.0-SNAPSHOT bulk-transfer https://github.com/manuelbl/JavaDoesUSB/examples/bulk_transfer UTF-8 - 21 - 21 + 22 + 22 net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT - + maven-clean-plugin - 3.1.0 + 3.3.2 maven-resources-plugin - 3.0.2 + 3.3.1 maven-compiler-plugin - 3.8.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 maven-surefire-plugin - 2.22.1 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=ALL-UNNAMED maven-jar-plugin - 3.0.2 + 3.3.0 maven-install-plugin - 2.5.2 + 3.1.1 maven-deploy-plugin - 2.8.2 + 3.1.1 maven-site-plugin - 3.7.1 + 3.12.1 maven-project-info-reports-plugin - 3.0.0 + 3.5.0 org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.1.1 java - --enable-preview --enable-native-access=ALL-UNNAMED -classpath diff --git a/examples/enumerate/.mvn/wrapper/maven-wrapper.properties b/examples/enumerate/.mvn/wrapper/maven-wrapper.properties index 6d3a566..f3283b0 100644 --- a/examples/enumerate/.mvn/wrapper/maven-wrapper.properties +++ b/examples/enumerate/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/enumerate/README.md b/examples/enumerate/README.md index 992275e..907e1cf 100644 --- a/examples/enumerate/README.md +++ b/examples/enumerate/README.md @@ -4,15 +4,15 @@ This sample enumerates the connected USB devices and provides information about ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -38,22 +38,21 @@ $ mvn compile exec:exec [INFO] Scanning for projects... [INFO] [INFO] ----------------< net.codecrete.usb.examples:enumerate >---------------- -[INFO] Building enumerate 0.7.1 +[INFO] Building enumerate 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] -[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ enumerate --- -[INFO] Using 'UTF-8' encoding to copy filtered resources. -[INFO] skip non existing resourceDirectory /Users/me/Documents/JavaDoesUSB/examples/enumerate/src/main/resources +[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ enumerate --- +[INFO] Copying 1 resource from src/main/resources to target/classes [INFO] -[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ enumerate --- -[INFO] Changes detected - recompiling the module! -[INFO] Compiling 2 source files to /Users/me/Documents/JavaDoesUSB/examples/enumerate/target/classes +[INFO] --- maven-compiler-plugin:3.12.1:compile (default-compile) @ enumerate --- +[INFO] Nothing to compile - all classes are up to date. [INFO] -[INFO] --- exec-maven-plugin:3.1.0:exec (default-cli) @ enumerate --- +[INFO] --- exec-maven-plugin:3.1.1:exec (default-cli) @ enumerate --- Device: VID: 0xcafe PID: 0xceaf Manufacturer: JavaDoesUSB Product name: Loopback + Serial number: 35A737883336 ... ``` diff --git a/examples/enumerate/mvnw.cmd b/examples/enumerate/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/enumerate/mvnw.cmd +++ b/examples/enumerate/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/enumerate/pom.xml b/examples/enumerate/pom.xml index 00aa0f9..c4df53d 100644 --- a/examples/enumerate/pom.xml +++ b/examples/enumerate/pom.xml @@ -6,22 +6,22 @@ net.codecrete.usb.examples enumerate - 0.7.1 + 1.0.0-SNAPSHOT enumerate https://github.com/manuelbl/JavaDoesUSB/examples/enumerate UTF-8 - 21 - 21 + 22 + 22 net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT org.tinylog @@ -41,66 +41,62 @@ - + maven-clean-plugin - 3.1.0 + 3.3.2 maven-resources-plugin - 3.0.2 + 3.3.1 maven-compiler-plugin - 3.8.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 maven-surefire-plugin - 2.22.1 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=ALL-UNNAMED maven-jar-plugin - 3.0.2 + 3.3.0 maven-install-plugin - 2.5.2 + 3.1.1 maven-deploy-plugin - 2.8.2 + 3.1.1 maven-site-plugin - 3.7.1 + 3.12.1 maven-project-info-reports-plugin - 3.0.0 + 3.5.0 org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.1.1 java - --enable-preview --enable-native-access=ALL-UNNAMED -classpath diff --git a/examples/enumerate_kotlin/.mvn/wrapper/maven-wrapper.properties b/examples/enumerate_kotlin/.mvn/wrapper/maven-wrapper.properties index eacdc9e..f3283b0 100644 --- a/examples/enumerate_kotlin/.mvn/wrapper/maven-wrapper.properties +++ b/examples/enumerate_kotlin/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/enumerate_kotlin/README.md b/examples/enumerate_kotlin/README.md index 6a5e14e..4f85c62 100644 --- a/examples/enumerate_kotlin/README.md +++ b/examples/enumerate_kotlin/README.md @@ -4,15 +4,15 @@ This sample enumerates the connected USB devices and provides information about ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -40,7 +40,7 @@ $ mvn clean package ### Run the jar ```shell -$ java --enable-preview --enable-native-access=ALL-UNNAMED -jar target/enumerate-0.7.1-jar-with-dependencies.jar +$ java --enable-native-access=ALL-UNNAMED -jar target/enumerate-1.0.0-SNAPSHOT-jar-with-dependencies.jar Device: VID: 0xcafe PID: 0xceaf diff --git a/examples/enumerate_kotlin/mvnw.cmd b/examples/enumerate_kotlin/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/enumerate_kotlin/mvnw.cmd +++ b/examples/enumerate_kotlin/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/enumerate_kotlin/pom.xml b/examples/enumerate_kotlin/pom.xml index 91d8b9a..c6e4124 100644 --- a/examples/enumerate_kotlin/pom.xml +++ b/examples/enumerate_kotlin/pom.xml @@ -4,7 +4,7 @@ net.codecrete.usb.examples enumerate - 0.7.1 + 1.0.0-SNAPSHOT jar enumerate @@ -64,22 +64,22 @@ net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT org.tinylog tinylog-api - 2.6.2 + 2.7.0 org.tinylog tinylog-impl - 2.6.2 + 2.7.0 org.tinylog jsl-tinylog - 2.6.2 + 2.7.0 junit diff --git a/examples/epaper_display/.mvn/wrapper/maven-wrapper.properties b/examples/epaper_display/.mvn/wrapper/maven-wrapper.properties index 6d3a566..f3283b0 100644 --- a/examples/epaper_display/.mvn/wrapper/maven-wrapper.properties +++ b/examples/epaper_display/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/epaper_display/README.md b/examples/epaper_display/README.md index 684bd25..7b98499 100644 --- a/examples/epaper_display/README.md +++ b/examples/epaper_display/README.md @@ -4,7 +4,7 @@ This sample shows how to communicate with an IT8951 controller for e-paper displ ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (macOS, Linux, Windows) - IT8951 controller @@ -17,9 +17,9 @@ be temporarily detached.) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -45,24 +45,22 @@ $ mvn compile exec:exec [INFO] Scanning for projects... [INFO] [INFO] -------------< net.codecrete.usb.examples:epaper-display >-------------- -[INFO] Building epaper-display 0.7.1 -[INFO] from pom.xml +[INFO] Building epaper-display 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] -[INFO] --- resources:3.3.1:resources (default-resources) @ epaper-display --- -[INFO] skip non existing resourceDirectory /Users/me/Documents/JavaDoesUSB/examples/epaper_display/src/main/resources +[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ epaper-display --- +[INFO] skip non existing resourceDirectory /home/user/Documents/JavaDoesUSB/examples/epaper_display/src/main/resources [INFO] -[INFO] --- compiler:3.11.0:compile (default-compile) @ epaper-display --- -[INFO] Changes detected - recompiling the module! :source -[INFO] Compiling 2 source files with javac [debug release 20] to target/classes +[INFO] --- maven-compiler-plugin:3.12.1:compile (default-compile) @ epaper-display --- +[INFO] Nothing to compile - all classes are up to date. [INFO] -[INFO] --- exec:3.1.0:exec (default-cli) @ epaper-display --- +[INFO] --- exec-maven-plugin:3.1.1:exec (default-cli) @ epaper-display --- Display size: 1200 x 825 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ -[INFO] Total time: 1.502 s -[INFO] Finished at: 2023-07-02T14:08:50+02:00 +[INFO] Total time: 2.247 s +[INFO] Finished at: 2024-02-18T16:48:43+01:00 [INFO] ------------------------------------------------------------------------ ``` @@ -81,6 +79,6 @@ $ sudo -i Password: $ cd /Users/me/Documents/JavaDoesUSB/examples/epaper_display $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-20.jdk/Contents/Home -$ $JAVA_HOME/bin/java --enable-preview --enable-native-access=ALL-UNNAMED -cp target/classes:/Users/me/.m2/repository/net/codecrete/usb/java-does-usb/0.7.1/java-does-usb-0.7.1.jar net.codecrete.usb.examples.EPaperDisplay +$ $JAVA_HOME/bin/java --enable-native-access=ALL-UNNAMED -cp target/classes:/Users/me/.m2/repository/net/codecrete/usb/java-does-usb/1.0.0-SNAPSHOT/java-does-usb-1.0.0-SNAPSHOT.jar net.codecrete.usb.examples.EPaperDisplay Display size: 1200 x 825 ``` diff --git a/examples/epaper_display/mvnw.cmd b/examples/epaper_display/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/epaper_display/mvnw.cmd +++ b/examples/epaper_display/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/epaper_display/pom.xml b/examples/epaper_display/pom.xml index 6f5ef1a..1cf46fb 100644 --- a/examples/epaper_display/pom.xml +++ b/examples/epaper_display/pom.xml @@ -6,32 +6,32 @@ net.codecrete.usb.examples epaper-display - 0.7.1 + 1.0.0-SNAPSHOT epaper-display https://github.com/manuelbl/JavaDoesUSB/examples/epaper_display UTF-8 - 21 - 21 + 22 + 22 net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT - + maven-clean-plugin - 3.3.1 + 3.3.2 @@ -40,26 +40,23 @@ maven-compiler-plugin - 3.11.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 maven-surefire-plugin - 2.22.1 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=ALL-UNNAMED maven-jar-plugin - 3.1.2 + 3.3.0 maven-install-plugin @@ -76,16 +73,15 @@ maven-project-info-reports-plugin - 3.4.5 + 3.5.0 org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.1.1 - ${JAVA_HOME}/bin/java + java - --enable-preview --enable-native-access=ALL-UNNAMED -classpath diff --git a/examples/monitor/.mvn/wrapper/maven-wrapper.properties b/examples/monitor/.mvn/wrapper/maven-wrapper.properties index 6d3a566..f3283b0 100644 --- a/examples/monitor/.mvn/wrapper/maven-wrapper.properties +++ b/examples/monitor/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/monitor/README.md b/examples/monitor/README.md index e267ff1..6c75896 100644 --- a/examples/monitor/README.md +++ b/examples/monitor/README.md @@ -4,15 +4,15 @@ This sample program monitors USB devices as they are connected and disconnected. ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -35,22 +35,30 @@ If it is not present, install it, typically using package manager like *Homebrew ```shell $ cd JavaDoesUSB/examples/monitor $ mvn compile exec:exec + [INFO] Scanning for projects... [INFO] [INFO] -----------------< net.codecrete.usb.examples:monitor >----------------- -[INFO] Building monitor 0.7.1 +[INFO] Building monitor 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] -[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ monitor --- -[INFO] Using 'UTF-8' encoding to copy filtered resources. -[INFO] skip non existing resourceDirectory /Users/me/Documents/JavaDoesUSB/examples/monitor/src/main/resources +[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ monitor --- +[INFO] Copying 1 resource from src/main/resources to target/classes [INFO] -[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ monitor --- -[INFO] Changes detected - recompiling the module! -[INFO] Compiling 1 source file to /Users/me/Documents/JavaDoesUSB/examples/monitor/target/classes +[INFO] --- maven-compiler-plugin:3.12.1:compile (default-compile) @ monitor --- +[INFO] Nothing to compile - all classes are up to date. [INFO] -[INFO] --- exec-maven-plugin:3.1.0:exec (default-cli) @ monitor --- -Present: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 8D8F515C5456, ID: 4295291950 -Present: VID: 0x1a40, PID: 0x0801, manufacturer: null, product: USB 2.0 Hub, serial: null, ID: 4295291734 +[INFO] --- exec-maven-plugin:3.1.1:exec (default-cli) @ monitor --- +Present: VID: 0x1d6b, PID: 0x0002, manufacturer: Linux 6.5.0-18-generic xhci-hcd, product: xHCI Host Controller, serial: 0000:00:14.0, ID: /dev/bus/usb/001/001 +Present: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/005 Monitoring... Press ENTER to quit. +Disconnected: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/005 +Connected: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/009 + +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 17.647 s +[INFO] Finished at: 2024-02-18T16:50:59+01:00 +[INFO] ----------------------------------------------------------------------- ``` diff --git a/examples/monitor/mvnw.cmd b/examples/monitor/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/monitor/mvnw.cmd +++ b/examples/monitor/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/monitor/pom.xml b/examples/monitor/pom.xml index 8b3d614..190039c 100644 --- a/examples/monitor/pom.xml +++ b/examples/monitor/pom.xml @@ -6,22 +6,22 @@ net.codecrete.usb.examples monitor - 0.7.1 + 1.0.0-SNAPSHOT monitor https://github.com/manuelbl/JavaDoesUSB/examples/monitor UTF-8 - 21 - 21 + 22 + 22 net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT org.tinylog @@ -41,66 +41,62 @@ - + maven-clean-plugin - 3.1.0 + 3.3.2 maven-resources-plugin - 3.0.2 + 3.3.1 maven-compiler-plugin - 3.8.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 maven-surefire-plugin - 2.22.1 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=ALL-UNNAMED maven-jar-plugin - 3.0.2 + 3.3.0 maven-install-plugin - 2.5.2 + 3.1.1 maven-deploy-plugin - 2.8.2 + 3.1.1 maven-site-plugin - 3.7.1 + 3.12.1 maven-project-info-reports-plugin - 3.0.0 + 3.5.0 org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.1.1 java - --enable-preview --enable-native-access=ALL-UNNAMED -classpath diff --git a/examples/monitor_kotlin/.mvn/wrapper/maven-wrapper.properties b/examples/monitor_kotlin/.mvn/wrapper/maven-wrapper.properties index eacdc9e..f3283b0 100644 --- a/examples/monitor_kotlin/.mvn/wrapper/maven-wrapper.properties +++ b/examples/monitor_kotlin/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/monitor_kotlin/README.md b/examples/monitor_kotlin/README.md index ba40402..af19925 100644 --- a/examples/monitor_kotlin/README.md +++ b/examples/monitor_kotlin/README.md @@ -4,15 +4,15 @@ This sample enumerates the connected USB devices and provides information about ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -40,10 +40,10 @@ $ mvn clean package ### Run the jar ```shell -$ java --enable-preview --enable-native-access=ALL-UNNAMED -jar target/monitor-0.7.1-jar-with-dependencies.jar -WARNING: "public static final void net.codecrete.usb.examples.MonitorKt.main()" chosen over "public static void net.codecrete.usb.examples.MonitorKt.main(java.lang.String[])" -Present: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: 4295265643 -Present: VID: 0x1a40, PID: 0x0801, manufacturer: null, product: USB 2.0 Hub, serial: null, ID: 4295259660 +$ java --enable-native-access=ALL-UNNAMED -jar target/monitor-1.0.0-SNAPSHOT-jar-with-dependencies.jar +Present: VID: 0x1d6b, PID: 0x0002, manufacturer: Linux 6.5.0-18-generic xhci-hcd, product: xHCI Host Controller, serial: 0000:00:14.0, ID: /dev/bus/usb/001/001 +Present: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/009 Monitoring... Press ENTER to quit. -... +Disconnected: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/009 +Connected: VID: 0xcafe, PID: 0xceaf, manufacturer: JavaDoesUSB, product: Loopback, serial: 35A737883336, ID: /dev/bus/usb/001/010 ``` diff --git a/examples/monitor_kotlin/mvnw.cmd b/examples/monitor_kotlin/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/monitor_kotlin/mvnw.cmd +++ b/examples/monitor_kotlin/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/monitor_kotlin/pom.xml b/examples/monitor_kotlin/pom.xml index b3e91b5..cdae381 100644 --- a/examples/monitor_kotlin/pom.xml +++ b/examples/monitor_kotlin/pom.xml @@ -4,7 +4,7 @@ net.codecrete.usb.examples monitor - 0.7.1 + 1.0.0-SNAPSHOT jar monitor @@ -64,22 +64,22 @@ net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT org.tinylog tinylog-api - 2.6.2 + 2.7.0 org.tinylog tinylog-impl - 2.6.2 + 2.7.0 org.tinylog jsl-tinylog - 2.6.2 + 2.7.0 junit diff --git a/examples/stm_dfu/.mvn/wrapper/maven-wrapper.properties b/examples/stm_dfu/.mvn/wrapper/maven-wrapper.properties index 6d3a566..f3283b0 100644 --- a/examples/stm_dfu/.mvn/wrapper/maven-wrapper.properties +++ b/examples/stm_dfu/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/examples/stm_dfu/README.md b/examples/stm_dfu/README.md index acab0b6..df76a71 100644 --- a/examples/stm_dfu/README.md +++ b/examples/stm_dfu/README.md @@ -6,15 +6,15 @@ Even though the DFU ## Prerequisites -- Java 21 +- Java 22 - Apache Maven - 64-bit operating system (Windows, macOS, Linux) ## How to run -### Install Java 21 +### Install Java 22 -Check that *Java 21* is installed: +Check that *Java 22* is installed: ```shell $ java -version @@ -58,7 +58,7 @@ Run the command below (adapting the file path depending on your specific board): ```shell $ mvn package -$ java --enable-preview --enable-native-access=ALL-UNNAMED -jar target/stm_dfu-0.7.1.jar ../../test-devices/loopback-stm32/bin/blackpill-f401cc.bin +$ java --enable-native-access=ALL-UNNAMED -jar target/stm_dfu-1.0.0-SNAPSHOT.jar ../../test-devices/loopback-stm32/bin/blackpill-f401cc.bin DFU device found with serial 35A737883336. Target memory segment: Internal Flash Erasing page at 0x8000000 (size 0x4000) diff --git a/examples/stm_dfu/mvnw.cmd b/examples/stm_dfu/mvnw.cmd index c4586b5..f80fbad 100644 --- a/examples/stm_dfu/mvnw.cmd +++ b/examples/stm_dfu/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/examples/stm_dfu/pom.xml b/examples/stm_dfu/pom.xml index 4891d1e..5a47b5a 100644 --- a/examples/stm_dfu/pom.xml +++ b/examples/stm_dfu/pom.xml @@ -4,61 +4,60 @@ net.codecrete.usb.examples stm_dfu - 0.7.1 + 1.0.0-SNAPSHOT stm_dfu https://github.com/manuelbl/JavaDoesUSB/examples/stm_dfu UTF-8 - 21 - 21 + 22 + 22 net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT + maven-clean-plugin - 3.1.0 + 3.3.2 + maven-resources-plugin - 3.0.2 + 3.3.1 maven-compiler-plugin - 3.8.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 maven-jar-plugin - 3.0.2 + 3.3.0 maven-surefire-plugin - 2.22.2 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=ALL-UNNAMED maven-shade-plugin - 3.3.0 + 3.5.1 package diff --git a/java-does-usb/.mvn/wrapper/maven-wrapper.properties b/java-does-usb/.mvn/wrapper/maven-wrapper.properties index ac18401..346d645 100644 --- a/java-does-usb/.mvn/wrapper/maven-wrapper.properties +++ b/java-does-usb/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/java-does-usb/jextract/README.md b/java-does-usb/jextract/README.md index 2054483..eb94c18 100644 --- a/java-does-usb/jextract/README.md +++ b/java-does-usb/jextract/README.md @@ -1,31 +1,21 @@ # Code Generation with *jextract* -Some of the binding code for accessing native functions and data structures is generated with [jextract](https://jdk.java.net/jextract/). The tool is still under construction and has its limitations. +A major part of the binding code for accessing native functions and data structures is generated with [jextract](https://jdk.java.net/jextract/). *jextract* is not bundled with the JDK. The binaries can be downloaded from [jdk.java.net/jextract](https://jdk.java.net/jextract/) -In order to generate the code, the scripts in the subdirectories have to be run (`linux/gen_linux.sh`, `macos/gen_macos.sh` and `/windowsgen_win.cmd`). Each script has to be run on the particular operating system. +In order to generate the code, the scripts in the subdirectories have to be run (`linux/gen_linux.sh`, `macos/gen_macos.sh` and `windows/gen_win.cmd`). Each script has to be run on the particular operating system. The scripts expect the *jextract* binary to be in a *jextract* directory at the same parent directory as the *Java Does USB* project. If that is not the case, the *jextract* path can be modified at the top of the scripts. -The code is generated in directories below `gen`, i.e. `main/java/net/codecrete/usb/linux/gen` and similar for the other operating systems. For each library (`xxx.so` or `xxx.dll`) and each macOS framework, a separate package is created. +The code is generated in directories below `gen`, i.e. `main/java/net/codecrete/usb/linux/gen` and similarly for the other operating systems. For each library (`xxx.so` or `xxx.dll`) and each macOS framework, a separate package is created. -The scripts explicitly specify the functions, structs etc. to include as generating code for entire operating system header files can result in an excessive amount of Java source files and classes. +The scripts explicitly specify the functions, structs etc. to include as generating code for entire operating system header files will result in an excessive amount of Java source files and classes. -The resulting code is then committed to the source code repository. Before the commit, imports are cleaned up to get rid of superfluous imports. Most IDEs provide a convenient command to execute this on entire directories. +The resulting code is then committed to the source code repository. ## General limitations -- The binaries for *jextract* on https://jdk.java.net/jextract/ have not been updated for JDK 21. So it must be built from source. Instructions can be found at [Building & Testing](https://github.com/openjdk/jextract#building--testing). - - According to the jextract mailing list, it would be required to create separate code for Intel x64 and ARM64 architecture. And jextract would need to be run on each architecture separately (no cross-compilation). Fortunately, this doesn't seem to be the case. Linux code generated on Intel x64 also runs on ARM64 without change. The same holds for macOS. However, jextract needs to be run on each operating system separately. -- JDK 20 introduced a new feature for saving the thread-specific error values (`GetLastError()` on Windows, `errno` on Linux). To use it, an additional parameter must be added to function calls. Unfortunately, this is not yet supported by jextract. So a good number of function bindings have to be written manually. - -- `typedef` and `struct`: - - 1. If only the `typedef` is included (`--include-typedef`), an empty Java class is generated. - 2. If both *typedef* and the `struct` it refers to are included, the `typedef` class inherits from the `struct` class, which contains all the `struct` members. - 3. If the `typedef` refers to an unnamed `struct`, the generated class contains all the `struct` members. - - Case 1 looks like a bug. +- The *Foreign Function And Memory* API has the abilitiy to save the thread-specific error values (`GetLastError()` on Windows, `errno` on Linux). This is required as the JVM calls operation system functions as well, which overwrite the result values. To save the values, an additional parameter must be added to function calls. Unfortunately, this is not supported by jextract. So a good number of function bindings have to be written manually. - *jextract* is not really transparent about what it does. It often skips elements without providing any information. In particular, it will silently skip a requested element in these cases: @@ -36,6 +26,7 @@ The resulting code is then committed to the source code repository. Before the c - `--include-typedef mystruct` if `mystruct` is actually a `struct`. - `--include-typedef mytypedef` if `mytypedef` is a `typedef` for a primitive type. +- *jextract* resolves all _typedef_s to their actual types. So this library does not use any _--include-typedef_ option. And there does not seem any obvious use for it beyond cosmetics. ## Linux @@ -48,34 +39,21 @@ sudo apt-get install libudev-dev On Linux, the limitations are: -- `usbdevice_fs.h`: The macro `USBDEVFS_CONTROL` and all similar ones are not generated. They are probably considered function-like macros. *jextract* does not generate code for function-like macros. But `USBDEVFS_CONTROL` evaluates to a constant. +- `usbdevice_fs.h`: The macro `USBDEVFS_CONTROL` and all similar ones are not generated. They are probably considered function-like macros. *jextract* does not generate code for function-like macros. `USBDEVFS_CONTROL` would evaluate to a constant. - `sd-device.h` (header file for *libsystemd*): *jextract* fails with *"Error: /usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'"*. The reason is yet unknown. This code is currently not needed as *libudev* is used instead of *libsystemd*. They are related, *libsystemd* is the future solution, but it is missing support for monitoring devices. -- `libudev.h`: After code generation, the class `RuntimeHelper.java` in `.../linux/gen/udev` must be manually modified as the code to access the library does not work for the directory the library is located in. So replace: - -``` -System.loadLibrary("udev"); -SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); -``` - -with: - -``` -SymbolLookup loaderLookup = SymbolLookup.libraryLookup("libudev.so", MemorySession.openImplicit()); -``` ## MacOS Most of the required native functions on macOS are part of a framework. Frameworks internally have a more complex file organization of header and binary files than appears from the outside. Thus, they require a special logic to locate framework header files. *clang* supports it with the `-F`. *jextract* allows to specify the options via `compiler_flags.txt` file. Since the file must be in the local directory and since it does not apply to Linux and Windows, separate directories must be used for the operating systems. -The generated code has the same problem as the Linux code for *udev*. It must be manually changed to use `SymbolLookup.libraryLookup()` for the frameworks `CoreFoundation` and `IOKit` respectively, and use an absolute path starting with `/System/Library/Frameworks/`. ## Windows -Most Windows SDK header files are not independent. They require that `Windows.h` is included first. So instead of specifying the target header files directly, a helper header file (`windows_headers.h` in this directory) is specified. +Most Windows SDK header files are not independent. They require `Windows.h` to be included first. So instead of specifying the target header files directly, a helper header file (`windows_headers.h` in this directory) is specified. Compared to Linux and macOS, the code generation on Windows is very slow (about 1 min vs 3 seconds). And jextract crashes sometimes. @@ -92,22 +70,24 @@ The known limitations are: - *jextract* turns off *echo mode*. So the first call will behave differently than the following calls. + ## Code Size *jextract* generates a comprehensive set of methods for each function, struct, struct member etc. Most of it will not be used as a typical application just uses a subset of struct members, might only read or write them etc. So a considerable amount of code is generated. For some types, it's a bit excessive. -The worst example is [`IOUSBInterfaceStruct190`](https://github.com/manuelbl/JavaDoesUSB/blob/main/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java) (macOS). This is a `struct` consisting of about 50 member functions. It's basically a vtable of a C++ class. For this single `struct`, *jextract* generates codes resulting in 70 class files with a total size of 227kByte. +The worst example is [`IOUSBInterfaceStruct190`](https://github.com/manuelbl/JavaDoesUSB/blob/main/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java) (macOS). This is a `struct` consisting of about 50 member functions. It's basically a vtable of a C++ class. For this single `struct`, *jextract* generates codes resulting in 100 class files with a total size of 213kByte. + +The table below shows class file size statistics for version 1.0.0 of the library: -The table below shows statistics for version 0.6.0 of the library: +| Operating Systems | Manually Written | % | Generated | % | Total | % | +|-------------------|-----------------:|------:|----------:|------:|----------:|--------:| +| Linux | 54,022 | 4.3% | 162,099 | 12.8% | 216,121 | 17.1% | +| macOS | 77,149 | 6.1% | 529,347 | 41.8% | 606,496 | 47.9% | +| Windows | 106,358 | 8.4% | 232,395 | 18.3% | 338,753 | 26.7% | +| Common | 105,423 | 8.3% | | | 105,423 | 8.3% | +| Grand Total | 342,952 | 27.1% | 923,841 | 72.9% | 1,266,793 | 100.0% | -| Operating Systems | Manually Created | % | Generated | % | Total | % | -|-------------------|-----------------:|-------:|----------:|-------:|----------:|--------:| -| Linux | 48,516 | 3.64% | 197,169 | 14.79% | 245,685 | 18.42% | -| macOS | 78,718 | 5.90% | 546,907 | 41.01% | 625,625 | 46.91% | -| Windows | 104,811 | 7.86% | 256,079 | 19.20% | 360,890 | 27.06% | -| Common | 101,364 | 7.60% | | | 101,364 | 7.60% | -| Grand Total | 333,409 | 25.00% | 1,000,155 | 75.00% | 1,333,564 | 100.00% | -*Code Size (compiled), in bytes and percentage of total size* +*Class File Size (compiled), in bytes and percentage of total size* If *jextract* could generate code for error state capturing, there would be even more generated and less manually written code. diff --git a/java-does-usb/jextract/linux/gen_linux.sh b/java-does-usb/jextract/linux/gen_linux.sh index 3b41d80..99ebe24 100755 --- a/java-does-usb/jextract/linux/gen_linux.sh +++ b/java-does-usb/jextract/linux/gen_linux.sh @@ -2,8 +2,10 @@ JEXTRACT=../../../../jextract/build/jextract/bin/jextract +rm -rf ../../src/main/java/net/codecrete/usb/linux/gen + # errno.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name errno \ --target-package net.codecrete.usb.linux.gen.errno \ --include-constant EPIPE \ @@ -15,14 +17,14 @@ $JEXTRACT --source --output ../../src/main/java \ /usr/include/errno.h # string.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name string \ --target-package net.codecrete.usb.linux.gen.string \ --include-function strerror \ /usr/include/string.h # fcntl.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name fcntl \ --target-package net.codecrete.usb.linux.gen.fcntl \ --include-constant O_CLOEXEC \ @@ -31,7 +33,7 @@ $JEXTRACT --source --output ../../src/main/java \ /usr/include/fcntl.h # unistd.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name unistd \ --target-package net.codecrete.usb.linux.gen.unistd \ --include-function close \ @@ -39,7 +41,7 @@ $JEXTRACT --source --output ../../src/main/java \ # usbdevice_fs.h # Missing constants like USBDEVFS_CLAIMINTERFACE -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name usbdevice_fs \ --target-package net.codecrete.usb.linux.gen.usbdevice_fs \ --include-struct usbdevfs_bulktransfer \ @@ -48,6 +50,7 @@ $JEXTRACT --source --output ../../src/main/java \ --include-struct usbdevfs_urb \ --include-struct usbdevfs_disconnect_claim \ --include-struct usbdevfs_ioctl \ + --include-struct usbdevfs_iso_packet_desc \ --include-constant USBDEVFS_URB_TYPE_INTERRUPT \ --include-constant USBDEVFS_URB_TYPE_CONTROL \ --include-constant USBDEVFS_URB_TYPE_BULK \ @@ -57,10 +60,10 @@ $JEXTRACT --source --output ../../src/main/java \ # libudev.h # (install libudev-dev if file is missing) -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name udev \ --target-package net.codecrete.usb.linux.gen.udev \ - -l udev \ + -l :libudev.so.1 \ --include-function udev_new \ --include-function udev_enumerate_new \ --include-function udev_enumerate_add_match_subsystem \ @@ -83,10 +86,9 @@ $JEXTRACT --source --output ../../src/main/java \ /usr/include/libudev.h # epoll.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ --header-class-name epoll \ --target-package net.codecrete.usb.linux.gen.epoll \ - --include-struct epoll_event \ --include-constant EPOLL_CTL_ADD \ --include-constant EPOLL_CTL_DEL \ --include-constant EPOLLIN \ diff --git a/java-does-usb/jextract/macos/gen_macos.sh b/java-does-usb/jextract/macos/gen_macos.sh index c74b586..24a0c05 100755 --- a/java-does-usb/jextract/macos/gen_macos.sh +++ b/java-does-usb/jextract/macos/gen_macos.sh @@ -1,17 +1,19 @@ #!/bin/sh -JEXTRACT=../../../../jextract/build/jextract/bin/jextract +JEXTRACT=../../../../jextract/bin/jextract # If SDK_DIR is changed, it needs to be changed in compile_flags.txt as well. SDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk +rm -rf ../../src/main/java/net/codecrete/usb/macos/gen + # CoreFoundation -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ -I $SDK_DIR/usr/include \ - -lCoreFoundation.framework \ + -l :/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation \ --header-class-name CoreFoundation \ --target-package net.codecrete.usb.macos.gen.corefoundation \ - --include-typedef CFRange \ - --include-typedef CFUUIDBytes \ + --include-struct CFRange \ + --include-struct CFUUIDBytes \ --include-function CFUUIDCreateFromUUIDBytes \ --include-function CFRelease \ --include-function CFStringGetLength \ @@ -25,14 +27,20 @@ $JEXTRACT --source --output ../../src/main/java \ --include-function CFRunLoopAddSource \ --include-function CFRunLoopRemoveSource \ --include-function CFRunLoopRun \ + --include-function CFMessagePortCreateLocal \ + --include-function CFMessagePortCreateRunLoopSource \ + --include-function CFMessagePortCreateRemote \ + --include-function CFMessagePortSendRequest \ + --include-function CFDataCreate \ + --include-function CFDataGetBytePtr \ --include-function CFUUIDGetUUIDBytes \ --include-constant kCFNumberSInt32Type \ cf_helper.h # IOKit -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ -I $SDK_DIR/usr/include \ - -lIOKit.framework \ + -l :/System/Library/Frameworks/IOKit.framework/IOKit \ --header-class-name IOKit \ --target-package net.codecrete.usb.macos.gen.iokit \ --include-var kIOMasterPortDefault \ @@ -42,7 +50,6 @@ $JEXTRACT --source --output ../../src/main/java \ --include-constant kIOReturnExclusiveAccess \ --include-var kCFRunLoopDefaultMode \ --include-struct IOCFPlugInInterfaceStruct \ - --include-typedef IOCFPlugInInterface \ --include-function IOObjectRelease \ --include-function IOIteratorNext \ --include-function IOCreatePlugInInterfaceForService \ @@ -53,21 +60,20 @@ $JEXTRACT --source --output ../../src/main/java \ --include-function IOServiceAddMatchingNotification \ --include-function IOServiceMatching \ --include-struct IOUSBDeviceStruct187 \ - --include-typedef IOUSBDeviceInterface187 \ --include-constant kIOUSBFindInterfaceDontCare \ - --include-typedef IOUSBFindInterfaceRequest \ - --include-typedef IOUSBDevRequest \ + --include-struct IOUSBFindInterfaceRequest \ + --include-struct IOUSBDevRequest \ --include-struct IOUSBInterfaceStruct190 \ - --include-typedef IOUSBInterfaceInterface190 \ --include-constant kIOUSBTransactionTimeout \ --include-constant kIOReturnAborted \ --include-constant kIOUSBPipeStalled \ --include-constant kUSBReEnumerateCaptureDeviceMask \ --include-constant kUSBReEnumerateReleaseDeviceMask \ + --include-struct CFUUIDBytes \ iokit_helper.h # mach.h -$JEXTRACT --source --output ../../src/main/java \ +$JEXTRACT --output ../../src/main/java \ -I $SDK_DIR/usr/include \ --header-class-name mach \ --target-package net.codecrete.usb.macos.gen.mach \ diff --git a/java-does-usb/jextract/windows/gen_win.cmd b/java-does-usb/jextract/windows/gen_win.cmd index a4084d2..d0cf4f1 100644 --- a/java-does-usb/jextract/windows/gen_win.cmd +++ b/java-does-usb/jextract/windows/gen_win.cmd @@ -1,12 +1,15 @@ -set JEXTRACT=..\..\..\..\jextract\build\jextract\bin\jextract.bat +set JEXTRACT=..\..\..\..\jextract\bin\jextract.bat set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0 -call %JEXTRACT% --source --output ../../src/main/java ^ +del /s /q ..\..\src\main\java\net\codecrete\usb\windows\gen +rmdir /s /q ..\..\src\main\java\net\codecrete\usb\windows\gen + +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ -l Kernel32 ^ - --header-class-name Kernel32 ^ + --header-class-name Kernel32 ^ --target-package net.codecrete.usb.windows.gen.kernel32 ^ --include-function CloseHandle ^ --include-function GetModuleHandleW ^ @@ -32,12 +35,10 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-constant FORMAT_MESSAGE_FROM_HMODULE ^ --include-constant INFINITE ^ --include-struct _GUID ^ - --include-typedef GUID ^ --include-struct _OVERLAPPED ^ - --include-typedef OVERLAPPED ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ @@ -47,13 +48,10 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-function SetupDiDestroyDeviceInfoList ^ --include-function SetupDiDeleteDeviceInterfaceData ^ --include-struct _SP_DEVINFO_DATA ^ - --include-typedef SP_DEVINFO_DATA ^ --include-struct _SP_DEVICE_INTERFACE_DATA ^ - --include-typedef SP_DEVICE_INTERFACE_DATA ^ --include-struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W ^ - --include-typedef SP_DEVICE_INTERFACE_DETAIL_DATA_W ^ --include-struct _DEVPROPKEY ^ - --include-typedef DEVPROPKEY ^ + --include-struct _GUID ^ --include-constant DIGCF_PRESENT ^ --include-constant DIGCF_DEVICEINTERFACE ^ --include-constant DEVPROP_TYPE_UINT32 ^ @@ -63,21 +61,22 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-constant DIREG_DEV ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ --header-class-name USBIoctl ^ --target-package net.codecrete.usb.windows.gen.usbioctl ^ --include-struct _USB_NODE_CONNECTION_INFORMATION_EX ^ - --include-typedef USB_NODE_CONNECTION_INFORMATION_EX ^ --include-struct _USB_DESCRIPTOR_REQUEST ^ - --include-typedef USB_DESCRIPTOR_REQUEST ^ + --include-struct _USB_DEVICE_DESCRIPTOR ^ + --include-struct _USB_ENDPOINT_DESCRIPTOR ^ + --include-struct _USB_PIPE_INFO ^ --include-constant IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX ^ --include-constant IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ @@ -92,16 +91,14 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-constant DBT_DEVICEREMOVECOMPLETE ^ --include-constant DBT_DEVTYP_DEVICEINTERFACE ^ --include-struct tagMSG ^ - --include-typedef MSG ^ + --include-struct tagPOINT ^ --include-struct tagWNDCLASSEXW ^ - --include-typedef WNDCLASSEXW ^ --include-struct _DEV_BROADCAST_HDR ^ - --include-typedef DEV_BROADCAST_HDR ^ --include-struct _DEV_BROADCAST_DEVICEINTERFACE_W ^ - --include-typedef DEV_BROADCAST_DEVICEINTERFACE_W ^ + --include-struct _GUID ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ @@ -113,7 +110,7 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-constant RAW_IO ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ @@ -125,7 +122,7 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-constant KEY_READ ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ @@ -135,7 +132,7 @@ call %JEXTRACT% --source --output ../../src/main/java ^ --include-function CLSIDFromString ^ windows_headers.h -call %JEXTRACT% --source --output ../../src/main/java ^ +call %JEXTRACT% --output ../../src/main/java ^ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^ -I "%SDK_DIR%\um" ^ -I "%SDK_DIR%\shared" ^ diff --git a/java-does-usb/pom.xml b/java-does-usb/pom.xml index 5924998..3d3e088 100644 --- a/java-does-usb/pom.xml +++ b/java-does-usb/pom.xml @@ -6,11 +6,11 @@ net.codecrete.usb java-does-usb - 0.7.1 + 1.0.0-SNAPSHOT - 21 - 21 + 22 + 22 UTF-8 @@ -54,28 +54,25 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.12.1 - 21 - - --enable-preview - - 21 - 21 + 22 + 22 + 22 org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.5 - --enable-preview --enable-native-access=ALL-UNNAMED + --enable-native-access=net.codecrete.usb org.apache.maven.plugins maven-javadoc-plugin - 3.6.0 + 3.6.3 attach-javadocs @@ -85,8 +82,7 @@ - 21 - --enable-preview + 22 ${java.home}/bin/javadoc @@ -140,31 +136,31 @@ org.jetbrains annotations - 24.0.1 + 24.1.0 compile org.junit.jupiter junit-jupiter - 5.10.0 + 5.10.2 test org.assertj assertj-core - 3.24.2 + 3.25.3 test org.tinylog tinylog-impl - 2.6.2 + 2.7.0 test org.tinylog jsl-tinylog - 2.6.2 + 2.7.0 test diff --git a/java-does-usb/src/main/java/net/codecrete/usb/Usb.java b/java-does-usb/src/main/java/net/codecrete/usb/Usb.java index 3c28730..99381a8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/Usb.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/Usb.java @@ -106,6 +106,15 @@ public static Optional findDevice(int vendorId, int productId) { /** * Sets the handler to be called when a USB device is connected. + *

+ * The handler is called from a background thread. + *

+ *

+ * The handler should not execute any time-consuming operations but rather return quickly. + * While the handler is being executed, maintaining the list of connected devices is paused, + * methods of this class (such as {@link #getDevices()}) will possibly work with an outdated list + * of connected devices and handlers for connect and disconnect events will not be called. + *

* * @param handler handler function, or {@code null} to remove a previous handler */ @@ -116,10 +125,24 @@ public static void setOnDeviceConnected(@Nullable Consumer handler) { /** * Sets the handler to be called when a USB device is disconnected. *

+ * The handler is called from a background thread. + *

+ *

* When the handler is called, the {@link UsbDevice} instance has already been closed. * Descriptive information (such as vendor and product ID, serial number, interfaces, endpoints) * can still be accessed. *

+ *

+ * If the application was communicating with the device when it was disconnected, it will also receive + * an error for those operations. Due to the concurrency of the USB stack, there is no particular order + * for the disconnect event and the transmission errors. + *

+ *

+ * The handler should not execute any time-consuming operations but rather return quickly. + * While the handler is being executed, maintaining the list of connected devices is paused, + * methods of this class (such as {@link #getDevices()}) will possibly work with an outdated list + * of connected devices and handlers for connect and disconnect events will not be called. + *

* * @param handler handler function, or {@code null} to remove a previous handler */ diff --git a/java-does-usb/src/main/java/net/codecrete/usb/UsbException.java b/java-does-usb/src/main/java/net/codecrete/usb/UsbException.java index 71a4114..d5e07fa 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/UsbException.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/UsbException.java @@ -37,7 +37,7 @@ public UsbException(@NotNull String message) { * @param errorCode the error code */ public UsbException(@NotNull String message, int errorCode) { - super(STR."\{message} (error code: \{errorCode})"); + super(message + " (error code:" + errorCode + ")"); code = errorCode; } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/ConfigurationParser.java b/java-does-usb/src/main/java/net/codecrete/usb/common/ConfigurationParser.java index 31b8298..f802329 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/common/ConfigurationParser.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/common/ConfigurationParser.java @@ -20,7 +20,10 @@ import java.lang.foreign.ValueLayout; import java.util.ArrayList; -import static net.codecrete.usb.usbstandard.Constants.*; +import static net.codecrete.usb.usbstandard.Constants.CONFIGURATION_DESCRIPTOR_TYPE; +import static net.codecrete.usb.usbstandard.Constants.ENDPOINT_DESCRIPTOR_TYPE; +import static net.codecrete.usb.usbstandard.Constants.INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE; +import static net.codecrete.usb.usbstandard.Constants.INTERFACE_DESCRIPTOR_TYPE; /** * Parser for USB configuration descriptors. diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/UsbDeviceImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/UsbDeviceImpl.java index 184ccb4..2d6a0c6 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/common/UsbDeviceImpl.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/common/UsbDeviceImpl.java @@ -7,7 +7,14 @@ package net.codecrete.usb.common; -import net.codecrete.usb.*; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbDirection; +import net.codecrete.usb.UsbEndpoint; +import net.codecrete.usb.UsbException; +import net.codecrete.usb.UsbInterface; +import net.codecrete.usb.UsbTimeoutException; +import net.codecrete.usb.UsbTransferType; +import net.codecrete.usb.Version; import net.codecrete.usb.usbstandard.DeviceDescriptor; import org.jetbrains.annotations.NotNull; @@ -350,14 +357,14 @@ protected void waitForTransfer(Transfer transfer, int timeout, UsbDirection dire if (hasTimedOut && transfer.resultCode() == 0) { abortTransfers(direction, endpointNumber); waitNoTimeout(transfer); - throw new UsbTimeoutException(STR."\{getOperationDescription(direction, endpointNumber)}aborted due to timeout"); + throw new UsbTimeoutException(getOperationDescription(direction, endpointNumber) + " aborted due to timeout"); } } // test for error if (transfer.resultCode() != 0) { var operation = getOperationDescription(direction, endpointNumber); - throwOSException(transfer.resultCode(), STR."\{operation} failed"); + throwOSException(transfer.resultCode(), operation + " failed"); } } @@ -449,7 +456,8 @@ public int hashCode() { @Override public String toString() { - return STR."VID: 0x\{String.format("%04x", vid)}, PID: 0x\{String.format("%04x", pid)}, manufacturer: \{manufacturerString}, product: \{productString}, serial: \{serialString}, ID: \{uniqueDeviceId}"; + return String.format("VID: 0x%04x, PID: 0x%04x, manufacturer: %s, product: %s, serial: %s, ID: %s", + vid, pid, manufacturerString, productString, serialString, uniqueDeviceId); } public record EndpointInfo(int interfaceNumber, int endpointNumber, byte endpointAddress, int packetSize, diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java index e9f8fb3..e644dd4 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/EPoll.java @@ -7,23 +7,52 @@ package net.codecrete.usb.linux; -import net.codecrete.usb.linux.gen.epoll.epoll_event; import net.codecrete.usb.linux.gen.errno.errno; -import java.lang.foreign.*; +import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.GroupLayout; +import java.lang.foreign.Linker; +import java.lang.foreign.MemoryLayout; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SequenceLayout; import java.lang.invoke.MethodHandle; import java.lang.invoke.VarHandle; import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.ADDRESS_UNALIGNED; import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_INT_UNALIGNED; +import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED; import static net.codecrete.usb.linux.Linux.allocateErrorState; import static net.codecrete.usb.linux.LinuxUsbException.throwLastError; -import static net.codecrete.usb.linux.gen.epoll.epoll.*; +import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_ADD; +import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLL_CTL_DEL; -@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100"}) +@SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100", "java:S1192"}) public class EPoll { + private EPoll() {} + + private static final boolean IS_AARCH64 = System.getProperty("os.arch").equals("aarch64"); + + private static final GroupLayout DATA$LAYOUT = MemoryLayout.unionLayout( + ADDRESS_UNALIGNED.withName("ptr"), + JAVA_INT_UNALIGNED.withName("fd"), + JAVA_INT_UNALIGNED.withName("u32"), + JAVA_LONG_UNALIGNED.withName("u64") + ).withName("epoll_data"); + + static final GroupLayout EVENT$LAYOUT = IS_AARCH64 + ? MemoryLayout.structLayout( + JAVA_INT.withName("events"), + MemoryLayout.paddingLayout(4), + DATA$LAYOUT.withName("data")).withName("epoll_event") + : MemoryLayout.structLayout( + JAVA_INT_UNALIGNED.withName("events"), + DATA$LAYOUT.withName("data")).withName("epoll_event"); + // Memory layout for an array of epoll_event structs - private static final SequenceLayout EVENT_ARRAY$LAYOUT = MemoryLayout.sequenceLayout(epoll_event.$LAYOUT()); + private static final SequenceLayout EVENT_ARRAY$LAYOUT = MemoryLayout.sequenceLayout(1, EVENT$LAYOUT); // varhandle to access the "fd" field in an array of epoll_event structs static final VarHandle EVENT_ARRAY_DATA_FD$VH = EVENT_ARRAY$LAYOUT.varHandle( @@ -33,13 +62,14 @@ public class EPoll { ); // varhandle to access the "fd" field in an epoll_event struct - static final VarHandle EVENT_DATA_FD$VH = epoll_event.$LAYOUT().varHandle( + private static final VarHandle EVENT_DATA_FD$VH = EVENT$LAYOUT.varHandle( MemoryLayout.PathElement.groupElement("data"), MemoryLayout.PathElement.groupElement("fd") ); - - private EPoll() {} + private static final VarHandle EVENTS$VH = EVENT$LAYOUT.varHandle( + MemoryLayout.PathElement.groupElement("events") + ); private static final Linker linker = Linker.nativeLinker(); @@ -83,9 +113,9 @@ static void addFileDescriptor(int epfd, int op, int fd) { try (var arena = Arena.ofConfined()) { var errorState = allocateErrorState(arena); - var event = arena.allocate(epoll_event.$LAYOUT()); - epoll_event.events$set(event, op); - EVENT_DATA_FD$VH.set(event, fd); + var event = arena.allocate(EVENT$LAYOUT); + EVENTS$VH.set(event, 0, op); + EVENT_DATA_FD$VH.set(event, 0, fd); var ret = epoll_ctl(epfd, EPOLL_CTL_ADD(), fd, event, errorState); if (ret < 0) throwLastError(errorState, "internal error (epoll_ctl_add)"); @@ -96,9 +126,9 @@ static void removeFileDescriptor(int epfd, int fd) { try (var arena = Arena.ofConfined()) { var errorState = allocateErrorState(arena); - var event = arena.allocate(epoll_event.$LAYOUT()); - epoll_event.events$set(event, 0); - EVENT_DATA_FD$VH.set(event, fd); + var event = arena.allocate(EVENT$LAYOUT); + EVENTS$VH.set(event, 0, 0); + EVENT_DATA_FD$VH.set(event, 0, fd); var ret = epoll_ctl(epfd, EPOLL_CTL_DEL(), fd, event, errorState); if (ret < 0) { var err = Linux.getErrno(errorState); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java index bfdc938..367deb8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java @@ -12,7 +12,9 @@ import java.lang.foreign.MemorySegment; import java.lang.invoke.MethodHandle; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; @SuppressWarnings({"OptionalGetWithoutIsPresent", "SameParameterValue", "java:S100"}) class IO { diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java index c8c7ac7..ab494b9 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java @@ -43,7 +43,7 @@ static MemorySegment allocateErrorState(Arena arena) { * @return error message */ static String getErrorMessage(int err) { - return string.strerror(err).getUtf8String(0); + return string.strerror(err).getString(0); } /** @@ -56,6 +56,6 @@ static String getErrorMessage(int err) { * @return error code */ static int getErrno(MemorySegment errorState) { - return (int) callState_errno$VH.get(errorState); + return (int) callState_errno$VH.get(errorState, 0); } } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxAsyncTask.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxAsyncTask.java index a01d6dc..1a33d16 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxAsyncTask.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxAsyncTask.java @@ -8,7 +8,6 @@ package net.codecrete.usb.linux; import net.codecrete.usb.UsbTransferType; -import net.codecrete.usb.linux.gen.epoll.epoll_event; import net.codecrete.usb.linux.gen.errno.errno; import net.codecrete.usb.linux.gen.usbdevice_fs.usbdevfs_urb; @@ -19,18 +18,25 @@ import java.util.List; import java.util.Map; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; import static net.codecrete.usb.common.ForeignMemory.dereference; import static net.codecrete.usb.linux.EPoll.epoll_create1; import static net.codecrete.usb.linux.EPoll.epoll_wait; import static net.codecrete.usb.linux.Linux.allocateErrorState; import static net.codecrete.usb.linux.LinuxUsbException.throwException; import static net.codecrete.usb.linux.LinuxUsbException.throwLastError; -import static net.codecrete.usb.linux.UsbDevFS.*; -import static net.codecrete.usb.linux.gen.epoll.epoll.*; -import static net.codecrete.usb.linux.gen.errno.errno.*; +import static net.codecrete.usb.linux.UsbDevFS.DISCARDURB; +import static net.codecrete.usb.linux.UsbDevFS.REAPURBNDELAY; +import static net.codecrete.usb.linux.UsbDevFS.SUBMITURB; +import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLLOUT; +import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLLWAKEUP; +import static net.codecrete.usb.linux.gen.errno.errno.EINTR; +import static net.codecrete.usb.linux.gen.errno.errno.ENODEV; import static net.codecrete.usb.linux.gen.fcntl.fcntl.FD_CLOEXEC; -import static net.codecrete.usb.linux.gen.usbdevice_fs.usbdevice_fs.*; +import static net.codecrete.usb.linux.gen.usbdevice_fs.usbdevice_fs.USBDEVFS_URB_TYPE_BULK; +import static net.codecrete.usb.linux.gen.usbdevice_fs.usbdevice_fs.USBDEVFS_URB_TYPE_CONTROL; +import static net.codecrete.usb.linux.gen.usbdevice_fs.usbdevice_fs.USBDEVFS_URB_TYPE_INTERRUPT; +import static net.codecrete.usb.linux.gen.usbdevice_fs.usbdevice_fs.USBDEVFS_URB_TYPE_ISO; /** * Background task for handling asynchronous transfers. @@ -77,7 +83,7 @@ private void asyncCompletionTask() { try (var arena = Arena.ofConfined()) { var errorState = allocateErrorState(arena); var urbPointerHolder = arena.allocate(ADDRESS); - var events = arena.allocateArray(epoll_event.$LAYOUT(), NUM_EVENTS); + var events = arena.allocate(EPoll.EVENT$LAYOUT, NUM_EVENTS); while (true) { @@ -92,7 +98,7 @@ private void asyncCompletionTask() { // for all ready file descriptors, reap URBs for (int i = 0; i < res; i++) { - var fd = (int) EPoll.EVENT_ARRAY_DATA_FD$VH.get(events, i); + var fd = (int) EPoll.EVENT_ARRAY_DATA_FD$VH.get(events, 0, i); reapURBs(fd, urbPointerHolder, errorState); } } @@ -163,12 +169,13 @@ synchronized void removeFromAsyncIOCompletion(LinuxUsbDevice device) { // reclaim stale URBs transfersByURB.entrySet().removeIf(e -> { var urb = e.getKey(); - var isMatch = usbdevfs_urb.usercontext$get(urb).address() == fd; + var isMatch = usbdevfs_urb.usercontext(urb).address() == fd; if (isMatch) { var transfer = e.getValue(); transfer.urb = null; - transfer.setResultCode(ENOENT()); + transfer.setResultCode(ENODEV()); transfer.setResultSize(0); + transfer.completion().completed(transfer); availableURBs.add(urb); } return isMatch; @@ -180,11 +187,11 @@ synchronized void submitTransfer(LinuxUsbDevice device, int endpointAddress, Usb linkToUrb(transfer); var urb = transfer.urb; - usbdevfs_urb.type$set(urb, (byte) urbTransferType(transferType)); - usbdevfs_urb.endpoint$set(urb, (byte) endpointAddress); - usbdevfs_urb.buffer$set(urb, transfer.data()); - usbdevfs_urb.buffer_length$set(urb, transfer.dataSize()); - usbdevfs_urb.usercontext$set(urb, MemorySegment.ofAddress(device.fileDescriptor())); + usbdevfs_urb.type(urb, (byte) urbTransferType(transferType)); + usbdevfs_urb.endpoint(urb, (byte) endpointAddress); + usbdevfs_urb.buffer(urb, transfer.data()); + usbdevfs_urb.buffer_length(urb, transfer.dataSize()); + usbdevfs_urb.usercontext(urb, MemorySegment.ofAddress(device.fileDescriptor())); try (var arena = Arena.ofConfined()) { var errorState = allocateErrorState(arena); @@ -241,8 +248,8 @@ private synchronized LinuxTransfer getTransferWithResult(MemorySegment urb) { if (transfer == null) throwException("internal error (unknown URB)"); - transfer.setResultCode(-usbdevfs_urb.status$get(transfer.urb)); - transfer.setResultSize(usbdevfs_urb.actual_length$get(transfer.urb)); + transfer.setResultCode(-usbdevfs_urb.status(transfer.urb)); + transfer.setResultSize(usbdevfs_urb.actual_length(transfer.urb)); availableURBs.add(transfer.urb); transfer.urb = null; @@ -260,8 +267,8 @@ synchronized void abortTransfers(LinuxUsbDevice device, byte endpointAddress) { // iterate all URBs and discard the ones for the specified endpoint transfersByURB.keySet().stream() .filter(urb -> - usbdevfs_urb.usercontext$get(urb).address() == fd - && usbdevfs_urb.endpoint$get(urb) == endpointAddress) + usbdevfs_urb.usercontext(urb).address() == fd + && usbdevfs_urb.endpoint(urb) == endpointAddress) .forEach(urb -> { if (IO.ioctl(fd, DISCARDURB, urb, errorState) < 0) { // ignore EINVAL; it occurs if the URB has completed at the same time diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDevice.java index d82aed8..b2fdf4d 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDevice.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDevice.java @@ -41,8 +41,7 @@ @SuppressWarnings("java:S2160") public class LinuxUsbDevice extends UsbDeviceImpl { - @SuppressWarnings("resource") - private static final MemorySegment DRIVER_NAME_USBFS = Arena.global().allocateUtf8String("usbfs"); + private static final MemorySegment DRIVER_NAME_USBFS = Arena.global().allocateFrom("usbfs"); private int fd = -1; @@ -96,7 +95,7 @@ public synchronized void open() { throwException("device is already open"); try (var arena = Arena.ofConfined()) { - var pathUtf8 = arena.allocateUtf8String(uniqueDeviceId.toString()); + var pathUtf8 = arena.allocateFrom(uniqueDeviceId.toString()); var errorState = allocateErrorState(arena); fd = IO.open(pathUtf8, fcntl.O_RDWR() | fcntl.O_CLOEXEC(), errorState); if (fd == -1) @@ -135,14 +134,15 @@ public synchronized void claimInterface(int interfaceNumber) { if (detachDrivers) { // claim interface (detaching kernel driver) var disconnectClaim = usbdevfs_disconnect_claim.allocate(arena); - usbdevfs_disconnect_claim.interface_$set(disconnectClaim, interfaceNumber); - usbdevfs_disconnect_claim.flags$set(disconnectClaim, usbdevice_fs.USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER()); - usbdevfs_disconnect_claim.driver$slice(disconnectClaim).copyFrom(DRIVER_NAME_USBFS); + usbdevfs_disconnect_claim.interface_(disconnectClaim, interfaceNumber); + usbdevfs_disconnect_claim.flags(disconnectClaim, usbdevice_fs.USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER()); + usbdevfs_disconnect_claim.driver(disconnectClaim).copyFrom(DRIVER_NAME_USBFS); ret = IO.ioctl(fd, UsbDevFS.DISCONNECT_CLAIM, disconnectClaim, errorState); } else { // claim interface (without detaching kernel driver) - var intfNumSegment = arena.allocate(JAVA_INT, interfaceNumber); + var intfNumSegment = arena.allocate(JAVA_INT); + intfNumSegment.setAtIndex(JAVA_INT, 0, interfaceNumber); ret = IO.ioctl(fd, UsbDevFS.CLAIMINTERFACE, intfNumSegment, errorState); } @@ -164,8 +164,8 @@ public synchronized void selectAlternateSetting(int interfaceNumber, int alterna try (var arena = Arena.ofConfined()) { var setIntfSegment = usbdevfs_setinterface.allocate(arena); - usbdevfs_setinterface.interface_$set(setIntfSegment, interfaceNumber); - usbdevfs_setinterface.altsetting$set(setIntfSegment, alternateNumber); + usbdevfs_setinterface.interface_(setIntfSegment, interfaceNumber); + usbdevfs_setinterface.altsetting(setIntfSegment, alternateNumber); var errorState = allocateErrorState(arena); var ret = IO.ioctl(fd, UsbDevFS.SETINTERFACE, setIntfSegment, errorState); if (ret != 0) @@ -181,7 +181,8 @@ public synchronized void releaseInterface(int interfaceNumber) { getInterfaceWithCheck(interfaceNumber, true); try (var arena = Arena.ofConfined()) { - var intfNumSegment = arena.allocate(JAVA_INT, interfaceNumber); + var intfNumSegment = arena.allocate(JAVA_INT); + intfNumSegment.setAtIndex(JAVA_INT, 0, interfaceNumber); var errorState = allocateErrorState(arena); var ret = IO.ioctl(fd, UsbDevFS.RELEASEINTERFACE, intfNumSegment, errorState); if (ret != 0) @@ -192,9 +193,9 @@ public synchronized void releaseInterface(int interfaceNumber) { if (detachDrivers) { // reattach kernel driver var request = usbdevfs_ioctl.allocate(arena); - usbdevfs_ioctl.ifno$set(request, interfaceNumber); - usbdevfs_ioctl.ioctl_code$set(request, UsbDevFS.CONNECT); - usbdevfs_ioctl.data$set(request, MemorySegment.NULL); + usbdevfs_ioctl.ifno(request, interfaceNumber); + usbdevfs_ioctl.ioctl_code(request, UsbDevFS.CONNECT); + usbdevfs_ioctl.data(request, MemorySegment.NULL); IO.ioctl(fd, UsbDevFS.IOCTL, request, errorState); } } @@ -323,7 +324,8 @@ public void clearHalt(UsbDirection direction, int endpointNumber) { var endpoint = getEndpoint(direction, endpointNumber, UsbTransferType.BULK, UsbTransferType.INTERRUPT); try (var arena = Arena.ofConfined()) { - var endpointAddrSegment = arena.allocate(JAVA_INT, endpoint.endpointAddress() & 0xff); + var endpointAddrSegment = arena.allocate(JAVA_INT); + endpointAddrSegment.setAtIndex(JAVA_INT, 0, endpoint.endpointAddress() & 0xff); var errorState = allocateErrorState(arena); var res = IO.ioctl(fd, UsbDevFS.CLEAR_HALT, endpointAddrSegment, errorState); if (res < 0) diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDeviceRegistry.java index 8ff5708..6c39abe 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDeviceRegistry.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUsbDeviceRegistry.java @@ -10,7 +10,6 @@ import net.codecrete.usb.UsbDevice; import net.codecrete.usb.common.ScopeCleanup; import net.codecrete.usb.common.UsbDeviceRegistry; -import net.codecrete.usb.linux.gen.epoll.epoll_event; import net.codecrete.usb.linux.gen.udev.udev; import java.lang.foreign.Arena; @@ -19,12 +18,14 @@ import java.util.List; import static java.lang.System.Logger.Level.INFO; +import static java.lang.foreign.MemorySegment.NULL; import static net.codecrete.usb.linux.EPoll.epoll_create1; import static net.codecrete.usb.linux.EPoll.epoll_wait; import static net.codecrete.usb.linux.Linux.allocateErrorState; import static net.codecrete.usb.linux.LinuxUsbException.throwException; import static net.codecrete.usb.linux.LinuxUsbException.throwLastError; -import static net.codecrete.usb.linux.gen.epoll.epoll.*; +import static net.codecrete.usb.linux.gen.epoll.epoll.EPOLLIN; +import static net.codecrete.usb.linux.gen.errno.errno.EINTR; import static net.codecrete.usb.linux.gen.fcntl.fcntl.FD_CLOEXEC; /** @@ -44,28 +45,25 @@ public class LinuxUsbDeviceRegistry extends UsbDeviceRegistry { private static final MemorySegment ATTR_PRODUCT; private static final MemorySegment ATTR_SERIAL; + private MemorySegment monitor; + private int monitorFd; + static { - @SuppressWarnings("resource") var global = Arena.global(); - SUBSYSTEM_USB = global.allocateUtf8String("usb"); - MONITOR_NAME = global.allocateUtf8String("udev"); - DEVTYPE_USB_DEVICE = global.allocateUtf8String("usb_device"); + SUBSYSTEM_USB = global.allocateFrom("usb"); + MONITOR_NAME = global.allocateFrom("udev"); + DEVTYPE_USB_DEVICE = global.allocateFrom("usb_device"); - ATTR_ID_VENDOR = global.allocateUtf8String("idVendor"); - ATTR_ID_PRODUCT = global.allocateUtf8String("idProduct"); - ATTR_MANUFACTURER = global.allocateUtf8String("manufacturer"); - ATTR_PRODUCT = global.allocateUtf8String("product"); - ATTR_SERIAL = global.allocateUtf8String("serial"); + ATTR_ID_VENDOR = global.allocateFrom("idVendor"); + ATTR_ID_PRODUCT = global.allocateFrom("idProduct"); + ATTR_MANUFACTURER = global.allocateFrom("manufacturer"); + ATTR_PRODUCT = global.allocateFrom("product"); + ATTR_SERIAL = global.allocateFrom("serial"); } - @SuppressWarnings({"java:S1181", "java:S2189"}) - @Override - protected void monitorDevices() { - - int fd; - MemorySegment monitor; - + @SuppressWarnings("java:S1181") + private boolean setupMonitor() { try { // setup udev monitor var udevInstance = udev.udev_new(); @@ -82,18 +80,26 @@ protected void monitorDevices() { if (udev.udev_monitor_enable_receiving(monitor) < 0) throwException("internal error (udev_monitor_enable_receiving)"); - fd = udev.udev_monitor_get_fd(monitor); - if (fd < 0) + monitorFd = udev.udev_monitor_get_fd(monitor); + if (monitorFd < 0) throwException("internal error (udev_monitor_get_fd)"); // create initial list of devices var deviceList = enumeratePresentDevices(udevInstance); setInitialDeviceList(deviceList); + return true; } catch (Throwable e) { enumerationFailed(e); - return; + return false; } + } + + @SuppressWarnings("java:S2189") + @Override + protected void monitorDevices() { + if (!setupMonitor()) + return; try (var arena = Arena.ofConfined()) { // create epoll @@ -101,10 +107,10 @@ protected void monitorDevices() { var epfd = epoll_create1(FD_CLOEXEC(), errorState); if (epfd < 0) throwLastError(errorState, "internal error (epoll_create)"); - EPoll.addFileDescriptor(epfd, EPOLLIN(), fd); + EPoll.addFileDescriptor(epfd, EPOLLIN(), monitorFd); // allocate event (as output for epoll_wait) - var event = arena.allocate(epoll_event.$LAYOUT()); + var event = arena.allocate(EPoll.EVENT$LAYOUT); // monitor device changes //noinspection InfiniteLoopStatement @@ -112,22 +118,27 @@ protected void monitorDevices() { try (var cleanup = new ScopeCleanup()) { // wait for next change - epoll_wait(epfd, event, 1, -1, errorState); + int res = epoll_wait(epfd, event, 1, -1, errorState); + if (res < 0) { + var err = Linux.getErrno(errorState); + if (err == EINTR()) + continue; // continue on interrupt + throwException(err, "internal error (epoll_wait)"); + } // retrieve change var udevDevice = udev.udev_monitor_receive_device(monitor); - if (udevDevice == null) - continue; // shouldn't happen - - cleanup.add(() -> udev.udev_device_unref(udevDevice)); + if (udevDevice != NULL) { + cleanup.add(() -> udev.udev_device_unref(udevDevice)); - // get details - var action = getDeviceAction(udevDevice); + // get details + var action = getDeviceAction(udevDevice); - if ("add".equals(action)) { - onDeviceConnected(udevDevice); - } else if ("remove".equals(action)) { - onDeviceDisconnected(udevDevice); + if ("add".equals(action)) { + onDeviceConnected(udevDevice); + } else if ("remove".equals(action)) { + onDeviceDisconnected(udevDevice); + } } } } @@ -250,14 +261,14 @@ private static String getDeviceAttribute(MemorySegment udevDevice, MemorySegment if (value.address() == 0) return null; - return value.getUtf8String(0); + return value.getString(0); } private static String getDeviceName(MemorySegment udevDevice) { - return udev.udev_device_get_devnode(udevDevice).getUtf8String(0); + return udev.udev_device_get_devnode(udevDevice).getString(0); } private static String getDeviceAction(MemorySegment udevDevice) { - return udev.udev_device_get_action(udevDevice).getUtf8String(0); + return udev.udev_device_get_action(udevDevice).getString(0); } } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/RuntimeHelper.java deleted file mode 100644 index 6259819..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.epoll; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/constants$0.java deleted file mode 100644 index f5fe605..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/constants$0.java +++ /dev/null @@ -1,27 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.epoll; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withByteAlignment(1).withName("events"), - MemoryLayout.unionLayout( - RuntimeHelper.POINTER.withByteAlignment(1).withName("ptr"), - JAVA_INT.withByteAlignment(1).withName("fd"), - JAVA_INT.withByteAlignment(1).withName("u32"), - JAVA_LONG.withByteAlignment(1).withName("u64") - ).withName("data") - ).withName("epoll_event"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("events")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll.java index ee58d00..99a0078 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll.java @@ -2,59 +2,116 @@ package net.codecrete.usb.linux.gen.epoll; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class epoll { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class epoll { + + epoll() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int EPOLL_CTL_ADD = (int)1L; /** - * {@snippet : + * {@snippet lang=c : * #define EPOLL_CTL_ADD 1 * } */ public static int EPOLL_CTL_ADD() { - return (int)1L; + return EPOLL_CTL_ADD; } + private static final int EPOLL_CTL_DEL = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define EPOLL_CTL_DEL 2 * } */ public static int EPOLL_CTL_DEL() { - return (int)2L; + return EPOLL_CTL_DEL; } + private static final int EPOLLIN = (int)1L; /** - * {@snippet : - * enum EPOLL_EVENTS.EPOLLIN = 1; + * {@snippet lang=c : + * enum EPOLL_EVENTS.EPOLLIN = 1 * } */ public static int EPOLLIN() { - return (int)1L; + return EPOLLIN; } + private static final int EPOLLOUT = (int)4L; /** - * {@snippet : - * enum EPOLL_EVENTS.EPOLLOUT = 4; + * {@snippet lang=c : + * enum EPOLL_EVENTS.EPOLLOUT = 4 * } */ public static int EPOLLOUT() { - return (int)4L; + return EPOLLOUT; } + private static final int EPOLLWAKEUP = (int)536870912L; /** - * {@snippet : - * enum EPOLL_EVENTS.EPOLLWAKEUP = 536870912; + * {@snippet lang=c : + * enum EPOLL_EVENTS.EPOLLWAKEUP = 536870912 * } */ public static int EPOLLWAKEUP() { - return (int)536870912L; + return EPOLLWAKEUP; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll_event.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll_event.java deleted file mode 100644 index e59d353..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/epoll/epoll_event.java +++ /dev/null @@ -1,61 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.epoll; - -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; -/** - * {@snippet : - * struct epoll_event { - * uint32_t events; - * epoll_data_t data; - * }; - * } - */ -public class epoll_event { - - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; - } - public static VarHandle events$VH() { - return constants$0.const$1; - } - /** - * Getter for field: - * {@snippet : - * uint32_t events; - * } - */ - public static int events$get(MemorySegment seg) { - return (int)constants$0.const$1.get(seg); - } - /** - * Setter for field: - * {@snippet : - * uint32_t events; - * } - */ - public static void events$set(MemorySegment seg, int x) { - constants$0.const$1.set(seg, x); - } - public static int events$get(MemorySegment seg, long index) { - return (int)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void events$set(MemorySegment seg, long index, int x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static MemorySegment data$slice(MemorySegment seg) { - return seg.asSlice(4, 8); - } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); - } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java deleted file mode 100644 index f46e44c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.errno; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java deleted file mode 100644 index d06cfe7..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java +++ /dev/null @@ -1,11 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.errno; - -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java index b9a9566..3d970a3 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java @@ -2,67 +2,125 @@ package net.codecrete.usb.linux.gen.errno; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class errno { +import static java.lang.foreign.MemoryLayout.PathElement.*; - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +public class errno { + + errno() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int ENOENT = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define ENOENT 2 * } */ public static int ENOENT() { - return (int)2L; + return ENOENT; } + private static final int EINTR = (int)4L; /** - * {@snippet : + * {@snippet lang=c : * #define EINTR 4 * } */ public static int EINTR() { - return (int)4L; + return EINTR; } + private static final int EAGAIN = (int)11L; /** - * {@snippet : + * {@snippet lang=c : * #define EAGAIN 11 * } */ public static int EAGAIN() { - return (int)11L; + return EAGAIN; } + private static final int ENODEV = (int)19L; /** - * {@snippet : + * {@snippet lang=c : * #define ENODEV 19 * } */ public static int ENODEV() { - return (int)19L; + return ENODEV; } + private static final int EINVAL = (int)22L; /** - * {@snippet : + * {@snippet lang=c : * #define EINVAL 22 * } */ public static int EINVAL() { - return (int)22L; + return EINVAL; } + private static final int EPIPE = (int)32L; /** - * {@snippet : + * {@snippet lang=c : * #define EPIPE 32 * } */ public static int EPIPE() { - return (int)32L; + return EPIPE; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java deleted file mode 100644 index 6b36ff8..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.fcntl; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java deleted file mode 100644 index 384b145..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java +++ /dev/null @@ -1,11 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.fcntl; - -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java index d3f2f2e..1fb5286 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java @@ -2,43 +2,98 @@ package net.codecrete.usb.linux.gen.fcntl; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class fcntl { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class fcntl { + + fcntl() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int O_RDWR = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define O_RDWR 2 * } */ public static int O_RDWR() { - return (int)2L; + return O_RDWR; } + private static final int FD_CLOEXEC = (int)1L; /** - * {@snippet : + * {@snippet lang=c : * #define FD_CLOEXEC 1 * } */ public static int FD_CLOEXEC() { - return (int)1L; + return FD_CLOEXEC; } + private static final int O_CLOEXEC = (int)524288L; /** - * {@snippet : + * {@snippet lang=c : * #define O_CLOEXEC 524288 * } */ public static int O_CLOEXEC() { - return (int)524288L; + return O_CLOEXEC; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/RuntimeHelper.java deleted file mode 100644 index e0a365d..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.string; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/constants$0.java deleted file mode 100644 index bfe9c83..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/constants$0.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.string; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "strerror", - constants$0.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/string.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/string.java index 895d225..f5cfc2d 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/string.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/string/string.java @@ -2,37 +2,118 @@ package net.codecrete.usb.linux.gen.string; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class string { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle strerror$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"strerror"); +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class string { + + string() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + + private static class strerror { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + string.C_POINTER, + string.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + string.findOrThrow("strerror"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern char *strerror(int __errnum) + * } + */ + public static FunctionDescriptor strerror$descriptor() { + return strerror.DESC; + } + /** - * {@snippet : - * char* strerror(int __errnum); + * Downcall method handle for: + * {@snippet lang=c : + * extern char *strerror(int __errnum) + * } + */ + public static MethodHandle strerror$handle() { + return strerror.HANDLE; + } + /** + * {@snippet lang=c : + * extern char *strerror(int __errnum) * } */ public static MemorySegment strerror(int __errnum) { - var mh$ = strerror$MH(); + var mh$ = strerror.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(__errnum); + if (TRACE_DOWNCALLS) { + traceDowncall("strerror", __errnum); + } + return (MemorySegment)mh$.invokeExact(__errnum); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java deleted file mode 100644 index c2ccf24..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java +++ /dev/null @@ -1,228 +0,0 @@ -package net.codecrete.usb.linux.gen.udev; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { -// System.loadLibrary("udev"); -// SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SymbolLookup loaderLookup = SymbolLookup.libraryLookup("libudev.so.1", Arena.global()); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java deleted file mode 100644 index 1017f6f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java +++ /dev/null @@ -1,33 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.udev; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "udev_new", - constants$0.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "udev_list_entry_get_next", - constants$0.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "udev_list_entry_get_name", - constants$0.const$2 - ); - static final MethodHandle const$5 = RuntimeHelper.downcallHandle( - "udev_device_unref", - constants$0.const$2 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java deleted file mode 100644 index 9d31802..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java +++ /dev/null @@ -1,37 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.udev; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "udev_device_new_from_syspath", - constants$1.const$0 - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "udev_device_get_devtype", - constants$0.const$2 - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "udev_device_get_devnode", - constants$0.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "udev_device_get_action", - constants$0.const$2 - ); - static final MethodHandle const$5 = RuntimeHelper.downcallHandle( - "udev_device_get_sysattr_value", - constants$1.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java deleted file mode 100644 index 88ac398..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.udev; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - "udev_monitor_new_from_netlink", - constants$1.const$0 - ); - static final FunctionDescriptor const$1 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "udev_monitor_enable_receiving", - constants$2.const$1 - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "udev_monitor_get_fd", - constants$2.const$1 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "udev_monitor_receive_device", - constants$0.const$2 - ); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "udev_monitor_filter_add_match_subsystem_devtype", - constants$2.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java deleted file mode 100644 index b469b77..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java +++ /dev/null @@ -1,39 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.udev; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$3 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$3() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - "udev_enumerate_unref", - constants$0.const$2 - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "udev_enumerate_new", - constants$0.const$2 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "udev_enumerate_add_match_subsystem", - constants$3.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "udev_enumerate_scan_devices", - constants$2.const$1 - ); - static final MethodHandle const$5 = RuntimeHelper.downcallHandle( - "udev_enumerate_get_list_entry", - constants$0.const$2 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java index bcc40cb..be48336 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java @@ -2,325 +2,969 @@ package net.codecrete.usb.linux.gen.udev; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class udev { +import static java.lang.foreign.MemoryLayout.PathElement.*; - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle udev_new$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"udev_new"); +public class udev { + + udev() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup("libudev.so.1", LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + + private static class udev_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_new"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev *udev_new(void) + * } + */ + public static FunctionDescriptor udev_new$descriptor() { + return udev_new.DESC; + } + /** - * {@snippet : - * struct udev* udev_new(); + * Downcall method handle for: + * {@snippet lang=c : + * struct udev *udev_new(void) + * } + */ + public static MethodHandle udev_new$handle() { + return udev_new.HANDLE; + } + /** + * {@snippet lang=c : + * struct udev *udev_new(void) * } */ public static MemorySegment udev_new() { - var mh$ = udev_new$MH(); + var mh$ = udev_new.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_new"); + } + return (MemorySegment)mh$.invokeExact(); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_list_entry_get_next$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$3,"udev_list_entry_get_next"); + + private static class udev_list_entry_get_next { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_list_entry_get_next"), + DESC); } + /** - * {@snippet : - * struct udev_list_entry* udev_list_entry_get_next(struct udev_list_entry* list_entry); + * Function descriptor for: + * {@snippet lang=c : + * struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) + * } + */ + public static FunctionDescriptor udev_list_entry_get_next$descriptor() { + return udev_list_entry_get_next.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) + * } + */ + public static MethodHandle udev_list_entry_get_next$handle() { + return udev_list_entry_get_next.HANDLE; + } + /** + * {@snippet lang=c : + * struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) * } */ public static MemorySegment udev_list_entry_get_next(MemorySegment list_entry) { - var mh$ = udev_list_entry_get_next$MH(); + var mh$ = udev_list_entry_get_next.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(list_entry); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_list_entry_get_next", list_entry); + } + return (MemorySegment)mh$.invokeExact(list_entry); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_list_entry_get_name$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$4,"udev_list_entry_get_name"); + + private static class udev_list_entry_get_name { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_list_entry_get_name"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) + * } + */ + public static FunctionDescriptor udev_list_entry_get_name$descriptor() { + return udev_list_entry_get_name.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) + * } + */ + public static MethodHandle udev_list_entry_get_name$handle() { + return udev_list_entry_get_name.HANDLE; } /** - * {@snippet : - * char* udev_list_entry_get_name(struct udev_list_entry* list_entry); + * {@snippet lang=c : + * const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) * } */ public static MemorySegment udev_list_entry_get_name(MemorySegment list_entry) { - var mh$ = udev_list_entry_get_name$MH(); + var mh$ = udev_list_entry_get_name.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(list_entry); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_list_entry_get_name", list_entry); + } + return (MemorySegment)mh$.invokeExact(list_entry); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_unref$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$5,"udev_device_unref"); + + private static class udev_device_unref { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_unref"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev_device *udev_device_unref(struct udev_device *udev_device) + * } + */ + public static FunctionDescriptor udev_device_unref$descriptor() { + return udev_device_unref.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_device *udev_device_unref(struct udev_device *udev_device) + * } + */ + public static MethodHandle udev_device_unref$handle() { + return udev_device_unref.HANDLE; } /** - * {@snippet : - * struct udev_device* udev_device_unref(struct udev_device* udev_device); + * {@snippet lang=c : + * struct udev_device *udev_device_unref(struct udev_device *udev_device) * } */ public static MemorySegment udev_device_unref(MemorySegment udev_device) { - var mh$ = udev_device_unref$MH(); + var mh$ = udev_device_unref.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_device); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_unref", udev_device); + } + return (MemorySegment)mh$.invokeExact(udev_device); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_new_from_syspath$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$1,"udev_device_new_from_syspath"); + + private static class udev_device_new_from_syspath { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_new_from_syspath"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) + * } + */ + public static FunctionDescriptor udev_device_new_from_syspath$descriptor() { + return udev_device_new_from_syspath.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) + * } + */ + public static MethodHandle udev_device_new_from_syspath$handle() { + return udev_device_new_from_syspath.HANDLE; } /** - * {@snippet : - * struct udev_device* udev_device_new_from_syspath(struct udev* udev, char* syspath); + * {@snippet lang=c : + * struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) * } */ public static MemorySegment udev_device_new_from_syspath(MemorySegment udev, MemorySegment syspath) { - var mh$ = udev_device_new_from_syspath$MH(); + var mh$ = udev_device_new_from_syspath.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev, syspath); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_new_from_syspath", udev, syspath); + } + return (MemorySegment)mh$.invokeExact(udev, syspath); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_get_devtype$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$2,"udev_device_get_devtype"); + + private static class udev_device_get_devtype { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_get_devtype"), + DESC); } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const char *udev_device_get_devtype(struct udev_device *udev_device) + * } + */ + public static FunctionDescriptor udev_device_get_devtype$descriptor() { + return udev_device_get_devtype.DESC; + } + /** - * {@snippet : - * char* udev_device_get_devtype(struct udev_device* udev_device); + * Downcall method handle for: + * {@snippet lang=c : + * const char *udev_device_get_devtype(struct udev_device *udev_device) + * } + */ + public static MethodHandle udev_device_get_devtype$handle() { + return udev_device_get_devtype.HANDLE; + } + /** + * {@snippet lang=c : + * const char *udev_device_get_devtype(struct udev_device *udev_device) * } */ public static MemorySegment udev_device_get_devtype(MemorySegment udev_device) { - var mh$ = udev_device_get_devtype$MH(); + var mh$ = udev_device_get_devtype.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_device); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_get_devtype", udev_device); + } + return (MemorySegment)mh$.invokeExact(udev_device); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_get_devnode$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$3,"udev_device_get_devnode"); + + private static class udev_device_get_devnode { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_get_devnode"), + DESC); } + /** - * {@snippet : - * char* udev_device_get_devnode(struct udev_device* udev_device); + * Function descriptor for: + * {@snippet lang=c : + * const char *udev_device_get_devnode(struct udev_device *udev_device) + * } + */ + public static FunctionDescriptor udev_device_get_devnode$descriptor() { + return udev_device_get_devnode.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const char *udev_device_get_devnode(struct udev_device *udev_device) + * } + */ + public static MethodHandle udev_device_get_devnode$handle() { + return udev_device_get_devnode.HANDLE; + } + /** + * {@snippet lang=c : + * const char *udev_device_get_devnode(struct udev_device *udev_device) * } */ public static MemorySegment udev_device_get_devnode(MemorySegment udev_device) { - var mh$ = udev_device_get_devnode$MH(); + var mh$ = udev_device_get_devnode.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_device); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_get_devnode", udev_device); + } + return (MemorySegment)mh$.invokeExact(udev_device); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_get_action$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$4,"udev_device_get_action"); + + private static class udev_device_get_action { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_get_action"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const char *udev_device_get_action(struct udev_device *udev_device) + * } + */ + public static FunctionDescriptor udev_device_get_action$descriptor() { + return udev_device_get_action.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const char *udev_device_get_action(struct udev_device *udev_device) + * } + */ + public static MethodHandle udev_device_get_action$handle() { + return udev_device_get_action.HANDLE; } /** - * {@snippet : - * char* udev_device_get_action(struct udev_device* udev_device); + * {@snippet lang=c : + * const char *udev_device_get_action(struct udev_device *udev_device) * } */ public static MemorySegment udev_device_get_action(MemorySegment udev_device) { - var mh$ = udev_device_get_action$MH(); + var mh$ = udev_device_get_action.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_device); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_get_action", udev_device); + } + return (MemorySegment)mh$.invokeExact(udev_device); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_device_get_sysattr_value$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$5,"udev_device_get_sysattr_value"); + + private static class udev_device_get_sysattr_value { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_device_get_sysattr_value"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) + * } + */ + public static FunctionDescriptor udev_device_get_sysattr_value$descriptor() { + return udev_device_get_sysattr_value.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) + * } + */ + public static MethodHandle udev_device_get_sysattr_value$handle() { + return udev_device_get_sysattr_value.HANDLE; } /** - * {@snippet : - * char* udev_device_get_sysattr_value(struct udev_device* udev_device, char* sysattr); + * {@snippet lang=c : + * const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) * } */ public static MemorySegment udev_device_get_sysattr_value(MemorySegment udev_device, MemorySegment sysattr) { - var mh$ = udev_device_get_sysattr_value$MH(); + var mh$ = udev_device_get_sysattr_value.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_device, sysattr); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_device_get_sysattr_value", udev_device, sysattr); + } + return (MemorySegment)mh$.invokeExact(udev_device, sysattr); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_monitor_new_from_netlink$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$0,"udev_monitor_new_from_netlink"); + + private static class udev_monitor_new_from_netlink { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_monitor_new_from_netlink"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) + * } + */ + public static FunctionDescriptor udev_monitor_new_from_netlink$descriptor() { + return udev_monitor_new_from_netlink.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) + * } + */ + public static MethodHandle udev_monitor_new_from_netlink$handle() { + return udev_monitor_new_from_netlink.HANDLE; } /** - * {@snippet : - * struct udev_monitor* udev_monitor_new_from_netlink(struct udev* udev, char* name); + * {@snippet lang=c : + * struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) * } */ public static MemorySegment udev_monitor_new_from_netlink(MemorySegment udev, MemorySegment name) { - var mh$ = udev_monitor_new_from_netlink$MH(); + var mh$ = udev_monitor_new_from_netlink.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev, name); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_monitor_new_from_netlink", udev, name); + } + return (MemorySegment)mh$.invokeExact(udev, name); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_monitor_enable_receiving$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$2,"udev_monitor_enable_receiving"); + + private static class udev_monitor_enable_receiving { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_INT, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_monitor_enable_receiving"), + DESC); } + /** - * {@snippet : - * int udev_monitor_enable_receiving(struct udev_monitor* udev_monitor); + * Function descriptor for: + * {@snippet lang=c : + * int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) + * } + */ + public static FunctionDescriptor udev_monitor_enable_receiving$descriptor() { + return udev_monitor_enable_receiving.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) + * } + */ + public static MethodHandle udev_monitor_enable_receiving$handle() { + return udev_monitor_enable_receiving.HANDLE; + } + /** + * {@snippet lang=c : + * int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) * } */ public static int udev_monitor_enable_receiving(MemorySegment udev_monitor) { - var mh$ = udev_monitor_enable_receiving$MH(); + var mh$ = udev_monitor_enable_receiving.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("udev_monitor_enable_receiving", udev_monitor); + } return (int)mh$.invokeExact(udev_monitor); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_monitor_get_fd$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$3,"udev_monitor_get_fd"); + + private static class udev_monitor_get_fd { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_INT, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_monitor_get_fd"), + DESC); } + /** - * {@snippet : - * int udev_monitor_get_fd(struct udev_monitor* udev_monitor); + * Function descriptor for: + * {@snippet lang=c : + * int udev_monitor_get_fd(struct udev_monitor *udev_monitor) + * } + */ + public static FunctionDescriptor udev_monitor_get_fd$descriptor() { + return udev_monitor_get_fd.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int udev_monitor_get_fd(struct udev_monitor *udev_monitor) + * } + */ + public static MethodHandle udev_monitor_get_fd$handle() { + return udev_monitor_get_fd.HANDLE; + } + /** + * {@snippet lang=c : + * int udev_monitor_get_fd(struct udev_monitor *udev_monitor) * } */ public static int udev_monitor_get_fd(MemorySegment udev_monitor) { - var mh$ = udev_monitor_get_fd$MH(); + var mh$ = udev_monitor_get_fd.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("udev_monitor_get_fd", udev_monitor); + } return (int)mh$.invokeExact(udev_monitor); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_monitor_receive_device$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$4,"udev_monitor_receive_device"); + + private static class udev_monitor_receive_device { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_monitor_receive_device"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor) + * } + */ + public static FunctionDescriptor udev_monitor_receive_device$descriptor() { + return udev_monitor_receive_device.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor) + * } + */ + public static MethodHandle udev_monitor_receive_device$handle() { + return udev_monitor_receive_device.HANDLE; } /** - * {@snippet : - * struct udev_device* udev_monitor_receive_device(struct udev_monitor* udev_monitor); + * {@snippet lang=c : + * struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor) * } */ public static MemorySegment udev_monitor_receive_device(MemorySegment udev_monitor) { - var mh$ = udev_monitor_receive_device$MH(); + var mh$ = udev_monitor_receive_device.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_monitor); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_monitor_receive_device", udev_monitor); + } + return (MemorySegment)mh$.invokeExact(udev_monitor); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_monitor_filter_add_match_subsystem_devtype$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$6,"udev_monitor_filter_add_match_subsystem_devtype"); + + private static class udev_monitor_filter_add_match_subsystem_devtype { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_INT, + udev.C_POINTER, + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_monitor_filter_add_match_subsystem_devtype"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype) + * } + */ + public static FunctionDescriptor udev_monitor_filter_add_match_subsystem_devtype$descriptor() { + return udev_monitor_filter_add_match_subsystem_devtype.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype) + * } + */ + public static MethodHandle udev_monitor_filter_add_match_subsystem_devtype$handle() { + return udev_monitor_filter_add_match_subsystem_devtype.HANDLE; } /** - * {@snippet : - * int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor* udev_monitor, char* subsystem, char* devtype); + * {@snippet lang=c : + * int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype) * } */ public static int udev_monitor_filter_add_match_subsystem_devtype(MemorySegment udev_monitor, MemorySegment subsystem, MemorySegment devtype) { - var mh$ = udev_monitor_filter_add_match_subsystem_devtype$MH(); + var mh$ = udev_monitor_filter_add_match_subsystem_devtype.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("udev_monitor_filter_add_match_subsystem_devtype", udev_monitor, subsystem, devtype); + } return (int)mh$.invokeExact(udev_monitor, subsystem, devtype); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_enumerate_unref$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$0,"udev_enumerate_unref"); + + private static class udev_enumerate_unref { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_enumerate_unref"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) + * } + */ + public static FunctionDescriptor udev_enumerate_unref$descriptor() { + return udev_enumerate_unref.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) + * } + */ + public static MethodHandle udev_enumerate_unref$handle() { + return udev_enumerate_unref.HANDLE; } /** - * {@snippet : - * struct udev_enumerate* udev_enumerate_unref(struct udev_enumerate* udev_enumerate); + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) * } */ public static MemorySegment udev_enumerate_unref(MemorySegment udev_enumerate) { - var mh$ = udev_enumerate_unref$MH(); + var mh$ = udev_enumerate_unref.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_enumerate); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_enumerate_unref", udev_enumerate); + } + return (MemorySegment)mh$.invokeExact(udev_enumerate); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_enumerate_new$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$1,"udev_enumerate_new"); + + private static class udev_enumerate_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_enumerate_new"), + DESC); } + /** - * {@snippet : - * struct udev_enumerate* udev_enumerate_new(struct udev* udev); + * Function descriptor for: + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_new(struct udev *udev) + * } + */ + public static FunctionDescriptor udev_enumerate_new$descriptor() { + return udev_enumerate_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_new(struct udev *udev) + * } + */ + public static MethodHandle udev_enumerate_new$handle() { + return udev_enumerate_new.HANDLE; + } + /** + * {@snippet lang=c : + * struct udev_enumerate *udev_enumerate_new(struct udev *udev) * } */ public static MemorySegment udev_enumerate_new(MemorySegment udev) { - var mh$ = udev_enumerate_new$MH(); + var mh$ = udev_enumerate_new.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_enumerate_new", udev); + } + return (MemorySegment)mh$.invokeExact(udev); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_enumerate_add_match_subsystem$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$3,"udev_enumerate_add_match_subsystem"); + + private static class udev_enumerate_add_match_subsystem { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_INT, + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_enumerate_add_match_subsystem"), + DESC); } + /** - * {@snippet : - * int udev_enumerate_add_match_subsystem(struct udev_enumerate* udev_enumerate, char* subsystem); + * Function descriptor for: + * {@snippet lang=c : + * int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) + * } + */ + public static FunctionDescriptor udev_enumerate_add_match_subsystem$descriptor() { + return udev_enumerate_add_match_subsystem.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) + * } + */ + public static MethodHandle udev_enumerate_add_match_subsystem$handle() { + return udev_enumerate_add_match_subsystem.HANDLE; + } + /** + * {@snippet lang=c : + * int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) * } */ public static int udev_enumerate_add_match_subsystem(MemorySegment udev_enumerate, MemorySegment subsystem) { - var mh$ = udev_enumerate_add_match_subsystem$MH(); + var mh$ = udev_enumerate_add_match_subsystem.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("udev_enumerate_add_match_subsystem", udev_enumerate, subsystem); + } return (int)mh$.invokeExact(udev_enumerate, subsystem); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_enumerate_scan_devices$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$4,"udev_enumerate_scan_devices"); + + private static class udev_enumerate_scan_devices { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_INT, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_enumerate_scan_devices"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) + * } + */ + public static FunctionDescriptor udev_enumerate_scan_devices$descriptor() { + return udev_enumerate_scan_devices.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) + * } + */ + public static MethodHandle udev_enumerate_scan_devices$handle() { + return udev_enumerate_scan_devices.HANDLE; } /** - * {@snippet : - * int udev_enumerate_scan_devices(struct udev_enumerate* udev_enumerate); + * {@snippet lang=c : + * int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) * } */ public static int udev_enumerate_scan_devices(MemorySegment udev_enumerate) { - var mh$ = udev_enumerate_scan_devices$MH(); + var mh$ = udev_enumerate_scan_devices.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("udev_enumerate_scan_devices", udev_enumerate); + } return (int)mh$.invokeExact(udev_enumerate); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle udev_enumerate_get_list_entry$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$5,"udev_enumerate_get_list_entry"); + + private static class udev_enumerate_get_list_entry { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + udev.C_POINTER, + udev.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + udev.findOrThrow("udev_enumerate_get_list_entry"), + DESC); } + /** - * {@snippet : - * struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* udev_enumerate); + * Function descriptor for: + * {@snippet lang=c : + * struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) + * } + */ + public static FunctionDescriptor udev_enumerate_get_list_entry$descriptor() { + return udev_enumerate_get_list_entry.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) + * } + */ + public static MethodHandle udev_enumerate_get_list_entry$handle() { + return udev_enumerate_get_list_entry.HANDLE; + } + /** + * {@snippet lang=c : + * struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) * } */ public static MemorySegment udev_enumerate_get_list_entry(MemorySegment udev_enumerate) { - var mh$ = udev_enumerate_get_list_entry$MH(); + var mh$ = udev_enumerate_get_list_entry.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(udev_enumerate); + if (TRACE_DOWNCALLS) { + traceDowncall("udev_enumerate_get_list_entry", udev_enumerate); + } + return (MemorySegment)mh$.invokeExact(udev_enumerate); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java deleted file mode 100644 index f3cff46..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.unistd; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java deleted file mode 100644 index 90d07fa..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.unistd; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - JAVA_INT - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "close", - constants$0.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java index 581e508..b0b3a13 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java @@ -2,36 +2,118 @@ package net.codecrete.usb.linux.gen.unistd; -import java.lang.foreign.AddressLayout; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class unistd { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle close$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"close"); +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class unistd { + + unistd() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + + private static class close { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + unistd.C_INT, + unistd.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + unistd.findOrThrow("close"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern int close(int __fd) + * } + */ + public static FunctionDescriptor close$descriptor() { + return close.DESC; + } + /** - * {@snippet : - * int close(int __fd); + * Downcall method handle for: + * {@snippet lang=c : + * extern int close(int __fd) + * } + */ + public static MethodHandle close$handle() { + return close.HANDLE; + } + /** + * {@snippet lang=c : + * extern int close(int __fd) * } */ public static int close(int __fd) { - var mh$ = close$MH(); + var mh$ = close.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("close", __fd); + } return (int)mh$.invokeExact(__fd); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java deleted file mode 100644 index 5e6d3cd..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.linux.gen.usbdevice_fs; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java deleted file mode 100644 index 24688f1..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java +++ /dev/null @@ -1,31 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_BYTE.withName("bRequestType"), - JAVA_BYTE.withName("bRequest"), - JAVA_SHORT.withName("wValue"), - JAVA_SHORT.withName("wIndex"), - JAVA_SHORT.withName("wLength"), - JAVA_INT.withName("timeout"), - MemoryLayout.paddingLayout(4), - RuntimeHelper.POINTER.withName("data") - ).withName("usbdevfs_ctrltransfer"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("bRequestType")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("bRequest")); - static final VarHandle const$3 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wValue")); - static final VarHandle const$4 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wIndex")); - static final VarHandle const$5 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wLength")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$1.java deleted file mode 100644 index 9666d21..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$1.java +++ /dev/null @@ -1,28 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final VarHandle const$0 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("timeout")); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("data")); - static final StructLayout const$2 = MemoryLayout.structLayout( - JAVA_INT.withName("ep"), - JAVA_INT.withName("len"), - JAVA_INT.withName("timeout"), - MemoryLayout.paddingLayout(4), - RuntimeHelper.POINTER.withName("data") - ).withName("usbdevfs_bulktransfer"); - static final VarHandle const$3 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("ep")); - static final VarHandle const$4 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("len")); - static final VarHandle const$5 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("timeout")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$2.java deleted file mode 100644 index 384a062..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$2.java +++ /dev/null @@ -1,49 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final VarHandle const$0 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("data")); - static final StructLayout const$1 = MemoryLayout.structLayout( - JAVA_INT.withName("interface"), - JAVA_INT.withName("altsetting") - ).withName("usbdevfs_setinterface"); - static final VarHandle const$2 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("interface")); - static final VarHandle const$3 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("altsetting")); - static final StructLayout const$4 = MemoryLayout.structLayout( - JAVA_BYTE.withName("type"), - JAVA_BYTE.withName("endpoint"), - MemoryLayout.paddingLayout(2), - JAVA_INT.withName("status"), - JAVA_INT.withName("flags"), - MemoryLayout.paddingLayout(4), - RuntimeHelper.POINTER.withName("buffer"), - JAVA_INT.withName("buffer_length"), - JAVA_INT.withName("actual_length"), - JAVA_INT.withName("start_frame"), - MemoryLayout.unionLayout( - JAVA_INT.withName("number_of_packets"), - JAVA_INT.withName("stream_id") - ).withName("$anon$0"), - JAVA_INT.withName("error_count"), - JAVA_INT.withName("signr"), - RuntimeHelper.POINTER.withName("usercontext"), - MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout( - JAVA_INT.withName("length"), - JAVA_INT.withName("actual_length"), - JAVA_INT.withName("status") - ).withName("usbdevfs_iso_packet_desc")).withName("iso_frame_desc") - ).withName("usbdevfs_urb"); - static final VarHandle const$5 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("type")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$3.java deleted file mode 100644 index 2f58300..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$3.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$3 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$3() {} - static final VarHandle const$0 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("endpoint")); - static final VarHandle const$1 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("status")); - static final VarHandle const$2 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("flags")); - static final VarHandle const$3 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("buffer")); - static final VarHandle const$4 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("buffer_length")); - static final VarHandle const$5 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("actual_length")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$4.java deleted file mode 100644 index dd410c6..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$4.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$4 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$4() {} - static final VarHandle const$0 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("start_frame")); - static final VarHandle const$1 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("number_of_packets")); - static final VarHandle const$2 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("stream_id")); - static final VarHandle const$3 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("error_count")); - static final VarHandle const$4 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("signr")); - static final VarHandle const$5 = constants$2.const$4.varHandle(MemoryLayout.PathElement.groupElement("usercontext")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$5.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$5.java deleted file mode 100644 index fedeaec..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$5.java +++ /dev/null @@ -1,31 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$5 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$5() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withName("ifno"), - JAVA_INT.withName("ioctl_code"), - RuntimeHelper.POINTER.withName("data") - ).withName("usbdevfs_ioctl"); - static final VarHandle const$1 = constants$5.const$0.varHandle(MemoryLayout.PathElement.groupElement("ifno")); - static final VarHandle const$2 = constants$5.const$0.varHandle(MemoryLayout.PathElement.groupElement("ioctl_code")); - static final VarHandle const$3 = constants$5.const$0.varHandle(MemoryLayout.PathElement.groupElement("data")); - static final StructLayout const$4 = MemoryLayout.structLayout( - JAVA_INT.withName("interface"), - JAVA_INT.withName("flags"), - MemoryLayout.sequenceLayout(256, JAVA_BYTE).withName("driver") - ).withName("usbdevfs_disconnect_claim"); - static final VarHandle const$5 = constants$5.const$4.varHandle(MemoryLayout.PathElement.groupElement("interface")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$6.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$6.java deleted file mode 100644 index 787c95d..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$6.java +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.linux.gen.usbdevice_fs; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$6 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$6() {} - static final VarHandle const$0 = constants$5.const$4.varHandle(MemoryLayout.PathElement.groupElement("flags")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java index 07aa5f5..f241c02 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java @@ -2,140 +2,265 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_bulktransfer { * unsigned int ep; * unsigned int len; * unsigned int timeout; - * void* data; - * }; + * void *data; + * } * } */ public class usbdevfs_bulktransfer { - public static MemoryLayout $LAYOUT() { - return constants$1.const$2; + usbdevfs_bulktransfer() { + // Should not be called directly } - public static VarHandle ep$VH() { - return constants$1.const$3; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_INT.withName("ep"), + usbdevice_fs.C_INT.withName("len"), + usbdevice_fs.C_INT.withName("timeout"), + MemoryLayout.paddingLayout(4), + usbdevice_fs.C_POINTER.withName("data") + ).withName("usbdevfs_bulktransfer"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt ep$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ep")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int ep + * } + */ + public static final OfInt ep$layout() { + return ep$LAYOUT; + } + + private static final long ep$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int ep + * } + */ + public static final long ep$offset() { + return ep$OFFSET; + } + /** * Getter for field: - * {@snippet : - * unsigned int ep; + * {@snippet lang=c : + * unsigned int ep * } */ - public static int ep$get(MemorySegment seg) { - return (int)constants$1.const$3.get(seg); + public static int ep(MemorySegment struct) { + return struct.get(ep$LAYOUT, ep$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int ep; + * {@snippet lang=c : + * unsigned int ep * } */ - public static void ep$set(MemorySegment seg, int x) { - constants$1.const$3.set(seg, x); + public static void ep(MemorySegment struct, int fieldValue) { + struct.set(ep$LAYOUT, ep$OFFSET, fieldValue); } - public static int ep$get(MemorySegment seg, long index) { - return (int)constants$1.const$3.get(seg.asSlice(index*sizeof())); - } - public static void ep$set(MemorySegment seg, long index, int x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt len$LAYOUT = (OfInt)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int len + * } + */ + public static final OfInt len$layout() { + return len$LAYOUT; } - public static VarHandle len$VH() { - return constants$1.const$4; + + private static final long len$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int len + * } + */ + public static final long len$offset() { + return len$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int len; + * {@snippet lang=c : + * unsigned int len * } */ - public static int len$get(MemorySegment seg) { - return (int)constants$1.const$4.get(seg); + public static int len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int len; + * {@snippet lang=c : + * unsigned int len * } */ - public static void len$set(MemorySegment seg, int x) { - constants$1.const$4.set(seg, x); + public static void len(MemorySegment struct, int fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); } - public static int len$get(MemorySegment seg, long index) { - return (int)constants$1.const$4.get(seg.asSlice(index*sizeof())); - } - public static void len$set(MemorySegment seg, long index, int x) { - constants$1.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt timeout$LAYOUT = (OfInt)$LAYOUT.select(groupElement("timeout")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int timeout + * } + */ + public static final OfInt timeout$layout() { + return timeout$LAYOUT; } - public static VarHandle timeout$VH() { - return constants$1.const$5; + + private static final long timeout$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int timeout + * } + */ + public static final long timeout$offset() { + return timeout$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int timeout; + * {@snippet lang=c : + * unsigned int timeout * } */ - public static int timeout$get(MemorySegment seg) { - return (int)constants$1.const$5.get(seg); + public static int timeout(MemorySegment struct) { + return struct.get(timeout$LAYOUT, timeout$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int timeout; + * {@snippet lang=c : + * unsigned int timeout * } */ - public static void timeout$set(MemorySegment seg, int x) { - constants$1.const$5.set(seg, x); - } - public static int timeout$get(MemorySegment seg, long index) { - return (int)constants$1.const$5.get(seg.asSlice(index*sizeof())); + public static void timeout(MemorySegment struct, int fieldValue) { + struct.set(timeout$LAYOUT, timeout$OFFSET, fieldValue); } - public static void timeout$set(MemorySegment seg, long index, int x) { - constants$1.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; } - public static VarHandle data$VH() { - return constants$2.const$0; + + private static final long data$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final long data$offset() { + return data$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static MemorySegment data$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$2.const$0.get(seg); + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); } + /** * Setter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static void data$set(MemorySegment seg, MemorySegment x) { - constants$2.const$0.set(seg, x); + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static MemorySegment data$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$2.const$0.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void data$set(MemorySegment seg, long index, MemorySegment x) { - constants$2.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java index c32eba2..e857dd1 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java @@ -2,13 +2,18 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_ctrltransfer { * __u8 bRequestType; * __u8 bRequest; @@ -16,210 +21,384 @@ * __u16 wIndex; * __u16 wLength; * __u32 timeout; - * void* data; - * }; + * void *data; + * } * } */ public class usbdevfs_ctrltransfer { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + usbdevfs_ctrltransfer() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_CHAR.withName("bRequestType"), + usbdevice_fs.C_CHAR.withName("bRequest"), + usbdevice_fs.C_SHORT.withName("wValue"), + usbdevice_fs.C_SHORT.withName("wIndex"), + usbdevice_fs.C_SHORT.withName("wLength"), + usbdevice_fs.C_INT.withName("timeout"), + MemoryLayout.paddingLayout(4), + usbdevice_fs.C_POINTER.withName("data") + ).withName("usbdevfs_ctrltransfer"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } - public static VarHandle bRequestType$VH() { - return constants$0.const$1; + + private static final OfByte bRequestType$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bRequestType")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u8 bRequestType + * } + */ + public static final OfByte bRequestType$layout() { + return bRequestType$LAYOUT; + } + + private static final long bRequestType$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * __u8 bRequestType + * } + */ + public static final long bRequestType$offset() { + return bRequestType$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u8 bRequestType; + * {@snippet lang=c : + * __u8 bRequestType * } */ - public static byte bRequestType$get(MemorySegment seg) { - return (byte)constants$0.const$1.get(seg); + public static byte bRequestType(MemorySegment struct) { + return struct.get(bRequestType$LAYOUT, bRequestType$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u8 bRequestType; + * {@snippet lang=c : + * __u8 bRequestType * } */ - public static void bRequestType$set(MemorySegment seg, byte x) { - constants$0.const$1.set(seg, x); + public static void bRequestType(MemorySegment struct, byte fieldValue) { + struct.set(bRequestType$LAYOUT, bRequestType$OFFSET, fieldValue); } - public static byte bRequestType$get(MemorySegment seg, long index) { - return (byte)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void bRequestType$set(MemorySegment seg, long index, byte x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte bRequest$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u8 bRequest + * } + */ + public static final OfByte bRequest$layout() { + return bRequest$LAYOUT; } - public static VarHandle bRequest$VH() { - return constants$0.const$2; + + private static final long bRequest$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * __u8 bRequest + * } + */ + public static final long bRequest$offset() { + return bRequest$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u8 bRequest; + * {@snippet lang=c : + * __u8 bRequest * } */ - public static byte bRequest$get(MemorySegment seg) { - return (byte)constants$0.const$2.get(seg); + public static byte bRequest(MemorySegment struct) { + return struct.get(bRequest$LAYOUT, bRequest$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u8 bRequest; + * {@snippet lang=c : + * __u8 bRequest * } */ - public static void bRequest$set(MemorySegment seg, byte x) { - constants$0.const$2.set(seg, x); + public static void bRequest(MemorySegment struct, byte fieldValue) { + struct.set(bRequest$LAYOUT, bRequest$OFFSET, fieldValue); } - public static byte bRequest$get(MemorySegment seg, long index) { - return (byte)constants$0.const$2.get(seg.asSlice(index*sizeof())); - } - public static void bRequest$set(MemorySegment seg, long index, byte x) { - constants$0.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wValue$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wValue")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u16 wValue + * } + */ + public static final OfShort wValue$layout() { + return wValue$LAYOUT; } - public static VarHandle wValue$VH() { - return constants$0.const$3; + + private static final long wValue$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * __u16 wValue + * } + */ + public static final long wValue$offset() { + return wValue$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u16 wValue; + * {@snippet lang=c : + * __u16 wValue * } */ - public static short wValue$get(MemorySegment seg) { - return (short)constants$0.const$3.get(seg); + public static short wValue(MemorySegment struct) { + return struct.get(wValue$LAYOUT, wValue$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u16 wValue; + * {@snippet lang=c : + * __u16 wValue * } */ - public static void wValue$set(MemorySegment seg, short x) { - constants$0.const$3.set(seg, x); + public static void wValue(MemorySegment struct, short fieldValue) { + struct.set(wValue$LAYOUT, wValue$OFFSET, fieldValue); } - public static short wValue$get(MemorySegment seg, long index) { - return (short)constants$0.const$3.get(seg.asSlice(index*sizeof())); - } - public static void wValue$set(MemorySegment seg, long index, short x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wIndex$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wIndex")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u16 wIndex + * } + */ + public static final OfShort wIndex$layout() { + return wIndex$LAYOUT; } - public static VarHandle wIndex$VH() { - return constants$0.const$4; + + private static final long wIndex$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * __u16 wIndex + * } + */ + public static final long wIndex$offset() { + return wIndex$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u16 wIndex; + * {@snippet lang=c : + * __u16 wIndex * } */ - public static short wIndex$get(MemorySegment seg) { - return (short)constants$0.const$4.get(seg); + public static short wIndex(MemorySegment struct) { + return struct.get(wIndex$LAYOUT, wIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u16 wIndex; + * {@snippet lang=c : + * __u16 wIndex * } */ - public static void wIndex$set(MemorySegment seg, short x) { - constants$0.const$4.set(seg, x); + public static void wIndex(MemorySegment struct, short fieldValue) { + struct.set(wIndex$LAYOUT, wIndex$OFFSET, fieldValue); } - public static short wIndex$get(MemorySegment seg, long index) { - return (short)constants$0.const$4.get(seg.asSlice(index*sizeof())); - } - public static void wIndex$set(MemorySegment seg, long index, short x) { - constants$0.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wLength$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wLength")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u16 wLength + * } + */ + public static final OfShort wLength$layout() { + return wLength$LAYOUT; } - public static VarHandle wLength$VH() { - return constants$0.const$5; + + private static final long wLength$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * __u16 wLength + * } + */ + public static final long wLength$offset() { + return wLength$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u16 wLength; + * {@snippet lang=c : + * __u16 wLength * } */ - public static short wLength$get(MemorySegment seg) { - return (short)constants$0.const$5.get(seg); + public static short wLength(MemorySegment struct) { + return struct.get(wLength$LAYOUT, wLength$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u16 wLength; + * {@snippet lang=c : + * __u16 wLength * } */ - public static void wLength$set(MemorySegment seg, short x) { - constants$0.const$5.set(seg, x); - } - public static short wLength$get(MemorySegment seg, long index) { - return (short)constants$0.const$5.get(seg.asSlice(index*sizeof())); + public static void wLength(MemorySegment struct, short fieldValue) { + struct.set(wLength$LAYOUT, wLength$OFFSET, fieldValue); } - public static void wLength$set(MemorySegment seg, long index, short x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt timeout$LAYOUT = (OfInt)$LAYOUT.select(groupElement("timeout")); + + /** + * Layout for field: + * {@snippet lang=c : + * __u32 timeout + * } + */ + public static final OfInt timeout$layout() { + return timeout$LAYOUT; } - public static VarHandle timeout$VH() { - return constants$1.const$0; + + private static final long timeout$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * __u32 timeout + * } + */ + public static final long timeout$offset() { + return timeout$OFFSET; } + /** * Getter for field: - * {@snippet : - * __u32 timeout; + * {@snippet lang=c : + * __u32 timeout * } */ - public static int timeout$get(MemorySegment seg) { - return (int)constants$1.const$0.get(seg); + public static int timeout(MemorySegment struct) { + return struct.get(timeout$LAYOUT, timeout$OFFSET); } + /** * Setter for field: - * {@snippet : - * __u32 timeout; + * {@snippet lang=c : + * __u32 timeout * } */ - public static void timeout$set(MemorySegment seg, int x) { - constants$1.const$0.set(seg, x); - } - public static int timeout$get(MemorySegment seg, long index) { - return (int)constants$1.const$0.get(seg.asSlice(index*sizeof())); + public static void timeout(MemorySegment struct, int fieldValue) { + struct.set(timeout$LAYOUT, timeout$OFFSET, fieldValue); } - public static void timeout$set(MemorySegment seg, long index, int x) { - constants$1.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; } - public static VarHandle data$VH() { - return constants$1.const$1; + + private static final long data$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final long data$offset() { + return data$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static MemorySegment data$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$1.get(seg); + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); } + /** * Setter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static void data$set(MemorySegment seg, MemorySegment x) { - constants$1.const$1.set(seg, x); + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static MemorySegment data$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$1.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void data$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java index e238d86..5fbea29 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java @@ -2,88 +2,251 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_disconnect_claim { * unsigned int interface; * unsigned int flags; * char driver[256]; - * }; + * } * } */ public class usbdevfs_disconnect_claim { - public static MemoryLayout $LAYOUT() { - return constants$5.const$4; + usbdevfs_disconnect_claim() { + // Should not be called directly } - public static VarHandle interface_$VH() { - return constants$5.const$5; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_INT.withName("interface"), + usbdevice_fs.C_INT.withName("flags"), + MemoryLayout.sequenceLayout(256, usbdevice_fs.C_CHAR).withName("driver") + ).withName("usbdevfs_disconnect_claim"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt interface_$LAYOUT = (OfInt)$LAYOUT.select(groupElement("interface")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int interface + * } + */ + public static final OfInt interface_$layout() { + return interface_$LAYOUT; + } + + private static final long interface_$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int interface + * } + */ + public static final long interface_$offset() { + return interface_$OFFSET; + } + /** * Getter for field: - * {@snippet : - * unsigned int interface; + * {@snippet lang=c : + * unsigned int interface * } */ - public static int interface_$get(MemorySegment seg) { - return (int)constants$5.const$5.get(seg); + public static int interface_(MemorySegment struct) { + return struct.get(interface_$LAYOUT, interface_$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int interface; + * {@snippet lang=c : + * unsigned int interface + * } + */ + public static void interface_(MemorySegment struct, int fieldValue) { + struct.set(interface_$LAYOUT, interface_$OFFSET, fieldValue); + } + + private static final OfInt flags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("flags")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int flags * } */ - public static void interface_$set(MemorySegment seg, int x) { - constants$5.const$5.set(seg, x); + public static final OfInt flags$layout() { + return flags$LAYOUT; } - public static int interface_$get(MemorySegment seg, long index) { - return (int)constants$5.const$5.get(seg.asSlice(index*sizeof())); + + private static final long flags$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int flags + * } + */ + public static final long flags$offset() { + return flags$OFFSET; } - public static void interface_$set(MemorySegment seg, long index, int x) { - constants$5.const$5.set(seg.asSlice(index*sizeof()), x); + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned int flags + * } + */ + public static int flags(MemorySegment struct) { + return struct.get(flags$LAYOUT, flags$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned int flags + * } + */ + public static void flags(MemorySegment struct, int fieldValue) { + struct.set(flags$LAYOUT, flags$OFFSET, fieldValue); + } + + private static final SequenceLayout driver$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("driver")); + + /** + * Layout for field: + * {@snippet lang=c : + * char driver[256] + * } + */ + public static final SequenceLayout driver$layout() { + return driver$LAYOUT; } - public static VarHandle flags$VH() { - return constants$6.const$0; + + private static final long driver$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * char driver[256] + * } + */ + public static final long driver$offset() { + return driver$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int flags; + * {@snippet lang=c : + * char driver[256] * } */ - public static int flags$get(MemorySegment seg) { - return (int)constants$6.const$0.get(seg); + public static MemorySegment driver(MemorySegment struct) { + return struct.asSlice(driver$OFFSET, driver$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * unsigned int flags; + * {@snippet lang=c : + * char driver[256] + * } + */ + public static void driver(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, driver$OFFSET, driver$LAYOUT.byteSize()); + } + + private static long[] driver$DIMS = { 256 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * char driver[256] + * } + */ + public static long[] driver$dimensions() { + return driver$DIMS; + } + private static final VarHandle driver$ELEM_HANDLE = driver$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * char driver[256] + * } + */ + public static byte driver(MemorySegment struct, long index0) { + return (byte)driver$ELEM_HANDLE.get(struct, 0L, index0); + } + + /** + * Indexed setter for field: + * {@snippet lang=c : + * char driver[256] * } */ - public static void flags$set(MemorySegment seg, int x) { - constants$6.const$0.set(seg, x); + public static void driver(MemorySegment struct, long index0, byte fieldValue) { + driver$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); } - public static int flags$get(MemorySegment seg, long index) { - return (int)constants$6.const$0.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void flags$set(MemorySegment seg, long index, int x) { - constants$6.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static MemorySegment driver$slice(MemorySegment seg) { - return seg.asSlice(8, 256); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java index 8135f57..0e8d44d 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java @@ -2,112 +2,218 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_ioctl { * int ifno; * int ioctl_code; - * void* data; - * }; + * void *data; + * } * } */ public class usbdevfs_ioctl { - public static MemoryLayout $LAYOUT() { - return constants$5.const$0; + usbdevfs_ioctl() { + // Should not be called directly } - public static VarHandle ifno$VH() { - return constants$5.const$1; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_INT.withName("ifno"), + usbdevice_fs.C_INT.withName("ioctl_code"), + usbdevice_fs.C_POINTER.withName("data") + ).withName("usbdevfs_ioctl"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ifno$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ifno")); + + /** + * Layout for field: + * {@snippet lang=c : + * int ifno + * } + */ + public static final OfInt ifno$layout() { + return ifno$LAYOUT; + } + + private static final long ifno$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int ifno + * } + */ + public static final long ifno$offset() { + return ifno$OFFSET; } + /** * Getter for field: - * {@snippet : - * int ifno; + * {@snippet lang=c : + * int ifno * } */ - public static int ifno$get(MemorySegment seg) { - return (int)constants$5.const$1.get(seg); + public static int ifno(MemorySegment struct) { + return struct.get(ifno$LAYOUT, ifno$OFFSET); } + /** * Setter for field: - * {@snippet : - * int ifno; + * {@snippet lang=c : + * int ifno * } */ - public static void ifno$set(MemorySegment seg, int x) { - constants$5.const$1.set(seg, x); - } - public static int ifno$get(MemorySegment seg, long index) { - return (int)constants$5.const$1.get(seg.asSlice(index*sizeof())); + public static void ifno(MemorySegment struct, int fieldValue) { + struct.set(ifno$LAYOUT, ifno$OFFSET, fieldValue); } - public static void ifno$set(MemorySegment seg, long index, int x) { - constants$5.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt ioctl_code$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ioctl_code")); + + /** + * Layout for field: + * {@snippet lang=c : + * int ioctl_code + * } + */ + public static final OfInt ioctl_code$layout() { + return ioctl_code$LAYOUT; } - public static VarHandle ioctl_code$VH() { - return constants$5.const$2; + + private static final long ioctl_code$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * int ioctl_code + * } + */ + public static final long ioctl_code$offset() { + return ioctl_code$OFFSET; } + /** * Getter for field: - * {@snippet : - * int ioctl_code; + * {@snippet lang=c : + * int ioctl_code * } */ - public static int ioctl_code$get(MemorySegment seg) { - return (int)constants$5.const$2.get(seg); + public static int ioctl_code(MemorySegment struct) { + return struct.get(ioctl_code$LAYOUT, ioctl_code$OFFSET); } + /** * Setter for field: - * {@snippet : - * int ioctl_code; + * {@snippet lang=c : + * int ioctl_code * } */ - public static void ioctl_code$set(MemorySegment seg, int x) { - constants$5.const$2.set(seg, x); + public static void ioctl_code(MemorySegment struct, int fieldValue) { + struct.set(ioctl_code$LAYOUT, ioctl_code$OFFSET, fieldValue); } - public static int ioctl_code$get(MemorySegment seg, long index) { - return (int)constants$5.const$2.get(seg.asSlice(index*sizeof())); - } - public static void ioctl_code$set(MemorySegment seg, long index, int x) { - constants$5.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; } - public static VarHandle data$VH() { - return constants$5.const$3; + + private static final long data$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * void *data + * } + */ + public static final long data$offset() { + return data$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static MemorySegment data$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$5.const$3.get(seg); + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); } + /** * Setter for field: - * {@snippet : - * void* data; + * {@snippet lang=c : + * void *data * } */ - public static void data$set(MemorySegment seg, MemorySegment x) { - constants$5.const$3.set(seg, x); + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static MemorySegment data$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$5.const$3.get(seg.asSlice(index*sizeof())); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static void data$set(MemorySegment seg, long index, MemorySegment x) { - constants$5.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java new file mode 100644 index 0000000..d4a335a --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java @@ -0,0 +1,219 @@ +// Generated by jextract + +package net.codecrete.usb.linux.gen.usbdevice_fs; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct usbdevfs_iso_packet_desc { + * unsigned int length; + * unsigned int actual_length; + * unsigned int status; + * } + * } + */ +public class usbdevfs_iso_packet_desc { + + usbdevfs_iso_packet_desc() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_INT.withName("length"), + usbdevice_fs.C_INT.withName("actual_length"), + usbdevice_fs.C_INT.withName("status") + ).withName("usbdevfs_iso_packet_desc"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt length$LAYOUT = (OfInt)$LAYOUT.select(groupElement("length")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int length + * } + */ + public static final OfInt length$layout() { + return length$LAYOUT; + } + + private static final long length$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int length + * } + */ + public static final long length$offset() { + return length$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned int length + * } + */ + public static int length(MemorySegment struct) { + return struct.get(length$LAYOUT, length$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned int length + * } + */ + public static void length(MemorySegment struct, int fieldValue) { + struct.set(length$LAYOUT, length$OFFSET, fieldValue); + } + + private static final OfInt actual_length$LAYOUT = (OfInt)$LAYOUT.select(groupElement("actual_length")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int actual_length + * } + */ + public static final OfInt actual_length$layout() { + return actual_length$LAYOUT; + } + + private static final long actual_length$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int actual_length + * } + */ + public static final long actual_length$offset() { + return actual_length$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned int actual_length + * } + */ + public static int actual_length(MemorySegment struct) { + return struct.get(actual_length$LAYOUT, actual_length$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned int actual_length + * } + */ + public static void actual_length(MemorySegment struct, int fieldValue) { + struct.set(actual_length$LAYOUT, actual_length$OFFSET, fieldValue); + } + + private static final OfInt status$LAYOUT = (OfInt)$LAYOUT.select(groupElement("status")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int status + * } + */ + public static final OfInt status$layout() { + return status$LAYOUT; + } + + private static final long status$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int status + * } + */ + public static final long status$offset() { + return status$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned int status + * } + */ + public static int status(MemorySegment struct) { + return struct.get(status$LAYOUT, status$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned int status + * } + */ + public static void status(MemorySegment struct, int fieldValue) { + struct.set(status$LAYOUT, status$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java index b998994..26b6181 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java @@ -2,84 +2,172 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_setinterface { * unsigned int interface; * unsigned int altsetting; - * }; + * } * } */ public class usbdevfs_setinterface { - public static MemoryLayout $LAYOUT() { - return constants$2.const$1; + usbdevfs_setinterface() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_INT.withName("interface"), + usbdevice_fs.C_INT.withName("altsetting") + ).withName("usbdevfs_setinterface"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt interface_$LAYOUT = (OfInt)$LAYOUT.select(groupElement("interface")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int interface + * } + */ + public static final OfInt interface_$layout() { + return interface_$LAYOUT; } - public static VarHandle interface_$VH() { - return constants$2.const$2; + + private static final long interface_$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int interface + * } + */ + public static final long interface_$offset() { + return interface_$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int interface; + * {@snippet lang=c : + * unsigned int interface * } */ - public static int interface_$get(MemorySegment seg) { - return (int)constants$2.const$2.get(seg); + public static int interface_(MemorySegment struct) { + return struct.get(interface_$LAYOUT, interface_$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int interface; + * {@snippet lang=c : + * unsigned int interface * } */ - public static void interface_$set(MemorySegment seg, int x) { - constants$2.const$2.set(seg, x); + public static void interface_(MemorySegment struct, int fieldValue) { + struct.set(interface_$LAYOUT, interface_$OFFSET, fieldValue); } - public static int interface_$get(MemorySegment seg, long index) { - return (int)constants$2.const$2.get(seg.asSlice(index*sizeof())); - } - public static void interface_$set(MemorySegment seg, long index, int x) { - constants$2.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt altsetting$LAYOUT = (OfInt)$LAYOUT.select(groupElement("altsetting")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int altsetting + * } + */ + public static final OfInt altsetting$layout() { + return altsetting$LAYOUT; } - public static VarHandle altsetting$VH() { - return constants$2.const$3; + + private static final long altsetting$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int altsetting + * } + */ + public static final long altsetting$offset() { + return altsetting$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int altsetting; + * {@snippet lang=c : + * unsigned int altsetting * } */ - public static int altsetting$get(MemorySegment seg) { - return (int)constants$2.const$3.get(seg); + public static int altsetting(MemorySegment struct) { + return struct.get(altsetting$LAYOUT, altsetting$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int altsetting; + * {@snippet lang=c : + * unsigned int altsetting * } */ - public static void altsetting$set(MemorySegment seg, int x) { - constants$2.const$3.set(seg, x); + public static void altsetting(MemorySegment struct, int fieldValue) { + struct.set(altsetting$LAYOUT, altsetting$OFFSET, fieldValue); } - public static int altsetting$get(MemorySegment seg, long index) { - return (int)constants$2.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void altsetting$set(MemorySegment seg, long index, int x) { - constants$2.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java index ab7fd8e..648718b 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java @@ -2,19 +2,24 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct usbdevfs_urb { * unsigned char type; * unsigned char endpoint; * int status; * unsigned int flags; - * void* buffer; + * void *buffer; * int buffer_length; * int actual_length; * int start_frame; @@ -24,373 +29,612 @@ * }; * int error_count; * unsigned int signr; - * void* usercontext; - * struct usbdevfs_iso_packet_desc iso_frame_desc[0]; - * }; + * void *usercontext; + * struct usbdevfs_iso_packet_desc iso_frame_desc[]; + * } * } */ public class usbdevfs_urb { - public static MemoryLayout $LAYOUT() { - return constants$2.const$4; + usbdevfs_urb() { + // Should not be called directly } - public static VarHandle type$VH() { - return constants$2.const$5; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + usbdevice_fs.C_CHAR.withName("type"), + usbdevice_fs.C_CHAR.withName("endpoint"), + MemoryLayout.paddingLayout(2), + usbdevice_fs.C_INT.withName("status"), + usbdevice_fs.C_INT.withName("flags"), + MemoryLayout.paddingLayout(4), + usbdevice_fs.C_POINTER.withName("buffer"), + usbdevice_fs.C_INT.withName("buffer_length"), + usbdevice_fs.C_INT.withName("actual_length"), + usbdevice_fs.C_INT.withName("start_frame"), + MemoryLayout.paddingLayout(4), + usbdevice_fs.C_INT.withName("error_count"), + usbdevice_fs.C_INT.withName("signr"), + usbdevice_fs.C_POINTER.withName("usercontext"), + MemoryLayout.sequenceLayout(0, usbdevfs_iso_packet_desc.layout()).withName("iso_frame_desc") + ).withName("usbdevfs_urb"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfByte type$LAYOUT = (OfByte)$LAYOUT.select(groupElement("type")); + /** - * Getter for field: - * {@snippet : - * unsigned char type; + * Layout for field: + * {@snippet lang=c : + * unsigned char type * } */ - public static byte type$get(MemorySegment seg) { - return (byte)constants$2.const$5.get(seg); + public static final OfByte type$layout() { + return type$LAYOUT; } + + private static final long type$OFFSET = 0; + /** - * Setter for field: - * {@snippet : - * unsigned char type; + * Offset for field: + * {@snippet lang=c : + * unsigned char type * } */ - public static void type$set(MemorySegment seg, byte x) { - constants$2.const$5.set(seg, x); - } - public static byte type$get(MemorySegment seg, long index) { - return (byte)constants$2.const$5.get(seg.asSlice(index*sizeof())); - } - public static void type$set(MemorySegment seg, long index, byte x) { - constants$2.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static VarHandle endpoint$VH() { - return constants$3.const$0; + public static final long type$offset() { + return type$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned char endpoint; + * {@snippet lang=c : + * unsigned char type * } */ - public static byte endpoint$get(MemorySegment seg) { - return (byte)constants$3.const$0.get(seg); + public static byte type(MemorySegment struct) { + return struct.get(type$LAYOUT, type$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned char endpoint; + * {@snippet lang=c : + * unsigned char type * } */ - public static void endpoint$set(MemorySegment seg, byte x) { - constants$3.const$0.set(seg, x); + public static void type(MemorySegment struct, byte fieldValue) { + struct.set(type$LAYOUT, type$OFFSET, fieldValue); } - public static byte endpoint$get(MemorySegment seg, long index) { - return (byte)constants$3.const$0.get(seg.asSlice(index*sizeof())); - } - public static void endpoint$set(MemorySegment seg, long index, byte x) { - constants$3.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte endpoint$LAYOUT = (OfByte)$LAYOUT.select(groupElement("endpoint")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned char endpoint + * } + */ + public static final OfByte endpoint$layout() { + return endpoint$LAYOUT; } - public static VarHandle status$VH() { - return constants$3.const$1; + + private static final long endpoint$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned char endpoint + * } + */ + public static final long endpoint$offset() { + return endpoint$OFFSET; } + /** * Getter for field: - * {@snippet : - * int status; + * {@snippet lang=c : + * unsigned char endpoint * } */ - public static int status$get(MemorySegment seg) { - return (int)constants$3.const$1.get(seg); + public static byte endpoint(MemorySegment struct) { + return struct.get(endpoint$LAYOUT, endpoint$OFFSET); } + /** * Setter for field: - * {@snippet : - * int status; + * {@snippet lang=c : + * unsigned char endpoint * } */ - public static void status$set(MemorySegment seg, int x) { - constants$3.const$1.set(seg, x); - } - public static int status$get(MemorySegment seg, long index) { - return (int)constants$3.const$1.get(seg.asSlice(index*sizeof())); + public static void endpoint(MemorySegment struct, byte fieldValue) { + struct.set(endpoint$LAYOUT, endpoint$OFFSET, fieldValue); } - public static void status$set(MemorySegment seg, long index, int x) { - constants$3.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt status$LAYOUT = (OfInt)$LAYOUT.select(groupElement("status")); + + /** + * Layout for field: + * {@snippet lang=c : + * int status + * } + */ + public static final OfInt status$layout() { + return status$LAYOUT; } - public static VarHandle flags$VH() { - return constants$3.const$2; + + private static final long status$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * int status + * } + */ + public static final long status$offset() { + return status$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int flags; + * {@snippet lang=c : + * int status * } */ - public static int flags$get(MemorySegment seg) { - return (int)constants$3.const$2.get(seg); + public static int status(MemorySegment struct) { + return struct.get(status$LAYOUT, status$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int flags; + * {@snippet lang=c : + * int status * } */ - public static void flags$set(MemorySegment seg, int x) { - constants$3.const$2.set(seg, x); + public static void status(MemorySegment struct, int fieldValue) { + struct.set(status$LAYOUT, status$OFFSET, fieldValue); } - public static int flags$get(MemorySegment seg, long index) { - return (int)constants$3.const$2.get(seg.asSlice(index*sizeof())); - } - public static void flags$set(MemorySegment seg, long index, int x) { - constants$3.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt flags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("flags")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int flags + * } + */ + public static final OfInt flags$layout() { + return flags$LAYOUT; } - public static VarHandle buffer$VH() { - return constants$3.const$3; + + private static final long flags$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int flags + * } + */ + public static final long flags$offset() { + return flags$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* buffer; + * {@snippet lang=c : + * unsigned int flags * } */ - public static MemorySegment buffer$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$3.const$3.get(seg); + public static int flags(MemorySegment struct) { + return struct.get(flags$LAYOUT, flags$OFFSET); } + /** * Setter for field: - * {@snippet : - * void* buffer; + * {@snippet lang=c : + * unsigned int flags * } */ - public static void buffer$set(MemorySegment seg, MemorySegment x) { - constants$3.const$3.set(seg, x); - } - public static MemorySegment buffer$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$3.const$3.get(seg.asSlice(index*sizeof())); + public static void flags(MemorySegment struct, int fieldValue) { + struct.set(flags$LAYOUT, flags$OFFSET, fieldValue); } - public static void buffer$set(MemorySegment seg, long index, MemorySegment x) { - constants$3.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout buffer$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("buffer")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *buffer + * } + */ + public static final AddressLayout buffer$layout() { + return buffer$LAYOUT; } - public static VarHandle buffer_length$VH() { - return constants$3.const$4; + + private static final long buffer$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * void *buffer + * } + */ + public static final long buffer$offset() { + return buffer$OFFSET; } + /** * Getter for field: - * {@snippet : - * int buffer_length; + * {@snippet lang=c : + * void *buffer * } */ - public static int buffer_length$get(MemorySegment seg) { - return (int)constants$3.const$4.get(seg); + public static MemorySegment buffer(MemorySegment struct) { + return struct.get(buffer$LAYOUT, buffer$OFFSET); } + /** * Setter for field: - * {@snippet : - * int buffer_length; + * {@snippet lang=c : + * void *buffer * } */ - public static void buffer_length$set(MemorySegment seg, int x) { - constants$3.const$4.set(seg, x); - } - public static int buffer_length$get(MemorySegment seg, long index) { - return (int)constants$3.const$4.get(seg.asSlice(index*sizeof())); + public static void buffer(MemorySegment struct, MemorySegment fieldValue) { + struct.set(buffer$LAYOUT, buffer$OFFSET, fieldValue); } - public static void buffer_length$set(MemorySegment seg, long index, int x) { - constants$3.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt buffer_length$LAYOUT = (OfInt)$LAYOUT.select(groupElement("buffer_length")); + + /** + * Layout for field: + * {@snippet lang=c : + * int buffer_length + * } + */ + public static final OfInt buffer_length$layout() { + return buffer_length$LAYOUT; } - public static VarHandle actual_length$VH() { - return constants$3.const$5; + + private static final long buffer_length$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * int buffer_length + * } + */ + public static final long buffer_length$offset() { + return buffer_length$OFFSET; } + /** * Getter for field: - * {@snippet : - * int actual_length; + * {@snippet lang=c : + * int buffer_length * } */ - public static int actual_length$get(MemorySegment seg) { - return (int)constants$3.const$5.get(seg); + public static int buffer_length(MemorySegment struct) { + return struct.get(buffer_length$LAYOUT, buffer_length$OFFSET); } + /** * Setter for field: - * {@snippet : - * int actual_length; + * {@snippet lang=c : + * int buffer_length * } */ - public static void actual_length$set(MemorySegment seg, int x) { - constants$3.const$5.set(seg, x); + public static void buffer_length(MemorySegment struct, int fieldValue) { + struct.set(buffer_length$LAYOUT, buffer_length$OFFSET, fieldValue); } - public static int actual_length$get(MemorySegment seg, long index) { - return (int)constants$3.const$5.get(seg.asSlice(index*sizeof())); - } - public static void actual_length$set(MemorySegment seg, long index, int x) { - constants$3.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt actual_length$LAYOUT = (OfInt)$LAYOUT.select(groupElement("actual_length")); + + /** + * Layout for field: + * {@snippet lang=c : + * int actual_length + * } + */ + public static final OfInt actual_length$layout() { + return actual_length$LAYOUT; } - public static VarHandle start_frame$VH() { - return constants$4.const$0; + + private static final long actual_length$OFFSET = 28; + + /** + * Offset for field: + * {@snippet lang=c : + * int actual_length + * } + */ + public static final long actual_length$offset() { + return actual_length$OFFSET; } + /** * Getter for field: - * {@snippet : - * int start_frame; + * {@snippet lang=c : + * int actual_length * } */ - public static int start_frame$get(MemorySegment seg) { - return (int)constants$4.const$0.get(seg); + public static int actual_length(MemorySegment struct) { + return struct.get(actual_length$LAYOUT, actual_length$OFFSET); } + /** * Setter for field: - * {@snippet : - * int start_frame; + * {@snippet lang=c : + * int actual_length * } */ - public static void start_frame$set(MemorySegment seg, int x) { - constants$4.const$0.set(seg, x); - } - public static int start_frame$get(MemorySegment seg, long index) { - return (int)constants$4.const$0.get(seg.asSlice(index*sizeof())); + public static void actual_length(MemorySegment struct, int fieldValue) { + struct.set(actual_length$LAYOUT, actual_length$OFFSET, fieldValue); } - public static void start_frame$set(MemorySegment seg, long index, int x) { - constants$4.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt start_frame$LAYOUT = (OfInt)$LAYOUT.select(groupElement("start_frame")); + + /** + * Layout for field: + * {@snippet lang=c : + * int start_frame + * } + */ + public static final OfInt start_frame$layout() { + return start_frame$LAYOUT; } - public static VarHandle number_of_packets$VH() { - return constants$4.const$1; + + private static final long start_frame$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * int start_frame + * } + */ + public static final long start_frame$offset() { + return start_frame$OFFSET; } + /** * Getter for field: - * {@snippet : - * int number_of_packets; + * {@snippet lang=c : + * int start_frame * } */ - public static int number_of_packets$get(MemorySegment seg) { - return (int)constants$4.const$1.get(seg); + public static int start_frame(MemorySegment struct) { + return struct.get(start_frame$LAYOUT, start_frame$OFFSET); } + /** * Setter for field: - * {@snippet : - * int number_of_packets; + * {@snippet lang=c : + * int start_frame * } */ - public static void number_of_packets$set(MemorySegment seg, int x) { - constants$4.const$1.set(seg, x); + public static void start_frame(MemorySegment struct, int fieldValue) { + struct.set(start_frame$LAYOUT, start_frame$OFFSET, fieldValue); } - public static int number_of_packets$get(MemorySegment seg, long index) { - return (int)constants$4.const$1.get(seg.asSlice(index*sizeof())); - } - public static void number_of_packets$set(MemorySegment seg, long index, int x) { - constants$4.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt error_count$LAYOUT = (OfInt)$LAYOUT.select(groupElement("error_count")); + + /** + * Layout for field: + * {@snippet lang=c : + * int error_count + * } + */ + public static final OfInt error_count$layout() { + return error_count$LAYOUT; } - public static VarHandle stream_id$VH() { - return constants$4.const$2; + + private static final long error_count$OFFSET = 40; + + /** + * Offset for field: + * {@snippet lang=c : + * int error_count + * } + */ + public static final long error_count$offset() { + return error_count$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int stream_id; + * {@snippet lang=c : + * int error_count * } */ - public static int stream_id$get(MemorySegment seg) { - return (int)constants$4.const$2.get(seg); + public static int error_count(MemorySegment struct) { + return struct.get(error_count$LAYOUT, error_count$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int stream_id; + * {@snippet lang=c : + * int error_count * } */ - public static void stream_id$set(MemorySegment seg, int x) { - constants$4.const$2.set(seg, x); - } - public static int stream_id$get(MemorySegment seg, long index) { - return (int)constants$4.const$2.get(seg.asSlice(index*sizeof())); + public static void error_count(MemorySegment struct, int fieldValue) { + struct.set(error_count$LAYOUT, error_count$OFFSET, fieldValue); } - public static void stream_id$set(MemorySegment seg, long index, int x) { - constants$4.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt signr$LAYOUT = (OfInt)$LAYOUT.select(groupElement("signr")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned int signr + * } + */ + public static final OfInt signr$layout() { + return signr$LAYOUT; } - public static VarHandle error_count$VH() { - return constants$4.const$3; + + private static final long signr$OFFSET = 44; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned int signr + * } + */ + public static final long signr$offset() { + return signr$OFFSET; } + /** * Getter for field: - * {@snippet : - * int error_count; + * {@snippet lang=c : + * unsigned int signr * } */ - public static int error_count$get(MemorySegment seg) { - return (int)constants$4.const$3.get(seg); + public static int signr(MemorySegment struct) { + return struct.get(signr$LAYOUT, signr$OFFSET); } + /** * Setter for field: - * {@snippet : - * int error_count; + * {@snippet lang=c : + * unsigned int signr * } */ - public static void error_count$set(MemorySegment seg, int x) { - constants$4.const$3.set(seg, x); + public static void signr(MemorySegment struct, int fieldValue) { + struct.set(signr$LAYOUT, signr$OFFSET, fieldValue); } - public static int error_count$get(MemorySegment seg, long index) { - return (int)constants$4.const$3.get(seg.asSlice(index*sizeof())); - } - public static void error_count$set(MemorySegment seg, long index, int x) { - constants$4.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout usercontext$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("usercontext")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *usercontext + * } + */ + public static final AddressLayout usercontext$layout() { + return usercontext$LAYOUT; } - public static VarHandle signr$VH() { - return constants$4.const$4; + + private static final long usercontext$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * void *usercontext + * } + */ + public static final long usercontext$offset() { + return usercontext$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned int signr; + * {@snippet lang=c : + * void *usercontext * } */ - public static int signr$get(MemorySegment seg) { - return (int)constants$4.const$4.get(seg); + public static MemorySegment usercontext(MemorySegment struct) { + return struct.get(usercontext$LAYOUT, usercontext$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned int signr; + * {@snippet lang=c : + * void *usercontext * } */ - public static void signr$set(MemorySegment seg, int x) { - constants$4.const$4.set(seg, x); - } - public static int signr$get(MemorySegment seg, long index) { - return (int)constants$4.const$4.get(seg.asSlice(index*sizeof())); + public static void usercontext(MemorySegment struct, MemorySegment fieldValue) { + struct.set(usercontext$LAYOUT, usercontext$OFFSET, fieldValue); } - public static void signr$set(MemorySegment seg, long index, int x) { - constants$4.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final SequenceLayout iso_frame_desc$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("iso_frame_desc")); + + /** + * Layout for field: + * {@snippet lang=c : + * struct usbdevfs_iso_packet_desc iso_frame_desc[] + * } + */ + public static final SequenceLayout iso_frame_desc$layout() { + return iso_frame_desc$LAYOUT; } - public static VarHandle usercontext$VH() { - return constants$4.const$5; + + private static final long iso_frame_desc$OFFSET = 56; + + /** + * Offset for field: + * {@snippet lang=c : + * struct usbdevfs_iso_packet_desc iso_frame_desc[] + * } + */ + public static final long iso_frame_desc$offset() { + return iso_frame_desc$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* usercontext; + * {@snippet lang=c : + * struct usbdevfs_iso_packet_desc iso_frame_desc[] * } */ - public static MemorySegment usercontext$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$4.const$5.get(seg); + public static MemorySegment iso_frame_desc(MemorySegment struct) { + return struct.asSlice(iso_frame_desc$OFFSET, iso_frame_desc$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * void* usercontext; + * {@snippet lang=c : + * struct usbdevfs_iso_packet_desc iso_frame_desc[] * } */ - public static void usercontext$set(MemorySegment seg, MemorySegment x) { - constants$4.const$5.set(seg, x); + public static void iso_frame_desc(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, iso_frame_desc$OFFSET, iso_frame_desc$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static MemorySegment usercontext$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$4.const$5.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void usercontext$set(MemorySegment seg, long index, MemorySegment x) { - constants$4.const$5.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java index 68d05fe..8153386 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java @@ -2,59 +2,116 @@ package net.codecrete.usb.linux.gen.usbdevice_fs; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class usbdevice_fs { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class usbdevice_fs { + + usbdevice_fs() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int USBDEVFS_URB_TYPE_ISO = (int)0L; /** - * {@snippet : + * {@snippet lang=c : * #define USBDEVFS_URB_TYPE_ISO 0 * } */ public static int USBDEVFS_URB_TYPE_ISO() { - return (int)0L; + return USBDEVFS_URB_TYPE_ISO; } + private static final int USBDEVFS_URB_TYPE_INTERRUPT = (int)1L; /** - * {@snippet : + * {@snippet lang=c : * #define USBDEVFS_URB_TYPE_INTERRUPT 1 * } */ public static int USBDEVFS_URB_TYPE_INTERRUPT() { - return (int)1L; + return USBDEVFS_URB_TYPE_INTERRUPT; } + private static final int USBDEVFS_URB_TYPE_CONTROL = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define USBDEVFS_URB_TYPE_CONTROL 2 * } */ public static int USBDEVFS_URB_TYPE_CONTROL() { - return (int)2L; + return USBDEVFS_URB_TYPE_CONTROL; } + private static final int USBDEVFS_URB_TYPE_BULK = (int)3L; /** - * {@snippet : + * {@snippet lang=c : * #define USBDEVFS_URB_TYPE_BULK 3 * } */ public static int USBDEVFS_URB_TYPE_BULK() { - return (int)3L; + return USBDEVFS_URB_TYPE_BULK; } + private static final int USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER 2 * } */ public static int USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER() { - return (int)2L; + return USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java index 74459d5..206d7a6 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java @@ -35,10 +35,10 @@ private CoreFoundationHelper() { static String stringFromCFStringRef(MemorySegment string, Arena arena) { var strLen = CoreFoundation.CFStringGetLength(string); - var buffer = arena.allocateArray(JAVA_CHAR, strLen); + var buffer = arena.allocate(JAVA_CHAR, strLen); var range = CFRange.allocate(arena); - CFRange.location$set(range, 0); - CFRange.length$set(range, strLen); + CFRange.location(range, 0); + CFRange.length(range, strLen); CoreFoundation.CFStringGetCharacters(string, range, buffer); return new String(buffer.toArray(JAVA_CHAR)); } @@ -56,7 +56,7 @@ static String stringFromCFStringRef(MemorySegment string, Arena arena) { */ static MemorySegment createCFStringRef(String string, SegmentAllocator allocator) { var charArray = string.toCharArray(); - var chars = allocator.allocateArray(JAVA_CHAR, charArray.length); + var chars = allocator.allocate(JAVA_CHAR, charArray.length); chars.copyFrom(MemorySegment.ofArray(charArray)); return CoreFoundation.CFStringCreateWithCharacters(NULL, chars, string.length()); } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java index 22786f0..08d3527 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java @@ -93,7 +93,7 @@ private IoKitHelper() { * @return vtable */ static MemorySegment getVtable(MemorySegment self) { - return (MemorySegment) vtable$VH.get(self); + return (MemorySegment) vtable$VH.get(self, 0); } /** @@ -111,9 +111,9 @@ static MemorySegment getVtable(MemorySegment self) { static MemorySegment getInterface(int service, MemorySegment pluginType, MemorySegment interfaceId) { try (var arena = Arena.ofConfined()) { // MemorySegment for holding IOCFPlugInInterface** - var plugHolder = arena.allocate(ADDRESS, NULL); + var plugHolder = arena.allocate(ADDRESS); // MemorySegment for holding score - var score = arena.allocate(JAVA_INT, 0); + var score = arena.allocate(JAVA_INT); var ret = IOKit.IOCreatePlugInInterfaceForService(service, pluginType, kIOCFPlugInInterfaceID, plugHolder , score); if (ret != 0) @@ -123,7 +123,7 @@ static MemorySegment getInterface(int service, MemorySegment pluginType, MemoryS // UUID bytes var refiid = CoreFoundation.CFUUIDGetUUIDBytes(arena, interfaceId); // MemorySegment for holding xxxInterface** - var intfHolder = arena.allocate(ADDRESS, NULL); + var intfHolder = arena.allocate(ADDRESS); ret = IoKitUsb.QueryInterface(plug, refiid, intfHolder); IoKitUsb.Release(plug); if (ret != 0) @@ -152,7 +152,7 @@ static Integer getPropertyInt(int service, MemorySegment key, Arena arena) { Integer result = null; var type = CoreFoundation.CFGetTypeID(value); if (type == CoreFoundation.CFNumberGetTypeID()) { - var numberValue = arena.allocate(JAVA_INT, 0); + var numberValue = arena.allocate(JAVA_INT); if (CoreFoundation.CFNumberGetValue(value, CoreFoundation.kCFNumberSInt32Type(), numberValue) != 0) result = numberValue.get(JAVA_INT, 0); } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUsb.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUsb.java index 6dd1e76..f15fa5b 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUsb.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUsb.java @@ -10,7 +10,6 @@ import net.codecrete.usb.macos.gen.iokit.IOUSBDeviceStruct187; import net.codecrete.usb.macos.gen.iokit.IOUSBInterfaceStruct190; -import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import static net.codecrete.usb.macos.IoKitHelper.getVtable; @@ -26,92 +25,92 @@ private IoKitUsb() { // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv) static int QueryInterface(MemorySegment self, MemorySegment iid, MemorySegment ppv) { - return IOUSBDeviceStruct187.QueryInterface(getVtable(self), Arena.global()).apply(self, iid, ppv); + return IOUSBDeviceStruct187.QueryInterface.invoke(IOUSBDeviceStruct187.QueryInterface(getVtable(self)), self, iid, ppv); } // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer) static int AddRef(MemorySegment self) { - return IOUSBDeviceStruct187.AddRef(getVtable(self), Arena.global()).apply(self); + return IOUSBDeviceStruct187.AddRef.invoke(IOUSBDeviceStruct187.AddRef(getVtable(self)), self); } // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer) static int Release(MemorySegment self) { - return IOUSBDeviceStruct187.Release(getVtable(self), Arena.global()).apply(self); + return IOUSBDeviceStruct187.Release.invoke(IOUSBDeviceStruct187.Release(getVtable(self)), self); } // IOReturn (* CreateDeviceAsyncEventSource)(void* self, CFRunLoopSourceRef* source) static int CreateDeviceAsyncEventSource(MemorySegment self, MemorySegment source) { - return IOUSBDeviceStruct187.CreateDeviceAsyncEventSource(getVtable(self), Arena.global()).apply(self, + return IOUSBDeviceStruct187.CreateDeviceAsyncEventSource.invoke(IOUSBDeviceStruct187.CreateDeviceAsyncEventSource(getVtable(self)), self, source); } // CFRunLoopSourceRef (* GetDeviceAsyncEventSource)(void* self) static MemorySegment GetDeviceAsyncEventSource(MemorySegment self) { - return IOUSBDeviceStruct187.GetDeviceAsyncEventSource(getVtable(self), Arena.global()).apply(self); + return IOUSBDeviceStruct187.GetDeviceAsyncEventSource.invoke(IOUSBDeviceStruct187.GetDeviceAsyncEventSource(getVtable(self)), self); } // IOReturn (*USBDeviceOpenSeize)(void *self) static int USBDeviceOpenSeize(MemorySegment self) { - return IOUSBDeviceStruct187.USBDeviceOpenSeize(getVtable(self), Arena.global()).apply(self); + return IOUSBDeviceStruct187.USBDeviceOpenSeize.invoke(IOUSBDeviceStruct187.USBDeviceOpenSeize(getVtable(self)), self); } // IOReturn (*USBDeviceClose)(void *self) static int USBDeviceClose(MemorySegment self) { - return IOUSBDeviceStruct187.USBDeviceClose(getVtable(self), Arena.global()).apply(self); + return IOUSBDeviceStruct187.USBDeviceClose.invoke(IOUSBDeviceStruct187.USBDeviceClose(getVtable(self)), self); } // IOReturn (* USBDeviceReEnumerate)(void* self, UInt32 options) static int USBDeviceReEnumerate(MemorySegment self, int options) { - return IOUSBDeviceStruct187.USBDeviceReEnumerate(getVtable(self), Arena.global()).apply(self, options); + return IOUSBDeviceStruct187.USBDeviceReEnumerate.invoke(IOUSBDeviceStruct187.USBDeviceReEnumerate(getVtable(self)), self, options); } // IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc) static int GetConfigurationDescriptorPtr(MemorySegment self, byte configIndex, MemorySegment descHolder) { - return IOUSBDeviceStruct187.GetConfigurationDescriptorPtr(getVtable(self), Arena.global()).apply(self, + return IOUSBDeviceStruct187.GetConfigurationDescriptorPtr.invoke(IOUSBDeviceStruct187.GetConfigurationDescriptorPtr(getVtable(self)), self, configIndex, descHolder); } // IOReturn (*SetConfiguration)(void *self, UInt8 configNum) static int SetConfiguration(MemorySegment self, byte configValue) { - return IOUSBDeviceStruct187.SetConfiguration(getVtable(self), Arena.global()).apply(self, configValue); + return IOUSBDeviceStruct187.SetConfiguration.invoke(IOUSBDeviceStruct187.SetConfiguration(getVtable(self)), self, configValue); } // IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter) static int CreateInterfaceIterator(MemorySegment self, MemorySegment req, MemorySegment iter) { - return IOUSBDeviceStruct187.CreateInterfaceIterator(getVtable(self), Arena.global()).apply(self, req, iter); + return IOUSBDeviceStruct187.CreateInterfaceIterator.invoke(IOUSBDeviceStruct187.CreateInterfaceIterator(getVtable(self)), self, req, iter); } // IOReturn (* DeviceRequest)(void* self, IOUSBDevRequest* req) static int DeviceRequest(MemorySegment self, MemorySegment deviceRequest) { - return IOUSBDeviceStruct187.DeviceRequest(getVtable(self), Arena.global()).apply(self, deviceRequest); + return IOUSBDeviceStruct187.DeviceRequest.invoke(IOUSBDeviceStruct187.DeviceRequest(getVtable(self)), self, deviceRequest); } // IOReturn (* DeviceRequestAsync)(void* self, IOUSBDevRequest* req, IOAsyncCallback1 callback, void* refCon) static int DeviceRequestAsync(MemorySegment self, MemorySegment deviceRequest, MemorySegment callback, MemorySegment refCon) { - return IOUSBDeviceStruct187.DeviceRequestAsync(getVtable(self), Arena.global()).apply(self, deviceRequest, + return IOUSBDeviceStruct187.DeviceRequestAsync.invoke(IOUSBDeviceStruct187.DeviceRequestAsync(getVtable(self)), self, deviceRequest, callback, refCon); } // IOReturn (*USBInterfaceOpen)(void *self) static int USBInterfaceOpen(MemorySegment self) { - return IOUSBInterfaceStruct190.USBInterfaceOpen(getVtable(self), Arena.global()).apply(self); + return IOUSBInterfaceStruct190.USBInterfaceOpen.invoke(IOUSBInterfaceStruct190.USBInterfaceOpen(getVtable(self)), self); } // IOReturn (*USBInterfaceClose)(void *self) static int USBInterfaceClose(MemorySegment self) { - return IOUSBInterfaceStruct190.USBInterfaceClose(getVtable(self), Arena.global()).apply(self); + return IOUSBInterfaceStruct190.USBInterfaceClose.invoke(IOUSBInterfaceStruct190.USBInterfaceClose(getVtable(self)), self); } // IOReturn (*GetInterfaceNumber)(void *self, UInt8 *intfNumber) static int GetInterfaceNumber(MemorySegment self, MemorySegment intfNumberHolder) { - return IOUSBInterfaceStruct190.GetInterfaceNumber(getVtable(self), Arena.global()).apply(self, + return IOUSBInterfaceStruct190.GetInterfaceNumber.invoke(IOUSBInterfaceStruct190.GetInterfaceNumber(getVtable(self)), self, intfNumberHolder); } // IOReturn (*GetNumEndpoints)(void *self, UInt8 *intfNumEndpoints) static int GetNumEndpoints(MemorySegment self, MemorySegment intfNumEndpointsHolder) { - return IOUSBInterfaceStruct190.GetNumEndpoints(getVtable(self), Arena.global()).apply(self, + return IOUSBInterfaceStruct190.GetNumEndpoints.invoke(IOUSBInterfaceStruct190.GetNumEndpoints(getVtable(self)), self, intfNumEndpointsHolder); } @@ -120,7 +119,7 @@ static int GetNumEndpoints(MemorySegment self, MemorySegment intfNumEndpointsHol static int GetPipeProperties(MemorySegment self, byte pipeRef, MemorySegment directionHolder, MemorySegment numberHolder, MemorySegment transferTypeHolder, MemorySegment maxPacketSizeHolder, MemorySegment intervalHolder) { - return IOUSBInterfaceStruct190.GetPipeProperties(getVtable(self), Arena.global()).apply(self, pipeRef, + return IOUSBInterfaceStruct190.GetPipeProperties.invoke(IOUSBInterfaceStruct190.GetPipeProperties(getVtable(self)), self, pipeRef, directionHolder, numberHolder, transferTypeHolder, maxPacketSizeHolder, intervalHolder); } @@ -128,7 +127,7 @@ static int GetPipeProperties(MemorySegment self, byte pipeRef, MemorySegment dir // *refcon) static int ReadPipeAsync(MemorySegment self, byte pipeRef, MemorySegment buf, int size, MemorySegment callback, MemorySegment refcon) { - return IOUSBInterfaceStruct190.ReadPipeAsync(getVtable(self), Arena.global()).apply(self, pipeRef, buf, + return IOUSBInterfaceStruct190.ReadPipeAsync.invoke(IOUSBInterfaceStruct190.ReadPipeAsync(getVtable(self)), self, pipeRef, buf, size, callback, refcon); } @@ -137,7 +136,7 @@ static int ReadPipeAsync(MemorySegment self, byte pipeRef, MemorySegment buf, in static int ReadPipeAsyncTO(MemorySegment self, byte pipeRef, MemorySegment buf, int size, int noDataTimeout, int completionTimeout, MemorySegment callback, MemorySegment refcon) { - return IOUSBInterfaceStruct190.ReadPipeAsyncTO(getVtable(self), Arena.global()).apply(self, pipeRef, buf, + return IOUSBInterfaceStruct190.ReadPipeAsyncTO.invoke(IOUSBInterfaceStruct190.ReadPipeAsyncTO(getVtable(self)), self, pipeRef, buf, size, noDataTimeout, completionTimeout, callback, refcon); } @@ -145,7 +144,7 @@ static int ReadPipeAsyncTO(MemorySegment self, byte pipeRef, MemorySegment buf, // void *refcon) static int WritePipeAsync(MemorySegment self, byte pipeRef, MemorySegment buf, int size, MemorySegment callback, MemorySegment refcon) { - return IOUSBInterfaceStruct190.WritePipeAsync(getVtable(self), Arena.global()).apply(self, pipeRef, buf, + return IOUSBInterfaceStruct190.WritePipeAsync.invoke(IOUSBInterfaceStruct190.WritePipeAsync(getVtable(self)), self, pipeRef, buf, size, callback, refcon); } @@ -154,34 +153,34 @@ static int WritePipeAsync(MemorySegment self, byte pipeRef, MemorySegment buf, i static int WritePipeAsyncTO(MemorySegment self, byte pipeRef, MemorySegment buf, int size, int noDataTimeout, int completionTimeout, MemorySegment callback, MemorySegment refcon) { - return IOUSBInterfaceStruct190.WritePipeAsyncTO(getVtable(self), Arena.global()).apply(self, pipeRef, buf, + return IOUSBInterfaceStruct190.WritePipeAsyncTO.invoke(IOUSBInterfaceStruct190.WritePipeAsyncTO(getVtable(self)), self, pipeRef, buf, size, noDataTimeout, completionTimeout, callback, refcon); } // IOReturn (* AbortPipe)(void* self, UInt8 pipeRef) static int AbortPipe(MemorySegment self, byte pipeRef) { - return IOUSBInterfaceStruct190.AbortPipe(getVtable(self), Arena.global()).apply(self, pipeRef); + return IOUSBInterfaceStruct190.AbortPipe.invoke(IOUSBInterfaceStruct190.AbortPipe(getVtable(self)), self, pipeRef); } // IOReturn (*SetAlternateInterface)(void *self, UInt8 alternateSetting) static int SetAlternateInterface(MemorySegment self, byte alternateSetting) { - return IOUSBInterfaceStruct190.SetAlternateInterface(getVtable(self), Arena.global()).apply(self, + return IOUSBInterfaceStruct190.SetAlternateInterface.invoke(IOUSBInterfaceStruct190.SetAlternateInterface(getVtable(self)), self, alternateSetting); } // IOReturn (* ClearPipeStallBothEnds)(void* self, UInt8 pipeRef) static int ClearPipeStallBothEnds(MemorySegment self, byte pipeRef) { - return IOUSBInterfaceStruct190.ClearPipeStallBothEnds(getVtable(self), Arena.global()).apply(self, pipeRef); + return IOUSBInterfaceStruct190.ClearPipeStallBothEnds.invoke(IOUSBInterfaceStruct190.ClearPipeStallBothEnds(getVtable(self)), self, pipeRef); } // CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void* self) static MemorySegment GetInterfaceAsyncEventSource(MemorySegment self) { - return IOUSBInterfaceStruct190.GetInterfaceAsyncEventSource(getVtable(self), Arena.global()).apply(self); + return IOUSBInterfaceStruct190.GetInterfaceAsyncEventSource.invoke(IOUSBInterfaceStruct190.GetInterfaceAsyncEventSource(getVtable(self)), self); } // IOReturn (*CreateInterfaceAsyncEventSource)(void *self, CFRunLoopSourceRef *source) static int CreateInterfaceAsyncEventSource(MemorySegment self, MemorySegment source) { - return IOUSBInterfaceStruct190.CreateInterfaceAsyncEventSource(getVtable(self), Arena.global()).apply(self + return IOUSBInterfaceStruct190.CreateInterfaceAsyncEventSource.invoke(IOUSBInterfaceStruct190.CreateInterfaceAsyncEventSource(getVtable(self)), self , source); } } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosAsyncTask.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosAsyncTask.java index c9992de..ec0bd96 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosAsyncTask.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosAsyncTask.java @@ -22,8 +22,12 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.foreign.MemorySegment.NULL; import static java.lang.foreign.ValueLayout.ADDRESS; import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; +import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED; + /** * Background task for handling asynchronous transfers. @@ -54,6 +58,7 @@ enum TaskState { private TaskState state = TaskState.NOT_STARTED; private MemorySegment asyncIoRunLoop; private MemorySegment completionUpcallStub; + private MemorySegment messagePort; private long lastTransferId; private final Map transfersById = new HashMap<>(); @@ -67,18 +72,12 @@ void addEventSource(MemorySegment source) { asyncIoLock.lock(); if (state != TaskState.RUNNING) { - if (state == TaskState.NOT_STARTED) { - startAsyncIOThread(source); - waitForRunLoopReady(); - return; - - } else { - // special case: run loop is not ready yet but background process is already starting - waitForRunLoopReady(); - } + if (state == TaskState.NOT_STARTED) + startAsyncIOThread(); + waitForRunLoopReady(); } - CoreFoundation.CFRunLoopAddSource(asyncIoRunLoop, source, IOKit.kCFRunLoopDefaultMode$get()); + CoreFoundation.CFRunLoopAddSource(asyncIoRunLoop, source, IOKit.kCFRunLoopDefaultMode()); } finally { asyncIoLock.unlock(); @@ -92,34 +91,60 @@ private void waitForRunLoopReady() { /** * Removes an event source from this background task. - * + *

+ * The event source is not immediately removed. Instead, it is posted to a message queue + * processed by the same background thread processing the completion callbacks. This ensures + * that the events from releasing interfaces and closing devices are processed. + *

* @param source event source */ void removeEventSource(MemorySegment source) { - CoreFoundation.CFRunLoopRemoveSource(asyncIoRunLoop, source, IOKit.kCFRunLoopDefaultMode$get()); + try (var arena = Arena.ofConfined()) { + var eventSourceRef = arena.allocate(JAVA_LONG, 1); + eventSourceRef.set(JAVA_LONG, 0, source.address()); + var dataRef = CoreFoundation.CFDataCreate(NULL, eventSourceRef, eventSourceRef.byteSize()); + CoreFoundation.CFMessagePortSendRequest(messagePort, 0, dataRef, 0, 0, NULL, NULL); + CoreFoundation.CFRelease(dataRef); + } } /** * Starts the background thread. - * - * @param firstSource first event source */ - private void startAsyncIOThread(MemorySegment firstSource) { + @SuppressWarnings("java:S125") + private void startAsyncIOThread() { + MemorySegment messagePortSource; + try { state = TaskState.STARTING; + + // create descriptor for completion callback function var completionHandlerFuncDesc = FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT, ADDRESS); var asyncIOCompletedMH = MethodHandles.lookup().findVirtual(MacosAsyncTask.class, "asyncIOCompleted", MethodType.methodType(void.class, MemorySegment.class, int.class, MemorySegment.class)); var methodHandle = asyncIOCompletedMH.bindTo(this); - completionUpcallStub = Linker.nativeLinker().upcallStub(methodHandle, completionHandlerFuncDesc, - Arena.global()); + completionUpcallStub = Linker.nativeLinker().upcallStub(methodHandle, completionHandlerFuncDesc, Arena.global()); + + // create descriptor for message port callback function + var messagePortCallbackFuncDec = FunctionDescriptor.of(ADDRESS, ADDRESS, JAVA_INT, ADDRESS, ADDRESS); + var messagePortCallbackMH = MethodHandles.lookup().findVirtual(MacosAsyncTask.class, "messagePortCallback", + MethodType.methodType(MemorySegment.class, MemorySegment.class, int.class, MemorySegment.class, MemorySegment.class)); + var messagePortCallbackHandle = messagePortCallbackMH.bindTo(this); + var messagePortCallbackStub = Linker.nativeLinker().upcallStub(messagePortCallbackHandle, messagePortCallbackFuncDec, Arena.global()); + + // create local and remote message ports + var pid = ProcessHandle.current().pid(); + var portName = CoreFoundationHelper.createCFStringRef("net.codecrete.usb.macos.eventsource." + pid, Arena.global()); + var localPort = CoreFoundation.CFMessagePortCreateLocal(NULL, portName, messagePortCallbackStub, NULL, NULL); + messagePortSource = CoreFoundation.CFMessagePortCreateRunLoopSource(NULL, localPort, 0); + messagePort = CoreFoundation.CFMessagePortCreateRemote(NULL, portName); } catch (IllegalAccessException | NoSuchMethodException e) { throw new UsbException("internal error (creating method handle)", e); } - var thread = new Thread(() -> asyncIOCompletionTask(firstSource), "USB async IO"); + var thread = new Thread(() -> asyncIOCompletionTask(messagePortSource), "USB async IO"); thread.setDaemon(true); thread.start(); } @@ -137,7 +162,7 @@ private void asyncIOCompletionTask(MemorySegment firstSource) { try { asyncIoLock.lock(); asyncIoRunLoop = CoreFoundation.CFRunLoopGetCurrent(); - CoreFoundation.CFRunLoopAddSource(asyncIoRunLoop, firstSource, IOKit.kCFRunLoopDefaultMode$get()); + CoreFoundation.CFRunLoopAddSource(asyncIoRunLoop, firstSource, IOKit.kCFRunLoopDefaultMode()); state = TaskState.RUNNING; asyncIoReady.signalAll(); } finally { @@ -184,6 +209,20 @@ private void asyncIOCompleted(MemorySegment refcon, int result, MemorySegment ar transfer.completion().completed(transfer); } + /** + * Callback function called when a message is received on the message port. + *

+ * All messages are related to removing event sources. They just contain the run loop source reference. + *

+ */ + @SuppressWarnings({"java:S1144", "unused"}) + private MemorySegment messagePortCallback(MemorySegment local, int msgid, MemorySegment data, MemorySegment info) { + var runloopSourceRefPtr = CoreFoundation.CFDataGetBytePtr(data); + var runloopSourceRef = MemorySegment.ofAddress(runloopSourceRefPtr.get(JAVA_LONG_UNALIGNED, 0)); + CoreFoundation.CFRunLoopRemoveSource(asyncIoRunLoop, runloopSourceRef, IOKit.kCFRunLoopDefaultMode()); + return NULL; + } + /** * Gets the native IO completion callback function for asynchronous transfers * to be handled by this background task. diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDevice.java index ae672a6..63ffd5c 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDevice.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDevice.java @@ -7,7 +7,12 @@ package net.codecrete.usb.macos; -import net.codecrete.usb.*; +import net.codecrete.usb.UsbControlTransfer; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbDirection; +import net.codecrete.usb.UsbRecipient; +import net.codecrete.usb.UsbRequestType; +import net.codecrete.usb.UsbTransferType; import net.codecrete.usb.common.ScopeCleanup; import net.codecrete.usb.common.Transfer; import net.codecrete.usb.common.UsbDeviceImpl; @@ -27,7 +32,10 @@ import java.util.List; import java.util.Map; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_SHORT; import static net.codecrete.usb.common.ForeignMemory.dereference; import static net.codecrete.usb.macos.MacosUsbException.throwException; @@ -135,22 +143,21 @@ public synchronized void close() { return; for (var interfaceInfo : claimedInterfaces) { + setClaimed(interfaceInfo.interfaceNumber, false); var source = IoKitUsb.GetInterfaceAsyncEventSource(interfaceInfo.iokitInterface()); - if (source.address() != 0) - asyncTask.removeEventSource(source); IoKitUsb.USBInterfaceClose(interfaceInfo.iokitInterface); IoKitUsb.Release(interfaceInfo.iokitInterface); - setClaimed(interfaceInfo.interfaceNumber, false); + if (source.address() != 0) + asyncTask.removeEventSource(source); } claimedInterfaces = null; endpoints = null; var source = IoKitUsb.GetDeviceAsyncEventSource(device); + IoKitUsb.USBDeviceClose(device); if (source.address() != 0) asyncTask.removeEventSource(source); - - IoKitUsb.USBDeviceClose(device); } synchronized void closeFully() { @@ -175,7 +182,7 @@ private void loadDescription(MemorySegment device) { if (ret != 0) throwException(ret, "querying device descriptor failed"); - var len = IOUSBDevRequest.wLenDone$get(deviceRequest); + var len = IOUSBDevRequest.wLenDone(deviceRequest); rawDeviceDescriptor = data.asSlice(0, len).toArray(JAVA_BYTE); configurationValue = 0; @@ -200,10 +207,10 @@ private InterfaceInfo findInterfaceInfo(int interfaceNumber) { try (var arena = Arena.ofConfined(); var outerCleanup = new ScopeCleanup()) { var request = IOUSBFindInterfaceRequest.allocate(arena); - IOUSBFindInterfaceRequest.bInterfaceClass$set(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); - IOUSBFindInterfaceRequest.bInterfaceSubClass$set(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); - IOUSBFindInterfaceRequest.bInterfaceProtocol$set(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); - IOUSBFindInterfaceRequest.bAlternateSetting$set(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); + IOUSBFindInterfaceRequest.bInterfaceClass(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); + IOUSBFindInterfaceRequest.bInterfaceSubClass(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); + IOUSBFindInterfaceRequest.bInterfaceProtocol(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); + IOUSBFindInterfaceRequest.bAlternateSetting(request, (short) IOKit.kIOUSBFindInterfaceDontCare()); var iterHolder = arena.allocate(JAVA_INT); var ret = IoKitUsb.CreateInterfaceIterator(device, request, iterHolder); @@ -381,12 +388,12 @@ private static MemorySegment createDeviceRequest(Arena arena, UsbDirection direc var deviceRequest = IOUSBDevRequest.allocate(arena); var bmRequestType = (direction == UsbDirection.IN ? 0x80 : 0x00) | (setup.requestType().ordinal() << 5) | setup.recipient().ordinal(); - IOUSBDevRequest.bmRequestType$set(deviceRequest, (byte) bmRequestType); - IOUSBDevRequest.bRequest$set(deviceRequest, (byte) setup.request()); - IOUSBDevRequest.wValue$set(deviceRequest, (short) setup.value()); - IOUSBDevRequest.wIndex$set(deviceRequest, (short) setup.index()); - IOUSBDevRequest.wLength$set(deviceRequest, (short) data.byteSize()); - IOUSBDevRequest.pData$set(deviceRequest, data); + IOUSBDevRequest.bmRequestType(deviceRequest, (byte) bmRequestType); + IOUSBDevRequest.bRequest(deviceRequest, (byte) setup.request()); + IOUSBDevRequest.wValue(deviceRequest, (short) setup.value()); + IOUSBDevRequest.wIndex(deviceRequest, (short) setup.index()); + IOUSBDevRequest.wLength(deviceRequest, (short) data.byteSize()); + IOUSBDevRequest.pData(deviceRequest, data); return deviceRequest; } @@ -434,7 +441,7 @@ public void transferOut(int endpointNumber, byte @NotNull [] data, int offset, i UsbTransferType.INTERRUPT); try (var arena = Arena.ofConfined()) { - var nativeData = arena.allocateArray(JAVA_BYTE, length); + var nativeData = arena.allocate(JAVA_BYTE, length); nativeData.copyFrom(MemorySegment.ofArray(data).asSlice(offset, length)); var transfer = new MacosTransfer(); @@ -464,7 +471,7 @@ public void transferOut(int endpointNumber, byte @NotNull [] data, int offset, i UsbTransferType.INTERRUPT); try (var arena = Arena.ofConfined()) { - var nativeData = arena.allocateArray(JAVA_BYTE, epInfo.packetSize()); + var nativeData = arena.allocate(JAVA_BYTE, epInfo.packetSize()); var transfer = new MacosTransfer(); transfer.setData(nativeData); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDeviceRegistry.java index dbb2ffc..36a9c5f 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDeviceRegistry.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbDeviceRegistry.java @@ -13,7 +13,11 @@ import net.codecrete.usb.macos.gen.corefoundation.CoreFoundation; import net.codecrete.usb.macos.gen.iokit.IOKit; -import java.lang.foreign.*; +import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Linker; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -22,7 +26,9 @@ import static java.lang.System.Logger.Level.INFO; import static java.lang.foreign.MemorySegment.NULL; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; import static net.codecrete.usb.macos.CoreFoundationHelper.createCFStringRef; import static net.codecrete.usb.macos.MacosUsbException.throwException; @@ -74,10 +80,10 @@ protected void monitorDevices() { try { // setup run loop, run loop source and notification port - var notifyPort = IOKit.IONotificationPortCreate(IOKit.kIOMasterPortDefault$get()); + var notifyPort = IOKit.IONotificationPortCreate(IOKit.kIOMasterPortDefault()); var runLoopSource = IOKit.IONotificationPortGetRunLoopSource(notifyPort); var runLoop = CoreFoundation.CFRunLoopGetCurrent(); - CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IOKit.kCFRunLoopDefaultMode$get()); + CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IOKit.kCFRunLoopDefaultMode()); // setup notification for connected devices var onDeviceConnectedMH = MethodHandles.lookup().findVirtual(MacosUsbDeviceRegistry.class, @@ -261,7 +267,7 @@ private void onDevicesConnected(MemorySegment ignoredRefCon, int iterator) { private void onDevicesDisconnected(MemorySegment ignoredRefCon, int iterator) { // process device iterator for disconnected devices - iterateDevices(iterator, (entryId, service, deviceIntf) -> { + iterateDevices(iterator, (entryId, _, _) -> { var device = findDevice(entryId); if (device == null) return; diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbException.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbException.java index 3f0c607..8731c61 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbException.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUsbException.java @@ -32,7 +32,7 @@ public MacosUsbException(String message, int errorCode) { private static String machErrorMessage(int errorCode) { var msg = mach.mach_error_string(errorCode); - return msg.getUtf8String(0); + return msg.getString(0); } /** diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFMessagePortCreateLocal$callout.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFMessagePortCreateLocal$callout.java new file mode 100644 index 0000000..df8fbed --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFMessagePortCreateLocal$callout.java @@ -0,0 +1,71 @@ +// Generated by jextract + +package net.codecrete.usb.macos.gen.corefoundation; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * CFMessagePortCallBack callout + * } + */ +public class CFMessagePortCreateLocal$callout { + + CFMessagePortCreateLocal$callout() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + MemorySegment apply(MemorySegment _x0, int _x1, MemorySegment _x2, MemorySegment _x3); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_INT, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = CoreFoundation.upcallHandle(CFMessagePortCreateLocal$callout.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CFMessagePortCreateLocal$callout.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1, MemorySegment _x2, MemorySegment _x3) { + try { + return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFRange.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFRange.java index f0f8887..07ec219 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFRange.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFRange.java @@ -2,84 +2,172 @@ package net.codecrete.usb.macos.gen.corefoundation; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct { * CFIndex location; * CFIndex length; - * }; + * } * } */ public class CFRange { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + CFRange() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + CoreFoundation.C_LONG.withName("location"), + CoreFoundation.C_LONG.withName("length") + ).withName("CFRange"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong location$LAYOUT = (OfLong)$LAYOUT.select(groupElement("location")); + + /** + * Layout for field: + * {@snippet lang=c : + * CFIndex location + * } + */ + public static final OfLong location$layout() { + return location$LAYOUT; } - public static VarHandle location$VH() { - return constants$0.const$1; + + private static final long location$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * CFIndex location + * } + */ + public static final long location$offset() { + return location$OFFSET; } + /** * Getter for field: - * {@snippet : - * CFIndex location; + * {@snippet lang=c : + * CFIndex location * } */ - public static long location$get(MemorySegment seg) { - return (long)constants$0.const$1.get(seg); + public static long location(MemorySegment struct) { + return struct.get(location$LAYOUT, location$OFFSET); } + /** * Setter for field: - * {@snippet : - * CFIndex location; + * {@snippet lang=c : + * CFIndex location * } */ - public static void location$set(MemorySegment seg, long x) { - constants$0.const$1.set(seg, x); + public static void location(MemorySegment struct, long fieldValue) { + struct.set(location$LAYOUT, location$OFFSET, fieldValue); } - public static long location$get(MemorySegment seg, long index) { - return (long)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void location$set(MemorySegment seg, long index, long x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong length$LAYOUT = (OfLong)$LAYOUT.select(groupElement("length")); + + /** + * Layout for field: + * {@snippet lang=c : + * CFIndex length + * } + */ + public static final OfLong length$layout() { + return length$LAYOUT; } - public static VarHandle length$VH() { - return constants$0.const$2; + + private static final long length$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * CFIndex length + * } + */ + public static final long length$offset() { + return length$OFFSET; } + /** * Getter for field: - * {@snippet : - * CFIndex length; + * {@snippet lang=c : + * CFIndex length * } */ - public static long length$get(MemorySegment seg) { - return (long)constants$0.const$2.get(seg); + public static long length(MemorySegment struct) { + return struct.get(length$LAYOUT, length$OFFSET); } + /** * Setter for field: - * {@snippet : - * CFIndex length; + * {@snippet lang=c : + * CFIndex length * } */ - public static void length$set(MemorySegment seg, long x) { - constants$0.const$2.set(seg, x); + public static void length(MemorySegment struct, long fieldValue) { + struct.set(length$LAYOUT, length$OFFSET, fieldValue); } - public static long length$get(MemorySegment seg, long index) { - return (long)constants$0.const$2.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void length$set(MemorySegment seg, long index, long x) { - constants$0.const$2.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFUUIDBytes.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFUUIDBytes.java index 26940ac..bcbb50a 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFUUIDBytes.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CFUUIDBytes.java @@ -2,13 +2,18 @@ package net.codecrete.usb.macos.gen.corefoundation; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct { * UInt8 byte0; * UInt8 byte1; @@ -26,452 +31,787 @@ * UInt8 byte13; * UInt8 byte14; * UInt8 byte15; - * }; + * } * } */ public class CFUUIDBytes { - public static MemoryLayout $LAYOUT() { - return constants$3.const$3; + CFUUIDBytes() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + CoreFoundation.C_CHAR.withName("byte0"), + CoreFoundation.C_CHAR.withName("byte1"), + CoreFoundation.C_CHAR.withName("byte2"), + CoreFoundation.C_CHAR.withName("byte3"), + CoreFoundation.C_CHAR.withName("byte4"), + CoreFoundation.C_CHAR.withName("byte5"), + CoreFoundation.C_CHAR.withName("byte6"), + CoreFoundation.C_CHAR.withName("byte7"), + CoreFoundation.C_CHAR.withName("byte8"), + CoreFoundation.C_CHAR.withName("byte9"), + CoreFoundation.C_CHAR.withName("byte10"), + CoreFoundation.C_CHAR.withName("byte11"), + CoreFoundation.C_CHAR.withName("byte12"), + CoreFoundation.C_CHAR.withName("byte13"), + CoreFoundation.C_CHAR.withName("byte14"), + CoreFoundation.C_CHAR.withName("byte15") + ).withName("CFUUIDBytes"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } - public static VarHandle byte0$VH() { - return constants$3.const$4; + + private static final OfByte byte0$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte0")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static final OfByte byte0$layout() { + return byte0$LAYOUT; + } + + private static final long byte0$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static final long byte0$offset() { + return byte0$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte0; + * {@snippet lang=c : + * UInt8 byte0 * } */ - public static byte byte0$get(MemorySegment seg) { - return (byte)constants$3.const$4.get(seg); + public static byte byte0(MemorySegment struct) { + return struct.get(byte0$LAYOUT, byte0$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte0; + * {@snippet lang=c : + * UInt8 byte0 * } */ - public static void byte0$set(MemorySegment seg, byte x) { - constants$3.const$4.set(seg, x); + public static void byte0(MemorySegment struct, byte fieldValue) { + struct.set(byte0$LAYOUT, byte0$OFFSET, fieldValue); } - public static byte byte0$get(MemorySegment seg, long index) { - return (byte)constants$3.const$4.get(seg.asSlice(index*sizeof())); - } - public static void byte0$set(MemorySegment seg, long index, byte x) { - constants$3.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte1$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte1")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static final OfByte byte1$layout() { + return byte1$LAYOUT; } - public static VarHandle byte1$VH() { - return constants$3.const$5; + + private static final long byte1$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static final long byte1$offset() { + return byte1$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte1; + * {@snippet lang=c : + * UInt8 byte1 * } */ - public static byte byte1$get(MemorySegment seg) { - return (byte)constants$3.const$5.get(seg); + public static byte byte1(MemorySegment struct) { + return struct.get(byte1$LAYOUT, byte1$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte1; + * {@snippet lang=c : + * UInt8 byte1 * } */ - public static void byte1$set(MemorySegment seg, byte x) { - constants$3.const$5.set(seg, x); + public static void byte1(MemorySegment struct, byte fieldValue) { + struct.set(byte1$LAYOUT, byte1$OFFSET, fieldValue); } - public static byte byte1$get(MemorySegment seg, long index) { - return (byte)constants$3.const$5.get(seg.asSlice(index*sizeof())); - } - public static void byte1$set(MemorySegment seg, long index, byte x) { - constants$3.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte2$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte2")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static final OfByte byte2$layout() { + return byte2$LAYOUT; } - public static VarHandle byte2$VH() { - return constants$4.const$0; + + private static final long byte2$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static final long byte2$offset() { + return byte2$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte2; + * {@snippet lang=c : + * UInt8 byte2 * } */ - public static byte byte2$get(MemorySegment seg) { - return (byte)constants$4.const$0.get(seg); + public static byte byte2(MemorySegment struct) { + return struct.get(byte2$LAYOUT, byte2$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte2; + * {@snippet lang=c : + * UInt8 byte2 * } */ - public static void byte2$set(MemorySegment seg, byte x) { - constants$4.const$0.set(seg, x); + public static void byte2(MemorySegment struct, byte fieldValue) { + struct.set(byte2$LAYOUT, byte2$OFFSET, fieldValue); } - public static byte byte2$get(MemorySegment seg, long index) { - return (byte)constants$4.const$0.get(seg.asSlice(index*sizeof())); - } - public static void byte2$set(MemorySegment seg, long index, byte x) { - constants$4.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte3$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte3")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static final OfByte byte3$layout() { + return byte3$LAYOUT; } - public static VarHandle byte3$VH() { - return constants$4.const$1; + + private static final long byte3$OFFSET = 3; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static final long byte3$offset() { + return byte3$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte3; + * {@snippet lang=c : + * UInt8 byte3 * } */ - public static byte byte3$get(MemorySegment seg) { - return (byte)constants$4.const$1.get(seg); + public static byte byte3(MemorySegment struct) { + return struct.get(byte3$LAYOUT, byte3$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte3; + * {@snippet lang=c : + * UInt8 byte3 * } */ - public static void byte3$set(MemorySegment seg, byte x) { - constants$4.const$1.set(seg, x); + public static void byte3(MemorySegment struct, byte fieldValue) { + struct.set(byte3$LAYOUT, byte3$OFFSET, fieldValue); } - public static byte byte3$get(MemorySegment seg, long index) { - return (byte)constants$4.const$1.get(seg.asSlice(index*sizeof())); - } - public static void byte3$set(MemorySegment seg, long index, byte x) { - constants$4.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte4$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte4")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static final OfByte byte4$layout() { + return byte4$LAYOUT; } - public static VarHandle byte4$VH() { - return constants$4.const$2; + + private static final long byte4$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static final long byte4$offset() { + return byte4$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte4; + * {@snippet lang=c : + * UInt8 byte4 * } */ - public static byte byte4$get(MemorySegment seg) { - return (byte)constants$4.const$2.get(seg); + public static byte byte4(MemorySegment struct) { + return struct.get(byte4$LAYOUT, byte4$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte4; + * {@snippet lang=c : + * UInt8 byte4 * } */ - public static void byte4$set(MemorySegment seg, byte x) { - constants$4.const$2.set(seg, x); - } - public static byte byte4$get(MemorySegment seg, long index) { - return (byte)constants$4.const$2.get(seg.asSlice(index*sizeof())); + public static void byte4(MemorySegment struct, byte fieldValue) { + struct.set(byte4$LAYOUT, byte4$OFFSET, fieldValue); } - public static void byte4$set(MemorySegment seg, long index, byte x) { - constants$4.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte5$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte5")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static final OfByte byte5$layout() { + return byte5$LAYOUT; } - public static VarHandle byte5$VH() { - return constants$4.const$3; + + private static final long byte5$OFFSET = 5; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static final long byte5$offset() { + return byte5$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte5; + * {@snippet lang=c : + * UInt8 byte5 * } */ - public static byte byte5$get(MemorySegment seg) { - return (byte)constants$4.const$3.get(seg); + public static byte byte5(MemorySegment struct) { + return struct.get(byte5$LAYOUT, byte5$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte5; + * {@snippet lang=c : + * UInt8 byte5 * } */ - public static void byte5$set(MemorySegment seg, byte x) { - constants$4.const$3.set(seg, x); - } - public static byte byte5$get(MemorySegment seg, long index) { - return (byte)constants$4.const$3.get(seg.asSlice(index*sizeof())); + public static void byte5(MemorySegment struct, byte fieldValue) { + struct.set(byte5$LAYOUT, byte5$OFFSET, fieldValue); } - public static void byte5$set(MemorySegment seg, long index, byte x) { - constants$4.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte6$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte6")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static final OfByte byte6$layout() { + return byte6$LAYOUT; } - public static VarHandle byte6$VH() { - return constants$4.const$4; + + private static final long byte6$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static final long byte6$offset() { + return byte6$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte6; + * {@snippet lang=c : + * UInt8 byte6 * } */ - public static byte byte6$get(MemorySegment seg) { - return (byte)constants$4.const$4.get(seg); + public static byte byte6(MemorySegment struct) { + return struct.get(byte6$LAYOUT, byte6$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte6; + * {@snippet lang=c : + * UInt8 byte6 * } */ - public static void byte6$set(MemorySegment seg, byte x) { - constants$4.const$4.set(seg, x); - } - public static byte byte6$get(MemorySegment seg, long index) { - return (byte)constants$4.const$4.get(seg.asSlice(index*sizeof())); + public static void byte6(MemorySegment struct, byte fieldValue) { + struct.set(byte6$LAYOUT, byte6$OFFSET, fieldValue); } - public static void byte6$set(MemorySegment seg, long index, byte x) { - constants$4.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte7$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte7")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static final OfByte byte7$layout() { + return byte7$LAYOUT; } - public static VarHandle byte7$VH() { - return constants$4.const$5; + + private static final long byte7$OFFSET = 7; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static final long byte7$offset() { + return byte7$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte7; + * {@snippet lang=c : + * UInt8 byte7 * } */ - public static byte byte7$get(MemorySegment seg) { - return (byte)constants$4.const$5.get(seg); + public static byte byte7(MemorySegment struct) { + return struct.get(byte7$LAYOUT, byte7$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte7; + * {@snippet lang=c : + * UInt8 byte7 * } */ - public static void byte7$set(MemorySegment seg, byte x) { - constants$4.const$5.set(seg, x); + public static void byte7(MemorySegment struct, byte fieldValue) { + struct.set(byte7$LAYOUT, byte7$OFFSET, fieldValue); } - public static byte byte7$get(MemorySegment seg, long index) { - return (byte)constants$4.const$5.get(seg.asSlice(index*sizeof())); - } - public static void byte7$set(MemorySegment seg, long index, byte x) { - constants$4.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte8$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte8")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static final OfByte byte8$layout() { + return byte8$LAYOUT; } - public static VarHandle byte8$VH() { - return constants$5.const$0; + + private static final long byte8$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static final long byte8$offset() { + return byte8$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte8; + * {@snippet lang=c : + * UInt8 byte8 * } */ - public static byte byte8$get(MemorySegment seg) { - return (byte)constants$5.const$0.get(seg); + public static byte byte8(MemorySegment struct) { + return struct.get(byte8$LAYOUT, byte8$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte8; + * {@snippet lang=c : + * UInt8 byte8 * } */ - public static void byte8$set(MemorySegment seg, byte x) { - constants$5.const$0.set(seg, x); + public static void byte8(MemorySegment struct, byte fieldValue) { + struct.set(byte8$LAYOUT, byte8$OFFSET, fieldValue); } - public static byte byte8$get(MemorySegment seg, long index) { - return (byte)constants$5.const$0.get(seg.asSlice(index*sizeof())); - } - public static void byte8$set(MemorySegment seg, long index, byte x) { - constants$5.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte9$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte9")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static final OfByte byte9$layout() { + return byte9$LAYOUT; } - public static VarHandle byte9$VH() { - return constants$5.const$1; + + private static final long byte9$OFFSET = 9; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static final long byte9$offset() { + return byte9$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte9; + * {@snippet lang=c : + * UInt8 byte9 * } */ - public static byte byte9$get(MemorySegment seg) { - return (byte)constants$5.const$1.get(seg); + public static byte byte9(MemorySegment struct) { + return struct.get(byte9$LAYOUT, byte9$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte9; + * {@snippet lang=c : + * UInt8 byte9 * } */ - public static void byte9$set(MemorySegment seg, byte x) { - constants$5.const$1.set(seg, x); + public static void byte9(MemorySegment struct, byte fieldValue) { + struct.set(byte9$LAYOUT, byte9$OFFSET, fieldValue); } - public static byte byte9$get(MemorySegment seg, long index) { - return (byte)constants$5.const$1.get(seg.asSlice(index*sizeof())); - } - public static void byte9$set(MemorySegment seg, long index, byte x) { - constants$5.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte10$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte10")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static final OfByte byte10$layout() { + return byte10$LAYOUT; } - public static VarHandle byte10$VH() { - return constants$5.const$2; + + private static final long byte10$OFFSET = 10; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static final long byte10$offset() { + return byte10$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte10; + * {@snippet lang=c : + * UInt8 byte10 * } */ - public static byte byte10$get(MemorySegment seg) { - return (byte)constants$5.const$2.get(seg); + public static byte byte10(MemorySegment struct) { + return struct.get(byte10$LAYOUT, byte10$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte10; + * {@snippet lang=c : + * UInt8 byte10 * } */ - public static void byte10$set(MemorySegment seg, byte x) { - constants$5.const$2.set(seg, x); + public static void byte10(MemorySegment struct, byte fieldValue) { + struct.set(byte10$LAYOUT, byte10$OFFSET, fieldValue); } - public static byte byte10$get(MemorySegment seg, long index) { - return (byte)constants$5.const$2.get(seg.asSlice(index*sizeof())); - } - public static void byte10$set(MemorySegment seg, long index, byte x) { - constants$5.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte11$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte11")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static final OfByte byte11$layout() { + return byte11$LAYOUT; } - public static VarHandle byte11$VH() { - return constants$5.const$3; + + private static final long byte11$OFFSET = 11; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static final long byte11$offset() { + return byte11$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte11; + * {@snippet lang=c : + * UInt8 byte11 * } */ - public static byte byte11$get(MemorySegment seg) { - return (byte)constants$5.const$3.get(seg); + public static byte byte11(MemorySegment struct) { + return struct.get(byte11$LAYOUT, byte11$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte11; + * {@snippet lang=c : + * UInt8 byte11 * } */ - public static void byte11$set(MemorySegment seg, byte x) { - constants$5.const$3.set(seg, x); + public static void byte11(MemorySegment struct, byte fieldValue) { + struct.set(byte11$LAYOUT, byte11$OFFSET, fieldValue); } - public static byte byte11$get(MemorySegment seg, long index) { - return (byte)constants$5.const$3.get(seg.asSlice(index*sizeof())); - } - public static void byte11$set(MemorySegment seg, long index, byte x) { - constants$5.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte12$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte12")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static final OfByte byte12$layout() { + return byte12$LAYOUT; } - public static VarHandle byte12$VH() { - return constants$5.const$4; + + private static final long byte12$OFFSET = 12; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static final long byte12$offset() { + return byte12$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte12; + * {@snippet lang=c : + * UInt8 byte12 * } */ - public static byte byte12$get(MemorySegment seg) { - return (byte)constants$5.const$4.get(seg); + public static byte byte12(MemorySegment struct) { + return struct.get(byte12$LAYOUT, byte12$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte12; + * {@snippet lang=c : + * UInt8 byte12 * } */ - public static void byte12$set(MemorySegment seg, byte x) { - constants$5.const$4.set(seg, x); - } - public static byte byte12$get(MemorySegment seg, long index) { - return (byte)constants$5.const$4.get(seg.asSlice(index*sizeof())); + public static void byte12(MemorySegment struct, byte fieldValue) { + struct.set(byte12$LAYOUT, byte12$OFFSET, fieldValue); } - public static void byte12$set(MemorySegment seg, long index, byte x) { - constants$5.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte13$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte13")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static final OfByte byte13$layout() { + return byte13$LAYOUT; } - public static VarHandle byte13$VH() { - return constants$5.const$5; + + private static final long byte13$OFFSET = 13; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static final long byte13$offset() { + return byte13$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte13; + * {@snippet lang=c : + * UInt8 byte13 * } */ - public static byte byte13$get(MemorySegment seg) { - return (byte)constants$5.const$5.get(seg); + public static byte byte13(MemorySegment struct) { + return struct.get(byte13$LAYOUT, byte13$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte13; + * {@snippet lang=c : + * UInt8 byte13 * } */ - public static void byte13$set(MemorySegment seg, byte x) { - constants$5.const$5.set(seg, x); + public static void byte13(MemorySegment struct, byte fieldValue) { + struct.set(byte13$LAYOUT, byte13$OFFSET, fieldValue); } - public static byte byte13$get(MemorySegment seg, long index) { - return (byte)constants$5.const$5.get(seg.asSlice(index*sizeof())); - } - public static void byte13$set(MemorySegment seg, long index, byte x) { - constants$5.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte14$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte14")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static final OfByte byte14$layout() { + return byte14$LAYOUT; } - public static VarHandle byte14$VH() { - return constants$6.const$0; + + private static final long byte14$OFFSET = 14; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static final long byte14$offset() { + return byte14$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte14; + * {@snippet lang=c : + * UInt8 byte14 * } */ - public static byte byte14$get(MemorySegment seg) { - return (byte)constants$6.const$0.get(seg); + public static byte byte14(MemorySegment struct) { + return struct.get(byte14$LAYOUT, byte14$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte14; + * {@snippet lang=c : + * UInt8 byte14 * } */ - public static void byte14$set(MemorySegment seg, byte x) { - constants$6.const$0.set(seg, x); + public static void byte14(MemorySegment struct, byte fieldValue) { + struct.set(byte14$LAYOUT, byte14$OFFSET, fieldValue); } - public static byte byte14$get(MemorySegment seg, long index) { - return (byte)constants$6.const$0.get(seg.asSlice(index*sizeof())); - } - public static void byte14$set(MemorySegment seg, long index, byte x) { - constants$6.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte byte15$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte15")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static final OfByte byte15$layout() { + return byte15$LAYOUT; } - public static VarHandle byte15$VH() { - return constants$6.const$1; + + private static final long byte15$OFFSET = 15; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static final long byte15$offset() { + return byte15$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 byte15; + * {@snippet lang=c : + * UInt8 byte15 * } */ - public static byte byte15$get(MemorySegment seg) { - return (byte)constants$6.const$1.get(seg); + public static byte byte15(MemorySegment struct) { + return struct.get(byte15$LAYOUT, byte15$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 byte15; + * {@snippet lang=c : + * UInt8 byte15 * } */ - public static void byte15$set(MemorySegment seg, byte x) { - constants$6.const$1.set(seg, x); + public static void byte15(MemorySegment struct, byte fieldValue) { + struct.set(byte15$LAYOUT, byte15$OFFSET, fieldValue); } - public static byte byte15$get(MemorySegment seg, long index) { - return (byte)constants$6.const$1.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void byte15$set(MemorySegment seg, long index, byte x) { - constants$6.const$1.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CoreFoundation.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CoreFoundation.java index 3b1c3e5..0413e52 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CoreFoundation.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/CoreFoundation.java @@ -2,254 +2,1034 @@ package net.codecrete.usb.macos.gen.corefoundation; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class CoreFoundation { +import static java.lang.foreign.MemoryLayout.PathElement.*; - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle CFGetTypeID$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$4,"CFGetTypeID"); +public class CoreFoundation { + + CoreFoundation() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + + private static class CFGetTypeID { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_LONG, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFGetTypeID"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFTypeID CFGetTypeID(CFTypeRef cf) + * } + */ + public static FunctionDescriptor CFGetTypeID$descriptor() { + return CFGetTypeID.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFTypeID CFGetTypeID(CFTypeRef cf) + * } + */ + public static MethodHandle CFGetTypeID$handle() { + return CFGetTypeID.HANDLE; } /** - * {@snippet : - * CFTypeID CFGetTypeID(CFTypeRef cf); + * {@snippet lang=c : + * extern CFTypeID CFGetTypeID(CFTypeRef cf) * } */ public static long CFGetTypeID(MemorySegment cf) { - var mh$ = CFGetTypeID$MH(); + var mh$ = CFGetTypeID.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFGetTypeID", cf); + } return (long)mh$.invokeExact(cf); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFRelease$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$6,"CFRelease"); + + private static class CFRelease { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFRelease"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern void CFRelease(CFTypeRef cf) + * } + */ + public static FunctionDescriptor CFRelease$descriptor() { + return CFRelease.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern void CFRelease(CFTypeRef cf) + * } + */ + public static MethodHandle CFRelease$handle() { + return CFRelease.HANDLE; } /** - * {@snippet : - * void CFRelease(CFTypeRef cf); + * {@snippet lang=c : + * extern void CFRelease(CFTypeRef cf) * } */ public static void CFRelease(MemorySegment cf) { - var mh$ = CFRelease$MH(); + var mh$ = CFRelease.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFRelease", cf); + } mh$.invokeExact(cf); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CFDataCreate { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_LONG + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFDataCreate"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFDataRef CFDataCreate(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length) + * } + */ + public static FunctionDescriptor CFDataCreate$descriptor() { + return CFDataCreate.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFDataRef CFDataCreate(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length) + * } + */ + public static MethodHandle CFDataCreate$handle() { + return CFDataCreate.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFDataRef CFDataCreate(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length) + * } + */ + public static MemorySegment CFDataCreate(MemorySegment allocator, MemorySegment bytes, long length) { + var mh$ = CFDataCreate.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFDataCreate", allocator, bytes, length); + } + return (MemorySegment)mh$.invokeExact(allocator, bytes, length); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CFDataGetBytePtr { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFDataGetBytePtr"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern const UInt8 *CFDataGetBytePtr(CFDataRef theData) + * } + */ + public static FunctionDescriptor CFDataGetBytePtr$descriptor() { + return CFDataGetBytePtr.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern const UInt8 *CFDataGetBytePtr(CFDataRef theData) + * } + */ + public static MethodHandle CFDataGetBytePtr$handle() { + return CFDataGetBytePtr.HANDLE; + } + /** + * {@snippet lang=c : + * extern const UInt8 *CFDataGetBytePtr(CFDataRef theData) + * } + */ + public static MemorySegment CFDataGetBytePtr(MemorySegment theData) { + var mh$ = CFDataGetBytePtr.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFDataGetBytePtr", theData); + } + return (MemorySegment)mh$.invokeExact(theData); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFStringGetTypeID$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$1,"CFStringGetTypeID"); + + private static class CFStringGetTypeID { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_LONG ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFStringGetTypeID"), + DESC); } + /** - * {@snippet : - * CFTypeID CFStringGetTypeID(); + * Function descriptor for: + * {@snippet lang=c : + * extern CFTypeID CFStringGetTypeID(void) + * } + */ + public static FunctionDescriptor CFStringGetTypeID$descriptor() { + return CFStringGetTypeID.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFTypeID CFStringGetTypeID(void) + * } + */ + public static MethodHandle CFStringGetTypeID$handle() { + return CFStringGetTypeID.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFTypeID CFStringGetTypeID(void) * } */ public static long CFStringGetTypeID() { - var mh$ = CFStringGetTypeID$MH(); + var mh$ = CFStringGetTypeID.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFStringGetTypeID"); + } return (long)mh$.invokeExact(); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFStringCreateWithCharacters$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$3,"CFStringCreateWithCharacters"); + + private static class CFStringCreateWithCharacters { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_LONG + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFStringCreateWithCharacters"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars) + * } + */ + public static FunctionDescriptor CFStringCreateWithCharacters$descriptor() { + return CFStringCreateWithCharacters.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars) + * } + */ + public static MethodHandle CFStringCreateWithCharacters$handle() { + return CFStringCreateWithCharacters.HANDLE; } /** - * {@snippet : - * CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar* chars, CFIndex numChars); + * {@snippet lang=c : + * extern CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars) * } */ public static MemorySegment CFStringCreateWithCharacters(MemorySegment alloc, MemorySegment chars, long numChars) { - var mh$ = CFStringCreateWithCharacters$MH(); + var mh$ = CFStringCreateWithCharacters.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(alloc, chars, numChars); + if (TRACE_DOWNCALLS) { + traceDowncall("CFStringCreateWithCharacters", alloc, chars, numChars); + } + return (MemorySegment)mh$.invokeExact(alloc, chars, numChars); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFStringGetLength$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$4,"CFStringGetLength"); + + private static class CFStringGetLength { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_LONG, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFStringGetLength"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFIndex CFStringGetLength(CFStringRef theString) + * } + */ + public static FunctionDescriptor CFStringGetLength$descriptor() { + return CFStringGetLength.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFIndex CFStringGetLength(CFStringRef theString) + * } + */ + public static MethodHandle CFStringGetLength$handle() { + return CFStringGetLength.HANDLE; } /** - * {@snippet : - * CFIndex CFStringGetLength(CFStringRef theString); + * {@snippet lang=c : + * extern CFIndex CFStringGetLength(CFStringRef theString) * } */ public static long CFStringGetLength(MemorySegment theString) { - var mh$ = CFStringGetLength$MH(); + var mh$ = CFStringGetLength.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFStringGetLength", theString); + } return (long)mh$.invokeExact(theString); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFStringGetCharacters$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$6,"CFStringGetCharacters"); + + private static class CFStringGetCharacters { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + CoreFoundation.C_POINTER, + CFRange.layout(), + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFStringGetCharacters"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer) + * } + */ + public static FunctionDescriptor CFStringGetCharacters$descriptor() { + return CFStringGetCharacters.DESC; } + /** - * {@snippet : - * void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar* buffer); + * Downcall method handle for: + * {@snippet lang=c : + * extern void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer) + * } + */ + public static MethodHandle CFStringGetCharacters$handle() { + return CFStringGetCharacters.HANDLE; + } + /** + * {@snippet lang=c : + * extern void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer) * } */ public static void CFStringGetCharacters(MemorySegment theString, MemorySegment range, MemorySegment buffer) { - var mh$ = CFStringGetCharacters$MH(); + var mh$ = CFStringGetCharacters.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFStringGetCharacters", theString, range, buffer); + } mh$.invokeExact(theString, range, buffer); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } + private static final int kCFNumberSInt32Type = (int)3L; /** - * {@snippet : - * enum .kCFNumberSInt32Type = 3; + * {@snippet lang=c : + * enum enum (unnamed at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFNumber.h:31:9).kCFNumberSInt32Type = 3 * } */ public static int kCFNumberSInt32Type() { - return (int)3L; + return kCFNumberSInt32Type; + } + + private static class CFNumberGetTypeID { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_LONG ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFNumberGetTypeID"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFTypeID CFNumberGetTypeID(void) + * } + */ + public static FunctionDescriptor CFNumberGetTypeID$descriptor() { + return CFNumberGetTypeID.DESC; } - public static MethodHandle CFNumberGetTypeID$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$0,"CFNumberGetTypeID"); + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFTypeID CFNumberGetTypeID(void) + * } + */ + public static MethodHandle CFNumberGetTypeID$handle() { + return CFNumberGetTypeID.HANDLE; } /** - * {@snippet : - * CFTypeID CFNumberGetTypeID(); + * {@snippet lang=c : + * extern CFTypeID CFNumberGetTypeID(void) * } */ public static long CFNumberGetTypeID() { - var mh$ = CFNumberGetTypeID$MH(); + var mh$ = CFNumberGetTypeID.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFNumberGetTypeID"); + } return (long)mh$.invokeExact(); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFNumberGetValue$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$2,"CFNumberGetValue"); + + private static class CFNumberGetValue { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_CHAR, + CoreFoundation.C_POINTER, + CoreFoundation.C_LONG, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFNumberGetValue"), + DESC); } + /** - * {@snippet : - * Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void* valuePtr); + * Function descriptor for: + * {@snippet lang=c : + * extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr) + * } + */ + public static FunctionDescriptor CFNumberGetValue$descriptor() { + return CFNumberGetValue.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr) + * } + */ + public static MethodHandle CFNumberGetValue$handle() { + return CFNumberGetValue.HANDLE; + } + /** + * {@snippet lang=c : + * extern Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr) * } */ public static byte CFNumberGetValue(MemorySegment number, long theType, MemorySegment valuePtr) { - var mh$ = CFNumberGetValue$MH(); + var mh$ = CFNumberGetValue.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFNumberGetValue", number, theType, valuePtr); + } return (byte)mh$.invokeExact(number, theType, valuePtr); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFRunLoopGetCurrent$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$4,"CFRunLoopGetCurrent"); + + private static class CFRunLoopGetCurrent { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFRunLoopGetCurrent"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFRunLoopRef CFRunLoopGetCurrent(void) + * } + */ + public static FunctionDescriptor CFRunLoopGetCurrent$descriptor() { + return CFRunLoopGetCurrent.DESC; } + /** - * {@snippet : - * CFRunLoopRef CFRunLoopGetCurrent(); + * Downcall method handle for: + * {@snippet lang=c : + * extern CFRunLoopRef CFRunLoopGetCurrent(void) + * } + */ + public static MethodHandle CFRunLoopGetCurrent$handle() { + return CFRunLoopGetCurrent.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFRunLoopRef CFRunLoopGetCurrent(void) * } */ public static MemorySegment CFRunLoopGetCurrent() { - var mh$ = CFRunLoopGetCurrent$MH(); + var mh$ = CFRunLoopGetCurrent.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(); + if (TRACE_DOWNCALLS) { + traceDowncall("CFRunLoopGetCurrent"); + } + return (MemorySegment)mh$.invokeExact(); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFRunLoopRun$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$6,"CFRunLoopRun"); + + private static class CFRunLoopRun { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFRunLoopRun"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern void CFRunLoopRun(void) + * } + */ + public static FunctionDescriptor CFRunLoopRun$descriptor() { + return CFRunLoopRun.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern void CFRunLoopRun(void) + * } + */ + public static MethodHandle CFRunLoopRun$handle() { + return CFRunLoopRun.HANDLE; } /** - * {@snippet : - * void CFRunLoopRun(); + * {@snippet lang=c : + * extern void CFRunLoopRun(void) * } */ public static void CFRunLoopRun() { - var mh$ = CFRunLoopRun$MH(); + var mh$ = CFRunLoopRun.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFRunLoopRun"); + } mh$.invokeExact(); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFRunLoopAddSource$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$1,"CFRunLoopAddSource"); + + private static class CFRunLoopAddSource { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFRunLoopAddSource"), + DESC); } + /** - * {@snippet : - * void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode); + * Function descriptor for: + * {@snippet lang=c : + * extern void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) + * } + */ + public static FunctionDescriptor CFRunLoopAddSource$descriptor() { + return CFRunLoopAddSource.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) + * } + */ + public static MethodHandle CFRunLoopAddSource$handle() { + return CFRunLoopAddSource.HANDLE; + } + /** + * {@snippet lang=c : + * extern void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) * } */ public static void CFRunLoopAddSource(MemorySegment rl, MemorySegment source, MemorySegment mode) { - var mh$ = CFRunLoopAddSource$MH(); + var mh$ = CFRunLoopAddSource.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFRunLoopAddSource", rl, source, mode); + } mh$.invokeExact(rl, source, mode); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFRunLoopRemoveSource$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$2,"CFRunLoopRemoveSource"); + + private static class CFRunLoopRemoveSource { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFRunLoopRemoveSource"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) + * } + */ + public static FunctionDescriptor CFRunLoopRemoveSource$descriptor() { + return CFRunLoopRemoveSource.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) + * } + */ + public static MethodHandle CFRunLoopRemoveSource$handle() { + return CFRunLoopRemoveSource.HANDLE; } /** - * {@snippet : - * void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode); + * {@snippet lang=c : + * extern void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode) * } */ public static void CFRunLoopRemoveSource(MemorySegment rl, MemorySegment source, MemorySegment mode) { - var mh$ = CFRunLoopRemoveSource$MH(); + var mh$ = CFRunLoopRemoveSource.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFRunLoopRemoveSource", rl, source, mode); + } mh$.invokeExact(rl, source, mode); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFUUIDGetUUIDBytes$MH() { - return RuntimeHelper.requireNonNull(constants$6.const$3,"CFUUIDGetUUIDBytes"); + + private static class CFUUIDGetUUIDBytes { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CFUUIDBytes.layout(), + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFUUIDGetUUIDBytes"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFUUIDBytes CFUUIDGetUUIDBytes(CFUUIDRef uuid) + * } + */ + public static FunctionDescriptor CFUUIDGetUUIDBytes$descriptor() { + return CFUUIDGetUUIDBytes.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFUUIDBytes CFUUIDGetUUIDBytes(CFUUIDRef uuid) + * } + */ + public static MethodHandle CFUUIDGetUUIDBytes$handle() { + return CFUUIDGetUUIDBytes.HANDLE; } /** - * {@snippet : - * CFUUIDBytes CFUUIDGetUUIDBytes(CFUUIDRef uuid); + * {@snippet lang=c : + * extern CFUUIDBytes CFUUIDGetUUIDBytes(CFUUIDRef uuid) * } */ public static MemorySegment CFUUIDGetUUIDBytes(SegmentAllocator allocator, MemorySegment uuid) { - var mh$ = CFUUIDGetUUIDBytes$MH(); + var mh$ = CFUUIDGetUUIDBytes.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(allocator, uuid); + if (TRACE_DOWNCALLS) { + traceDowncall("CFUUIDGetUUIDBytes", allocator, uuid); + } + return (MemorySegment)mh$.invokeExact(allocator, uuid); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle CFUUIDCreateFromUUIDBytes$MH() { - return RuntimeHelper.requireNonNull(constants$6.const$5,"CFUUIDCreateFromUUIDBytes"); + + private static class CFUUIDCreateFromUUIDBytes { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CFUUIDBytes.layout() + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFUUIDCreateFromUUIDBytes"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes) + * } + */ + public static FunctionDescriptor CFUUIDCreateFromUUIDBytes$descriptor() { + return CFUUIDCreateFromUUIDBytes.DESC; } + /** - * {@snippet : - * CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes); + * Downcall method handle for: + * {@snippet lang=c : + * extern CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes) + * } + */ + public static MethodHandle CFUUIDCreateFromUUIDBytes$handle() { + return CFUUIDCreateFromUUIDBytes.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes) * } */ public static MemorySegment CFUUIDCreateFromUUIDBytes(MemorySegment alloc, MemorySegment bytes) { - var mh$ = CFUUIDCreateFromUUIDBytes$MH(); + var mh$ = CFUUIDCreateFromUUIDBytes.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(alloc, bytes); + if (TRACE_DOWNCALLS) { + traceDowncall("CFUUIDCreateFromUUIDBytes", alloc, bytes); + } + return (MemorySegment)mh$.invokeExact(alloc, bytes); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } -} + private static class CFMessagePortCreateLocal { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFMessagePortCreateLocal"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateLocal(CFAllocatorRef allocator, CFStringRef name, CFMessagePortCallBack callout, CFMessagePortContext *context, Boolean *shouldFreeInfo) + * } + */ + public static FunctionDescriptor CFMessagePortCreateLocal$descriptor() { + return CFMessagePortCreateLocal.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateLocal(CFAllocatorRef allocator, CFStringRef name, CFMessagePortCallBack callout, CFMessagePortContext *context, Boolean *shouldFreeInfo) + * } + */ + public static MethodHandle CFMessagePortCreateLocal$handle() { + return CFMessagePortCreateLocal.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateLocal(CFAllocatorRef allocator, CFStringRef name, CFMessagePortCallBack callout, CFMessagePortContext *context, Boolean *shouldFreeInfo) + * } + */ + public static MemorySegment CFMessagePortCreateLocal(MemorySegment allocator, MemorySegment name, MemorySegment callout, MemorySegment context, MemorySegment shouldFreeInfo) { + var mh$ = CFMessagePortCreateLocal.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFMessagePortCreateLocal", allocator, name, callout, context, shouldFreeInfo); + } + return (MemorySegment)mh$.invokeExact(allocator, name, callout, context, shouldFreeInfo); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CFMessagePortCreateRemote { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFMessagePortCreateRemote"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateRemote(CFAllocatorRef allocator, CFStringRef name) + * } + */ + public static FunctionDescriptor CFMessagePortCreateRemote$descriptor() { + return CFMessagePortCreateRemote.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateRemote(CFAllocatorRef allocator, CFStringRef name) + * } + */ + public static MethodHandle CFMessagePortCreateRemote$handle() { + return CFMessagePortCreateRemote.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFMessagePortRef CFMessagePortCreateRemote(CFAllocatorRef allocator, CFStringRef name) + * } + */ + public static MemorySegment CFMessagePortCreateRemote(MemorySegment allocator, MemorySegment name) { + var mh$ = CFMessagePortCreateRemote.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFMessagePortCreateRemote", allocator, name); + } + return (MemorySegment)mh$.invokeExact(allocator, name); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CFMessagePortSendRequest { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_INT, + CoreFoundation.C_POINTER, + CoreFoundation.C_INT, + CoreFoundation.C_POINTER, + CoreFoundation.C_DOUBLE, + CoreFoundation.C_DOUBLE, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFMessagePortSendRequest"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern SInt32 CFMessagePortSendRequest(CFMessagePortRef remote, SInt32 msgid, CFDataRef data, CFTimeInterval sendTimeout, CFTimeInterval rcvTimeout, CFStringRef replyMode, CFDataRef *returnData) + * } + */ + public static FunctionDescriptor CFMessagePortSendRequest$descriptor() { + return CFMessagePortSendRequest.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern SInt32 CFMessagePortSendRequest(CFMessagePortRef remote, SInt32 msgid, CFDataRef data, CFTimeInterval sendTimeout, CFTimeInterval rcvTimeout, CFStringRef replyMode, CFDataRef *returnData) + * } + */ + public static MethodHandle CFMessagePortSendRequest$handle() { + return CFMessagePortSendRequest.HANDLE; + } + /** + * {@snippet lang=c : + * extern SInt32 CFMessagePortSendRequest(CFMessagePortRef remote, SInt32 msgid, CFDataRef data, CFTimeInterval sendTimeout, CFTimeInterval rcvTimeout, CFStringRef replyMode, CFDataRef *returnData) + * } + */ + public static int CFMessagePortSendRequest(MemorySegment remote, int msgid, MemorySegment data, double sendTimeout, double rcvTimeout, MemorySegment replyMode, MemorySegment returnData) { + var mh$ = CFMessagePortSendRequest.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFMessagePortSendRequest", remote, msgid, data, sendTimeout, rcvTimeout, replyMode, returnData); + } + return (int)mh$.invokeExact(remote, msgid, data, sendTimeout, rcvTimeout, replyMode, returnData); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CFMessagePortCreateRunLoopSource { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_POINTER, + CoreFoundation.C_LONG + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + CoreFoundation.findOrThrow("CFMessagePortCreateRunLoopSource"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern CFRunLoopSourceRef CFMessagePortCreateRunLoopSource(CFAllocatorRef allocator, CFMessagePortRef local, CFIndex order) + * } + */ + public static FunctionDescriptor CFMessagePortCreateRunLoopSource$descriptor() { + return CFMessagePortCreateRunLoopSource.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern CFRunLoopSourceRef CFMessagePortCreateRunLoopSource(CFAllocatorRef allocator, CFMessagePortRef local, CFIndex order) + * } + */ + public static MethodHandle CFMessagePortCreateRunLoopSource$handle() { + return CFMessagePortCreateRunLoopSource.HANDLE; + } + /** + * {@snippet lang=c : + * extern CFRunLoopSourceRef CFMessagePortCreateRunLoopSource(CFAllocatorRef allocator, CFMessagePortRef local, CFIndex order) + * } + */ + public static MemorySegment CFMessagePortCreateRunLoopSource(MemorySegment allocator, MemorySegment local, long order) { + var mh$ = CFMessagePortCreateRunLoopSource.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CFMessagePortCreateRunLoopSource", allocator, local, order); + } + return (MemorySegment)mh$.invokeExact(allocator, local, order); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/RuntimeHelper.java deleted file mode 100644 index 69967de..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/RuntimeHelper.java +++ /dev/null @@ -1,228 +0,0 @@ -package net.codecrete.usb.macos.gen.corefoundation; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { -// System.loadLibrary("CoreFoundation.framework"); -// SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SymbolLookup loaderLookup = SymbolLookup.libraryLookup("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", Arena.global()); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$0.java deleted file mode 100644 index ec347d5..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$0.java +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_LONG.withName("location"), - JAVA_LONG.withName("length") - ).withName(""); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("location")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("length")); - static final FunctionDescriptor const$3 = FunctionDescriptor.of(JAVA_LONG, - RuntimeHelper.POINTER - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "CFGetTypeID", - constants$0.const$3 - ); - static final FunctionDescriptor const$5 = FunctionDescriptor.ofVoid( - RuntimeHelper.POINTER - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "CFRelease", - constants$0.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$1.java deleted file mode 100644 index d7550d1..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$1.java +++ /dev/null @@ -1,46 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_LONG); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "CFStringGetTypeID", - constants$1.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - JAVA_LONG - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "CFStringCreateWithCharacters", - constants$1.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "CFStringGetLength", - constants$0.const$3 - ); - static final FunctionDescriptor const$5 = FunctionDescriptor.ofVoid( - RuntimeHelper.POINTER, - MemoryLayout.structLayout( - JAVA_LONG.withName("location"), - JAVA_LONG.withName("length") - ).withName(""), - RuntimeHelper.POINTER - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "CFStringGetCharacters", - constants$1.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$2.java deleted file mode 100644 index 7db1c6c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$2.java +++ /dev/null @@ -1,39 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - "CFNumberGetTypeID", - constants$1.const$0 - ); - static final FunctionDescriptor const$1 = FunctionDescriptor.of(JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_LONG, - RuntimeHelper.POINTER - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "CFNumberGetValue", - constants$2.const$1 - ); - static final FunctionDescriptor const$3 = FunctionDescriptor.of(RuntimeHelper.POINTER); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "CFRunLoopGetCurrent", - constants$2.const$3 - ); - static final FunctionDescriptor const$5 = FunctionDescriptor.ofVoid(); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "CFRunLoopRun", - constants$2.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$3.java deleted file mode 100644 index 1a0a9ed..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$3.java +++ /dev/null @@ -1,51 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -final class constants$3 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$3() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.ofVoid( - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "CFRunLoopAddSource", - constants$3.const$0 - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "CFRunLoopRemoveSource", - constants$3.const$0 - ); - static final StructLayout const$3 = MemoryLayout.structLayout( - JAVA_BYTE.withName("byte0"), - JAVA_BYTE.withName("byte1"), - JAVA_BYTE.withName("byte2"), - JAVA_BYTE.withName("byte3"), - JAVA_BYTE.withName("byte4"), - JAVA_BYTE.withName("byte5"), - JAVA_BYTE.withName("byte6"), - JAVA_BYTE.withName("byte7"), - JAVA_BYTE.withName("byte8"), - JAVA_BYTE.withName("byte9"), - JAVA_BYTE.withName("byte10"), - JAVA_BYTE.withName("byte11"), - JAVA_BYTE.withName("byte12"), - JAVA_BYTE.withName("byte13"), - JAVA_BYTE.withName("byte14"), - JAVA_BYTE.withName("byte15") - ).withName(""); - static final VarHandle const$4 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte0")); - static final VarHandle const$5 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte1")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$4.java deleted file mode 100644 index 52637eb..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$4.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$4 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$4() {} - static final VarHandle const$0 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte2")); - static final VarHandle const$1 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte3")); - static final VarHandle const$2 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte4")); - static final VarHandle const$3 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte5")); - static final VarHandle const$4 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte6")); - static final VarHandle const$5 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte7")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$5.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$5.java deleted file mode 100644 index 075afe3..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$5.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$5 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$5() {} - static final VarHandle const$0 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte8")); - static final VarHandle const$1 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte9")); - static final VarHandle const$2 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte10")); - static final VarHandle const$3 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte11")); - static final VarHandle const$4 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte12")); - static final VarHandle const$5 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte13")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$6.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$6.java deleted file mode 100644 index 748e65c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/corefoundation/constants$6.java +++ /dev/null @@ -1,68 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.corefoundation; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -final class constants$6 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$6() {} - static final VarHandle const$0 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte14")); - static final VarHandle const$1 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("byte15")); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(MemoryLayout.structLayout( - JAVA_BYTE.withName("byte0"), - JAVA_BYTE.withName("byte1"), - JAVA_BYTE.withName("byte2"), - JAVA_BYTE.withName("byte3"), - JAVA_BYTE.withName("byte4"), - JAVA_BYTE.withName("byte5"), - JAVA_BYTE.withName("byte6"), - JAVA_BYTE.withName("byte7"), - JAVA_BYTE.withName("byte8"), - JAVA_BYTE.withName("byte9"), - JAVA_BYTE.withName("byte10"), - JAVA_BYTE.withName("byte11"), - JAVA_BYTE.withName("byte12"), - JAVA_BYTE.withName("byte13"), - JAVA_BYTE.withName("byte14"), - JAVA_BYTE.withName("byte15") - ).withName(""), - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "CFUUIDGetUUIDBytes", - constants$6.const$2 - ); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - MemoryLayout.structLayout( - JAVA_BYTE.withName("byte0"), - JAVA_BYTE.withName("byte1"), - JAVA_BYTE.withName("byte2"), - JAVA_BYTE.withName("byte3"), - JAVA_BYTE.withName("byte4"), - JAVA_BYTE.withName("byte5"), - JAVA_BYTE.withName("byte6"), - JAVA_BYTE.withName("byte7"), - JAVA_BYTE.withName("byte8"), - JAVA_BYTE.withName("byte9"), - JAVA_BYTE.withName("byte10"), - JAVA_BYTE.withName("byte11"), - JAVA_BYTE.withName("byte12"), - JAVA_BYTE.withName("byte13"), - JAVA_BYTE.withName("byte14"), - JAVA_BYTE.withName("byte15") - ).withName("") - ); - static final MethodHandle const$5 = RuntimeHelper.downcallHandle( - "CFUUIDCreateFromUUIDBytes", - constants$6.const$4 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/CFUUIDBytes.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/CFUUIDBytes.java new file mode 100644 index 0000000..4885f49 --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/CFUUIDBytes.java @@ -0,0 +1,817 @@ +// Generated by jextract + +package net.codecrete.usb.macos.gen.iokit; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct { + * UInt8 byte0; + * UInt8 byte1; + * UInt8 byte2; + * UInt8 byte3; + * UInt8 byte4; + * UInt8 byte5; + * UInt8 byte6; + * UInt8 byte7; + * UInt8 byte8; + * UInt8 byte9; + * UInt8 byte10; + * UInt8 byte11; + * UInt8 byte12; + * UInt8 byte13; + * UInt8 byte14; + * UInt8 byte15; + * } + * } + */ +public class CFUUIDBytes { + + CFUUIDBytes() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_CHAR.withName("byte0"), + IOKit.C_CHAR.withName("byte1"), + IOKit.C_CHAR.withName("byte2"), + IOKit.C_CHAR.withName("byte3"), + IOKit.C_CHAR.withName("byte4"), + IOKit.C_CHAR.withName("byte5"), + IOKit.C_CHAR.withName("byte6"), + IOKit.C_CHAR.withName("byte7"), + IOKit.C_CHAR.withName("byte8"), + IOKit.C_CHAR.withName("byte9"), + IOKit.C_CHAR.withName("byte10"), + IOKit.C_CHAR.withName("byte11"), + IOKit.C_CHAR.withName("byte12"), + IOKit.C_CHAR.withName("byte13"), + IOKit.C_CHAR.withName("byte14"), + IOKit.C_CHAR.withName("byte15") + ).withName("CFUUIDBytes"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte byte0$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte0")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static final OfByte byte0$layout() { + return byte0$LAYOUT; + } + + private static final long byte0$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static final long byte0$offset() { + return byte0$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static byte byte0(MemorySegment struct) { + return struct.get(byte0$LAYOUT, byte0$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte0 + * } + */ + public static void byte0(MemorySegment struct, byte fieldValue) { + struct.set(byte0$LAYOUT, byte0$OFFSET, fieldValue); + } + + private static final OfByte byte1$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte1")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static final OfByte byte1$layout() { + return byte1$LAYOUT; + } + + private static final long byte1$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static final long byte1$offset() { + return byte1$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static byte byte1(MemorySegment struct) { + return struct.get(byte1$LAYOUT, byte1$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte1 + * } + */ + public static void byte1(MemorySegment struct, byte fieldValue) { + struct.set(byte1$LAYOUT, byte1$OFFSET, fieldValue); + } + + private static final OfByte byte2$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte2")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static final OfByte byte2$layout() { + return byte2$LAYOUT; + } + + private static final long byte2$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static final long byte2$offset() { + return byte2$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static byte byte2(MemorySegment struct) { + return struct.get(byte2$LAYOUT, byte2$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte2 + * } + */ + public static void byte2(MemorySegment struct, byte fieldValue) { + struct.set(byte2$LAYOUT, byte2$OFFSET, fieldValue); + } + + private static final OfByte byte3$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte3")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static final OfByte byte3$layout() { + return byte3$LAYOUT; + } + + private static final long byte3$OFFSET = 3; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static final long byte3$offset() { + return byte3$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static byte byte3(MemorySegment struct) { + return struct.get(byte3$LAYOUT, byte3$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte3 + * } + */ + public static void byte3(MemorySegment struct, byte fieldValue) { + struct.set(byte3$LAYOUT, byte3$OFFSET, fieldValue); + } + + private static final OfByte byte4$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte4")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static final OfByte byte4$layout() { + return byte4$LAYOUT; + } + + private static final long byte4$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static final long byte4$offset() { + return byte4$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static byte byte4(MemorySegment struct) { + return struct.get(byte4$LAYOUT, byte4$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte4 + * } + */ + public static void byte4(MemorySegment struct, byte fieldValue) { + struct.set(byte4$LAYOUT, byte4$OFFSET, fieldValue); + } + + private static final OfByte byte5$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte5")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static final OfByte byte5$layout() { + return byte5$LAYOUT; + } + + private static final long byte5$OFFSET = 5; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static final long byte5$offset() { + return byte5$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static byte byte5(MemorySegment struct) { + return struct.get(byte5$LAYOUT, byte5$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte5 + * } + */ + public static void byte5(MemorySegment struct, byte fieldValue) { + struct.set(byte5$LAYOUT, byte5$OFFSET, fieldValue); + } + + private static final OfByte byte6$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte6")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static final OfByte byte6$layout() { + return byte6$LAYOUT; + } + + private static final long byte6$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static final long byte6$offset() { + return byte6$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static byte byte6(MemorySegment struct) { + return struct.get(byte6$LAYOUT, byte6$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte6 + * } + */ + public static void byte6(MemorySegment struct, byte fieldValue) { + struct.set(byte6$LAYOUT, byte6$OFFSET, fieldValue); + } + + private static final OfByte byte7$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte7")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static final OfByte byte7$layout() { + return byte7$LAYOUT; + } + + private static final long byte7$OFFSET = 7; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static final long byte7$offset() { + return byte7$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static byte byte7(MemorySegment struct) { + return struct.get(byte7$LAYOUT, byte7$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte7 + * } + */ + public static void byte7(MemorySegment struct, byte fieldValue) { + struct.set(byte7$LAYOUT, byte7$OFFSET, fieldValue); + } + + private static final OfByte byte8$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte8")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static final OfByte byte8$layout() { + return byte8$LAYOUT; + } + + private static final long byte8$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static final long byte8$offset() { + return byte8$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static byte byte8(MemorySegment struct) { + return struct.get(byte8$LAYOUT, byte8$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte8 + * } + */ + public static void byte8(MemorySegment struct, byte fieldValue) { + struct.set(byte8$LAYOUT, byte8$OFFSET, fieldValue); + } + + private static final OfByte byte9$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte9")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static final OfByte byte9$layout() { + return byte9$LAYOUT; + } + + private static final long byte9$OFFSET = 9; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static final long byte9$offset() { + return byte9$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static byte byte9(MemorySegment struct) { + return struct.get(byte9$LAYOUT, byte9$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte9 + * } + */ + public static void byte9(MemorySegment struct, byte fieldValue) { + struct.set(byte9$LAYOUT, byte9$OFFSET, fieldValue); + } + + private static final OfByte byte10$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte10")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static final OfByte byte10$layout() { + return byte10$LAYOUT; + } + + private static final long byte10$OFFSET = 10; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static final long byte10$offset() { + return byte10$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static byte byte10(MemorySegment struct) { + return struct.get(byte10$LAYOUT, byte10$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte10 + * } + */ + public static void byte10(MemorySegment struct, byte fieldValue) { + struct.set(byte10$LAYOUT, byte10$OFFSET, fieldValue); + } + + private static final OfByte byte11$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte11")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static final OfByte byte11$layout() { + return byte11$LAYOUT; + } + + private static final long byte11$OFFSET = 11; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static final long byte11$offset() { + return byte11$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static byte byte11(MemorySegment struct) { + return struct.get(byte11$LAYOUT, byte11$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte11 + * } + */ + public static void byte11(MemorySegment struct, byte fieldValue) { + struct.set(byte11$LAYOUT, byte11$OFFSET, fieldValue); + } + + private static final OfByte byte12$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte12")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static final OfByte byte12$layout() { + return byte12$LAYOUT; + } + + private static final long byte12$OFFSET = 12; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static final long byte12$offset() { + return byte12$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static byte byte12(MemorySegment struct) { + return struct.get(byte12$LAYOUT, byte12$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte12 + * } + */ + public static void byte12(MemorySegment struct, byte fieldValue) { + struct.set(byte12$LAYOUT, byte12$OFFSET, fieldValue); + } + + private static final OfByte byte13$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte13")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static final OfByte byte13$layout() { + return byte13$LAYOUT; + } + + private static final long byte13$OFFSET = 13; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static final long byte13$offset() { + return byte13$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static byte byte13(MemorySegment struct) { + return struct.get(byte13$LAYOUT, byte13$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte13 + * } + */ + public static void byte13(MemorySegment struct, byte fieldValue) { + struct.set(byte13$LAYOUT, byte13$OFFSET, fieldValue); + } + + private static final OfByte byte14$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte14")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static final OfByte byte14$layout() { + return byte14$LAYOUT; + } + + private static final long byte14$OFFSET = 14; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static final long byte14$offset() { + return byte14$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static byte byte14(MemorySegment struct) { + return struct.get(byte14$LAYOUT, byte14$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte14 + * } + */ + public static void byte14(MemorySegment struct, byte fieldValue) { + struct.set(byte14$LAYOUT, byte14$OFFSET, fieldValue); + } + + private static final OfByte byte15$LAYOUT = (OfByte)$LAYOUT.select(groupElement("byte15")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static final OfByte byte15$layout() { + return byte15$LAYOUT; + } + + private static final long byte15$OFFSET = 15; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static final long byte15$offset() { + return byte15$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static byte byte15(MemorySegment struct) { + return struct.get(byte15$LAYOUT, byte15$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UInt8 byte15 + * } + */ + public static void byte15(MemorySegment struct, byte fieldValue) { + struct.set(byte15$LAYOUT, byte15$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterface.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterface.java deleted file mode 100644 index 0b23bb5..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterface.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -/** - * {@snippet : - * typedef struct IOCFPlugInInterfaceStruct IOCFPlugInInterface; - * } - */ -public final class IOCFPlugInInterface extends IOCFPlugInInterfaceStruct { - - // Suppresses default constructor, ensuring non-instantiability. - private IOCFPlugInInterface() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterfaceStruct.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterfaceStruct.java index 92d54af..26862c8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterfaceStruct.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOCFPlugInInterfaceStruct.java @@ -2,436 +2,826 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct IOCFPlugInInterfaceStruct { - * void* _reserved; - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); - * ULONG (*AddRef)(void*); - * ULONG (*Release)(void*); + * void *_reserved; + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *); + * ULONG (*AddRef)(void *); + * ULONG (*Release)(void *); * UInt16 version; * UInt16 revision; - * IOReturn (*Probe)(void*,CFDictionaryRef,io_service_t,SInt32*); - * IOReturn (*Start)(void*,CFDictionaryRef,io_service_t); - * IOReturn (*Stop)(void*); - * }; + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *); + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t); + * IOReturn (*Stop)(void *); + * } * } */ public class IOCFPlugInInterfaceStruct { - public static MemoryLayout $LAYOUT() { - return constants$40.const$2; + IOCFPlugInInterfaceStruct() { + // Should not be called directly } - public static VarHandle _reserved$VH() { - return constants$40.const$3; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_POINTER.withName("_reserved"), + IOKit.C_POINTER.withName("QueryInterface"), + IOKit.C_POINTER.withName("AddRef"), + IOKit.C_POINTER.withName("Release"), + IOKit.C_SHORT.withName("version"), + IOKit.C_SHORT.withName("revision"), + MemoryLayout.paddingLayout(4), + IOKit.C_POINTER.withName("Probe"), + IOKit.C_POINTER.withName("Start"), + IOKit.C_POINTER.withName("Stop") + ).withName("IOCFPlugInInterfaceStruct"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final AddressLayout _reserved$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("_reserved")); + /** - * Getter for field: - * {@snippet : - * void* _reserved; + * Layout for field: + * {@snippet lang=c : + * void *_reserved * } */ - public static MemorySegment _reserved$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$40.const$3.get(seg); + public static final AddressLayout _reserved$layout() { + return _reserved$LAYOUT; } + + private static final long _reserved$OFFSET = 0; + /** - * Setter for field: - * {@snippet : - * void* _reserved; + * Offset for field: + * {@snippet lang=c : + * void *_reserved * } */ - public static void _reserved$set(MemorySegment seg, MemorySegment x) { - constants$40.const$3.set(seg, x); + public static final long _reserved$offset() { + return _reserved$OFFSET; } - public static MemorySegment _reserved$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$40.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Getter for field: + * {@snippet lang=c : + * void *_reserved + * } + */ + public static MemorySegment _reserved(MemorySegment struct) { + return struct.get(_reserved$LAYOUT, _reserved$OFFSET); } - public static void _reserved$set(MemorySegment seg, long index, MemorySegment x) { - constants$40.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Setter for field: + * {@snippet lang=c : + * void *_reserved + * } + */ + public static void _reserved(MemorySegment struct, MemorySegment fieldValue) { + struct.set(_reserved$LAYOUT, _reserved$OFFSET, fieldValue); } + /** - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public interface QueryInterface { + public static class QueryInterface { + + QueryInterface() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); + } - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(QueryInterface fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$40.const$4, fi, constants$5.const$1, scope); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + CFUUIDBytes.layout(), + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; } - static QueryInterface ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$5.const$3.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle UP$MH = IOKit.upcallHandle(QueryInterface.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(QueryInterface.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout QueryInterface$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("QueryInterface")); + + /** + * Layout for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) + * } + */ + public static final AddressLayout QueryInterface$layout() { + return QueryInterface$LAYOUT; } - public static VarHandle QueryInterface$VH() { - return constants$40.const$5; + private static final long QueryInterface$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) + * } + */ + public static final long QueryInterface$offset() { + return QueryInterface$OFFSET; } + /** * Getter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static MemorySegment QueryInterface$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$40.const$5.get(seg); + public static MemorySegment QueryInterface(MemorySegment struct) { + return struct.get(QueryInterface$LAYOUT, QueryInterface$OFFSET); } + /** * Setter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static void QueryInterface$set(MemorySegment seg, MemorySegment x) { - constants$40.const$5.set(seg, x); - } - public static MemorySegment QueryInterface$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$40.const$5.get(seg.asSlice(index*sizeof())); - } - public static void QueryInterface$set(MemorySegment seg, long index, MemorySegment x) { - constants$40.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static QueryInterface QueryInterface(MemorySegment segment, Arena scope) { - return QueryInterface.ofAddress(QueryInterface$get(segment), scope); + public static void QueryInterface(MemorySegment struct, MemorySegment fieldValue) { + struct.set(QueryInterface$LAYOUT, QueryInterface$OFFSET, fieldValue); } + /** - * {@snippet : - * ULONG (*AddRef)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public interface AddRef { + public static class AddRef { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(AddRef fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$41.const$0, fi, constants$5.const$5, scope); + AddRef() { + // Should not be called directly } - static AddRef ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(AddRef.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(AddRef.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout AddRef$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("AddRef")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) + * } + */ + public static final AddressLayout AddRef$layout() { + return AddRef$LAYOUT; } - public static VarHandle AddRef$VH() { - return constants$41.const$1; + private static final long AddRef$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) + * } + */ + public static final long AddRef$offset() { + return AddRef$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG (*AddRef)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static MemorySegment AddRef$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$41.const$1.get(seg); + public static MemorySegment AddRef(MemorySegment struct) { + return struct.get(AddRef$LAYOUT, AddRef$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG (*AddRef)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static void AddRef$set(MemorySegment seg, MemorySegment x) { - constants$41.const$1.set(seg, x); - } - public static MemorySegment AddRef$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$41.const$1.get(seg.asSlice(index*sizeof())); - } - public static void AddRef$set(MemorySegment seg, long index, MemorySegment x) { - constants$41.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static AddRef AddRef(MemorySegment segment, Arena scope) { - return AddRef.ofAddress(AddRef$get(segment), scope); + public static void AddRef(MemorySegment struct, MemorySegment fieldValue) { + struct.set(AddRef$LAYOUT, AddRef$OFFSET, fieldValue); } + /** - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public interface Release { + public static class Release { + + Release() { + // Should not be called directly + } - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(Release fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$41.const$2, fi, constants$5.const$5, scope); + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - static Release ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Release.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Release.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) + * } + */ + public static final AddressLayout Release$layout() { + return Release$LAYOUT; } - public static VarHandle Release$VH() { - return constants$41.const$3; + private static final long Release$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) + * } + */ + public static final long Release$offset() { + return Release$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static MemorySegment Release$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$41.const$3.get(seg); + public static MemorySegment Release(MemorySegment struct) { + return struct.get(Release$LAYOUT, Release$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static void Release$set(MemorySegment seg, MemorySegment x) { - constants$41.const$3.set(seg, x); + public static void Release(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Release$LAYOUT, Release$OFFSET, fieldValue); } - public static MemorySegment Release$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$41.const$3.get(seg.asSlice(index*sizeof())); - } - public static void Release$set(MemorySegment seg, long index, MemorySegment x) { - constants$41.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static Release Release(MemorySegment segment, Arena scope) { - return Release.ofAddress(Release$get(segment), scope); + + private static final OfShort version$LAYOUT = (OfShort)$LAYOUT.select(groupElement("version")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 version + * } + */ + public static final OfShort version$layout() { + return version$LAYOUT; } - public static VarHandle version$VH() { - return constants$41.const$4; + + private static final long version$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 version + * } + */ + public static final long version$offset() { + return version$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 version; + * {@snippet lang=c : + * UInt16 version * } */ - public static short version$get(MemorySegment seg) { - return (short)constants$41.const$4.get(seg); + public static short version(MemorySegment struct) { + return struct.get(version$LAYOUT, version$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 version; + * {@snippet lang=c : + * UInt16 version * } */ - public static void version$set(MemorySegment seg, short x) { - constants$41.const$4.set(seg, x); - } - public static short version$get(MemorySegment seg, long index) { - return (short)constants$41.const$4.get(seg.asSlice(index*sizeof())); + public static void version(MemorySegment struct, short fieldValue) { + struct.set(version$LAYOUT, version$OFFSET, fieldValue); } - public static void version$set(MemorySegment seg, long index, short x) { - constants$41.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort revision$LAYOUT = (OfShort)$LAYOUT.select(groupElement("revision")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 revision + * } + */ + public static final OfShort revision$layout() { + return revision$LAYOUT; } - public static VarHandle revision$VH() { - return constants$41.const$5; + + private static final long revision$OFFSET = 34; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 revision + * } + */ + public static final long revision$offset() { + return revision$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 revision; + * {@snippet lang=c : + * UInt16 revision * } */ - public static short revision$get(MemorySegment seg) { - return (short)constants$41.const$5.get(seg); + public static short revision(MemorySegment struct) { + return struct.get(revision$LAYOUT, revision$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 revision; + * {@snippet lang=c : + * UInt16 revision * } */ - public static void revision$set(MemorySegment seg, short x) { - constants$41.const$5.set(seg, x); - } - public static short revision$get(MemorySegment seg, long index) { - return (short)constants$41.const$5.get(seg.asSlice(index*sizeof())); - } - public static void revision$set(MemorySegment seg, long index, short x) { - constants$41.const$5.set(seg.asSlice(index*sizeof()), x); + public static void revision(MemorySegment struct, short fieldValue) { + struct.set(revision$LAYOUT, revision$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*Probe)(void*,CFDictionaryRef,io_service_t,SInt32*); + * {@snippet lang=c : + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *) * } */ - public interface Probe { + public static class Probe { + + Probe() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, int _x2, MemorySegment _x3); + } - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, int _x2, java.lang.foreign.MemorySegment _x3); - static MemorySegment allocate(Probe fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$42.const$1, fi, constants$42.const$0, scope); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; } - static Probe ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, int __x2, java.lang.foreign.MemorySegment __x3) -> { - try { - return (int)constants$42.const$2.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Probe.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Probe.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, int _x2, MemorySegment _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout Probe$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Probe")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *) + * } + */ + public static final AddressLayout Probe$layout() { + return Probe$LAYOUT; } - public static VarHandle Probe$VH() { - return constants$42.const$3; + private static final long Probe$OFFSET = 40; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *) + * } + */ + public static final long Probe$offset() { + return Probe$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*Probe)(void*,CFDictionaryRef,io_service_t,SInt32*); + * {@snippet lang=c : + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *) * } */ - public static MemorySegment Probe$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$42.const$3.get(seg); + public static MemorySegment Probe(MemorySegment struct) { + return struct.get(Probe$LAYOUT, Probe$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*Probe)(void*,CFDictionaryRef,io_service_t,SInt32*); + * {@snippet lang=c : + * IOReturn (*Probe)(void *, CFDictionaryRef, io_service_t, SInt32 *) * } */ - public static void Probe$set(MemorySegment seg, MemorySegment x) { - constants$42.const$3.set(seg, x); - } - public static MemorySegment Probe$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$42.const$3.get(seg.asSlice(index*sizeof())); - } - public static void Probe$set(MemorySegment seg, long index, MemorySegment x) { - constants$42.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static Probe Probe(MemorySegment segment, Arena scope) { - return Probe.ofAddress(Probe$get(segment), scope); + public static void Probe(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Probe$LAYOUT, Probe$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*Start)(void*,CFDictionaryRef,io_service_t); + * {@snippet lang=c : + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t) * } */ - public interface Start { + public static class Start { + + Start() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, int _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Start.Function.class, "apply", $DESC); - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, int _x2); - static MemorySegment allocate(Start fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$42.const$5, fi, constants$42.const$4, scope); + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Start.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } - static Start ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, int __x2) -> { - try { - return (int)constants$43.const$0.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, int _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle Start$VH() { - return constants$43.const$1; + private static final AddressLayout Start$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Start")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t) + * } + */ + public static final AddressLayout Start$layout() { + return Start$LAYOUT; + } + + private static final long Start$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t) + * } + */ + public static final long Start$offset() { + return Start$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*Start)(void*,CFDictionaryRef,io_service_t); + * {@snippet lang=c : + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t) * } */ - public static MemorySegment Start$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$43.const$1.get(seg); + public static MemorySegment Start(MemorySegment struct) { + return struct.get(Start$LAYOUT, Start$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*Start)(void*,CFDictionaryRef,io_service_t); + * {@snippet lang=c : + * IOReturn (*Start)(void *, CFDictionaryRef, io_service_t) * } */ - public static void Start$set(MemorySegment seg, MemorySegment x) { - constants$43.const$1.set(seg, x); - } - public static MemorySegment Start$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$43.const$1.get(seg.asSlice(index*sizeof())); - } - public static void Start$set(MemorySegment seg, long index, MemorySegment x) { - constants$43.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static Start Start(MemorySegment segment, Arena scope) { - return Start.ofAddress(Start$get(segment), scope); + public static void Start(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Start$LAYOUT, Start$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*Stop)(void*); + * {@snippet lang=c : + * IOReturn (*Stop)(void *) * } */ - public interface Stop { + public static class Stop { + + Stop() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Stop.Function.class, "apply", $DESC); - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(Stop fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$43.const$2, fi, constants$5.const$5, scope); + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Stop.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } - static Stop ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle Stop$VH() { - return constants$43.const$3; + private static final AddressLayout Stop$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Stop")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*Stop)(void *) + * } + */ + public static final AddressLayout Stop$layout() { + return Stop$LAYOUT; } + + private static final long Stop$OFFSET = 56; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*Stop)(void *) + * } + */ + public static final long Stop$offset() { + return Stop$OFFSET; + } + /** * Getter for field: - * {@snippet : - * IOReturn (*Stop)(void*); + * {@snippet lang=c : + * IOReturn (*Stop)(void *) * } */ - public static MemorySegment Stop$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$43.const$3.get(seg); + public static MemorySegment Stop(MemorySegment struct) { + return struct.get(Stop$LAYOUT, Stop$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*Stop)(void*); + * {@snippet lang=c : + * IOReturn (*Stop)(void *) * } */ - public static void Stop$set(MemorySegment seg, MemorySegment x) { - constants$43.const$3.set(seg, x); + public static void Stop(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Stop$LAYOUT, Stop$OFFSET, fieldValue); } - public static MemorySegment Stop$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$43.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void Stop$set(MemorySegment seg, long index, MemorySegment x) { - constants$43.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static Stop Stop(MemorySegment segment, Arena scope) { - return Stop.ofAddress(Stop$get(segment), scope); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOKit.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOKit.java index f03e1d0..ff60862 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOKit.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOKit.java @@ -2,301 +2,697 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class IOKit { +import static java.lang.foreign.MemoryLayout.PathElement.*; - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +public class IOKit { + + IOKit() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup("/System/Library/Frameworks/IOKit.framework/IOKit", LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int kIOUSBFindInterfaceDontCare = (int)65535L; /** - * {@snippet : - * enum .kIOUSBFindInterfaceDontCare = 65535; + * {@snippet lang=c : + * enum enum (unnamed at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:898:1).kIOUSBFindInterfaceDontCare = 65535 * } */ public static int kIOUSBFindInterfaceDontCare() { - return (int)65535L; + return kIOUSBFindInterfaceDontCare; } + private static final int kUSBReEnumerateCaptureDeviceMask = (int)1073741824L; /** - * {@snippet : - * enum .kUSBReEnumerateCaptureDeviceMask = 1073741824; + * {@snippet lang=c : + * enum USBReEnumerateOptions.kUSBReEnumerateCaptureDeviceMask = 1073741824 * } */ public static int kUSBReEnumerateCaptureDeviceMask() { - return (int)1073741824L; + return kUSBReEnumerateCaptureDeviceMask; } + private static final int kUSBReEnumerateReleaseDeviceMask = (int)536870912L; /** - * {@snippet : - * enum .kUSBReEnumerateReleaseDeviceMask = 536870912; + * {@snippet lang=c : + * enum USBReEnumerateOptions.kUSBReEnumerateReleaseDeviceMask = 536870912 * } */ public static int kUSBReEnumerateReleaseDeviceMask() { - return (int)536870912L; + return kUSBReEnumerateReleaseDeviceMask; } - public static MemoryLayout kCFRunLoopDefaultMode$LAYOUT() { - return RuntimeHelper.POINTER; + + private static class kCFRunLoopDefaultMode$constants { + public static final AddressLayout LAYOUT = IOKit.C_POINTER; + public static final MemorySegment SEGMENT = IOKit.findOrThrow("kCFRunLoopDefaultMode").reinterpret(LAYOUT.byteSize()); } - public static VarHandle kCFRunLoopDefaultMode$VH() { - return constants$2.const$1; + + /** + * Layout for variable: + * {@snippet lang=c : + * extern const CFRunLoopMode kCFRunLoopDefaultMode + * } + */ + public static AddressLayout kCFRunLoopDefaultMode$layout() { + return kCFRunLoopDefaultMode$constants.LAYOUT; } - public static MemorySegment kCFRunLoopDefaultMode$SEGMENT() { - return RuntimeHelper.requireNonNull(constants$2.const$2,"kCFRunLoopDefaultMode"); + + /** + * Segment for variable: + * {@snippet lang=c : + * extern const CFRunLoopMode kCFRunLoopDefaultMode + * } + */ + public static MemorySegment kCFRunLoopDefaultMode$segment() { + return kCFRunLoopDefaultMode$constants.SEGMENT; } + /** * Getter for variable: - * {@snippet : - * const CFRunLoopMode kCFRunLoopDefaultMode; + * {@snippet lang=c : + * extern const CFRunLoopMode kCFRunLoopDefaultMode * } */ - public static MemorySegment kCFRunLoopDefaultMode$get() { - return (java.lang.foreign.MemorySegment) constants$2.const$1.get(RuntimeHelper.requireNonNull(constants$2.const$2, "kCFRunLoopDefaultMode")); + public static MemorySegment kCFRunLoopDefaultMode() { + return kCFRunLoopDefaultMode$constants.SEGMENT.get(kCFRunLoopDefaultMode$constants.LAYOUT, 0L); } + /** * Setter for variable: - * {@snippet : - * const CFRunLoopMode kCFRunLoopDefaultMode; + * {@snippet lang=c : + * extern const CFRunLoopMode kCFRunLoopDefaultMode * } */ - public static void kCFRunLoopDefaultMode$set(MemorySegment x) { - constants$2.const$1.set(RuntimeHelper.requireNonNull(constants$2.const$2, "kCFRunLoopDefaultMode"), x); + public static void kCFRunLoopDefaultMode(MemorySegment varValue) { + kCFRunLoopDefaultMode$constants.SEGMENT.set(kCFRunLoopDefaultMode$constants.LAYOUT, 0L, varValue); } - public static MemoryLayout kIOMasterPortDefault$LAYOUT() { - return JAVA_INT; + + private static class kIOMasterPortDefault$constants { + public static final OfInt LAYOUT = IOKit.C_INT; + public static final MemorySegment SEGMENT = IOKit.findOrThrow("kIOMasterPortDefault").reinterpret(LAYOUT.byteSize()); } - public static VarHandle kIOMasterPortDefault$VH() { - return constants$2.const$3; + + /** + * Layout for variable: + * {@snippet lang=c : + * extern const mach_port_t kIOMasterPortDefault + * } + */ + public static OfInt kIOMasterPortDefault$layout() { + return kIOMasterPortDefault$constants.LAYOUT; } - public static MemorySegment kIOMasterPortDefault$SEGMENT() { - return RuntimeHelper.requireNonNull(constants$2.const$4,"kIOMasterPortDefault"); + + /** + * Segment for variable: + * {@snippet lang=c : + * extern const mach_port_t kIOMasterPortDefault + * } + */ + public static MemorySegment kIOMasterPortDefault$segment() { + return kIOMasterPortDefault$constants.SEGMENT; } + /** * Getter for variable: - * {@snippet : - * const mach_port_t kIOMasterPortDefault; + * {@snippet lang=c : + * extern const mach_port_t kIOMasterPortDefault * } */ - public static int kIOMasterPortDefault$get() { - return (int) constants$2.const$3.get(RuntimeHelper.requireNonNull(constants$2.const$4, "kIOMasterPortDefault")); + public static int kIOMasterPortDefault() { + return kIOMasterPortDefault$constants.SEGMENT.get(kIOMasterPortDefault$constants.LAYOUT, 0L); } + /** * Setter for variable: - * {@snippet : - * const mach_port_t kIOMasterPortDefault; + * {@snippet lang=c : + * extern const mach_port_t kIOMasterPortDefault * } */ - public static void kIOMasterPortDefault$set(int x) { - constants$2.const$3.set(RuntimeHelper.requireNonNull(constants$2.const$4, "kIOMasterPortDefault"), x); + public static void kIOMasterPortDefault(int varValue) { + kIOMasterPortDefault$constants.SEGMENT.set(kIOMasterPortDefault$constants.LAYOUT, 0L, varValue); } - public static MethodHandle IONotificationPortCreate$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$6,"IONotificationPortCreate"); + + private static class IONotificationPortCreate { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IONotificationPortCreate"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort) + * } + */ + public static FunctionDescriptor IONotificationPortCreate$descriptor() { + return IONotificationPortCreate.DESC; } + /** - * {@snippet : - * IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort); + * Downcall method handle for: + * {@snippet lang=c : + * IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort) + * } + */ + public static MethodHandle IONotificationPortCreate$handle() { + return IONotificationPortCreate.HANDLE; + } + /** + * {@snippet lang=c : + * IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort) * } */ public static MemorySegment IONotificationPortCreate(int mainPort) { - var mh$ = IONotificationPortCreate$MH(); + var mh$ = IONotificationPortCreate.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(mainPort); + if (TRACE_DOWNCALLS) { + traceDowncall("IONotificationPortCreate", mainPort); + } + return (MemorySegment)mh$.invokeExact(mainPort); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IONotificationPortGetRunLoopSource$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$1,"IONotificationPortGetRunLoopSource"); + + private static class IONotificationPortGetRunLoopSource { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IONotificationPortGetRunLoopSource"), + DESC); } + + /** + * Function descriptor for: + * {@snippet lang=c : + * CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify) + * } + */ + public static FunctionDescriptor IONotificationPortGetRunLoopSource$descriptor() { + return IONotificationPortGetRunLoopSource.DESC; + } + /** - * {@snippet : - * CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify); + * Downcall method handle for: + * {@snippet lang=c : + * CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify) + * } + */ + public static MethodHandle IONotificationPortGetRunLoopSource$handle() { + return IONotificationPortGetRunLoopSource.HANDLE; + } + /** + * {@snippet lang=c : + * CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify) * } */ public static MemorySegment IONotificationPortGetRunLoopSource(MemorySegment notify) { - var mh$ = IONotificationPortGetRunLoopSource$MH(); + var mh$ = IONotificationPortGetRunLoopSource.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(notify); + if (TRACE_DOWNCALLS) { + traceDowncall("IONotificationPortGetRunLoopSource", notify); + } + return (MemorySegment)mh$.invokeExact(notify); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IOObjectRelease$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$3,"IOObjectRelease"); + + private static class IOObjectRelease { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IOObjectRelease"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * kern_return_t IOObjectRelease(io_object_t object) + * } + */ + public static FunctionDescriptor IOObjectRelease$descriptor() { + return IOObjectRelease.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * kern_return_t IOObjectRelease(io_object_t object) + * } + */ + public static MethodHandle IOObjectRelease$handle() { + return IOObjectRelease.HANDLE; } /** - * {@snippet : - * kern_return_t IOObjectRelease(io_object_t object); + * {@snippet lang=c : + * kern_return_t IOObjectRelease(io_object_t object) * } */ public static int IOObjectRelease(int object) { - var mh$ = IOObjectRelease$MH(); + var mh$ = IOObjectRelease.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("IOObjectRelease", object); + } return (int)mh$.invokeExact(object); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IOIteratorNext$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$4,"IOIteratorNext"); + + private static class IOIteratorNext { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IOIteratorNext"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * io_object_t IOIteratorNext(io_iterator_t iterator) + * } + */ + public static FunctionDescriptor IOIteratorNext$descriptor() { + return IOIteratorNext.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * io_object_t IOIteratorNext(io_iterator_t iterator) + * } + */ + public static MethodHandle IOIteratorNext$handle() { + return IOIteratorNext.HANDLE; } /** - * {@snippet : - * io_object_t IOIteratorNext(io_iterator_t iterator); + * {@snippet lang=c : + * io_object_t IOIteratorNext(io_iterator_t iterator) * } */ public static int IOIteratorNext(int iterator) { - var mh$ = IOIteratorNext$MH(); + var mh$ = IOIteratorNext.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("IOIteratorNext", iterator); + } return (int)mh$.invokeExact(iterator); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IOServiceAddMatchingNotification$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$6,"IOServiceAddMatchingNotification"); + + private static class IOServiceAddMatchingNotification { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IOServiceAddMatchingNotification"), + DESC); } + /** - * {@snippet : - * kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void* refCon, io_iterator_t* notification); + * Function descriptor for: + * {@snippet lang=c : + * kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification) + * } + */ + public static FunctionDescriptor IOServiceAddMatchingNotification$descriptor() { + return IOServiceAddMatchingNotification.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification) + * } + */ + public static MethodHandle IOServiceAddMatchingNotification$handle() { + return IOServiceAddMatchingNotification.HANDLE; + } + /** + * {@snippet lang=c : + * kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification) * } */ public static int IOServiceAddMatchingNotification(MemorySegment notifyPort, MemorySegment notificationType, MemorySegment matching, MemorySegment callback, MemorySegment refCon, MemorySegment notification) { - var mh$ = IOServiceAddMatchingNotification$MH(); + var mh$ = IOServiceAddMatchingNotification.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("IOServiceAddMatchingNotification", notifyPort, notificationType, matching, callback, refCon, notification); + } return (int)mh$.invokeExact(notifyPort, notificationType, matching, callback, refCon, notification); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IORegistryEntryGetRegistryEntryID$MH() { - return RuntimeHelper.requireNonNull(constants$4.const$1,"IORegistryEntryGetRegistryEntryID"); + + private static class IORegistryEntryGetRegistryEntryID { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IORegistryEntryGetRegistryEntryID"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID) + * } + */ + public static FunctionDescriptor IORegistryEntryGetRegistryEntryID$descriptor() { + return IORegistryEntryGetRegistryEntryID.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID) + * } + */ + public static MethodHandle IORegistryEntryGetRegistryEntryID$handle() { + return IORegistryEntryGetRegistryEntryID.HANDLE; } /** - * {@snippet : - * kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t* entryID); + * {@snippet lang=c : + * kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID) * } */ public static int IORegistryEntryGetRegistryEntryID(int entry, MemorySegment entryID) { - var mh$ = IORegistryEntryGetRegistryEntryID$MH(); + var mh$ = IORegistryEntryGetRegistryEntryID.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("IORegistryEntryGetRegistryEntryID", entry, entryID); + } return (int)mh$.invokeExact(entry, entryID); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IORegistryEntryCreateCFProperty$MH() { - return RuntimeHelper.requireNonNull(constants$4.const$3,"IORegistryEntryCreateCFProperty"); + + private static class IORegistryEntryCreateCFProperty { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IORegistryEntryCreateCFProperty"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options) + * } + */ + public static FunctionDescriptor IORegistryEntryCreateCFProperty$descriptor() { + return IORegistryEntryCreateCFProperty.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options) + * } + */ + public static MethodHandle IORegistryEntryCreateCFProperty$handle() { + return IORegistryEntryCreateCFProperty.HANDLE; } /** - * {@snippet : - * CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options); + * {@snippet lang=c : + * CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options) * } */ public static MemorySegment IORegistryEntryCreateCFProperty(int entry, MemorySegment key, MemorySegment allocator, int options) { - var mh$ = IORegistryEntryCreateCFProperty$MH(); + var mh$ = IORegistryEntryCreateCFProperty.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(entry, key, allocator, options); + if (TRACE_DOWNCALLS) { + traceDowncall("IORegistryEntryCreateCFProperty", entry, key, allocator, options); + } + return (MemorySegment)mh$.invokeExact(entry, key, allocator, options); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IOServiceMatching$MH() { - return RuntimeHelper.requireNonNull(constants$4.const$4,"IOServiceMatching"); + + private static class IOServiceMatching { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IOServiceMatching"), + DESC); } + /** - * {@snippet : - * CFMutableDictionaryRef IOServiceMatching(char* name); + * Function descriptor for: + * {@snippet lang=c : + * CFMutableDictionaryRef IOServiceMatching(const char *name) + * } + */ + public static FunctionDescriptor IOServiceMatching$descriptor() { + return IOServiceMatching.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * CFMutableDictionaryRef IOServiceMatching(const char *name) + * } + */ + public static MethodHandle IOServiceMatching$handle() { + return IOServiceMatching.HANDLE; + } + /** + * {@snippet lang=c : + * CFMutableDictionaryRef IOServiceMatching(const char *name) * } */ public static MemorySegment IOServiceMatching(MemorySegment name) { - var mh$ = IOServiceMatching$MH(); + var mh$ = IOServiceMatching.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(name); + if (TRACE_DOWNCALLS) { + traceDowncall("IOServiceMatching", name); + } + return (MemorySegment)mh$.invokeExact(name); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle IOCreatePlugInInterfaceForService$MH() { - return RuntimeHelper.requireNonNull(constants$43.const$5,"IOCreatePlugInInterfaceForService"); + + private static class IOCreatePlugInInterfaceForService { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + IOKit.findOrThrow("IOCreatePlugInInterfaceForService"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore) + * } + */ + public static FunctionDescriptor IOCreatePlugInInterfaceForService$descriptor() { + return IOCreatePlugInInterfaceForService.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore) + * } + */ + public static MethodHandle IOCreatePlugInInterfaceForService$handle() { + return IOCreatePlugInInterfaceForService.HANDLE; } /** - * {@snippet : - * kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface*** theInterface, SInt32* theScore); + * {@snippet lang=c : + * kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore) * } */ public static int IOCreatePlugInInterfaceForService(int service, MemorySegment pluginType, MemorySegment interfaceType, MemorySegment theInterface, MemorySegment theScore) { - var mh$ = IOCreatePlugInInterfaceForService$MH(); + var mh$ = IOCreatePlugInInterfaceForService.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("IOCreatePlugInInterfaceForService", service, pluginType, interfaceType, theInterface, theScore); + } return (int)mh$.invokeExact(service, pluginType, interfaceType, theInterface, theScore); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } + private static final int kIOReturnExclusiveAccess = (int)-536870203L; /** - * {@snippet : + * {@snippet lang=c : * #define kIOReturnExclusiveAccess -536870203 * } */ public static int kIOReturnExclusiveAccess() { - return (int)-536870203L; + return kIOReturnExclusiveAccess; } + private static final int kIOReturnAborted = (int)-536870165L; /** - * {@snippet : + * {@snippet lang=c : * #define kIOReturnAborted -536870165 * } */ public static int kIOReturnAborted() { - return (int)-536870165L; + return kIOReturnAborted; } + private static final int kIOUSBPipeStalled = (int)-536854449L; /** - * {@snippet : + * {@snippet lang=c : * #define kIOUSBPipeStalled -536854449 * } */ public static int kIOUSBPipeStalled() { - return (int)-536854449L; + return kIOUSBPipeStalled; } + private static final int kIOUSBTransactionTimeout = (int)-536854447L; /** - * {@snippet : + * {@snippet lang=c : * #define kIOUSBTransactionTimeout -536854447 * } */ public static int kIOUSBTransactionTimeout() { - return (int)-536854447L; + return kIOUSBTransactionTimeout; } /** - * {@snippet : + * {@snippet lang=c : * #define kIOFirstMatchNotification "IOServiceFirstMatch" * } */ public static MemorySegment kIOFirstMatchNotification() { - return constants$44.const$0; + class Holder { + static final MemorySegment kIOFirstMatchNotification + = IOKit.LIBRARY_ARENA.allocateFrom("IOServiceFirstMatch"); + } + return Holder.kIOFirstMatchNotification; } /** - * {@snippet : + * {@snippet lang=c : * #define kIOTerminatedNotification "IOServiceTerminate" * } */ public static MemorySegment kIOTerminatedNotification() { - return constants$44.const$1; + class Holder { + static final MemorySegment kIOTerminatedNotification + = IOKit.LIBRARY_ARENA.allocateFrom("IOServiceTerminate"); + } + return Holder.kIOTerminatedNotification; } /** - * {@snippet : + * {@snippet lang=c : * #define kIOUSBDeviceClassName "IOUSBDevice" * } */ public static MemorySegment kIOUSBDeviceClassName() { - return constants$44.const$2; + class Holder { + static final MemorySegment kIOUSBDeviceClassName + = IOKit.LIBRARY_ARENA.allocateFrom("IOUSBDevice"); + } + return Holder.kIOUSBDeviceClassName; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOServiceAddMatchingNotification$callback.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOServiceAddMatchingNotification$callback.java new file mode 100644 index 0000000..c57ad0c --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOServiceAddMatchingNotification$callback.java @@ -0,0 +1,68 @@ +// Generated by jextract + +package net.codecrete.usb.macos.gen.iokit; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * IOServiceMatchingCallback callback + * } + */ +public class IOServiceAddMatchingNotification$callback { + + IOServiceAddMatchingNotification$callback() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + void apply(MemorySegment _x0, int _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid( + IOKit.C_POINTER, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(IOServiceAddMatchingNotification$callback.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(IOServiceAddMatchingNotification$callback.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static void invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { + try { + DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDevRequest.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDevRequest.java index ae3953c..d57579d 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDevRequest.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDevRequest.java @@ -2,224 +2,403 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct { * UInt8 bmRequestType; * UInt8 bRequest; * UInt16 wValue; * UInt16 wIndex; * UInt16 wLength; - * void* pData; + * void *pData; * UInt32 wLenDone; - * }; + * } * } */ public class IOUSBDevRequest { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + IOUSBDevRequest() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_CHAR.withName("bmRequestType"), + IOKit.C_CHAR.withName("bRequest"), + IOKit.C_SHORT.withName("wValue"), + IOKit.C_SHORT.withName("wIndex"), + IOKit.C_SHORT.withName("wLength"), + IOKit.C_POINTER.withName("pData"), + IOKit.C_INT.withName("wLenDone"), + MemoryLayout.paddingLayout(4) + ).withName("IOUSBDevRequest"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } - public static VarHandle bmRequestType$VH() { - return constants$0.const$1; + + private static final OfByte bmRequestType$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bmRequestType")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 bmRequestType + * } + */ + public static final OfByte bmRequestType$layout() { + return bmRequestType$LAYOUT; + } + + private static final long bmRequestType$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 bmRequestType + * } + */ + public static final long bmRequestType$offset() { + return bmRequestType$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 bmRequestType; + * {@snippet lang=c : + * UInt8 bmRequestType * } */ - public static byte bmRequestType$get(MemorySegment seg) { - return (byte)constants$0.const$1.get(seg); + public static byte bmRequestType(MemorySegment struct) { + return struct.get(bmRequestType$LAYOUT, bmRequestType$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 bmRequestType; + * {@snippet lang=c : + * UInt8 bmRequestType * } */ - public static void bmRequestType$set(MemorySegment seg, byte x) { - constants$0.const$1.set(seg, x); + public static void bmRequestType(MemorySegment struct, byte fieldValue) { + struct.set(bmRequestType$LAYOUT, bmRequestType$OFFSET, fieldValue); } - public static byte bmRequestType$get(MemorySegment seg, long index) { - return (byte)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void bmRequestType$set(MemorySegment seg, long index, byte x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte bRequest$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt8 bRequest + * } + */ + public static final OfByte bRequest$layout() { + return bRequest$LAYOUT; } - public static VarHandle bRequest$VH() { - return constants$0.const$2; + + private static final long bRequest$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt8 bRequest + * } + */ + public static final long bRequest$offset() { + return bRequest$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt8 bRequest; + * {@snippet lang=c : + * UInt8 bRequest * } */ - public static byte bRequest$get(MemorySegment seg) { - return (byte)constants$0.const$2.get(seg); + public static byte bRequest(MemorySegment struct) { + return struct.get(bRequest$LAYOUT, bRequest$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt8 bRequest; + * {@snippet lang=c : + * UInt8 bRequest * } */ - public static void bRequest$set(MemorySegment seg, byte x) { - constants$0.const$2.set(seg, x); + public static void bRequest(MemorySegment struct, byte fieldValue) { + struct.set(bRequest$LAYOUT, bRequest$OFFSET, fieldValue); } - public static byte bRequest$get(MemorySegment seg, long index) { - return (byte)constants$0.const$2.get(seg.asSlice(index*sizeof())); - } - public static void bRequest$set(MemorySegment seg, long index, byte x) { - constants$0.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wValue$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wValue")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 wValue + * } + */ + public static final OfShort wValue$layout() { + return wValue$LAYOUT; } - public static VarHandle wValue$VH() { - return constants$0.const$3; + + private static final long wValue$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 wValue + * } + */ + public static final long wValue$offset() { + return wValue$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 wValue; + * {@snippet lang=c : + * UInt16 wValue * } */ - public static short wValue$get(MemorySegment seg) { - return (short)constants$0.const$3.get(seg); + public static short wValue(MemorySegment struct) { + return struct.get(wValue$LAYOUT, wValue$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 wValue; + * {@snippet lang=c : + * UInt16 wValue * } */ - public static void wValue$set(MemorySegment seg, short x) { - constants$0.const$3.set(seg, x); + public static void wValue(MemorySegment struct, short fieldValue) { + struct.set(wValue$LAYOUT, wValue$OFFSET, fieldValue); } - public static short wValue$get(MemorySegment seg, long index) { - return (short)constants$0.const$3.get(seg.asSlice(index*sizeof())); - } - public static void wValue$set(MemorySegment seg, long index, short x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wIndex$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wIndex")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 wIndex + * } + */ + public static final OfShort wIndex$layout() { + return wIndex$LAYOUT; } - public static VarHandle wIndex$VH() { - return constants$0.const$4; + + private static final long wIndex$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 wIndex + * } + */ + public static final long wIndex$offset() { + return wIndex$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 wIndex; + * {@snippet lang=c : + * UInt16 wIndex * } */ - public static short wIndex$get(MemorySegment seg) { - return (short)constants$0.const$4.get(seg); + public static short wIndex(MemorySegment struct) { + return struct.get(wIndex$LAYOUT, wIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 wIndex; + * {@snippet lang=c : + * UInt16 wIndex * } */ - public static void wIndex$set(MemorySegment seg, short x) { - constants$0.const$4.set(seg, x); + public static void wIndex(MemorySegment struct, short fieldValue) { + struct.set(wIndex$LAYOUT, wIndex$OFFSET, fieldValue); } - public static short wIndex$get(MemorySegment seg, long index) { - return (short)constants$0.const$4.get(seg.asSlice(index*sizeof())); - } - public static void wIndex$set(MemorySegment seg, long index, short x) { - constants$0.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wLength$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wLength")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 wLength + * } + */ + public static final OfShort wLength$layout() { + return wLength$LAYOUT; } - public static VarHandle wLength$VH() { - return constants$0.const$5; + + private static final long wLength$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 wLength + * } + */ + public static final long wLength$offset() { + return wLength$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 wLength; + * {@snippet lang=c : + * UInt16 wLength * } */ - public static short wLength$get(MemorySegment seg) { - return (short)constants$0.const$5.get(seg); + public static short wLength(MemorySegment struct) { + return struct.get(wLength$LAYOUT, wLength$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 wLength; + * {@snippet lang=c : + * UInt16 wLength * } */ - public static void wLength$set(MemorySegment seg, short x) { - constants$0.const$5.set(seg, x); - } - public static short wLength$get(MemorySegment seg, long index) { - return (short)constants$0.const$5.get(seg.asSlice(index*sizeof())); + public static void wLength(MemorySegment struct, short fieldValue) { + struct.set(wLength$LAYOUT, wLength$OFFSET, fieldValue); } - public static void wLength$set(MemorySegment seg, long index, short x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout pData$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("pData")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *pData + * } + */ + public static final AddressLayout pData$layout() { + return pData$LAYOUT; } - public static VarHandle pData$VH() { - return constants$1.const$0; + + private static final long pData$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * void *pData + * } + */ + public static final long pData$offset() { + return pData$OFFSET; } + /** * Getter for field: - * {@snippet : - * void* pData; + * {@snippet lang=c : + * void *pData * } */ - public static MemorySegment pData$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$0.get(seg); + public static MemorySegment pData(MemorySegment struct) { + return struct.get(pData$LAYOUT, pData$OFFSET); } + /** * Setter for field: - * {@snippet : - * void* pData; + * {@snippet lang=c : + * void *pData * } */ - public static void pData$set(MemorySegment seg, MemorySegment x) { - constants$1.const$0.set(seg, x); - } - public static MemorySegment pData$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$0.get(seg.asSlice(index*sizeof())); + public static void pData(MemorySegment struct, MemorySegment fieldValue) { + struct.set(pData$LAYOUT, pData$OFFSET, fieldValue); } - public static void pData$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt wLenDone$LAYOUT = (OfInt)$LAYOUT.select(groupElement("wLenDone")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt32 wLenDone + * } + */ + public static final OfInt wLenDone$layout() { + return wLenDone$LAYOUT; } - public static VarHandle wLenDone$VH() { - return constants$1.const$1; + + private static final long wLenDone$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt32 wLenDone + * } + */ + public static final long wLenDone$offset() { + return wLenDone$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt32 wLenDone; + * {@snippet lang=c : + * UInt32 wLenDone * } */ - public static int wLenDone$get(MemorySegment seg) { - return (int)constants$1.const$1.get(seg); + public static int wLenDone(MemorySegment struct) { + return struct.get(wLenDone$LAYOUT, wLenDone$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt32 wLenDone; + * {@snippet lang=c : + * UInt32 wLenDone * } */ - public static void wLenDone$set(MemorySegment seg, int x) { - constants$1.const$1.set(seg, x); + public static void wLenDone(MemorySegment struct, int fieldValue) { + struct.set(wLenDone$LAYOUT, wLenDone$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static int wLenDone$get(MemorySegment seg, long index) { - return (int)constants$1.const$1.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void wLenDone$set(MemorySegment seg, long index, int x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceInterface187.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceInterface187.java deleted file mode 100644 index be0be08..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceInterface187.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -/** - * {@snippet : - * typedef struct IOUSBDeviceStruct187 IOUSBDeviceInterface187; - * } - */ -public final class IOUSBDeviceInterface187 extends IOUSBDeviceStruct187 { - - // Suppresses default constructor, ensuring non-instantiability. - private IOUSBDeviceInterface187() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceStruct187.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceStruct187.java index ad8d79c..dbbe8e3 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceStruct187.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceStruct187.java @@ -2,2054 +2,3862 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct IOUSBDeviceStruct187 { - * void* _reserved; - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); - * ULONG (*AddRef)(void*); - * ULONG (*Release)(void*); - * IOReturn (*CreateDeviceAsyncEventSource)(void*,CFRunLoopSourceRef*); - * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void*); - * IOReturn (*CreateDeviceAsyncPort)(void*,mach_port_t*); - * mach_port_t (*GetDeviceAsyncPort)(void*); - * IOReturn (*USBDeviceOpen)(void*); - * IOReturn (*USBDeviceClose)(void*); - * IOReturn (*GetDeviceClass)(void*,UInt8*); - * IOReturn (*GetDeviceSubClass)(void*,UInt8*); - * IOReturn (*GetDeviceProtocol)(void*,UInt8*); - * IOReturn (*GetDeviceVendor)(void*,UInt16*); - * IOReturn (*GetDeviceProduct)(void*,UInt16*); - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); - * IOReturn (*GetDeviceAddress)(void*,USBDeviceAddress*); - * IOReturn (*GetDeviceBusPowerAvailable)(void*,UInt32*); - * IOReturn (*GetDeviceSpeed)(void*,UInt8*); - * IOReturn (*GetNumberOfConfigurations)(void*,UInt8*); - * IOReturn (*GetLocationID)(void*,UInt32*); - * IOReturn (*GetConfigurationDescriptorPtr)(void*,UInt8,IOUSBConfigurationDescriptorPtr*); - * IOReturn (*GetConfiguration)(void*,UInt8*); - * IOReturn (*SetConfiguration)(void*,UInt8); - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); - * IOReturn (*ResetDevice)(void*); - * IOReturn (*DeviceRequest)(void*,IOUSBDevRequest*); - * IOReturn (*DeviceRequestAsync)(void*,IOUSBDevRequest*,IOAsyncCallback1,void*); - * IOReturn (*CreateInterfaceIterator)(void*,IOUSBFindInterfaceRequest*,io_iterator_t*); - * IOReturn (*USBDeviceOpenSeize)(void*); - * IOReturn (*DeviceRequestTO)(void*,IOUSBDevRequestTO*); - * IOReturn (*DeviceRequestAsyncTO)(void*,IOUSBDevRequestTO*,IOAsyncCallback1,void*); - * IOReturn (*USBDeviceSuspend)(void*,Boolean); - * IOReturn (*USBDeviceAbortPipeZero)(void*); - * IOReturn (*USBGetManufacturerStringIndex)(void*,UInt8*); - * IOReturn (*USBGetProductStringIndex)(void*,UInt8*); - * IOReturn (*USBGetSerialNumberStringIndex)(void*,UInt8*); - * IOReturn (*USBDeviceReEnumerate)(void*,UInt32); - * }; + * void *_reserved; + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *); + * ULONG (*AddRef)(void *); + * ULONG (*Release)(void *); + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *); + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *); + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *); + * mach_port_t (*GetDeviceAsyncPort)(void *); + * IOReturn (*USBDeviceOpen)(void *); + * IOReturn (*USBDeviceClose)(void *); + * IOReturn (*GetDeviceClass)(void *, UInt8 *); + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *); + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *); + * IOReturn (*GetDeviceVendor)(void *, UInt16 *); + * IOReturn (*GetDeviceProduct)(void *, UInt16 *); + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *); + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *); + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *); + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *); + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *); + * IOReturn (*GetLocationID)(void *, UInt32 *); + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *); + * IOReturn (*GetConfiguration)(void *, UInt8 *); + * IOReturn (*SetConfiguration)(void *, UInt8); + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *); + * IOReturn (*ResetDevice)(void *); + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *); + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *); + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *); + * IOReturn (*USBDeviceOpenSeize)(void *); + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *); + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *); + * IOReturn (*USBDeviceSuspend)(void *, Boolean); + * IOReturn (*USBDeviceAbortPipeZero)(void *); + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *); + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *); + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *); + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32); + * } * } */ public class IOUSBDeviceStruct187 { - public static MemoryLayout $LAYOUT() { - return constants$4.const$5; - } - public static VarHandle _reserved$VH() { - return constants$5.const$0; + IOUSBDeviceStruct187() { + // Should not be called directly } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_POINTER.withName("_reserved"), + IOKit.C_POINTER.withName("QueryInterface"), + IOKit.C_POINTER.withName("AddRef"), + IOKit.C_POINTER.withName("Release"), + IOKit.C_POINTER.withName("CreateDeviceAsyncEventSource"), + IOKit.C_POINTER.withName("GetDeviceAsyncEventSource"), + IOKit.C_POINTER.withName("CreateDeviceAsyncPort"), + IOKit.C_POINTER.withName("GetDeviceAsyncPort"), + IOKit.C_POINTER.withName("USBDeviceOpen"), + IOKit.C_POINTER.withName("USBDeviceClose"), + IOKit.C_POINTER.withName("GetDeviceClass"), + IOKit.C_POINTER.withName("GetDeviceSubClass"), + IOKit.C_POINTER.withName("GetDeviceProtocol"), + IOKit.C_POINTER.withName("GetDeviceVendor"), + IOKit.C_POINTER.withName("GetDeviceProduct"), + IOKit.C_POINTER.withName("GetDeviceReleaseNumber"), + IOKit.C_POINTER.withName("GetDeviceAddress"), + IOKit.C_POINTER.withName("GetDeviceBusPowerAvailable"), + IOKit.C_POINTER.withName("GetDeviceSpeed"), + IOKit.C_POINTER.withName("GetNumberOfConfigurations"), + IOKit.C_POINTER.withName("GetLocationID"), + IOKit.C_POINTER.withName("GetConfigurationDescriptorPtr"), + IOKit.C_POINTER.withName("GetConfiguration"), + IOKit.C_POINTER.withName("SetConfiguration"), + IOKit.C_POINTER.withName("GetBusFrameNumber"), + IOKit.C_POINTER.withName("ResetDevice"), + IOKit.C_POINTER.withName("DeviceRequest"), + IOKit.C_POINTER.withName("DeviceRequestAsync"), + IOKit.C_POINTER.withName("CreateInterfaceIterator"), + IOKit.C_POINTER.withName("USBDeviceOpenSeize"), + IOKit.C_POINTER.withName("DeviceRequestTO"), + IOKit.C_POINTER.withName("DeviceRequestAsyncTO"), + IOKit.C_POINTER.withName("USBDeviceSuspend"), + IOKit.C_POINTER.withName("USBDeviceAbortPipeZero"), + IOKit.C_POINTER.withName("USBGetManufacturerStringIndex"), + IOKit.C_POINTER.withName("USBGetProductStringIndex"), + IOKit.C_POINTER.withName("USBGetSerialNumberStringIndex"), + IOKit.C_POINTER.withName("USBDeviceReEnumerate") + ).withName("IOUSBDeviceStruct187"); + /** - * Getter for field: - * {@snippet : - * void* _reserved; - * } + * The layout of this struct */ - public static MemorySegment _reserved$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$5.const$0.get(seg); + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final AddressLayout _reserved$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("_reserved")); + /** - * Setter for field: - * {@snippet : - * void* _reserved; + * Layout for field: + * {@snippet lang=c : + * void *_reserved * } */ - public static void _reserved$set(MemorySegment seg, MemorySegment x) { - constants$5.const$0.set(seg, x); - } - public static MemorySegment _reserved$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$5.const$0.get(seg.asSlice(index*sizeof())); - } - public static void _reserved$set(MemorySegment seg, long index, MemorySegment x) { - constants$5.const$0.set(seg.asSlice(index*sizeof()), x); + public static final AddressLayout _reserved$layout() { + return _reserved$LAYOUT; } + + private static final long _reserved$OFFSET = 0; + /** - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * Offset for field: + * {@snippet lang=c : + * void *_reserved * } */ - public interface QueryInterface { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(QueryInterface fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$5.const$2, fi, constants$5.const$1, scope); - } - static QueryInterface ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$5.const$3.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long _reserved$offset() { + return _reserved$OFFSET; } - public static VarHandle QueryInterface$VH() { - return constants$5.const$4; - } /** * Getter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * void *_reserved * } */ - public static MemorySegment QueryInterface$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$5.const$4.get(seg); + public static MemorySegment _reserved(MemorySegment struct) { + return struct.get(_reserved$LAYOUT, _reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * void *_reserved * } */ - public static void QueryInterface$set(MemorySegment seg, MemorySegment x) { - constants$5.const$4.set(seg, x); - } - public static MemorySegment QueryInterface$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$5.const$4.get(seg.asSlice(index*sizeof())); - } - public static void QueryInterface$set(MemorySegment seg, long index, MemorySegment x) { - constants$5.const$4.set(seg.asSlice(index*sizeof()), x); - } - public static QueryInterface QueryInterface(MemorySegment segment, Arena scope) { - return QueryInterface.ofAddress(QueryInterface$get(segment), scope); + public static void _reserved(MemorySegment struct, MemorySegment fieldValue) { + struct.set(_reserved$LAYOUT, _reserved$OFFSET, fieldValue); } + /** - * {@snippet : - * ULONG (*AddRef)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public interface AddRef { + public static class QueryInterface { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(AddRef fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$6.const$0, fi, constants$5.const$5, scope); + QueryInterface() { + // Should not be called directly } - static AddRef ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); } - } - public static VarHandle AddRef$VH() { - return constants$6.const$2; - } - /** - * Getter for field: - * {@snippet : - * ULONG (*AddRef)(void*); - * } - */ - public static MemorySegment AddRef$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$6.const$2.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + CFUUIDBytes.layout(), + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(QueryInterface.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(QueryInterface.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout QueryInterface$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("QueryInterface")); + /** - * Setter for field: - * {@snippet : - * ULONG (*AddRef)(void*); + * Layout for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static void AddRef$set(MemorySegment seg, MemorySegment x) { - constants$6.const$2.set(seg, x); - } - public static MemorySegment AddRef$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$6.const$2.get(seg.asSlice(index*sizeof())); - } - public static void AddRef$set(MemorySegment seg, long index, MemorySegment x) { - constants$6.const$2.set(seg.asSlice(index*sizeof()), x); - } - public static AddRef AddRef(MemorySegment segment, Arena scope) { - return AddRef.ofAddress(AddRef$get(segment), scope); + public static final AddressLayout QueryInterface$layout() { + return QueryInterface$LAYOUT; } + + private static final long QueryInterface$OFFSET = 8; + /** - * {@snippet : - * ULONG (*Release)(void*); + * Offset for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public interface Release { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(Release fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$6.const$3, fi, constants$5.const$5, scope); - } - static Release ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long QueryInterface$offset() { + return QueryInterface$OFFSET; } - public static VarHandle Release$VH() { - return constants$6.const$4; - } /** * Getter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static MemorySegment Release$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$6.const$4.get(seg); + public static MemorySegment QueryInterface(MemorySegment struct) { + return struct.get(QueryInterface$LAYOUT, QueryInterface$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static void Release$set(MemorySegment seg, MemorySegment x) { - constants$6.const$4.set(seg, x); - } - public static MemorySegment Release$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$6.const$4.get(seg.asSlice(index*sizeof())); - } - public static void Release$set(MemorySegment seg, long index, MemorySegment x) { - constants$6.const$4.set(seg.asSlice(index*sizeof()), x); - } - public static Release Release(MemorySegment segment, Arena scope) { - return Release.ofAddress(Release$get(segment), scope); + public static void QueryInterface(MemorySegment struct, MemorySegment fieldValue) { + struct.set(QueryInterface$LAYOUT, QueryInterface$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*CreateDeviceAsyncEventSource)(void*,CFRunLoopSourceRef*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public interface CreateDeviceAsyncEventSource { + public static class AddRef { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(CreateDeviceAsyncEventSource fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$7.const$0, fi, constants$6.const$5, scope); + AddRef() { + // Should not be called directly } - static CreateDeviceAsyncEventSource ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle CreateDeviceAsyncEventSource$VH() { - return constants$7.const$2; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*CreateDeviceAsyncEventSource)(void*,CFRunLoopSourceRef*); - * } - */ - public static MemorySegment CreateDeviceAsyncEventSource$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$7.const$2.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(AddRef.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(AddRef.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout AddRef$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("AddRef")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*CreateDeviceAsyncEventSource)(void*,CFRunLoopSourceRef*); + * Layout for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static void CreateDeviceAsyncEventSource$set(MemorySegment seg, MemorySegment x) { - constants$7.const$2.set(seg, x); - } - public static MemorySegment CreateDeviceAsyncEventSource$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$7.const$2.get(seg.asSlice(index*sizeof())); - } - public static void CreateDeviceAsyncEventSource$set(MemorySegment seg, long index, MemorySegment x) { - constants$7.const$2.set(seg.asSlice(index*sizeof()), x); - } - public static CreateDeviceAsyncEventSource CreateDeviceAsyncEventSource(MemorySegment segment, Arena scope) { - return CreateDeviceAsyncEventSource.ofAddress(CreateDeviceAsyncEventSource$get(segment), scope); + public static final AddressLayout AddRef$layout() { + return AddRef$LAYOUT; } + + private static final long AddRef$OFFSET = 16; + /** - * {@snippet : - * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void*); + * Offset for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public interface GetDeviceAsyncEventSource { - - java.lang.foreign.MemorySegment apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(GetDeviceAsyncEventSource fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$7.const$3, fi, constants$3.const$0, scope); - } - static GetDeviceAsyncEventSource ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (java.lang.foreign.MemorySegment)constants$7.const$4.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long AddRef$offset() { + return AddRef$OFFSET; } - public static VarHandle GetDeviceAsyncEventSource$VH() { - return constants$7.const$5; - } /** * Getter for field: - * {@snippet : - * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static MemorySegment GetDeviceAsyncEventSource$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$7.const$5.get(seg); + public static MemorySegment AddRef(MemorySegment struct) { + return struct.get(AddRef$LAYOUT, AddRef$OFFSET); } + /** * Setter for field: - * {@snippet : - * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static void GetDeviceAsyncEventSource$set(MemorySegment seg, MemorySegment x) { - constants$7.const$5.set(seg, x); - } - public static MemorySegment GetDeviceAsyncEventSource$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$7.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceAsyncEventSource$set(MemorySegment seg, long index, MemorySegment x) { - constants$7.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceAsyncEventSource GetDeviceAsyncEventSource(MemorySegment segment, Arena scope) { - return GetDeviceAsyncEventSource.ofAddress(GetDeviceAsyncEventSource$get(segment), scope); + public static void AddRef(MemorySegment struct, MemorySegment fieldValue) { + struct.set(AddRef$LAYOUT, AddRef$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*CreateDeviceAsyncPort)(void*,mach_port_t*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public interface CreateDeviceAsyncPort { + public static class Release { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(CreateDeviceAsyncPort fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$8.const$0, fi, constants$6.const$5, scope); + Release() { + // Should not be called directly } - static CreateDeviceAsyncPort ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle CreateDeviceAsyncPort$VH() { - return constants$8.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*CreateDeviceAsyncPort)(void*,mach_port_t*); - * } - */ - public static MemorySegment CreateDeviceAsyncPort$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$8.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Release.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Release.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*CreateDeviceAsyncPort)(void*,mach_port_t*); + * Layout for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static void CreateDeviceAsyncPort$set(MemorySegment seg, MemorySegment x) { - constants$8.const$1.set(seg, x); - } - public static MemorySegment CreateDeviceAsyncPort$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$8.const$1.get(seg.asSlice(index*sizeof())); - } - public static void CreateDeviceAsyncPort$set(MemorySegment seg, long index, MemorySegment x) { - constants$8.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static CreateDeviceAsyncPort CreateDeviceAsyncPort(MemorySegment segment, Arena scope) { - return CreateDeviceAsyncPort.ofAddress(CreateDeviceAsyncPort$get(segment), scope); + public static final AddressLayout Release$layout() { + return Release$LAYOUT; } + + private static final long Release$OFFSET = 24; + /** - * {@snippet : - * mach_port_t (*GetDeviceAsyncPort)(void*); + * Offset for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public interface GetDeviceAsyncPort { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(GetDeviceAsyncPort fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$8.const$2, fi, constants$5.const$5, scope); - } - static GetDeviceAsyncPort ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long Release$offset() { + return Release$OFFSET; } - public static VarHandle GetDeviceAsyncPort$VH() { - return constants$8.const$3; - } /** * Getter for field: - * {@snippet : - * mach_port_t (*GetDeviceAsyncPort)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static MemorySegment GetDeviceAsyncPort$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$8.const$3.get(seg); + public static MemorySegment Release(MemorySegment struct) { + return struct.get(Release$LAYOUT, Release$OFFSET); } + /** * Setter for field: - * {@snippet : - * mach_port_t (*GetDeviceAsyncPort)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static void GetDeviceAsyncPort$set(MemorySegment seg, MemorySegment x) { - constants$8.const$3.set(seg, x); - } - public static MemorySegment GetDeviceAsyncPort$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$8.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceAsyncPort$set(MemorySegment seg, long index, MemorySegment x) { - constants$8.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceAsyncPort GetDeviceAsyncPort(MemorySegment segment, Arena scope) { - return GetDeviceAsyncPort.ofAddress(GetDeviceAsyncPort$get(segment), scope); + public static void Release(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Release$LAYOUT, Release$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBDeviceOpen)(void*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public interface USBDeviceOpen { + public static class CreateDeviceAsyncEventSource { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBDeviceOpen fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$8.const$4, fi, constants$5.const$5, scope); + CreateDeviceAsyncEventSource() { + // Should not be called directly } - static USBDeviceOpen ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle USBDeviceOpen$VH() { - return constants$8.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceOpen)(void*); - * } - */ - public static MemorySegment USBDeviceOpen$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$8.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(CreateDeviceAsyncEventSource.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CreateDeviceAsyncEventSource.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout CreateDeviceAsyncEventSource$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateDeviceAsyncEventSource")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceOpen)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static void USBDeviceOpen$set(MemorySegment seg, MemorySegment x) { - constants$8.const$5.set(seg, x); - } - public static MemorySegment USBDeviceOpen$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$8.const$5.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceOpen$set(MemorySegment seg, long index, MemorySegment x) { - constants$8.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceOpen USBDeviceOpen(MemorySegment segment, Arena scope) { - return USBDeviceOpen.ofAddress(USBDeviceOpen$get(segment), scope); + public static final AddressLayout CreateDeviceAsyncEventSource$layout() { + return CreateDeviceAsyncEventSource$LAYOUT; } + + private static final long CreateDeviceAsyncEventSource$OFFSET = 32; + /** - * {@snippet : - * IOReturn (*USBDeviceClose)(void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public interface USBDeviceClose { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBDeviceClose fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$9.const$0, fi, constants$5.const$5, scope); - } - static USBDeviceClose ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long CreateDeviceAsyncEventSource$offset() { + return CreateDeviceAsyncEventSource$OFFSET; } - public static VarHandle USBDeviceClose$VH() { - return constants$9.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceClose)(void*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static MemorySegment USBDeviceClose$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$9.const$1.get(seg); + public static MemorySegment CreateDeviceAsyncEventSource(MemorySegment struct) { + return struct.get(CreateDeviceAsyncEventSource$LAYOUT, CreateDeviceAsyncEventSource$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceClose)(void*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static void USBDeviceClose$set(MemorySegment seg, MemorySegment x) { - constants$9.const$1.set(seg, x); - } - public static MemorySegment USBDeviceClose$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$9.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceClose$set(MemorySegment seg, long index, MemorySegment x) { - constants$9.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceClose USBDeviceClose(MemorySegment segment, Arena scope) { - return USBDeviceClose.ofAddress(USBDeviceClose$get(segment), scope); + public static void CreateDeviceAsyncEventSource(MemorySegment struct, MemorySegment fieldValue) { + struct.set(CreateDeviceAsyncEventSource$LAYOUT, CreateDeviceAsyncEventSource$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *) * } */ - public interface GetDeviceClass { + public static class GetDeviceAsyncEventSource { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceClass fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$9.const$2, fi, constants$6.const$5, scope); + GetDeviceAsyncEventSource() { + // Should not be called directly } - static GetDeviceClass ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + MemorySegment apply(MemorySegment _x0); } - } - public static VarHandle GetDeviceClass$VH() { - return constants$9.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceClass)(void*,UInt8*); - * } - */ - public static MemorySegment GetDeviceClass$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$9.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceAsyncEventSource.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceAsyncEventSource.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetDeviceAsyncEventSource$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceAsyncEventSource")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceClass)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *) * } */ - public static void GetDeviceClass$set(MemorySegment seg, MemorySegment x) { - constants$9.const$3.set(seg, x); - } - public static MemorySegment GetDeviceClass$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$9.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceClass$set(MemorySegment seg, long index, MemorySegment x) { - constants$9.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceClass GetDeviceClass(MemorySegment segment, Arena scope) { - return GetDeviceClass.ofAddress(GetDeviceClass$get(segment), scope); + public static final AddressLayout GetDeviceAsyncEventSource$layout() { + return GetDeviceAsyncEventSource$LAYOUT; } + + private static final long GetDeviceAsyncEventSource$OFFSET = 40; + /** - * {@snippet : - * IOReturn (*GetDeviceSubClass)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *) * } */ - public interface GetDeviceSubClass { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceSubClass fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$9.const$4, fi, constants$6.const$5, scope); - } - static GetDeviceSubClass ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetDeviceAsyncEventSource$offset() { + return GetDeviceAsyncEventSource$OFFSET; } - public static VarHandle GetDeviceSubClass$VH() { - return constants$9.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceSubClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *) * } */ - public static MemorySegment GetDeviceSubClass$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$9.const$5.get(seg); + public static MemorySegment GetDeviceAsyncEventSource(MemorySegment struct) { + return struct.get(GetDeviceAsyncEventSource$LAYOUT, GetDeviceAsyncEventSource$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceSubClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *) * } */ - public static void GetDeviceSubClass$set(MemorySegment seg, MemorySegment x) { - constants$9.const$5.set(seg, x); - } - public static MemorySegment GetDeviceSubClass$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$9.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceSubClass$set(MemorySegment seg, long index, MemorySegment x) { - constants$9.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceSubClass GetDeviceSubClass(MemorySegment segment, Arena scope) { - return GetDeviceSubClass.ofAddress(GetDeviceSubClass$get(segment), scope); + public static void GetDeviceAsyncEventSource(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceAsyncEventSource$LAYOUT, GetDeviceAsyncEventSource$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceProtocol)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *) * } */ - public interface GetDeviceProtocol { + public static class CreateDeviceAsyncPort { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceProtocol fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$10.const$0, fi, constants$6.const$5, scope); + CreateDeviceAsyncPort() { + // Should not be called directly } - static GetDeviceProtocol ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle GetDeviceProtocol$VH() { - return constants$10.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceProtocol)(void*,UInt8*); - * } - */ - public static MemorySegment GetDeviceProtocol$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$10.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(CreateDeviceAsyncPort.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CreateDeviceAsyncPort.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout CreateDeviceAsyncPort$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateDeviceAsyncPort")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceProtocol)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *) * } */ - public static void GetDeviceProtocol$set(MemorySegment seg, MemorySegment x) { - constants$10.const$1.set(seg, x); - } - public static MemorySegment GetDeviceProtocol$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$10.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceProtocol$set(MemorySegment seg, long index, MemorySegment x) { - constants$10.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceProtocol GetDeviceProtocol(MemorySegment segment, Arena scope) { - return GetDeviceProtocol.ofAddress(GetDeviceProtocol$get(segment), scope); + public static final AddressLayout CreateDeviceAsyncPort$layout() { + return CreateDeviceAsyncPort$LAYOUT; } + + private static final long CreateDeviceAsyncPort$OFFSET = 48; + /** - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *) * } */ - public interface GetDeviceVendor { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceVendor fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$10.const$2, fi, constants$6.const$5, scope); - } - static GetDeviceVendor ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long CreateDeviceAsyncPort$offset() { + return CreateDeviceAsyncPort$OFFSET; } - public static VarHandle GetDeviceVendor$VH() { - return constants$10.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *) * } */ - public static MemorySegment GetDeviceVendor$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$10.const$3.get(seg); + public static MemorySegment CreateDeviceAsyncPort(MemorySegment struct) { + return struct.get(CreateDeviceAsyncPort$LAYOUT, CreateDeviceAsyncPort$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * {@snippet lang=c : + * IOReturn (*CreateDeviceAsyncPort)(void *, mach_port_t *) * } */ - public static void GetDeviceVendor$set(MemorySegment seg, MemorySegment x) { - constants$10.const$3.set(seg, x); - } - public static MemorySegment GetDeviceVendor$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$10.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceVendor$set(MemorySegment seg, long index, MemorySegment x) { - constants$10.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceVendor GetDeviceVendor(MemorySegment segment, Arena scope) { - return GetDeviceVendor.ofAddress(GetDeviceVendor$get(segment), scope); + public static void CreateDeviceAsyncPort(MemorySegment struct, MemorySegment fieldValue) { + struct.set(CreateDeviceAsyncPort$LAYOUT, CreateDeviceAsyncPort$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetDeviceAsyncPort)(void *) * } */ - public interface GetDeviceProduct { + public static class GetDeviceAsyncPort { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceProduct fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$10.const$4, fi, constants$6.const$5, scope); + GetDeviceAsyncPort() { + // Should not be called directly } - static GetDeviceProduct ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle GetDeviceProduct$VH() { - return constants$10.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); - * } - */ - public static MemorySegment GetDeviceProduct$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$10.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceAsyncPort.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceAsyncPort.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetDeviceAsyncPort$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceAsyncPort")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); + * Layout for field: + * {@snippet lang=c : + * mach_port_t (*GetDeviceAsyncPort)(void *) * } */ - public static void GetDeviceProduct$set(MemorySegment seg, MemorySegment x) { - constants$10.const$5.set(seg, x); - } - public static MemorySegment GetDeviceProduct$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$10.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceProduct$set(MemorySegment seg, long index, MemorySegment x) { - constants$10.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceProduct GetDeviceProduct(MemorySegment segment, Arena scope) { - return GetDeviceProduct.ofAddress(GetDeviceProduct$get(segment), scope); + public static final AddressLayout GetDeviceAsyncPort$layout() { + return GetDeviceAsyncPort$LAYOUT; } + + private static final long GetDeviceAsyncPort$OFFSET = 56; + /** - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * Offset for field: + * {@snippet lang=c : + * mach_port_t (*GetDeviceAsyncPort)(void *) * } */ - public interface GetDeviceReleaseNumber { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceReleaseNumber fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$11.const$0, fi, constants$6.const$5, scope); - } - static GetDeviceReleaseNumber ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetDeviceAsyncPort$offset() { + return GetDeviceAsyncPort$OFFSET; } - public static VarHandle GetDeviceReleaseNumber$VH() { - return constants$11.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetDeviceAsyncPort)(void *) * } */ - public static MemorySegment GetDeviceReleaseNumber$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$11.const$1.get(seg); + public static MemorySegment GetDeviceAsyncPort(MemorySegment struct) { + return struct.get(GetDeviceAsyncPort$LAYOUT, GetDeviceAsyncPort$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetDeviceAsyncPort)(void *) * } */ - public static void GetDeviceReleaseNumber$set(MemorySegment seg, MemorySegment x) { - constants$11.const$1.set(seg, x); - } - public static MemorySegment GetDeviceReleaseNumber$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$11.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceReleaseNumber$set(MemorySegment seg, long index, MemorySegment x) { - constants$11.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceReleaseNumber GetDeviceReleaseNumber(MemorySegment segment, Arena scope) { - return GetDeviceReleaseNumber.ofAddress(GetDeviceReleaseNumber$get(segment), scope); + public static void GetDeviceAsyncPort(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceAsyncPort$LAYOUT, GetDeviceAsyncPort$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceAddress)(void*,USBDeviceAddress*); + * {@snippet lang=c : + * IOReturn (*USBDeviceOpen)(void *) * } */ - public interface GetDeviceAddress { + public static class USBDeviceOpen { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceAddress fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$11.const$2, fi, constants$6.const$5, scope); + USBDeviceOpen() { + // Should not be called directly } - static GetDeviceAddress ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle GetDeviceAddress$VH() { - return constants$11.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceAddress)(void*,USBDeviceAddress*); - * } - */ - public static MemorySegment GetDeviceAddress$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$11.const$3.get(seg); - } + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceOpen.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceOpen.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout USBDeviceOpen$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceOpen")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceAddress)(void*,USBDeviceAddress*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpen)(void *) * } */ - public static void GetDeviceAddress$set(MemorySegment seg, MemorySegment x) { - constants$11.const$3.set(seg, x); + public static final AddressLayout USBDeviceOpen$layout() { + return USBDeviceOpen$LAYOUT; } - public static MemorySegment GetDeviceAddress$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$11.const$3.get(seg.asSlice(index*sizeof())); + + private static final long USBDeviceOpen$OFFSET = 64; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpen)(void *) + * } + */ + public static final long USBDeviceOpen$offset() { + return USBDeviceOpen$OFFSET; } - public static void GetDeviceAddress$set(MemorySegment seg, long index, MemorySegment x) { - constants$11.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpen)(void *) + * } + */ + public static MemorySegment USBDeviceOpen(MemorySegment struct) { + return struct.get(USBDeviceOpen$LAYOUT, USBDeviceOpen$OFFSET); } - public static GetDeviceAddress GetDeviceAddress(MemorySegment segment, Arena scope) { - return GetDeviceAddress.ofAddress(GetDeviceAddress$get(segment), scope); + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpen)(void *) + * } + */ + public static void USBDeviceOpen(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceOpen$LAYOUT, USBDeviceOpen$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceBusPowerAvailable)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*USBDeviceClose)(void *) * } */ - public interface GetDeviceBusPowerAvailable { + public static class USBDeviceClose { + + USBDeviceClose() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); + } - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceBusPowerAvailable fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$11.const$4, fi, constants$6.const$5, scope); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceClose.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceClose.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } - static GetDeviceBusPowerAvailable ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle GetDeviceBusPowerAvailable$VH() { - return constants$11.const$5; + private static final AddressLayout USBDeviceClose$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceClose")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceClose)(void *) + * } + */ + public static final AddressLayout USBDeviceClose$layout() { + return USBDeviceClose$LAYOUT; + } + + private static final long USBDeviceClose$OFFSET = 72; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceClose)(void *) + * } + */ + public static final long USBDeviceClose$offset() { + return USBDeviceClose$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceBusPowerAvailable)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*USBDeviceClose)(void *) * } */ - public static MemorySegment GetDeviceBusPowerAvailable$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$11.const$5.get(seg); + public static MemorySegment USBDeviceClose(MemorySegment struct) { + return struct.get(USBDeviceClose$LAYOUT, USBDeviceClose$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceBusPowerAvailable)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*USBDeviceClose)(void *) * } */ - public static void GetDeviceBusPowerAvailable$set(MemorySegment seg, MemorySegment x) { - constants$11.const$5.set(seg, x); - } - public static MemorySegment GetDeviceBusPowerAvailable$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$11.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceBusPowerAvailable$set(MemorySegment seg, long index, MemorySegment x) { - constants$11.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceBusPowerAvailable GetDeviceBusPowerAvailable(MemorySegment segment, Arena scope) { - return GetDeviceBusPowerAvailable.ofAddress(GetDeviceBusPowerAvailable$get(segment), scope); + public static void USBDeviceClose(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceClose$LAYOUT, USBDeviceClose$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceSpeed)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceClass)(void *, UInt8 *) * } */ - public interface GetDeviceSpeed { + public static class GetDeviceClass { + + GetDeviceClass() { + // Should not be called directly + } - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceSpeed fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$12.const$0, fi, constants$6.const$5, scope); + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - static GetDeviceSpeed ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceClass.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceClass.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle GetDeviceSpeed$VH() { - return constants$12.const$1; + private static final AddressLayout GetDeviceClass$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceClass)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetDeviceClass$layout() { + return GetDeviceClass$LAYOUT; + } + + private static final long GetDeviceClass$OFFSET = 80; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceClass)(void *, UInt8 *) + * } + */ + public static final long GetDeviceClass$offset() { + return GetDeviceClass$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceSpeed)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceClass)(void *, UInt8 *) * } */ - public static MemorySegment GetDeviceSpeed$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$12.const$1.get(seg); + public static MemorySegment GetDeviceClass(MemorySegment struct) { + return struct.get(GetDeviceClass$LAYOUT, GetDeviceClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceSpeed)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceClass)(void *, UInt8 *) * } */ - public static void GetDeviceSpeed$set(MemorySegment seg, MemorySegment x) { - constants$12.const$1.set(seg, x); - } - public static MemorySegment GetDeviceSpeed$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$12.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceSpeed$set(MemorySegment seg, long index, MemorySegment x) { - constants$12.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceSpeed GetDeviceSpeed(MemorySegment segment, Arena scope) { - return GetDeviceSpeed.ofAddress(GetDeviceSpeed$get(segment), scope); + public static void GetDeviceClass(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceClass$LAYOUT, GetDeviceClass$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetNumberOfConfigurations)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *) * } */ - public interface GetNumberOfConfigurations { + public static class GetDeviceSubClass { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetNumberOfConfigurations fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$12.const$2, fi, constants$6.const$5, scope); + GetDeviceSubClass() { + // Should not be called directly } - static GetNumberOfConfigurations ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceSubClass.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceSubClass.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle GetNumberOfConfigurations$VH() { - return constants$12.const$3; + private static final AddressLayout GetDeviceSubClass$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceSubClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetDeviceSubClass$layout() { + return GetDeviceSubClass$LAYOUT; + } + + private static final long GetDeviceSubClass$OFFSET = 88; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *) + * } + */ + public static final long GetDeviceSubClass$offset() { + return GetDeviceSubClass$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*GetNumberOfConfigurations)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *) * } */ - public static MemorySegment GetNumberOfConfigurations$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$12.const$3.get(seg); + public static MemorySegment GetDeviceSubClass(MemorySegment struct) { + return struct.get(GetDeviceSubClass$LAYOUT, GetDeviceSubClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetNumberOfConfigurations)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceSubClass)(void *, UInt8 *) + * } + */ + public static void GetDeviceSubClass(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceSubClass$LAYOUT, GetDeviceSubClass$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *) + * } + */ + public static class GetDeviceProtocol { + + GetDeviceProtocol() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceProtocol.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceProtocol.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetDeviceProtocol$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceProtocol")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *) * } */ - public static void GetNumberOfConfigurations$set(MemorySegment seg, MemorySegment x) { - constants$12.const$3.set(seg, x); + public static final AddressLayout GetDeviceProtocol$layout() { + return GetDeviceProtocol$LAYOUT; } - public static MemorySegment GetNumberOfConfigurations$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$12.const$3.get(seg.asSlice(index*sizeof())); + + private static final long GetDeviceProtocol$OFFSET = 96; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *) + * } + */ + public static final long GetDeviceProtocol$offset() { + return GetDeviceProtocol$OFFSET; } - public static void GetNumberOfConfigurations$set(MemorySegment seg, long index, MemorySegment x) { - constants$12.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *) + * } + */ + public static MemorySegment GetDeviceProtocol(MemorySegment struct) { + return struct.get(GetDeviceProtocol$LAYOUT, GetDeviceProtocol$OFFSET); } - public static GetNumberOfConfigurations GetNumberOfConfigurations(MemorySegment segment, Arena scope) { - return GetNumberOfConfigurations.ofAddress(GetNumberOfConfigurations$get(segment), scope); + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProtocol)(void *, UInt8 *) + * } + */ + public static void GetDeviceProtocol(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceProtocol$LAYOUT, GetDeviceProtocol$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public interface GetLocationID { + public static class GetDeviceVendor { + + GetDeviceVendor() { + // Should not be called directly + } - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetLocationID fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$12.const$4, fi, constants$6.const$5, scope); + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - static GetLocationID ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceVendor.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceVendor.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle GetLocationID$VH() { - return constants$12.const$5; + private static final AddressLayout GetDeviceVendor$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceVendor")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) + * } + */ + public static final AddressLayout GetDeviceVendor$layout() { + return GetDeviceVendor$LAYOUT; + } + + private static final long GetDeviceVendor$OFFSET = 104; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) + * } + */ + public static final long GetDeviceVendor$offset() { + return GetDeviceVendor$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public static MemorySegment GetLocationID$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$12.const$5.get(seg); + public static MemorySegment GetDeviceVendor(MemorySegment struct) { + return struct.get(GetDeviceVendor$LAYOUT, GetDeviceVendor$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) + * } + */ + public static void GetDeviceVendor(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceVendor$LAYOUT, GetDeviceVendor$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) + * } + */ + public static class GetDeviceProduct { + + GetDeviceProduct() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceProduct.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceProduct.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetDeviceProduct$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceProduct")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public static void GetLocationID$set(MemorySegment seg, MemorySegment x) { - constants$12.const$5.set(seg, x); + public static final AddressLayout GetDeviceProduct$layout() { + return GetDeviceProduct$LAYOUT; } - public static MemorySegment GetLocationID$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$12.const$5.get(seg.asSlice(index*sizeof())); + + private static final long GetDeviceProduct$OFFSET = 112; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) + * } + */ + public static final long GetDeviceProduct$offset() { + return GetDeviceProduct$OFFSET; } - public static void GetLocationID$set(MemorySegment seg, long index, MemorySegment x) { - constants$12.const$5.set(seg.asSlice(index*sizeof()), x); + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) + * } + */ + public static MemorySegment GetDeviceProduct(MemorySegment struct) { + return struct.get(GetDeviceProduct$LAYOUT, GetDeviceProduct$OFFSET); } - public static GetLocationID GetLocationID(MemorySegment segment, Arena scope) { - return GetLocationID.ofAddress(GetLocationID$get(segment), scope); + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) + * } + */ + public static void GetDeviceProduct(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceProduct$LAYOUT, GetDeviceProduct$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetConfigurationDescriptorPtr)(void*,UInt8,IOUSBConfigurationDescriptorPtr*); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public interface GetConfigurationDescriptorPtr { + public static class GetDeviceReleaseNumber { + + GetDeviceReleaseNumber() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(GetConfigurationDescriptorPtr fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$13.const$1, fi, constants$13.const$0, scope); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceReleaseNumber.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceReleaseNumber.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } - static GetConfigurationDescriptorPtr ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$13.const$2.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } } - public static VarHandle GetConfigurationDescriptorPtr$VH() { - return constants$13.const$3; + private static final AddressLayout GetDeviceReleaseNumber$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceReleaseNumber")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) + * } + */ + public static final AddressLayout GetDeviceReleaseNumber$layout() { + return GetDeviceReleaseNumber$LAYOUT; + } + + private static final long GetDeviceReleaseNumber$OFFSET = 120; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) + * } + */ + public static final long GetDeviceReleaseNumber$offset() { + return GetDeviceReleaseNumber$OFFSET; } + /** * Getter for field: - * {@snippet : - * IOReturn (*GetConfigurationDescriptorPtr)(void*,UInt8,IOUSBConfigurationDescriptorPtr*); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public static MemorySegment GetConfigurationDescriptorPtr$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$13.const$3.get(seg); + public static MemorySegment GetDeviceReleaseNumber(MemorySegment struct) { + return struct.get(GetDeviceReleaseNumber$LAYOUT, GetDeviceReleaseNumber$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetConfigurationDescriptorPtr)(void*,UInt8,IOUSBConfigurationDescriptorPtr*); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) + * } + */ + public static void GetDeviceReleaseNumber(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceReleaseNumber$LAYOUT, GetDeviceReleaseNumber$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *) * } */ - public static void GetConfigurationDescriptorPtr$set(MemorySegment seg, MemorySegment x) { - constants$13.const$3.set(seg, x); + public static class GetDeviceAddress { + + GetDeviceAddress() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceAddress.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceAddress.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } - public static MemorySegment GetConfigurationDescriptorPtr$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$13.const$3.get(seg.asSlice(index*sizeof())); + + private static final AddressLayout GetDeviceAddress$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceAddress")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *) + * } + */ + public static final AddressLayout GetDeviceAddress$layout() { + return GetDeviceAddress$LAYOUT; } - public static void GetConfigurationDescriptorPtr$set(MemorySegment seg, long index, MemorySegment x) { - constants$13.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final long GetDeviceAddress$OFFSET = 128; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *) + * } + */ + public static final long GetDeviceAddress$offset() { + return GetDeviceAddress$OFFSET; } - public static GetConfigurationDescriptorPtr GetConfigurationDescriptorPtr(MemorySegment segment, Arena scope) { - return GetConfigurationDescriptorPtr.ofAddress(GetConfigurationDescriptorPtr$get(segment), scope); + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *) + * } + */ + public static MemorySegment GetDeviceAddress(MemorySegment struct) { + return struct.get(GetDeviceAddress$LAYOUT, GetDeviceAddress$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceAddress)(void *, USBDeviceAddress *) + * } + */ + public static void GetDeviceAddress(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceAddress$LAYOUT, GetDeviceAddress$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *) + * } + */ + public static class GetDeviceBusPowerAvailable { + + GetDeviceBusPowerAvailable() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceBusPowerAvailable.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceBusPowerAvailable.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetDeviceBusPowerAvailable$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceBusPowerAvailable")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *) + * } + */ + public static final AddressLayout GetDeviceBusPowerAvailable$layout() { + return GetDeviceBusPowerAvailable$LAYOUT; + } + + private static final long GetDeviceBusPowerAvailable$OFFSET = 136; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *) + * } + */ + public static final long GetDeviceBusPowerAvailable$offset() { + return GetDeviceBusPowerAvailable$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *) + * } + */ + public static MemorySegment GetDeviceBusPowerAvailable(MemorySegment struct) { + return struct.get(GetDeviceBusPowerAvailable$LAYOUT, GetDeviceBusPowerAvailable$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceBusPowerAvailable)(void *, UInt32 *) + * } + */ + public static void GetDeviceBusPowerAvailable(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceBusPowerAvailable$LAYOUT, GetDeviceBusPowerAvailable$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *) + * } + */ + public static class GetDeviceSpeed { + + GetDeviceSpeed() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceSpeed.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceSpeed.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetDeviceSpeed$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceSpeed")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetDeviceSpeed$layout() { + return GetDeviceSpeed$LAYOUT; + } + + private static final long GetDeviceSpeed$OFFSET = 144; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *) + * } + */ + public static final long GetDeviceSpeed$offset() { + return GetDeviceSpeed$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *) + * } + */ + public static MemorySegment GetDeviceSpeed(MemorySegment struct) { + return struct.get(GetDeviceSpeed$LAYOUT, GetDeviceSpeed$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceSpeed)(void *, UInt8 *) + * } + */ + public static void GetDeviceSpeed(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceSpeed$LAYOUT, GetDeviceSpeed$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *) + * } + */ + public static class GetNumberOfConfigurations { + + GetNumberOfConfigurations() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetNumberOfConfigurations.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetNumberOfConfigurations.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetNumberOfConfigurations$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetNumberOfConfigurations")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetNumberOfConfigurations$layout() { + return GetNumberOfConfigurations$LAYOUT; + } + + private static final long GetNumberOfConfigurations$OFFSET = 152; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *) + * } + */ + public static final long GetNumberOfConfigurations$offset() { + return GetNumberOfConfigurations$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *) + * } + */ + public static MemorySegment GetNumberOfConfigurations(MemorySegment struct) { + return struct.get(GetNumberOfConfigurations$LAYOUT, GetNumberOfConfigurations$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetNumberOfConfigurations)(void *, UInt8 *) + * } + */ + public static void GetNumberOfConfigurations(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetNumberOfConfigurations$LAYOUT, GetNumberOfConfigurations$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static class GetLocationID { + + GetLocationID() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetLocationID.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetLocationID.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetLocationID$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetLocationID")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static final AddressLayout GetLocationID$layout() { + return GetLocationID$LAYOUT; + } + + private static final long GetLocationID$OFFSET = 160; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static final long GetLocationID$offset() { + return GetLocationID$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static MemorySegment GetLocationID(MemorySegment struct) { + return struct.get(GetLocationID$LAYOUT, GetLocationID$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static void GetLocationID(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetLocationID$LAYOUT, GetLocationID$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *) + * } + */ + public static class GetConfigurationDescriptorPtr { + + GetConfigurationDescriptorPtr() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetConfigurationDescriptorPtr.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetConfigurationDescriptorPtr.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetConfigurationDescriptorPtr$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetConfigurationDescriptorPtr")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *) + * } + */ + public static final AddressLayout GetConfigurationDescriptorPtr$layout() { + return GetConfigurationDescriptorPtr$LAYOUT; + } + + private static final long GetConfigurationDescriptorPtr$OFFSET = 168; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *) + * } + */ + public static final long GetConfigurationDescriptorPtr$offset() { + return GetConfigurationDescriptorPtr$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *) + * } + */ + public static MemorySegment GetConfigurationDescriptorPtr(MemorySegment struct) { + return struct.get(GetConfigurationDescriptorPtr$LAYOUT, GetConfigurationDescriptorPtr$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationDescriptorPtr)(void *, UInt8, IOUSBConfigurationDescriptorPtr *) + * } + */ + public static void GetConfigurationDescriptorPtr(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetConfigurationDescriptorPtr$LAYOUT, GetConfigurationDescriptorPtr$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetConfiguration)(void *, UInt8 *) + * } + */ + public static class GetConfiguration { + + GetConfiguration() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetConfiguration.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetConfiguration.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetConfiguration$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetConfiguration")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetConfiguration)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetConfiguration$layout() { + return GetConfiguration$LAYOUT; + } + + private static final long GetConfiguration$OFFSET = 176; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetConfiguration)(void *, UInt8 *) + * } + */ + public static final long GetConfiguration$offset() { + return GetConfiguration$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetConfiguration)(void *, UInt8 *) + * } + */ + public static MemorySegment GetConfiguration(MemorySegment struct) { + return struct.get(GetConfiguration$LAYOUT, GetConfiguration$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetConfiguration)(void *, UInt8 *) + * } + */ + public static void GetConfiguration(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetConfiguration$LAYOUT, GetConfiguration$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*SetConfiguration)(void *, UInt8) + * } + */ + public static class SetConfiguration { + + SetConfiguration() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(SetConfiguration.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(SetConfiguration.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout SetConfiguration$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("SetConfiguration")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*SetConfiguration)(void *, UInt8) + * } + */ + public static final AddressLayout SetConfiguration$layout() { + return SetConfiguration$LAYOUT; + } + + private static final long SetConfiguration$OFFSET = 184; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*SetConfiguration)(void *, UInt8) + * } + */ + public static final long SetConfiguration$offset() { + return SetConfiguration$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*SetConfiguration)(void *, UInt8) + * } + */ + public static MemorySegment SetConfiguration(MemorySegment struct) { + return struct.get(SetConfiguration$LAYOUT, SetConfiguration$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*SetConfiguration)(void *, UInt8) + * } + */ + public static void SetConfiguration(MemorySegment struct, MemorySegment fieldValue) { + struct.set(SetConfiguration$LAYOUT, SetConfiguration$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static class GetBusFrameNumber { + + GetBusFrameNumber() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetBusFrameNumber.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetBusFrameNumber.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetBusFrameNumber$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetBusFrameNumber")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static final AddressLayout GetBusFrameNumber$layout() { + return GetBusFrameNumber$LAYOUT; + } + + private static final long GetBusFrameNumber$OFFSET = 192; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static final long GetBusFrameNumber$offset() { + return GetBusFrameNumber$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static MemorySegment GetBusFrameNumber(MemorySegment struct) { + return struct.get(GetBusFrameNumber$LAYOUT, GetBusFrameNumber$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static void GetBusFrameNumber(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetBusFrameNumber$LAYOUT, GetBusFrameNumber$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ResetDevice)(void *) + * } + */ + public static class ResetDevice { + + ResetDevice() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ResetDevice.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ResetDevice.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ResetDevice$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ResetDevice")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ResetDevice)(void *) + * } + */ + public static final AddressLayout ResetDevice$layout() { + return ResetDevice$LAYOUT; + } + + private static final long ResetDevice$OFFSET = 200; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ResetDevice)(void *) + * } + */ + public static final long ResetDevice$offset() { + return ResetDevice$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ResetDevice)(void *) + * } + */ + public static MemorySegment ResetDevice(MemorySegment struct) { + return struct.get(ResetDevice$LAYOUT, ResetDevice$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ResetDevice)(void *) + * } + */ + public static void ResetDevice(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ResetDevice$LAYOUT, ResetDevice$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *) + * } + */ + public static class DeviceRequest { + + DeviceRequest() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(DeviceRequest.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(DeviceRequest.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout DeviceRequest$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("DeviceRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *) + * } + */ + public static final AddressLayout DeviceRequest$layout() { + return DeviceRequest$LAYOUT; + } + + private static final long DeviceRequest$OFFSET = 208; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *) + * } + */ + public static final long DeviceRequest$offset() { + return DeviceRequest$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *) + * } + */ + public static MemorySegment DeviceRequest(MemorySegment struct) { + return struct.get(DeviceRequest$LAYOUT, DeviceRequest$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequest)(void *, IOUSBDevRequest *) + * } + */ + public static void DeviceRequest(MemorySegment struct, MemorySegment fieldValue) { + struct.set(DeviceRequest$LAYOUT, DeviceRequest$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static class DeviceRequestAsync { + + DeviceRequestAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, MemorySegment _x3); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(DeviceRequestAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(DeviceRequestAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, MemorySegment _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout DeviceRequestAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("DeviceRequestAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout DeviceRequestAsync$layout() { + return DeviceRequestAsync$LAYOUT; + } + + private static final long DeviceRequestAsync$OFFSET = 216; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static final long DeviceRequestAsync$offset() { + return DeviceRequestAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment DeviceRequestAsync(MemorySegment struct) { + return struct.get(DeviceRequestAsync$LAYOUT, DeviceRequestAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsync)(void *, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static void DeviceRequestAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(DeviceRequestAsync$LAYOUT, DeviceRequestAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *) + * } + */ + public static class CreateInterfaceIterator { + + CreateInterfaceIterator() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(CreateInterfaceIterator.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CreateInterfaceIterator.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout CreateInterfaceIterator$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateInterfaceIterator")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *) + * } + */ + public static final AddressLayout CreateInterfaceIterator$layout() { + return CreateInterfaceIterator$LAYOUT; + } + + private static final long CreateInterfaceIterator$OFFSET = 224; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *) + * } + */ + public static final long CreateInterfaceIterator$offset() { + return CreateInterfaceIterator$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *) + * } + */ + public static MemorySegment CreateInterfaceIterator(MemorySegment struct) { + return struct.get(CreateInterfaceIterator$LAYOUT, CreateInterfaceIterator$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceIterator)(void *, IOUSBFindInterfaceRequest *, io_iterator_t *) + * } + */ + public static void CreateInterfaceIterator(MemorySegment struct, MemorySegment fieldValue) { + struct.set(CreateInterfaceIterator$LAYOUT, CreateInterfaceIterator$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*USBDeviceOpenSeize)(void *) + * } + */ + public static class USBDeviceOpenSeize { + + USBDeviceOpenSeize() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceOpenSeize.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceOpenSeize.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout USBDeviceOpenSeize$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceOpenSeize")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpenSeize)(void *) + * } + */ + public static final AddressLayout USBDeviceOpenSeize$layout() { + return USBDeviceOpenSeize$LAYOUT; + } + + private static final long USBDeviceOpenSeize$OFFSET = 232; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpenSeize)(void *) + * } + */ + public static final long USBDeviceOpenSeize$offset() { + return USBDeviceOpenSeize$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpenSeize)(void *) + * } + */ + public static MemorySegment USBDeviceOpenSeize(MemorySegment struct) { + return struct.get(USBDeviceOpenSeize$LAYOUT, USBDeviceOpenSeize$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceOpenSeize)(void *) + * } + */ + public static void USBDeviceOpenSeize(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceOpenSeize$LAYOUT, USBDeviceOpenSeize$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *) + * } + */ + public static class DeviceRequestTO { + + DeviceRequestTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(DeviceRequestTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(DeviceRequestTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout DeviceRequestTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("DeviceRequestTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *) + * } + */ + public static final AddressLayout DeviceRequestTO$layout() { + return DeviceRequestTO$LAYOUT; } + + private static final long DeviceRequestTO$OFFSET = 240; + /** - * {@snippet : - * IOReturn (*GetConfiguration)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *) * } */ - public interface GetConfiguration { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetConfiguration fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$13.const$4, fi, constants$6.const$5, scope); - } - static GetConfiguration ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long DeviceRequestTO$offset() { + return DeviceRequestTO$OFFSET; } - public static VarHandle GetConfiguration$VH() { - return constants$13.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetConfiguration)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *) * } */ - public static MemorySegment GetConfiguration$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$13.const$5.get(seg); + public static MemorySegment DeviceRequestTO(MemorySegment struct) { + return struct.get(DeviceRequestTO$LAYOUT, DeviceRequestTO$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetConfiguration)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*DeviceRequestTO)(void *, IOUSBDevRequestTO *) * } */ - public static void GetConfiguration$set(MemorySegment seg, MemorySegment x) { - constants$13.const$5.set(seg, x); - } - public static MemorySegment GetConfiguration$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$13.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetConfiguration$set(MemorySegment seg, long index, MemorySegment x) { - constants$13.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetConfiguration GetConfiguration(MemorySegment segment, Arena scope) { - return GetConfiguration.ofAddress(GetConfiguration$get(segment), scope); + public static void DeviceRequestTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(DeviceRequestTO$LAYOUT, DeviceRequestTO$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*SetConfiguration)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *) * } */ - public interface SetConfiguration { + public static class DeviceRequestAsyncTO { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(SetConfiguration fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$14.const$1, fi, constants$14.const$0, scope); + DeviceRequestAsyncTO() { + // Should not be called directly } - static SetConfiguration ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, MemorySegment _x3); } - } - public static VarHandle SetConfiguration$VH() { - return constants$14.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*SetConfiguration)(void*,UInt8); - * } - */ - public static MemorySegment SetConfiguration$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$14.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(DeviceRequestAsyncTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(DeviceRequestAsyncTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2, MemorySegment _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout DeviceRequestAsyncTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("DeviceRequestAsyncTO")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*SetConfiguration)(void*,UInt8); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *) * } */ - public static void SetConfiguration$set(MemorySegment seg, MemorySegment x) { - constants$14.const$3.set(seg, x); - } - public static MemorySegment SetConfiguration$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$14.const$3.get(seg.asSlice(index*sizeof())); - } - public static void SetConfiguration$set(MemorySegment seg, long index, MemorySegment x) { - constants$14.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static SetConfiguration SetConfiguration(MemorySegment segment, Arena scope) { - return SetConfiguration.ofAddress(SetConfiguration$get(segment), scope); + public static final AddressLayout DeviceRequestAsyncTO$layout() { + return DeviceRequestAsyncTO$LAYOUT; } + + private static final long DeviceRequestAsyncTO$OFFSET = 248; + /** - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *) * } */ - public interface GetBusFrameNumber { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(GetBusFrameNumber fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$14.const$5, fi, constants$14.const$4, scope); - } - static GetBusFrameNumber ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$15.const$0.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long DeviceRequestAsyncTO$offset() { + return DeviceRequestAsyncTO$OFFSET; } - public static VarHandle GetBusFrameNumber$VH() { - return constants$15.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *) * } */ - public static MemorySegment GetBusFrameNumber$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$15.const$1.get(seg); + public static MemorySegment DeviceRequestAsyncTO(MemorySegment struct) { + return struct.get(DeviceRequestAsyncTO$LAYOUT, DeviceRequestAsyncTO$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * {@snippet lang=c : + * IOReturn (*DeviceRequestAsyncTO)(void *, IOUSBDevRequestTO *, IOAsyncCallback1, void *) * } */ - public static void GetBusFrameNumber$set(MemorySegment seg, MemorySegment x) { - constants$15.const$1.set(seg, x); - } - public static MemorySegment GetBusFrameNumber$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$15.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetBusFrameNumber$set(MemorySegment seg, long index, MemorySegment x) { - constants$15.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetBusFrameNumber GetBusFrameNumber(MemorySegment segment, Arena scope) { - return GetBusFrameNumber.ofAddress(GetBusFrameNumber$get(segment), scope); + public static void DeviceRequestAsyncTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(DeviceRequestAsyncTO$LAYOUT, DeviceRequestAsyncTO$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*ResetDevice)(void*); + * {@snippet lang=c : + * IOReturn (*USBDeviceSuspend)(void *, Boolean) * } */ - public interface ResetDevice { + public static class USBDeviceSuspend { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(ResetDevice fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$15.const$2, fi, constants$5.const$5, scope); + USBDeviceSuspend() { + // Should not be called directly } - static ResetDevice ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); } - } - public static VarHandle ResetDevice$VH() { - return constants$15.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*ResetDevice)(void*); - * } - */ - public static MemorySegment ResetDevice$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$15.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceSuspend.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceSuspend.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBDeviceSuspend$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceSuspend")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*ResetDevice)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceSuspend)(void *, Boolean) * } */ - public static void ResetDevice$set(MemorySegment seg, MemorySegment x) { - constants$15.const$3.set(seg, x); - } - public static MemorySegment ResetDevice$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$15.const$3.get(seg.asSlice(index*sizeof())); - } - public static void ResetDevice$set(MemorySegment seg, long index, MemorySegment x) { - constants$15.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static ResetDevice ResetDevice(MemorySegment segment, Arena scope) { - return ResetDevice.ofAddress(ResetDevice$get(segment), scope); + public static final AddressLayout USBDeviceSuspend$layout() { + return USBDeviceSuspend$LAYOUT; } + + private static final long USBDeviceSuspend$OFFSET = 256; + /** - * {@snippet : - * IOReturn (*DeviceRequest)(void*,IOUSBDevRequest*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceSuspend)(void *, Boolean) * } */ - public interface DeviceRequest { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(DeviceRequest fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$15.const$4, fi, constants$6.const$5, scope); - } - static DeviceRequest ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBDeviceSuspend$offset() { + return USBDeviceSuspend$OFFSET; } - public static VarHandle DeviceRequest$VH() { - return constants$15.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*DeviceRequest)(void*,IOUSBDevRequest*); + * {@snippet lang=c : + * IOReturn (*USBDeviceSuspend)(void *, Boolean) * } */ - public static MemorySegment DeviceRequest$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$15.const$5.get(seg); + public static MemorySegment USBDeviceSuspend(MemorySegment struct) { + return struct.get(USBDeviceSuspend$LAYOUT, USBDeviceSuspend$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*DeviceRequest)(void*,IOUSBDevRequest*); + * {@snippet lang=c : + * IOReturn (*USBDeviceSuspend)(void *, Boolean) * } */ - public static void DeviceRequest$set(MemorySegment seg, MemorySegment x) { - constants$15.const$5.set(seg, x); - } - public static MemorySegment DeviceRequest$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$15.const$5.get(seg.asSlice(index*sizeof())); - } - public static void DeviceRequest$set(MemorySegment seg, long index, MemorySegment x) { - constants$15.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static DeviceRequest DeviceRequest(MemorySegment segment, Arena scope) { - return DeviceRequest.ofAddress(DeviceRequest$get(segment), scope); + public static void USBDeviceSuspend(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceSuspend$LAYOUT, USBDeviceSuspend$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*DeviceRequestAsync)(void*,IOUSBDevRequest*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*USBDeviceAbortPipeZero)(void *) * } */ - public interface DeviceRequestAsync { + public static class USBDeviceAbortPipeZero { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3); - static MemorySegment allocate(DeviceRequestAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$16.const$1, fi, constants$16.const$0, scope); + USBDeviceAbortPipeZero() { + // Should not be called directly } - static DeviceRequestAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3) -> { - try { - return (int)constants$16.const$2.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle DeviceRequestAsync$VH() { - return constants$16.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*DeviceRequestAsync)(void*,IOUSBDevRequest*,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment DeviceRequestAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$16.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceAbortPipeZero.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceAbortPipeZero.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBDeviceAbortPipeZero$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceAbortPipeZero")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*DeviceRequestAsync)(void*,IOUSBDevRequest*,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceAbortPipeZero)(void *) * } */ - public static void DeviceRequestAsync$set(MemorySegment seg, MemorySegment x) { - constants$16.const$3.set(seg, x); - } - public static MemorySegment DeviceRequestAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$16.const$3.get(seg.asSlice(index*sizeof())); - } - public static void DeviceRequestAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$16.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static DeviceRequestAsync DeviceRequestAsync(MemorySegment segment, Arena scope) { - return DeviceRequestAsync.ofAddress(DeviceRequestAsync$get(segment), scope); + public static final AddressLayout USBDeviceAbortPipeZero$layout() { + return USBDeviceAbortPipeZero$LAYOUT; } + + private static final long USBDeviceAbortPipeZero$OFFSET = 264; + /** - * {@snippet : - * IOReturn (*CreateInterfaceIterator)(void*,IOUSBFindInterfaceRequest*,io_iterator_t*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceAbortPipeZero)(void *) * } */ - public interface CreateInterfaceIterator { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(CreateInterfaceIterator fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$16.const$4, fi, constants$14.const$4, scope); - } - static CreateInterfaceIterator ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$15.const$0.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBDeviceAbortPipeZero$offset() { + return USBDeviceAbortPipeZero$OFFSET; } - public static VarHandle CreateInterfaceIterator$VH() { - return constants$16.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*CreateInterfaceIterator)(void*,IOUSBFindInterfaceRequest*,io_iterator_t*); + * {@snippet lang=c : + * IOReturn (*USBDeviceAbortPipeZero)(void *) * } */ - public static MemorySegment CreateInterfaceIterator$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$16.const$5.get(seg); + public static MemorySegment USBDeviceAbortPipeZero(MemorySegment struct) { + return struct.get(USBDeviceAbortPipeZero$LAYOUT, USBDeviceAbortPipeZero$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*CreateInterfaceIterator)(void*,IOUSBFindInterfaceRequest*,io_iterator_t*); + * {@snippet lang=c : + * IOReturn (*USBDeviceAbortPipeZero)(void *) * } */ - public static void CreateInterfaceIterator$set(MemorySegment seg, MemorySegment x) { - constants$16.const$5.set(seg, x); - } - public static MemorySegment CreateInterfaceIterator$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$16.const$5.get(seg.asSlice(index*sizeof())); - } - public static void CreateInterfaceIterator$set(MemorySegment seg, long index, MemorySegment x) { - constants$16.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static CreateInterfaceIterator CreateInterfaceIterator(MemorySegment segment, Arena scope) { - return CreateInterfaceIterator.ofAddress(CreateInterfaceIterator$get(segment), scope); + public static void USBDeviceAbortPipeZero(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceAbortPipeZero$LAYOUT, USBDeviceAbortPipeZero$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBDeviceOpenSeize)(void*); + * {@snippet lang=c : + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *) * } */ - public interface USBDeviceOpenSeize { + public static class USBGetManufacturerStringIndex { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBDeviceOpenSeize fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$17.const$0, fi, constants$5.const$5, scope); + USBGetManufacturerStringIndex() { + // Should not be called directly } - static USBDeviceOpenSeize ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle USBDeviceOpenSeize$VH() { - return constants$17.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceOpenSeize)(void*); - * } - */ - public static MemorySegment USBDeviceOpenSeize$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$17.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBGetManufacturerStringIndex.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBGetManufacturerStringIndex.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBGetManufacturerStringIndex$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBGetManufacturerStringIndex")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceOpenSeize)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *) * } */ - public static void USBDeviceOpenSeize$set(MemorySegment seg, MemorySegment x) { - constants$17.const$1.set(seg, x); - } - public static MemorySegment USBDeviceOpenSeize$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$17.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceOpenSeize$set(MemorySegment seg, long index, MemorySegment x) { - constants$17.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceOpenSeize USBDeviceOpenSeize(MemorySegment segment, Arena scope) { - return USBDeviceOpenSeize.ofAddress(USBDeviceOpenSeize$get(segment), scope); + public static final AddressLayout USBGetManufacturerStringIndex$layout() { + return USBGetManufacturerStringIndex$LAYOUT; } + + private static final long USBGetManufacturerStringIndex$OFFSET = 272; + /** - * {@snippet : - * IOReturn (*DeviceRequestTO)(void*,IOUSBDevRequestTO*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *) * } */ - public interface DeviceRequestTO { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(DeviceRequestTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$17.const$2, fi, constants$6.const$5, scope); - } - static DeviceRequestTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBGetManufacturerStringIndex$offset() { + return USBGetManufacturerStringIndex$OFFSET; } - public static VarHandle DeviceRequestTO$VH() { - return constants$17.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*DeviceRequestTO)(void*,IOUSBDevRequestTO*); + * {@snippet lang=c : + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *) * } */ - public static MemorySegment DeviceRequestTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$17.const$3.get(seg); + public static MemorySegment USBGetManufacturerStringIndex(MemorySegment struct) { + return struct.get(USBGetManufacturerStringIndex$LAYOUT, USBGetManufacturerStringIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*DeviceRequestTO)(void*,IOUSBDevRequestTO*); + * {@snippet lang=c : + * IOReturn (*USBGetManufacturerStringIndex)(void *, UInt8 *) * } */ - public static void DeviceRequestTO$set(MemorySegment seg, MemorySegment x) { - constants$17.const$3.set(seg, x); - } - public static MemorySegment DeviceRequestTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$17.const$3.get(seg.asSlice(index*sizeof())); - } - public static void DeviceRequestTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$17.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static DeviceRequestTO DeviceRequestTO(MemorySegment segment, Arena scope) { - return DeviceRequestTO.ofAddress(DeviceRequestTO$get(segment), scope); + public static void USBGetManufacturerStringIndex(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBGetManufacturerStringIndex$LAYOUT, USBGetManufacturerStringIndex$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*DeviceRequestAsyncTO)(void*,IOUSBDevRequestTO*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *) * } */ - public interface DeviceRequestAsyncTO { + public static class USBGetProductStringIndex { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3); - static MemorySegment allocate(DeviceRequestAsyncTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$17.const$4, fi, constants$16.const$0, scope); + USBGetProductStringIndex() { + // Should not be called directly } - static DeviceRequestAsyncTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3) -> { - try { - return (int)constants$16.const$2.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle DeviceRequestAsyncTO$VH() { - return constants$17.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*DeviceRequestAsyncTO)(void*,IOUSBDevRequestTO*,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment DeviceRequestAsyncTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$17.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBGetProductStringIndex.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBGetProductStringIndex.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBGetProductStringIndex$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBGetProductStringIndex")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*DeviceRequestAsyncTO)(void*,IOUSBDevRequestTO*,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *) * } */ - public static void DeviceRequestAsyncTO$set(MemorySegment seg, MemorySegment x) { - constants$17.const$5.set(seg, x); - } - public static MemorySegment DeviceRequestAsyncTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$17.const$5.get(seg.asSlice(index*sizeof())); - } - public static void DeviceRequestAsyncTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$17.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static DeviceRequestAsyncTO DeviceRequestAsyncTO(MemorySegment segment, Arena scope) { - return DeviceRequestAsyncTO.ofAddress(DeviceRequestAsyncTO$get(segment), scope); + public static final AddressLayout USBGetProductStringIndex$layout() { + return USBGetProductStringIndex$LAYOUT; } + + private static final long USBGetProductStringIndex$OFFSET = 280; + /** - * {@snippet : - * IOReturn (*USBDeviceSuspend)(void*,Boolean); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *) * } */ - public interface USBDeviceSuspend { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(USBDeviceSuspend fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$18.const$0, fi, constants$14.const$0, scope); - } - static USBDeviceSuspend ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBGetProductStringIndex$offset() { + return USBGetProductStringIndex$OFFSET; } - public static VarHandle USBDeviceSuspend$VH() { - return constants$18.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceSuspend)(void*,Boolean); + * {@snippet lang=c : + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *) * } */ - public static MemorySegment USBDeviceSuspend$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$18.const$1.get(seg); + public static MemorySegment USBGetProductStringIndex(MemorySegment struct) { + return struct.get(USBGetProductStringIndex$LAYOUT, USBGetProductStringIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceSuspend)(void*,Boolean); + * {@snippet lang=c : + * IOReturn (*USBGetProductStringIndex)(void *, UInt8 *) * } */ - public static void USBDeviceSuspend$set(MemorySegment seg, MemorySegment x) { - constants$18.const$1.set(seg, x); - } - public static MemorySegment USBDeviceSuspend$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$18.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceSuspend$set(MemorySegment seg, long index, MemorySegment x) { - constants$18.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceSuspend USBDeviceSuspend(MemorySegment segment, Arena scope) { - return USBDeviceSuspend.ofAddress(USBDeviceSuspend$get(segment), scope); + public static void USBGetProductStringIndex(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBGetProductStringIndex$LAYOUT, USBGetProductStringIndex$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBDeviceAbortPipeZero)(void*); + * {@snippet lang=c : + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *) * } */ - public interface USBDeviceAbortPipeZero { + public static class USBGetSerialNumberStringIndex { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBDeviceAbortPipeZero fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$18.const$2, fi, constants$5.const$5, scope); + USBGetSerialNumberStringIndex() { + // Should not be called directly } - static USBDeviceAbortPipeZero ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle USBDeviceAbortPipeZero$VH() { - return constants$18.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceAbortPipeZero)(void*); - * } - */ - public static MemorySegment USBDeviceAbortPipeZero$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$18.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBGetSerialNumberStringIndex.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBGetSerialNumberStringIndex.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBGetSerialNumberStringIndex$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBGetSerialNumberStringIndex")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceAbortPipeZero)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *) * } */ - public static void USBDeviceAbortPipeZero$set(MemorySegment seg, MemorySegment x) { - constants$18.const$3.set(seg, x); - } - public static MemorySegment USBDeviceAbortPipeZero$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$18.const$3.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceAbortPipeZero$set(MemorySegment seg, long index, MemorySegment x) { - constants$18.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceAbortPipeZero USBDeviceAbortPipeZero(MemorySegment segment, Arena scope) { - return USBDeviceAbortPipeZero.ofAddress(USBDeviceAbortPipeZero$get(segment), scope); + public static final AddressLayout USBGetSerialNumberStringIndex$layout() { + return USBGetSerialNumberStringIndex$LAYOUT; } + + private static final long USBGetSerialNumberStringIndex$OFFSET = 288; + /** - * {@snippet : - * IOReturn (*USBGetManufacturerStringIndex)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *) * } */ - public interface USBGetManufacturerStringIndex { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(USBGetManufacturerStringIndex fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$18.const$4, fi, constants$6.const$5, scope); - } - static USBGetManufacturerStringIndex ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBGetSerialNumberStringIndex$offset() { + return USBGetSerialNumberStringIndex$OFFSET; } - public static VarHandle USBGetManufacturerStringIndex$VH() { - return constants$18.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBGetManufacturerStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *) * } */ - public static MemorySegment USBGetManufacturerStringIndex$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$18.const$5.get(seg); + public static MemorySegment USBGetSerialNumberStringIndex(MemorySegment struct) { + return struct.get(USBGetSerialNumberStringIndex$LAYOUT, USBGetSerialNumberStringIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBGetManufacturerStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBGetSerialNumberStringIndex)(void *, UInt8 *) * } */ - public static void USBGetManufacturerStringIndex$set(MemorySegment seg, MemorySegment x) { - constants$18.const$5.set(seg, x); - } - public static MemorySegment USBGetManufacturerStringIndex$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$18.const$5.get(seg.asSlice(index*sizeof())); - } - public static void USBGetManufacturerStringIndex$set(MemorySegment seg, long index, MemorySegment x) { - constants$18.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static USBGetManufacturerStringIndex USBGetManufacturerStringIndex(MemorySegment segment, Arena scope) { - return USBGetManufacturerStringIndex.ofAddress(USBGetManufacturerStringIndex$get(segment), scope); + public static void USBGetSerialNumberStringIndex(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBGetSerialNumberStringIndex$LAYOUT, USBGetSerialNumberStringIndex$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBGetProductStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32) * } */ - public interface USBGetProductStringIndex { + public static class USBDeviceReEnumerate { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(USBGetProductStringIndex fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$19.const$0, fi, constants$6.const$5, scope); + USBDeviceReEnumerate() { + // Should not be called directly } - static USBGetProductStringIndex ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, int _x1); } - } - public static VarHandle USBGetProductStringIndex$VH() { - return constants$19.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBGetProductStringIndex)(void*,UInt8*); - * } - */ - public static MemorySegment USBGetProductStringIndex$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$19.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBDeviceReEnumerate.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBDeviceReEnumerate.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBDeviceReEnumerate$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBDeviceReEnumerate")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBGetProductStringIndex)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32) * } */ - public static void USBGetProductStringIndex$set(MemorySegment seg, MemorySegment x) { - constants$19.const$1.set(seg, x); - } - public static MemorySegment USBGetProductStringIndex$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$19.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBGetProductStringIndex$set(MemorySegment seg, long index, MemorySegment x) { - constants$19.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBGetProductStringIndex USBGetProductStringIndex(MemorySegment segment, Arena scope) { - return USBGetProductStringIndex.ofAddress(USBGetProductStringIndex$get(segment), scope); + public static final AddressLayout USBDeviceReEnumerate$layout() { + return USBDeviceReEnumerate$LAYOUT; } + + private static final long USBDeviceReEnumerate$OFFSET = 296; + /** - * {@snippet : - * IOReturn (*USBGetSerialNumberStringIndex)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32) * } */ - public interface USBGetSerialNumberStringIndex { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(USBGetSerialNumberStringIndex fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$19.const$2, fi, constants$6.const$5, scope); - } - static USBGetSerialNumberStringIndex ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBDeviceReEnumerate$offset() { + return USBDeviceReEnumerate$OFFSET; } - public static VarHandle USBGetSerialNumberStringIndex$VH() { - return constants$19.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBGetSerialNumberStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32) * } */ - public static MemorySegment USBGetSerialNumberStringIndex$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$19.const$3.get(seg); + public static MemorySegment USBDeviceReEnumerate(MemorySegment struct) { + return struct.get(USBDeviceReEnumerate$LAYOUT, USBDeviceReEnumerate$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBGetSerialNumberStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBDeviceReEnumerate)(void *, UInt32) * } */ - public static void USBGetSerialNumberStringIndex$set(MemorySegment seg, MemorySegment x) { - constants$19.const$3.set(seg, x); + public static void USBDeviceReEnumerate(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBDeviceReEnumerate$LAYOUT, USBDeviceReEnumerate$OFFSET, fieldValue); } - public static MemorySegment USBGetSerialNumberStringIndex$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$19.const$3.get(seg.asSlice(index*sizeof())); - } - public static void USBGetSerialNumberStringIndex$set(MemorySegment seg, long index, MemorySegment x) { - constants$19.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static USBGetSerialNumberStringIndex USBGetSerialNumberStringIndex(MemorySegment segment, Arena scope) { - return USBGetSerialNumberStringIndex.ofAddress(USBGetSerialNumberStringIndex$get(segment), scope); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } + /** - * {@snippet : - * IOReturn (*USBDeviceReEnumerate)(void*,UInt32); - * } + * The size (in bytes) of this struct */ - public interface USBDeviceReEnumerate { + public static long sizeof() { return layout().byteSize(); } - int apply(java.lang.foreign.MemorySegment _x0, int _x1); - static MemorySegment allocate(USBDeviceReEnumerate fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$19.const$5, fi, constants$19.const$4, scope); - } - static USBDeviceReEnumerate ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, int __x1) -> { - try { - return (int)constants$20.const$0.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static VarHandle USBDeviceReEnumerate$VH() { - return constants$20.const$1; - } /** - * Getter for field: - * {@snippet : - * IOReturn (*USBDeviceReEnumerate)(void*,UInt32); - * } + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. */ - public static MemorySegment USBDeviceReEnumerate$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$20.const$1.get(seg); + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBDeviceReEnumerate)(void*,UInt32); - * } + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} */ - public static void USBDeviceReEnumerate$set(MemorySegment seg, MemorySegment x) { - constants$20.const$1.set(seg, x); - } - public static MemorySegment USBDeviceReEnumerate$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$20.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBDeviceReEnumerate$set(MemorySegment seg, long index, MemorySegment x) { - constants$20.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBDeviceReEnumerate USBDeviceReEnumerate(MemorySegment segment, Arena scope) { - return USBDeviceReEnumerate.ofAddress(USBDeviceReEnumerate$get(segment), scope); + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBFindInterfaceRequest.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBFindInterfaceRequest.java index 007fbbf..9f54341 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBFindInterfaceRequest.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBFindInterfaceRequest.java @@ -2,140 +2,264 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct { * UInt16 bInterfaceClass; * UInt16 bInterfaceSubClass; * UInt16 bInterfaceProtocol; * UInt16 bAlternateSetting; - * }; + * } * } */ public class IOUSBFindInterfaceRequest { - public static MemoryLayout $LAYOUT() { - return constants$1.const$2; + IOUSBFindInterfaceRequest() { + // Should not be called directly } - public static VarHandle bInterfaceClass$VH() { - return constants$1.const$3; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_SHORT.withName("bInterfaceClass"), + IOKit.C_SHORT.withName("bInterfaceSubClass"), + IOKit.C_SHORT.withName("bInterfaceProtocol"), + IOKit.C_SHORT.withName("bAlternateSetting") + ).withName("IOUSBFindInterfaceRequest"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfShort bInterfaceClass$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bInterfaceClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 bInterfaceClass + * } + */ + public static final OfShort bInterfaceClass$layout() { + return bInterfaceClass$LAYOUT; + } + + private static final long bInterfaceClass$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 bInterfaceClass + * } + */ + public static final long bInterfaceClass$offset() { + return bInterfaceClass$OFFSET; + } + /** * Getter for field: - * {@snippet : - * UInt16 bInterfaceClass; + * {@snippet lang=c : + * UInt16 bInterfaceClass * } */ - public static short bInterfaceClass$get(MemorySegment seg) { - return (short)constants$1.const$3.get(seg); + public static short bInterfaceClass(MemorySegment struct) { + return struct.get(bInterfaceClass$LAYOUT, bInterfaceClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 bInterfaceClass; + * {@snippet lang=c : + * UInt16 bInterfaceClass * } */ - public static void bInterfaceClass$set(MemorySegment seg, short x) { - constants$1.const$3.set(seg, x); + public static void bInterfaceClass(MemorySegment struct, short fieldValue) { + struct.set(bInterfaceClass$LAYOUT, bInterfaceClass$OFFSET, fieldValue); } - public static short bInterfaceClass$get(MemorySegment seg, long index) { - return (short)constants$1.const$3.get(seg.asSlice(index*sizeof())); - } - public static void bInterfaceClass$set(MemorySegment seg, long index, short x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort bInterfaceSubClass$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bInterfaceSubClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 bInterfaceSubClass + * } + */ + public static final OfShort bInterfaceSubClass$layout() { + return bInterfaceSubClass$LAYOUT; } - public static VarHandle bInterfaceSubClass$VH() { - return constants$1.const$4; + + private static final long bInterfaceSubClass$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 bInterfaceSubClass + * } + */ + public static final long bInterfaceSubClass$offset() { + return bInterfaceSubClass$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 bInterfaceSubClass; + * {@snippet lang=c : + * UInt16 bInterfaceSubClass * } */ - public static short bInterfaceSubClass$get(MemorySegment seg) { - return (short)constants$1.const$4.get(seg); + public static short bInterfaceSubClass(MemorySegment struct) { + return struct.get(bInterfaceSubClass$LAYOUT, bInterfaceSubClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 bInterfaceSubClass; + * {@snippet lang=c : + * UInt16 bInterfaceSubClass * } */ - public static void bInterfaceSubClass$set(MemorySegment seg, short x) { - constants$1.const$4.set(seg, x); + public static void bInterfaceSubClass(MemorySegment struct, short fieldValue) { + struct.set(bInterfaceSubClass$LAYOUT, bInterfaceSubClass$OFFSET, fieldValue); } - public static short bInterfaceSubClass$get(MemorySegment seg, long index) { - return (short)constants$1.const$4.get(seg.asSlice(index*sizeof())); - } - public static void bInterfaceSubClass$set(MemorySegment seg, long index, short x) { - constants$1.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort bInterfaceProtocol$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bInterfaceProtocol")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 bInterfaceProtocol + * } + */ + public static final OfShort bInterfaceProtocol$layout() { + return bInterfaceProtocol$LAYOUT; } - public static VarHandle bInterfaceProtocol$VH() { - return constants$1.const$5; + + private static final long bInterfaceProtocol$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 bInterfaceProtocol + * } + */ + public static final long bInterfaceProtocol$offset() { + return bInterfaceProtocol$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 bInterfaceProtocol; + * {@snippet lang=c : + * UInt16 bInterfaceProtocol * } */ - public static short bInterfaceProtocol$get(MemorySegment seg) { - return (short)constants$1.const$5.get(seg); + public static short bInterfaceProtocol(MemorySegment struct) { + return struct.get(bInterfaceProtocol$LAYOUT, bInterfaceProtocol$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 bInterfaceProtocol; + * {@snippet lang=c : + * UInt16 bInterfaceProtocol * } */ - public static void bInterfaceProtocol$set(MemorySegment seg, short x) { - constants$1.const$5.set(seg, x); - } - public static short bInterfaceProtocol$get(MemorySegment seg, long index) { - return (short)constants$1.const$5.get(seg.asSlice(index*sizeof())); + public static void bInterfaceProtocol(MemorySegment struct, short fieldValue) { + struct.set(bInterfaceProtocol$LAYOUT, bInterfaceProtocol$OFFSET, fieldValue); } - public static void bInterfaceProtocol$set(MemorySegment seg, long index, short x) { - constants$1.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort bAlternateSetting$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bAlternateSetting")); + + /** + * Layout for field: + * {@snippet lang=c : + * UInt16 bAlternateSetting + * } + */ + public static final OfShort bAlternateSetting$layout() { + return bAlternateSetting$LAYOUT; } - public static VarHandle bAlternateSetting$VH() { - return constants$2.const$0; + + private static final long bAlternateSetting$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UInt16 bAlternateSetting + * } + */ + public static final long bAlternateSetting$offset() { + return bAlternateSetting$OFFSET; } + /** * Getter for field: - * {@snippet : - * UInt16 bAlternateSetting; + * {@snippet lang=c : + * UInt16 bAlternateSetting * } */ - public static short bAlternateSetting$get(MemorySegment seg) { - return (short)constants$2.const$0.get(seg); + public static short bAlternateSetting(MemorySegment struct) { + return struct.get(bAlternateSetting$LAYOUT, bAlternateSetting$OFFSET); } + /** * Setter for field: - * {@snippet : - * UInt16 bAlternateSetting; + * {@snippet lang=c : + * UInt16 bAlternateSetting * } */ - public static void bAlternateSetting$set(MemorySegment seg, short x) { - constants$2.const$0.set(seg, x); + public static void bAlternateSetting(MemorySegment struct, short fieldValue) { + struct.set(bAlternateSetting$LAYOUT, bAlternateSetting$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static short bAlternateSetting$get(MemorySegment seg, long index) { - return (short)constants$2.const$0.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void bAlternateSetting$set(MemorySegment seg, long index, short x) { - constants$2.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceInterface190.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceInterface190.java deleted file mode 100644 index 44ead20..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceInterface190.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -/** - * {@snippet : - * typedef struct IOUSBInterfaceStruct190 IOUSBInterfaceInterface190; - * } - */ -public final class IOUSBInterfaceInterface190 extends IOUSBInterfaceStruct190 { - - // Suppresses default constructor, ensuring non-instantiability. - private IOUSBInterfaceInterface190() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java index 0cdc715..46cc32e 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBInterfaceStruct190.java @@ -2,2648 +2,5033 @@ package net.codecrete.usb.macos.gen.iokit; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct IOUSBInterfaceStruct190 { - * void* _reserved; - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); - * ULONG (*AddRef)(void*); - * ULONG (*Release)(void*); - * IOReturn (*CreateInterfaceAsyncEventSource)(void*,CFRunLoopSourceRef*); - * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void*); - * IOReturn (*CreateInterfaceAsyncPort)(void*,mach_port_t*); - * mach_port_t (*GetInterfaceAsyncPort)(void*); - * IOReturn (*USBInterfaceOpen)(void*); - * IOReturn (*USBInterfaceClose)(void*); - * IOReturn (*GetInterfaceClass)(void*,UInt8*); - * IOReturn (*GetInterfaceSubClass)(void*,UInt8*); - * IOReturn (*GetInterfaceProtocol)(void*,UInt8*); - * IOReturn (*GetDeviceVendor)(void*,UInt16*); - * IOReturn (*GetDeviceProduct)(void*,UInt16*); - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); - * IOReturn (*GetConfigurationValue)(void*,UInt8*); - * IOReturn (*GetInterfaceNumber)(void*,UInt8*); - * IOReturn (*GetAlternateSetting)(void*,UInt8*); - * IOReturn (*GetNumEndpoints)(void*,UInt8*); - * IOReturn (*GetLocationID)(void*,UInt32*); - * IOReturn (*GetDevice)(void*,io_service_t*); - * IOReturn (*SetAlternateInterface)(void*,UInt8); - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); - * IOReturn (*ControlRequest)(void*,UInt8,IOUSBDevRequest*); - * IOReturn (*ControlRequestAsync)(void*,UInt8,IOUSBDevRequest*,IOAsyncCallback1,void*); - * IOReturn (*GetPipeProperties)(void*,UInt8,UInt8*,UInt8*,UInt8*,UInt16*,UInt8*); - * IOReturn (*GetPipeStatus)(void*,UInt8); - * IOReturn (*AbortPipe)(void*,UInt8); - * IOReturn (*ResetPipe)(void*,UInt8); - * IOReturn (*ClearPipeStall)(void*,UInt8); - * IOReturn (*ReadPipe)(void*,UInt8,void*,UInt32*); - * IOReturn (*WritePipe)(void*,UInt8,void*,UInt32); - * IOReturn (*ReadPipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); - * IOReturn (*WritePipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); - * IOReturn (*ReadIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); - * IOReturn (*WriteIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); - * IOReturn (*ControlRequestTO)(void*,UInt8,IOUSBDevRequestTO*); - * IOReturn (*ControlRequestAsyncTO)(void*,UInt8,IOUSBDevRequestTO*,IOAsyncCallback1,void*); - * IOReturn (*ReadPipeTO)(void*,UInt8,void*,UInt32*,UInt32,UInt32); - * IOReturn (*WritePipeTO)(void*,UInt8,void*,UInt32,UInt32,UInt32); - * IOReturn (*ReadPipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); - * IOReturn (*WritePipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); - * IOReturn (*USBInterfaceGetStringIndex)(void*,UInt8*); - * IOReturn (*USBInterfaceOpenSeize)(void*); - * IOReturn (*ClearPipeStallBothEnds)(void*,UInt8); - * IOReturn (*SetPipePolicy)(void*,UInt8,UInt16,UInt8); - * IOReturn (*GetBandwidthAvailable)(void*,UInt32*); - * IOReturn (*GetEndpointProperties)(void*,UInt8,UInt8,UInt8,UInt8*,UInt16*,UInt8*); - * }; + * void *_reserved; + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *); + * ULONG (*AddRef)(void *); + * ULONG (*Release)(void *); + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *); + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *); + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *); + * mach_port_t (*GetInterfaceAsyncPort)(void *); + * IOReturn (*USBInterfaceOpen)(void *); + * IOReturn (*USBInterfaceClose)(void *); + * IOReturn (*GetInterfaceClass)(void *, UInt8 *); + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *); + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *); + * IOReturn (*GetDeviceVendor)(void *, UInt16 *); + * IOReturn (*GetDeviceProduct)(void *, UInt16 *); + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *); + * IOReturn (*GetConfigurationValue)(void *, UInt8 *); + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *); + * IOReturn (*GetAlternateSetting)(void *, UInt8 *); + * IOReturn (*GetNumEndpoints)(void *, UInt8 *); + * IOReturn (*GetLocationID)(void *, UInt32 *); + * IOReturn (*GetDevice)(void *, io_service_t *); + * IOReturn (*SetAlternateInterface)(void *, UInt8); + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *); + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *); + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *); + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *); + * IOReturn (*GetPipeStatus)(void *, UInt8); + * IOReturn (*AbortPipe)(void *, UInt8); + * IOReturn (*ResetPipe)(void *, UInt8); + * IOReturn (*ClearPipeStall)(void *, UInt8); + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *); + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32); + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *); + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *); + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *); + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *); + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *); + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *); + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32); + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32); + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *); + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *); + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *); + * IOReturn (*USBInterfaceOpenSeize)(void *); + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8); + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8); + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *); + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *); + * } * } */ public class IOUSBInterfaceStruct190 { - public static MemoryLayout $LAYOUT() { - return constants$20.const$2; - } - public static VarHandle _reserved$VH() { - return constants$20.const$3; + IOUSBInterfaceStruct190() { + // Should not be called directly } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + IOKit.C_POINTER.withName("_reserved"), + IOKit.C_POINTER.withName("QueryInterface"), + IOKit.C_POINTER.withName("AddRef"), + IOKit.C_POINTER.withName("Release"), + IOKit.C_POINTER.withName("CreateInterfaceAsyncEventSource"), + IOKit.C_POINTER.withName("GetInterfaceAsyncEventSource"), + IOKit.C_POINTER.withName("CreateInterfaceAsyncPort"), + IOKit.C_POINTER.withName("GetInterfaceAsyncPort"), + IOKit.C_POINTER.withName("USBInterfaceOpen"), + IOKit.C_POINTER.withName("USBInterfaceClose"), + IOKit.C_POINTER.withName("GetInterfaceClass"), + IOKit.C_POINTER.withName("GetInterfaceSubClass"), + IOKit.C_POINTER.withName("GetInterfaceProtocol"), + IOKit.C_POINTER.withName("GetDeviceVendor"), + IOKit.C_POINTER.withName("GetDeviceProduct"), + IOKit.C_POINTER.withName("GetDeviceReleaseNumber"), + IOKit.C_POINTER.withName("GetConfigurationValue"), + IOKit.C_POINTER.withName("GetInterfaceNumber"), + IOKit.C_POINTER.withName("GetAlternateSetting"), + IOKit.C_POINTER.withName("GetNumEndpoints"), + IOKit.C_POINTER.withName("GetLocationID"), + IOKit.C_POINTER.withName("GetDevice"), + IOKit.C_POINTER.withName("SetAlternateInterface"), + IOKit.C_POINTER.withName("GetBusFrameNumber"), + IOKit.C_POINTER.withName("ControlRequest"), + IOKit.C_POINTER.withName("ControlRequestAsync"), + IOKit.C_POINTER.withName("GetPipeProperties"), + IOKit.C_POINTER.withName("GetPipeStatus"), + IOKit.C_POINTER.withName("AbortPipe"), + IOKit.C_POINTER.withName("ResetPipe"), + IOKit.C_POINTER.withName("ClearPipeStall"), + IOKit.C_POINTER.withName("ReadPipe"), + IOKit.C_POINTER.withName("WritePipe"), + IOKit.C_POINTER.withName("ReadPipeAsync"), + IOKit.C_POINTER.withName("WritePipeAsync"), + IOKit.C_POINTER.withName("ReadIsochPipeAsync"), + IOKit.C_POINTER.withName("WriteIsochPipeAsync"), + IOKit.C_POINTER.withName("ControlRequestTO"), + IOKit.C_POINTER.withName("ControlRequestAsyncTO"), + IOKit.C_POINTER.withName("ReadPipeTO"), + IOKit.C_POINTER.withName("WritePipeTO"), + IOKit.C_POINTER.withName("ReadPipeAsyncTO"), + IOKit.C_POINTER.withName("WritePipeAsyncTO"), + IOKit.C_POINTER.withName("USBInterfaceGetStringIndex"), + IOKit.C_POINTER.withName("USBInterfaceOpenSeize"), + IOKit.C_POINTER.withName("ClearPipeStallBothEnds"), + IOKit.C_POINTER.withName("SetPipePolicy"), + IOKit.C_POINTER.withName("GetBandwidthAvailable"), + IOKit.C_POINTER.withName("GetEndpointProperties") + ).withName("IOUSBInterfaceStruct190"); + /** - * Getter for field: - * {@snippet : - * void* _reserved; - * } + * The layout of this struct */ - public static MemorySegment _reserved$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$20.const$3.get(seg); + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final AddressLayout _reserved$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("_reserved")); + /** - * Setter for field: - * {@snippet : - * void* _reserved; + * Layout for field: + * {@snippet lang=c : + * void *_reserved * } */ - public static void _reserved$set(MemorySegment seg, MemorySegment x) { - constants$20.const$3.set(seg, x); - } - public static MemorySegment _reserved$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$20.const$3.get(seg.asSlice(index*sizeof())); - } - public static void _reserved$set(MemorySegment seg, long index, MemorySegment x) { - constants$20.const$3.set(seg.asSlice(index*sizeof()), x); + public static final AddressLayout _reserved$layout() { + return _reserved$LAYOUT; } + + private static final long _reserved$OFFSET = 0; + /** - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * Offset for field: + * {@snippet lang=c : + * void *_reserved * } */ - public interface QueryInterface { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(QueryInterface fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$20.const$4, fi, constants$5.const$1, scope); - } - static QueryInterface ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$5.const$3.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long _reserved$offset() { + return _reserved$OFFSET; } - public static VarHandle QueryInterface$VH() { - return constants$20.const$5; - } /** * Getter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * void *_reserved * } */ - public static MemorySegment QueryInterface$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$20.const$5.get(seg); + public static MemorySegment _reserved(MemorySegment struct) { + return struct.get(_reserved$LAYOUT, _reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * HRESULT (*QueryInterface)(void*,REFIID,LPVOID*); + * {@snippet lang=c : + * void *_reserved * } */ - public static void QueryInterface$set(MemorySegment seg, MemorySegment x) { - constants$20.const$5.set(seg, x); - } - public static MemorySegment QueryInterface$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$20.const$5.get(seg.asSlice(index*sizeof())); - } - public static void QueryInterface$set(MemorySegment seg, long index, MemorySegment x) { - constants$20.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static QueryInterface QueryInterface(MemorySegment segment, Arena scope) { - return QueryInterface.ofAddress(QueryInterface$get(segment), scope); + public static void _reserved(MemorySegment struct, MemorySegment fieldValue) { + struct.set(_reserved$LAYOUT, _reserved$OFFSET, fieldValue); } + /** - * {@snippet : - * ULONG (*AddRef)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public interface AddRef { + public static class QueryInterface { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(AddRef fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$21.const$0, fi, constants$5.const$5, scope); + QueryInterface() { + // Should not be called directly } - static AddRef ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); } - } - public static VarHandle AddRef$VH() { - return constants$21.const$1; - } - /** - * Getter for field: - * {@snippet : - * ULONG (*AddRef)(void*); - * } - */ - public static MemorySegment AddRef$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$21.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + CFUUIDBytes.layout(), + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(QueryInterface.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(QueryInterface.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout QueryInterface$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("QueryInterface")); + /** - * Setter for field: - * {@snippet : - * ULONG (*AddRef)(void*); + * Layout for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static void AddRef$set(MemorySegment seg, MemorySegment x) { - constants$21.const$1.set(seg, x); - } - public static MemorySegment AddRef$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$21.const$1.get(seg.asSlice(index*sizeof())); - } - public static void AddRef$set(MemorySegment seg, long index, MemorySegment x) { - constants$21.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static AddRef AddRef(MemorySegment segment, Arena scope) { - return AddRef.ofAddress(AddRef$get(segment), scope); + public static final AddressLayout QueryInterface$layout() { + return QueryInterface$LAYOUT; } + + private static final long QueryInterface$OFFSET = 8; + /** - * {@snippet : - * ULONG (*Release)(void*); + * Offset for field: + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public interface Release { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(Release fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$21.const$2, fi, constants$5.const$5, scope); - } - static Release ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long QueryInterface$offset() { + return QueryInterface$OFFSET; } - public static VarHandle Release$VH() { - return constants$21.const$3; - } /** * Getter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static MemorySegment Release$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$21.const$3.get(seg); + public static MemorySegment QueryInterface(MemorySegment struct) { + return struct.get(QueryInterface$LAYOUT, QueryInterface$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG (*Release)(void*); + * {@snippet lang=c : + * HRESULT (*QueryInterface)(void *, REFIID, LPVOID *) * } */ - public static void Release$set(MemorySegment seg, MemorySegment x) { - constants$21.const$3.set(seg, x); - } - public static MemorySegment Release$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$21.const$3.get(seg.asSlice(index*sizeof())); - } - public static void Release$set(MemorySegment seg, long index, MemorySegment x) { - constants$21.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static Release Release(MemorySegment segment, Arena scope) { - return Release.ofAddress(Release$get(segment), scope); + public static void QueryInterface(MemorySegment struct, MemorySegment fieldValue) { + struct.set(QueryInterface$LAYOUT, QueryInterface$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*CreateInterfaceAsyncEventSource)(void*,CFRunLoopSourceRef*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public interface CreateInterfaceAsyncEventSource { + public static class AddRef { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(CreateInterfaceAsyncEventSource fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$21.const$4, fi, constants$6.const$5, scope); + AddRef() { + // Should not be called directly } - static CreateInterfaceAsyncEventSource ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle CreateInterfaceAsyncEventSource$VH() { - return constants$21.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*CreateInterfaceAsyncEventSource)(void*,CFRunLoopSourceRef*); - * } - */ - public static MemorySegment CreateInterfaceAsyncEventSource$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$21.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(AddRef.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(AddRef.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout AddRef$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("AddRef")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*CreateInterfaceAsyncEventSource)(void*,CFRunLoopSourceRef*); + * Layout for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static void CreateInterfaceAsyncEventSource$set(MemorySegment seg, MemorySegment x) { - constants$21.const$5.set(seg, x); - } - public static MemorySegment CreateInterfaceAsyncEventSource$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$21.const$5.get(seg.asSlice(index*sizeof())); - } - public static void CreateInterfaceAsyncEventSource$set(MemorySegment seg, long index, MemorySegment x) { - constants$21.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static CreateInterfaceAsyncEventSource CreateInterfaceAsyncEventSource(MemorySegment segment, Arena scope) { - return CreateInterfaceAsyncEventSource.ofAddress(CreateInterfaceAsyncEventSource$get(segment), scope); + public static final AddressLayout AddRef$layout() { + return AddRef$LAYOUT; } + + private static final long AddRef$OFFSET = 16; + /** - * {@snippet : - * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void*); + * Offset for field: + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public interface GetInterfaceAsyncEventSource { - - java.lang.foreign.MemorySegment apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(GetInterfaceAsyncEventSource fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$22.const$0, fi, constants$3.const$0, scope); - } - static GetInterfaceAsyncEventSource ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (java.lang.foreign.MemorySegment)constants$7.const$4.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long AddRef$offset() { + return AddRef$OFFSET; } - public static VarHandle GetInterfaceAsyncEventSource$VH() { - return constants$22.const$1; - } /** * Getter for field: - * {@snippet : - * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static MemorySegment GetInterfaceAsyncEventSource$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$22.const$1.get(seg); + public static MemorySegment AddRef(MemorySegment struct) { + return struct.get(AddRef$LAYOUT, AddRef$OFFSET); } + /** * Setter for field: - * {@snippet : - * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void*); + * {@snippet lang=c : + * ULONG (*AddRef)(void *) * } */ - public static void GetInterfaceAsyncEventSource$set(MemorySegment seg, MemorySegment x) { - constants$22.const$1.set(seg, x); - } - public static MemorySegment GetInterfaceAsyncEventSource$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$22.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceAsyncEventSource$set(MemorySegment seg, long index, MemorySegment x) { - constants$22.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceAsyncEventSource GetInterfaceAsyncEventSource(MemorySegment segment, Arena scope) { - return GetInterfaceAsyncEventSource.ofAddress(GetInterfaceAsyncEventSource$get(segment), scope); + public static void AddRef(MemorySegment struct, MemorySegment fieldValue) { + struct.set(AddRef$LAYOUT, AddRef$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*CreateInterfaceAsyncPort)(void*,mach_port_t*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public interface CreateInterfaceAsyncPort { + public static class Release { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(CreateInterfaceAsyncPort fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$22.const$2, fi, constants$6.const$5, scope); + Release() { + // Should not be called directly } - static CreateInterfaceAsyncPort ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle CreateInterfaceAsyncPort$VH() { - return constants$22.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*CreateInterfaceAsyncPort)(void*,mach_port_t*); - * } - */ - public static MemorySegment CreateInterfaceAsyncPort$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$22.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(Release.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(Release.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*CreateInterfaceAsyncPort)(void*,mach_port_t*); + * Layout for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static void CreateInterfaceAsyncPort$set(MemorySegment seg, MemorySegment x) { - constants$22.const$3.set(seg, x); - } - public static MemorySegment CreateInterfaceAsyncPort$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$22.const$3.get(seg.asSlice(index*sizeof())); - } - public static void CreateInterfaceAsyncPort$set(MemorySegment seg, long index, MemorySegment x) { - constants$22.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static CreateInterfaceAsyncPort CreateInterfaceAsyncPort(MemorySegment segment, Arena scope) { - return CreateInterfaceAsyncPort.ofAddress(CreateInterfaceAsyncPort$get(segment), scope); + public static final AddressLayout Release$layout() { + return Release$LAYOUT; } + + private static final long Release$OFFSET = 24; + /** - * {@snippet : - * mach_port_t (*GetInterfaceAsyncPort)(void*); + * Offset for field: + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public interface GetInterfaceAsyncPort { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(GetInterfaceAsyncPort fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$22.const$4, fi, constants$5.const$5, scope); - } - static GetInterfaceAsyncPort ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long Release$offset() { + return Release$OFFSET; } - public static VarHandle GetInterfaceAsyncPort$VH() { - return constants$22.const$5; - } /** * Getter for field: - * {@snippet : - * mach_port_t (*GetInterfaceAsyncPort)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static MemorySegment GetInterfaceAsyncPort$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$22.const$5.get(seg); + public static MemorySegment Release(MemorySegment struct) { + return struct.get(Release$LAYOUT, Release$OFFSET); } + /** * Setter for field: - * {@snippet : - * mach_port_t (*GetInterfaceAsyncPort)(void*); + * {@snippet lang=c : + * ULONG (*Release)(void *) * } */ - public static void GetInterfaceAsyncPort$set(MemorySegment seg, MemorySegment x) { - constants$22.const$5.set(seg, x); - } - public static MemorySegment GetInterfaceAsyncPort$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$22.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceAsyncPort$set(MemorySegment seg, long index, MemorySegment x) { - constants$22.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceAsyncPort GetInterfaceAsyncPort(MemorySegment segment, Arena scope) { - return GetInterfaceAsyncPort.ofAddress(GetInterfaceAsyncPort$get(segment), scope); + public static void Release(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Release$LAYOUT, Release$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBInterfaceOpen)(void*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public interface USBInterfaceOpen { + public static class CreateInterfaceAsyncEventSource { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBInterfaceOpen fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$23.const$0, fi, constants$5.const$5, scope); + CreateInterfaceAsyncEventSource() { + // Should not be called directly } - static USBInterfaceOpen ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle USBInterfaceOpen$VH() { - return constants$23.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBInterfaceOpen)(void*); - * } - */ - public static MemorySegment USBInterfaceOpen$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$23.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(CreateInterfaceAsyncEventSource.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CreateInterfaceAsyncEventSource.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout CreateInterfaceAsyncEventSource$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateInterfaceAsyncEventSource")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBInterfaceOpen)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static void USBInterfaceOpen$set(MemorySegment seg, MemorySegment x) { - constants$23.const$1.set(seg, x); - } - public static MemorySegment USBInterfaceOpen$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$23.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBInterfaceOpen$set(MemorySegment seg, long index, MemorySegment x) { - constants$23.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBInterfaceOpen USBInterfaceOpen(MemorySegment segment, Arena scope) { - return USBInterfaceOpen.ofAddress(USBInterfaceOpen$get(segment), scope); + public static final AddressLayout CreateInterfaceAsyncEventSource$layout() { + return CreateInterfaceAsyncEventSource$LAYOUT; } + + private static final long CreateInterfaceAsyncEventSource$OFFSET = 32; + /** - * {@snippet : - * IOReturn (*USBInterfaceClose)(void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public interface USBInterfaceClose { - - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBInterfaceClose fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$23.const$2, fi, constants$5.const$5, scope); - } - static USBInterfaceClose ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long CreateInterfaceAsyncEventSource$offset() { + return CreateInterfaceAsyncEventSource$OFFSET; } - public static VarHandle USBInterfaceClose$VH() { - return constants$23.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBInterfaceClose)(void*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static MemorySegment USBInterfaceClose$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$23.const$3.get(seg); + public static MemorySegment CreateInterfaceAsyncEventSource(MemorySegment struct) { + return struct.get(CreateInterfaceAsyncEventSource$LAYOUT, CreateInterfaceAsyncEventSource$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBInterfaceClose)(void*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncEventSource)(void *, CFRunLoopSourceRef *) * } */ - public static void USBInterfaceClose$set(MemorySegment seg, MemorySegment x) { - constants$23.const$3.set(seg, x); - } - public static MemorySegment USBInterfaceClose$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$23.const$3.get(seg.asSlice(index*sizeof())); - } - public static void USBInterfaceClose$set(MemorySegment seg, long index, MemorySegment x) { - constants$23.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static USBInterfaceClose USBInterfaceClose(MemorySegment segment, Arena scope) { - return USBInterfaceClose.ofAddress(USBInterfaceClose$get(segment), scope); + public static void CreateInterfaceAsyncEventSource(MemorySegment struct, MemorySegment fieldValue) { + struct.set(CreateInterfaceAsyncEventSource$LAYOUT, CreateInterfaceAsyncEventSource$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetInterfaceClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *) * } */ - public interface GetInterfaceClass { + public static class GetInterfaceAsyncEventSource { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetInterfaceClass fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$23.const$4, fi, constants$6.const$5, scope); + GetInterfaceAsyncEventSource() { + // Should not be called directly } - static GetInterfaceClass ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + MemorySegment apply(MemorySegment _x0); } - } - public static VarHandle GetInterfaceClass$VH() { - return constants$23.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetInterfaceClass)(void*,UInt8*); - * } - */ - public static MemorySegment GetInterfaceClass$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$23.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceAsyncEventSource.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceAsyncEventSource.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetInterfaceAsyncEventSource$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceAsyncEventSource")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetInterfaceClass)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *) * } */ - public static void GetInterfaceClass$set(MemorySegment seg, MemorySegment x) { - constants$23.const$5.set(seg, x); - } - public static MemorySegment GetInterfaceClass$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$23.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceClass$set(MemorySegment seg, long index, MemorySegment x) { - constants$23.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceClass GetInterfaceClass(MemorySegment segment, Arena scope) { - return GetInterfaceClass.ofAddress(GetInterfaceClass$get(segment), scope); + public static final AddressLayout GetInterfaceAsyncEventSource$layout() { + return GetInterfaceAsyncEventSource$LAYOUT; } + + private static final long GetInterfaceAsyncEventSource$OFFSET = 40; + /** - * {@snippet : - * IOReturn (*GetInterfaceSubClass)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *) * } */ - public interface GetInterfaceSubClass { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetInterfaceSubClass fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$24.const$0, fi, constants$6.const$5, scope); - } - static GetInterfaceSubClass ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetInterfaceAsyncEventSource$offset() { + return GetInterfaceAsyncEventSource$OFFSET; } - public static VarHandle GetInterfaceSubClass$VH() { - return constants$24.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetInterfaceSubClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *) * } */ - public static MemorySegment GetInterfaceSubClass$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$24.const$1.get(seg); + public static MemorySegment GetInterfaceAsyncEventSource(MemorySegment struct) { + return struct.get(GetInterfaceAsyncEventSource$LAYOUT, GetInterfaceAsyncEventSource$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetInterfaceSubClass)(void*,UInt8*); + * {@snippet lang=c : + * CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *) * } */ - public static void GetInterfaceSubClass$set(MemorySegment seg, MemorySegment x) { - constants$24.const$1.set(seg, x); - } - public static MemorySegment GetInterfaceSubClass$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$24.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceSubClass$set(MemorySegment seg, long index, MemorySegment x) { - constants$24.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceSubClass GetInterfaceSubClass(MemorySegment segment, Arena scope) { - return GetInterfaceSubClass.ofAddress(GetInterfaceSubClass$get(segment), scope); + public static void GetInterfaceAsyncEventSource(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceAsyncEventSource$LAYOUT, GetInterfaceAsyncEventSource$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetInterfaceProtocol)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *) * } */ - public interface GetInterfaceProtocol { + public static class CreateInterfaceAsyncPort { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetInterfaceProtocol fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$24.const$2, fi, constants$6.const$5, scope); + CreateInterfaceAsyncPort() { + // Should not be called directly } - static GetInterfaceProtocol ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle GetInterfaceProtocol$VH() { - return constants$24.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetInterfaceProtocol)(void*,UInt8*); - * } - */ - public static MemorySegment GetInterfaceProtocol$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$24.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(CreateInterfaceAsyncPort.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(CreateInterfaceAsyncPort.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout CreateInterfaceAsyncPort$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("CreateInterfaceAsyncPort")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetInterfaceProtocol)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *) * } */ - public static void GetInterfaceProtocol$set(MemorySegment seg, MemorySegment x) { - constants$24.const$3.set(seg, x); - } - public static MemorySegment GetInterfaceProtocol$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$24.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceProtocol$set(MemorySegment seg, long index, MemorySegment x) { - constants$24.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceProtocol GetInterfaceProtocol(MemorySegment segment, Arena scope) { - return GetInterfaceProtocol.ofAddress(GetInterfaceProtocol$get(segment), scope); + public static final AddressLayout CreateInterfaceAsyncPort$layout() { + return CreateInterfaceAsyncPort$LAYOUT; } + + private static final long CreateInterfaceAsyncPort$OFFSET = 48; + /** - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *) * } */ - public interface GetDeviceVendor { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceVendor fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$24.const$4, fi, constants$6.const$5, scope); - } - static GetDeviceVendor ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long CreateInterfaceAsyncPort$offset() { + return CreateInterfaceAsyncPort$OFFSET; } - public static VarHandle GetDeviceVendor$VH() { - return constants$24.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *) * } */ - public static MemorySegment GetDeviceVendor$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$24.const$5.get(seg); + public static MemorySegment CreateInterfaceAsyncPort(MemorySegment struct) { + return struct.get(CreateInterfaceAsyncPort$LAYOUT, CreateInterfaceAsyncPort$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceVendor)(void*,UInt16*); + * {@snippet lang=c : + * IOReturn (*CreateInterfaceAsyncPort)(void *, mach_port_t *) * } */ - public static void GetDeviceVendor$set(MemorySegment seg, MemorySegment x) { - constants$24.const$5.set(seg, x); - } - public static MemorySegment GetDeviceVendor$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$24.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceVendor$set(MemorySegment seg, long index, MemorySegment x) { - constants$24.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceVendor GetDeviceVendor(MemorySegment segment, Arena scope) { - return GetDeviceVendor.ofAddress(GetDeviceVendor$get(segment), scope); + public static void CreateInterfaceAsyncPort(MemorySegment struct, MemorySegment fieldValue) { + struct.set(CreateInterfaceAsyncPort$LAYOUT, CreateInterfaceAsyncPort$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetInterfaceAsyncPort)(void *) * } */ - public interface GetDeviceProduct { + public static class GetInterfaceAsyncPort { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceProduct fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$25.const$0, fi, constants$6.const$5, scope); + GetInterfaceAsyncPort() { + // Should not be called directly } - static GetDeviceProduct ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle GetDeviceProduct$VH() { - return constants$25.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); - * } - */ - public static MemorySegment GetDeviceProduct$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$25.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceAsyncPort.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceAsyncPort.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetInterfaceAsyncPort$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceAsyncPort")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceProduct)(void*,UInt16*); + * Layout for field: + * {@snippet lang=c : + * mach_port_t (*GetInterfaceAsyncPort)(void *) * } */ - public static void GetDeviceProduct$set(MemorySegment seg, MemorySegment x) { - constants$25.const$1.set(seg, x); - } - public static MemorySegment GetDeviceProduct$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$25.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceProduct$set(MemorySegment seg, long index, MemorySegment x) { - constants$25.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceProduct GetDeviceProduct(MemorySegment segment, Arena scope) { - return GetDeviceProduct.ofAddress(GetDeviceProduct$get(segment), scope); + public static final AddressLayout GetInterfaceAsyncPort$layout() { + return GetInterfaceAsyncPort$LAYOUT; } + + private static final long GetInterfaceAsyncPort$OFFSET = 56; + /** - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * Offset for field: + * {@snippet lang=c : + * mach_port_t (*GetInterfaceAsyncPort)(void *) * } */ - public interface GetDeviceReleaseNumber { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDeviceReleaseNumber fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$25.const$2, fi, constants$6.const$5, scope); - } - static GetDeviceReleaseNumber ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetInterfaceAsyncPort$offset() { + return GetInterfaceAsyncPort$OFFSET; } - public static VarHandle GetDeviceReleaseNumber$VH() { - return constants$25.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetInterfaceAsyncPort)(void *) * } */ - public static MemorySegment GetDeviceReleaseNumber$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$25.const$3.get(seg); + public static MemorySegment GetInterfaceAsyncPort(MemorySegment struct) { + return struct.get(GetInterfaceAsyncPort$LAYOUT, GetInterfaceAsyncPort$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDeviceReleaseNumber)(void*,UInt16*); + * {@snippet lang=c : + * mach_port_t (*GetInterfaceAsyncPort)(void *) * } */ - public static void GetDeviceReleaseNumber$set(MemorySegment seg, MemorySegment x) { - constants$25.const$3.set(seg, x); - } - public static MemorySegment GetDeviceReleaseNumber$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$25.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetDeviceReleaseNumber$set(MemorySegment seg, long index, MemorySegment x) { - constants$25.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetDeviceReleaseNumber GetDeviceReleaseNumber(MemorySegment segment, Arena scope) { - return GetDeviceReleaseNumber.ofAddress(GetDeviceReleaseNumber$get(segment), scope); + public static void GetInterfaceAsyncPort(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceAsyncPort$LAYOUT, GetInterfaceAsyncPort$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetConfigurationValue)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpen)(void *) * } */ - public interface GetConfigurationValue { + public static class USBInterfaceOpen { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetConfigurationValue fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$25.const$4, fi, constants$6.const$5, scope); + USBInterfaceOpen() { + // Should not be called directly } - static GetConfigurationValue ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle GetConfigurationValue$VH() { - return constants$25.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetConfigurationValue)(void*,UInt8*); - * } - */ - public static MemorySegment GetConfigurationValue$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$25.const$5.get(seg); - } + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBInterfaceOpen.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBInterfaceOpen.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout USBInterfaceOpen$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBInterfaceOpen")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetConfigurationValue)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpen)(void *) * } */ - public static void GetConfigurationValue$set(MemorySegment seg, MemorySegment x) { - constants$25.const$5.set(seg, x); - } - public static MemorySegment GetConfigurationValue$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$25.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetConfigurationValue$set(MemorySegment seg, long index, MemorySegment x) { - constants$25.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetConfigurationValue GetConfigurationValue(MemorySegment segment, Arena scope) { - return GetConfigurationValue.ofAddress(GetConfigurationValue$get(segment), scope); + public static final AddressLayout USBInterfaceOpen$layout() { + return USBInterfaceOpen$LAYOUT; } + + private static final long USBInterfaceOpen$OFFSET = 64; + /** - * {@snippet : - * IOReturn (*GetInterfaceNumber)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpen)(void *) * } */ - public interface GetInterfaceNumber { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetInterfaceNumber fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$26.const$0, fi, constants$6.const$5, scope); - } - static GetInterfaceNumber ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBInterfaceOpen$offset() { + return USBInterfaceOpen$OFFSET; } - public static VarHandle GetInterfaceNumber$VH() { - return constants$26.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetInterfaceNumber)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpen)(void *) * } */ - public static MemorySegment GetInterfaceNumber$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$26.const$1.get(seg); + public static MemorySegment USBInterfaceOpen(MemorySegment struct) { + return struct.get(USBInterfaceOpen$LAYOUT, USBInterfaceOpen$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetInterfaceNumber)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpen)(void *) * } */ - public static void GetInterfaceNumber$set(MemorySegment seg, MemorySegment x) { - constants$26.const$1.set(seg, x); - } - public static MemorySegment GetInterfaceNumber$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$26.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetInterfaceNumber$set(MemorySegment seg, long index, MemorySegment x) { - constants$26.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetInterfaceNumber GetInterfaceNumber(MemorySegment segment, Arena scope) { - return GetInterfaceNumber.ofAddress(GetInterfaceNumber$get(segment), scope); + public static void USBInterfaceOpen(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBInterfaceOpen$LAYOUT, USBInterfaceOpen$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetAlternateSetting)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceClose)(void *) * } */ - public interface GetAlternateSetting { + public static class USBInterfaceClose { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetAlternateSetting fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$26.const$2, fi, constants$6.const$5, scope); + USBInterfaceClose() { + // Should not be called directly } - static GetAlternateSetting ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle GetAlternateSetting$VH() { - return constants$26.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetAlternateSetting)(void*,UInt8*); - * } - */ - public static MemorySegment GetAlternateSetting$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$26.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBInterfaceClose.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBInterfaceClose.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBInterfaceClose$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBInterfaceClose")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetAlternateSetting)(void*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceClose)(void *) * } */ - public static void GetAlternateSetting$set(MemorySegment seg, MemorySegment x) { - constants$26.const$3.set(seg, x); - } - public static MemorySegment GetAlternateSetting$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$26.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetAlternateSetting$set(MemorySegment seg, long index, MemorySegment x) { - constants$26.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetAlternateSetting GetAlternateSetting(MemorySegment segment, Arena scope) { - return GetAlternateSetting.ofAddress(GetAlternateSetting$get(segment), scope); + public static final AddressLayout USBInterfaceClose$layout() { + return USBInterfaceClose$LAYOUT; } + + private static final long USBInterfaceClose$OFFSET = 72; + /** - * {@snippet : - * IOReturn (*GetNumEndpoints)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceClose)(void *) * } */ - public interface GetNumEndpoints { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetNumEndpoints fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$26.const$4, fi, constants$6.const$5, scope); - } - static GetNumEndpoints ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBInterfaceClose$offset() { + return USBInterfaceClose$OFFSET; } - public static VarHandle GetNumEndpoints$VH() { - return constants$26.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetNumEndpoints)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceClose)(void *) * } */ - public static MemorySegment GetNumEndpoints$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$26.const$5.get(seg); + public static MemorySegment USBInterfaceClose(MemorySegment struct) { + return struct.get(USBInterfaceClose$LAYOUT, USBInterfaceClose$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetNumEndpoints)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceClose)(void *) * } */ - public static void GetNumEndpoints$set(MemorySegment seg, MemorySegment x) { - constants$26.const$5.set(seg, x); - } - public static MemorySegment GetNumEndpoints$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$26.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetNumEndpoints$set(MemorySegment seg, long index, MemorySegment x) { - constants$26.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetNumEndpoints GetNumEndpoints(MemorySegment segment, Arena scope) { - return GetNumEndpoints.ofAddress(GetNumEndpoints$get(segment), scope); + public static void USBInterfaceClose(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBInterfaceClose$LAYOUT, USBInterfaceClose$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceClass)(void *, UInt8 *) * } */ - public interface GetLocationID { + public static class GetInterfaceClass { - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetLocationID fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$27.const$0, fi, constants$6.const$5, scope); + GetInterfaceClass() { + // Should not be called directly } - static GetLocationID ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle GetLocationID$VH() { - return constants$27.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); - * } - */ - public static MemorySegment GetLocationID$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$27.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceClass.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceClass.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetInterfaceClass$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceClass")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetLocationID)(void*,UInt32*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceClass)(void *, UInt8 *) * } */ - public static void GetLocationID$set(MemorySegment seg, MemorySegment x) { - constants$27.const$1.set(seg, x); - } - public static MemorySegment GetLocationID$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$27.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetLocationID$set(MemorySegment seg, long index, MemorySegment x) { - constants$27.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetLocationID GetLocationID(MemorySegment segment, Arena scope) { - return GetLocationID.ofAddress(GetLocationID$get(segment), scope); + public static final AddressLayout GetInterfaceClass$layout() { + return GetInterfaceClass$LAYOUT; } + + private static final long GetInterfaceClass$OFFSET = 80; + /** - * {@snippet : - * IOReturn (*GetDevice)(void*,io_service_t*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceClass)(void *, UInt8 *) * } */ - public interface GetDevice { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetDevice fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$27.const$2, fi, constants$6.const$5, scope); - } - static GetDevice ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetInterfaceClass$offset() { + return GetInterfaceClass$OFFSET; } - public static VarHandle GetDevice$VH() { - return constants$27.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetDevice)(void*,io_service_t*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceClass)(void *, UInt8 *) * } */ - public static MemorySegment GetDevice$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$27.const$3.get(seg); + public static MemorySegment GetInterfaceClass(MemorySegment struct) { + return struct.get(GetInterfaceClass$LAYOUT, GetInterfaceClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetDevice)(void*,io_service_t*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceClass)(void *, UInt8 *) * } */ - public static void GetDevice$set(MemorySegment seg, MemorySegment x) { - constants$27.const$3.set(seg, x); - } - public static MemorySegment GetDevice$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$27.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetDevice$set(MemorySegment seg, long index, MemorySegment x) { - constants$27.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetDevice GetDevice(MemorySegment segment, Arena scope) { - return GetDevice.ofAddress(GetDevice$get(segment), scope); + public static void GetInterfaceClass(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceClass$LAYOUT, GetInterfaceClass$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*SetAlternateInterface)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *) * } */ - public interface SetAlternateInterface { + public static class GetInterfaceSubClass { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(SetAlternateInterface fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$27.const$4, fi, constants$14.const$0, scope); + GetInterfaceSubClass() { + // Should not be called directly } - static SetAlternateInterface ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle SetAlternateInterface$VH() { - return constants$27.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*SetAlternateInterface)(void*,UInt8); - * } - */ - public static MemorySegment SetAlternateInterface$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$27.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceSubClass.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceSubClass.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetInterfaceSubClass$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceSubClass")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*SetAlternateInterface)(void*,UInt8); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *) * } */ - public static void SetAlternateInterface$set(MemorySegment seg, MemorySegment x) { - constants$27.const$5.set(seg, x); - } - public static MemorySegment SetAlternateInterface$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$27.const$5.get(seg.asSlice(index*sizeof())); - } - public static void SetAlternateInterface$set(MemorySegment seg, long index, MemorySegment x) { - constants$27.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static SetAlternateInterface SetAlternateInterface(MemorySegment segment, Arena scope) { - return SetAlternateInterface.ofAddress(SetAlternateInterface$get(segment), scope); + public static final AddressLayout GetInterfaceSubClass$layout() { + return GetInterfaceSubClass$LAYOUT; } + + private static final long GetInterfaceSubClass$OFFSET = 88; + /** - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *) * } */ - public interface GetBusFrameNumber { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(GetBusFrameNumber fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$28.const$0, fi, constants$14.const$4, scope); - } - static GetBusFrameNumber ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$15.const$0.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetInterfaceSubClass$offset() { + return GetInterfaceSubClass$OFFSET; } - public static VarHandle GetBusFrameNumber$VH() { - return constants$28.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *) * } */ - public static MemorySegment GetBusFrameNumber$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$28.const$1.get(seg); + public static MemorySegment GetInterfaceSubClass(MemorySegment struct) { + return struct.get(GetInterfaceSubClass$LAYOUT, GetInterfaceSubClass$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetBusFrameNumber)(void*,UInt64*,AbsoluteTime*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceSubClass)(void *, UInt8 *) * } */ - public static void GetBusFrameNumber$set(MemorySegment seg, MemorySegment x) { - constants$28.const$1.set(seg, x); - } - public static MemorySegment GetBusFrameNumber$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$28.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetBusFrameNumber$set(MemorySegment seg, long index, MemorySegment x) { - constants$28.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetBusFrameNumber GetBusFrameNumber(MemorySegment segment, Arena scope) { - return GetBusFrameNumber.ofAddress(GetBusFrameNumber$get(segment), scope); + public static void GetInterfaceSubClass(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceSubClass$LAYOUT, GetInterfaceSubClass$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*ControlRequest)(void*,UInt8,IOUSBDevRequest*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *) * } */ - public interface ControlRequest { + public static class GetInterfaceProtocol { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(ControlRequest fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$28.const$2, fi, constants$13.const$0, scope); + GetInterfaceProtocol() { + // Should not be called directly } - static ControlRequest ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$13.const$2.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle ControlRequest$VH() { - return constants$28.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*ControlRequest)(void*,UInt8,IOUSBDevRequest*); - * } - */ - public static MemorySegment ControlRequest$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$28.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceProtocol.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceProtocol.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetInterfaceProtocol$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceProtocol")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*ControlRequest)(void*,UInt8,IOUSBDevRequest*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *) * } */ - public static void ControlRequest$set(MemorySegment seg, MemorySegment x) { - constants$28.const$3.set(seg, x); - } - public static MemorySegment ControlRequest$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$28.const$3.get(seg.asSlice(index*sizeof())); - } - public static void ControlRequest$set(MemorySegment seg, long index, MemorySegment x) { - constants$28.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static ControlRequest ControlRequest(MemorySegment segment, Arena scope) { - return ControlRequest.ofAddress(ControlRequest$get(segment), scope); + public static final AddressLayout GetInterfaceProtocol$layout() { + return GetInterfaceProtocol$LAYOUT; } + + private static final long GetInterfaceProtocol$OFFSET = 96; + /** - * {@snippet : - * IOReturn (*ControlRequestAsync)(void*,UInt8,IOUSBDevRequest*,IOAsyncCallback1,void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *) * } */ - public interface ControlRequestAsync { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3, java.lang.foreign.MemorySegment _x4); - static MemorySegment allocate(ControlRequestAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$28.const$5, fi, constants$28.const$4, scope); - } - static ControlRequestAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3, java.lang.foreign.MemorySegment __x4) -> { - try { - return (int)constants$29.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetInterfaceProtocol$offset() { + return GetInterfaceProtocol$OFFSET; } - public static VarHandle ControlRequestAsync$VH() { - return constants$29.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ControlRequestAsync)(void*,UInt8,IOUSBDevRequest*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *) * } */ - public static MemorySegment ControlRequestAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$29.const$1.get(seg); + public static MemorySegment GetInterfaceProtocol(MemorySegment struct) { + return struct.get(GetInterfaceProtocol$LAYOUT, GetInterfaceProtocol$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ControlRequestAsync)(void*,UInt8,IOUSBDevRequest*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*GetInterfaceProtocol)(void *, UInt8 *) * } */ - public static void ControlRequestAsync$set(MemorySegment seg, MemorySegment x) { - constants$29.const$1.set(seg, x); - } - public static MemorySegment ControlRequestAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$29.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ControlRequestAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$29.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ControlRequestAsync ControlRequestAsync(MemorySegment segment, Arena scope) { - return ControlRequestAsync.ofAddress(ControlRequestAsync$get(segment), scope); + public static void GetInterfaceProtocol(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceProtocol$LAYOUT, GetInterfaceProtocol$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*GetPipeProperties)(void*,UInt8,UInt8*,UInt8*,UInt8*,UInt16*,UInt8*); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public interface GetPipeProperties { + public static class GetDeviceVendor { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3, java.lang.foreign.MemorySegment _x4, java.lang.foreign.MemorySegment _x5, java.lang.foreign.MemorySegment _x6); - static MemorySegment allocate(GetPipeProperties fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$29.const$3, fi, constants$29.const$2, scope); + GetDeviceVendor() { + // Should not be called directly } - static GetPipeProperties ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3, java.lang.foreign.MemorySegment __x4, java.lang.foreign.MemorySegment __x5, java.lang.foreign.MemorySegment __x6) -> { - try { - return (int)constants$29.const$4.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle GetPipeProperties$VH() { - return constants$29.const$5; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*GetPipeProperties)(void*,UInt8,UInt8*,UInt8*,UInt8*,UInt16*,UInt8*); - * } - */ - public static MemorySegment GetPipeProperties$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$29.const$5.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceVendor.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceVendor.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetDeviceVendor$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceVendor")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetPipeProperties)(void*,UInt8,UInt8*,UInt8*,UInt8*,UInt16*,UInt8*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public static void GetPipeProperties$set(MemorySegment seg, MemorySegment x) { - constants$29.const$5.set(seg, x); - } - public static MemorySegment GetPipeProperties$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$29.const$5.get(seg.asSlice(index*sizeof())); - } - public static void GetPipeProperties$set(MemorySegment seg, long index, MemorySegment x) { - constants$29.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static GetPipeProperties GetPipeProperties(MemorySegment segment, Arena scope) { - return GetPipeProperties.ofAddress(GetPipeProperties$get(segment), scope); + public static final AddressLayout GetDeviceVendor$layout() { + return GetDeviceVendor$LAYOUT; } + + private static final long GetDeviceVendor$OFFSET = 104; + /** - * {@snippet : - * IOReturn (*GetPipeStatus)(void*,UInt8); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public interface GetPipeStatus { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(GetPipeStatus fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$30.const$0, fi, constants$14.const$0, scope); - } - static GetPipeStatus ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetDeviceVendor$offset() { + return GetDeviceVendor$OFFSET; } - public static VarHandle GetPipeStatus$VH() { - return constants$30.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetPipeStatus)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public static MemorySegment GetPipeStatus$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$30.const$1.get(seg); + public static MemorySegment GetDeviceVendor(MemorySegment struct) { + return struct.get(GetDeviceVendor$LAYOUT, GetDeviceVendor$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetPipeStatus)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceVendor)(void *, UInt16 *) * } */ - public static void GetPipeStatus$set(MemorySegment seg, MemorySegment x) { - constants$30.const$1.set(seg, x); - } - public static MemorySegment GetPipeStatus$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$30.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetPipeStatus$set(MemorySegment seg, long index, MemorySegment x) { - constants$30.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetPipeStatus GetPipeStatus(MemorySegment segment, Arena scope) { - return GetPipeStatus.ofAddress(GetPipeStatus$get(segment), scope); + public static void GetDeviceVendor(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceVendor$LAYOUT, GetDeviceVendor$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*AbortPipe)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public interface AbortPipe { + public static class GetDeviceProduct { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(AbortPipe fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$30.const$2, fi, constants$14.const$0, scope); + GetDeviceProduct() { + // Should not be called directly } - static AbortPipe ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle AbortPipe$VH() { - return constants$30.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*AbortPipe)(void*,UInt8); - * } - */ - public static MemorySegment AbortPipe$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$30.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceProduct.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceProduct.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetDeviceProduct$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceProduct")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*AbortPipe)(void*,UInt8); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public static void AbortPipe$set(MemorySegment seg, MemorySegment x) { - constants$30.const$3.set(seg, x); - } - public static MemorySegment AbortPipe$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$30.const$3.get(seg.asSlice(index*sizeof())); - } - public static void AbortPipe$set(MemorySegment seg, long index, MemorySegment x) { - constants$30.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static AbortPipe AbortPipe(MemorySegment segment, Arena scope) { - return AbortPipe.ofAddress(AbortPipe$get(segment), scope); + public static final AddressLayout GetDeviceProduct$layout() { + return GetDeviceProduct$LAYOUT; } + + private static final long GetDeviceProduct$OFFSET = 112; + /** - * {@snippet : - * IOReturn (*ResetPipe)(void*,UInt8); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public interface ResetPipe { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(ResetPipe fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$30.const$4, fi, constants$14.const$0, scope); - } - static ResetPipe ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetDeviceProduct$offset() { + return GetDeviceProduct$OFFSET; } - public static VarHandle ResetPipe$VH() { - return constants$30.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ResetPipe)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public static MemorySegment ResetPipe$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$30.const$5.get(seg); + public static MemorySegment GetDeviceProduct(MemorySegment struct) { + return struct.get(GetDeviceProduct$LAYOUT, GetDeviceProduct$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ResetPipe)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceProduct)(void *, UInt16 *) * } */ - public static void ResetPipe$set(MemorySegment seg, MemorySegment x) { - constants$30.const$5.set(seg, x); - } - public static MemorySegment ResetPipe$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$30.const$5.get(seg.asSlice(index*sizeof())); - } - public static void ResetPipe$set(MemorySegment seg, long index, MemorySegment x) { - constants$30.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static ResetPipe ResetPipe(MemorySegment segment, Arena scope) { - return ResetPipe.ofAddress(ResetPipe$get(segment), scope); + public static void GetDeviceProduct(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceProduct$LAYOUT, GetDeviceProduct$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*ClearPipeStall)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public interface ClearPipeStall { + public static class GetDeviceReleaseNumber { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(ClearPipeStall fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$31.const$0, fi, constants$14.const$0, scope); + GetDeviceReleaseNumber() { + // Should not be called directly } - static ClearPipeStall ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle ClearPipeStall$VH() { - return constants$31.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*ClearPipeStall)(void*,UInt8); - * } - */ - public static MemorySegment ClearPipeStall$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$31.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDeviceReleaseNumber.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDeviceReleaseNumber.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetDeviceReleaseNumber$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDeviceReleaseNumber")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*ClearPipeStall)(void*,UInt8); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public static void ClearPipeStall$set(MemorySegment seg, MemorySegment x) { - constants$31.const$1.set(seg, x); - } - public static MemorySegment ClearPipeStall$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$31.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ClearPipeStall$set(MemorySegment seg, long index, MemorySegment x) { - constants$31.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ClearPipeStall ClearPipeStall(MemorySegment segment, Arena scope) { - return ClearPipeStall.ofAddress(ClearPipeStall$get(segment), scope); + public static final AddressLayout GetDeviceReleaseNumber$layout() { + return GetDeviceReleaseNumber$LAYOUT; } + + private static final long GetDeviceReleaseNumber$OFFSET = 120; + /** - * {@snippet : - * IOReturn (*ReadPipe)(void*,UInt8,void*,UInt32*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public interface ReadPipe { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3); - static MemorySegment allocate(ReadPipe fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$31.const$3, fi, constants$31.const$2, scope); - } - static ReadPipe ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3) -> { - try { - return (int)constants$31.const$4.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetDeviceReleaseNumber$offset() { + return GetDeviceReleaseNumber$OFFSET; } - public static VarHandle ReadPipe$VH() { - return constants$31.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ReadPipe)(void*,UInt8,void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public static MemorySegment ReadPipe$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$31.const$5.get(seg); + public static MemorySegment GetDeviceReleaseNumber(MemorySegment struct) { + return struct.get(GetDeviceReleaseNumber$LAYOUT, GetDeviceReleaseNumber$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ReadPipe)(void*,UInt8,void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetDeviceReleaseNumber)(void *, UInt16 *) * } */ - public static void ReadPipe$set(MemorySegment seg, MemorySegment x) { - constants$31.const$5.set(seg, x); - } - public static MemorySegment ReadPipe$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$31.const$5.get(seg.asSlice(index*sizeof())); - } - public static void ReadPipe$set(MemorySegment seg, long index, MemorySegment x) { - constants$31.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static ReadPipe ReadPipe(MemorySegment segment, Arena scope) { - return ReadPipe.ofAddress(ReadPipe$get(segment), scope); + public static void GetDeviceReleaseNumber(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDeviceReleaseNumber$LAYOUT, GetDeviceReleaseNumber$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*WritePipe)(void*,UInt8,void*,UInt32); + * {@snippet lang=c : + * IOReturn (*GetConfigurationValue)(void *, UInt8 *) * } */ - public interface WritePipe { + public static class GetConfigurationValue { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3); - static MemorySegment allocate(WritePipe fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$32.const$1, fi, constants$32.const$0, scope); + GetConfigurationValue() { + // Should not be called directly } - static WritePipe ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3) -> { - try { - return (int)constants$32.const$2.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle WritePipe$VH() { - return constants$32.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*WritePipe)(void*,UInt8,void*,UInt32); - * } + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetConfigurationValue.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetConfigurationValue.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetConfigurationValue$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetConfigurationValue")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationValue)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetConfigurationValue$layout() { + return GetConfigurationValue$LAYOUT; + } + + private static final long GetConfigurationValue$OFFSET = 128; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationValue)(void *, UInt8 *) + * } + */ + public static final long GetConfigurationValue$offset() { + return GetConfigurationValue$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationValue)(void *, UInt8 *) + * } + */ + public static MemorySegment GetConfigurationValue(MemorySegment struct) { + return struct.get(GetConfigurationValue$LAYOUT, GetConfigurationValue$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetConfigurationValue)(void *, UInt8 *) + * } + */ + public static void GetConfigurationValue(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetConfigurationValue$LAYOUT, GetConfigurationValue$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *) + * } + */ + public static class GetInterfaceNumber { + + GetInterfaceNumber() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetInterfaceNumber.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetInterfaceNumber.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetInterfaceNumber$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetInterfaceNumber")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetInterfaceNumber$layout() { + return GetInterfaceNumber$LAYOUT; + } + + private static final long GetInterfaceNumber$OFFSET = 136; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *) + * } + */ + public static final long GetInterfaceNumber$offset() { + return GetInterfaceNumber$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *) + * } + */ + public static MemorySegment GetInterfaceNumber(MemorySegment struct) { + return struct.get(GetInterfaceNumber$LAYOUT, GetInterfaceNumber$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetInterfaceNumber)(void *, UInt8 *) + * } + */ + public static void GetInterfaceNumber(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetInterfaceNumber$LAYOUT, GetInterfaceNumber$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetAlternateSetting)(void *, UInt8 *) + * } + */ + public static class GetAlternateSetting { + + GetAlternateSetting() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetAlternateSetting.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetAlternateSetting.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetAlternateSetting$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetAlternateSetting")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetAlternateSetting)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetAlternateSetting$layout() { + return GetAlternateSetting$LAYOUT; + } + + private static final long GetAlternateSetting$OFFSET = 144; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetAlternateSetting)(void *, UInt8 *) + * } + */ + public static final long GetAlternateSetting$offset() { + return GetAlternateSetting$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetAlternateSetting)(void *, UInt8 *) + * } + */ + public static MemorySegment GetAlternateSetting(MemorySegment struct) { + return struct.get(GetAlternateSetting$LAYOUT, GetAlternateSetting$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetAlternateSetting)(void *, UInt8 *) + * } + */ + public static void GetAlternateSetting(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetAlternateSetting$LAYOUT, GetAlternateSetting$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetNumEndpoints)(void *, UInt8 *) + * } + */ + public static class GetNumEndpoints { + + GetNumEndpoints() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetNumEndpoints.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetNumEndpoints.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetNumEndpoints$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetNumEndpoints")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetNumEndpoints)(void *, UInt8 *) + * } + */ + public static final AddressLayout GetNumEndpoints$layout() { + return GetNumEndpoints$LAYOUT; + } + + private static final long GetNumEndpoints$OFFSET = 152; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetNumEndpoints)(void *, UInt8 *) + * } + */ + public static final long GetNumEndpoints$offset() { + return GetNumEndpoints$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetNumEndpoints)(void *, UInt8 *) + * } + */ + public static MemorySegment GetNumEndpoints(MemorySegment struct) { + return struct.get(GetNumEndpoints$LAYOUT, GetNumEndpoints$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetNumEndpoints)(void *, UInt8 *) + * } + */ + public static void GetNumEndpoints(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetNumEndpoints$LAYOUT, GetNumEndpoints$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static class GetLocationID { + + GetLocationID() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetLocationID.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetLocationID.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetLocationID$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetLocationID")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static final AddressLayout GetLocationID$layout() { + return GetLocationID$LAYOUT; + } + + private static final long GetLocationID$OFFSET = 160; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static final long GetLocationID$offset() { + return GetLocationID$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static MemorySegment GetLocationID(MemorySegment struct) { + return struct.get(GetLocationID$LAYOUT, GetLocationID$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetLocationID)(void *, UInt32 *) + * } + */ + public static void GetLocationID(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetLocationID$LAYOUT, GetLocationID$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetDevice)(void *, io_service_t *) + * } + */ + public static class GetDevice { + + GetDevice() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetDevice.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetDevice.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetDevice$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetDevice")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetDevice)(void *, io_service_t *) + * } + */ + public static final AddressLayout GetDevice$layout() { + return GetDevice$LAYOUT; + } + + private static final long GetDevice$OFFSET = 168; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetDevice)(void *, io_service_t *) + * } + */ + public static final long GetDevice$offset() { + return GetDevice$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetDevice)(void *, io_service_t *) + * } + */ + public static MemorySegment GetDevice(MemorySegment struct) { + return struct.get(GetDevice$LAYOUT, GetDevice$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetDevice)(void *, io_service_t *) + * } + */ + public static void GetDevice(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetDevice$LAYOUT, GetDevice$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*SetAlternateInterface)(void *, UInt8) + * } + */ + public static class SetAlternateInterface { + + SetAlternateInterface() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(SetAlternateInterface.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(SetAlternateInterface.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout SetAlternateInterface$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("SetAlternateInterface")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*SetAlternateInterface)(void *, UInt8) + * } + */ + public static final AddressLayout SetAlternateInterface$layout() { + return SetAlternateInterface$LAYOUT; + } + + private static final long SetAlternateInterface$OFFSET = 176; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*SetAlternateInterface)(void *, UInt8) + * } + */ + public static final long SetAlternateInterface$offset() { + return SetAlternateInterface$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*SetAlternateInterface)(void *, UInt8) + * } + */ + public static MemorySegment SetAlternateInterface(MemorySegment struct) { + return struct.get(SetAlternateInterface$LAYOUT, SetAlternateInterface$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*SetAlternateInterface)(void *, UInt8) + * } + */ + public static void SetAlternateInterface(MemorySegment struct, MemorySegment fieldValue) { + struct.set(SetAlternateInterface$LAYOUT, SetAlternateInterface$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static class GetBusFrameNumber { + + GetBusFrameNumber() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetBusFrameNumber.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetBusFrameNumber.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetBusFrameNumber$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetBusFrameNumber")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static final AddressLayout GetBusFrameNumber$layout() { + return GetBusFrameNumber$LAYOUT; + } + + private static final long GetBusFrameNumber$OFFSET = 184; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static final long GetBusFrameNumber$offset() { + return GetBusFrameNumber$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static MemorySegment GetBusFrameNumber(MemorySegment struct) { + return struct.get(GetBusFrameNumber$LAYOUT, GetBusFrameNumber$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetBusFrameNumber)(void *, UInt64 *, AbsoluteTime *) + * } + */ + public static void GetBusFrameNumber(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetBusFrameNumber$LAYOUT, GetBusFrameNumber$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *) + * } + */ + public static class ControlRequest { + + ControlRequest() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ControlRequest.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ControlRequest.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ControlRequest$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ControlRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *) + * } + */ + public static final AddressLayout ControlRequest$layout() { + return ControlRequest$LAYOUT; + } + + private static final long ControlRequest$OFFSET = 192; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *) + * } + */ + public static final long ControlRequest$offset() { + return ControlRequest$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *) + * } + */ + public static MemorySegment ControlRequest(MemorySegment struct) { + return struct.get(ControlRequest$LAYOUT, ControlRequest$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequest)(void *, UInt8, IOUSBDevRequest *) + * } + */ + public static void ControlRequest(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ControlRequest$LAYOUT, ControlRequest$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static class ControlRequestAsync { + + ControlRequestAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ControlRequestAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ControlRequestAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ControlRequestAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ControlRequestAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout ControlRequestAsync$layout() { + return ControlRequestAsync$LAYOUT; + } + + private static final long ControlRequestAsync$OFFSET = 200; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static final long ControlRequestAsync$offset() { + return ControlRequestAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment ControlRequestAsync(MemorySegment struct) { + return struct.get(ControlRequestAsync$LAYOUT, ControlRequestAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsync)(void *, UInt8, IOUSBDevRequest *, IOAsyncCallback1, void *) + * } + */ + public static void ControlRequestAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ControlRequestAsync$LAYOUT, ControlRequestAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *) + * } + */ + public static class GetPipeProperties { + + GetPipeProperties() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4, MemorySegment _x5, MemorySegment _x6); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetPipeProperties.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetPipeProperties.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4, MemorySegment _x5, MemorySegment _x6) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetPipeProperties$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetPipeProperties")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *) + * } + */ + public static final AddressLayout GetPipeProperties$layout() { + return GetPipeProperties$LAYOUT; + } + + private static final long GetPipeProperties$OFFSET = 208; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *) + * } + */ + public static final long GetPipeProperties$offset() { + return GetPipeProperties$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *) + * } + */ + public static MemorySegment GetPipeProperties(MemorySegment struct) { + return struct.get(GetPipeProperties$LAYOUT, GetPipeProperties$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetPipeProperties)(void *, UInt8, UInt8 *, UInt8 *, UInt8 *, UInt16 *, UInt8 *) + * } + */ + public static void GetPipeProperties(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetPipeProperties$LAYOUT, GetPipeProperties$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*GetPipeStatus)(void *, UInt8) + * } + */ + public static class GetPipeStatus { + + GetPipeStatus() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetPipeStatus.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetPipeStatus.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout GetPipeStatus$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetPipeStatus")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetPipeStatus)(void *, UInt8) + * } + */ + public static final AddressLayout GetPipeStatus$layout() { + return GetPipeStatus$LAYOUT; + } + + private static final long GetPipeStatus$OFFSET = 216; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetPipeStatus)(void *, UInt8) + * } + */ + public static final long GetPipeStatus$offset() { + return GetPipeStatus$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*GetPipeStatus)(void *, UInt8) + * } + */ + public static MemorySegment GetPipeStatus(MemorySegment struct) { + return struct.get(GetPipeStatus$LAYOUT, GetPipeStatus$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*GetPipeStatus)(void *, UInt8) + * } + */ + public static void GetPipeStatus(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetPipeStatus$LAYOUT, GetPipeStatus$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*AbortPipe)(void *, UInt8) + * } + */ + public static class AbortPipe { + + AbortPipe() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(AbortPipe.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(AbortPipe.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout AbortPipe$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("AbortPipe")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*AbortPipe)(void *, UInt8) + * } + */ + public static final AddressLayout AbortPipe$layout() { + return AbortPipe$LAYOUT; + } + + private static final long AbortPipe$OFFSET = 224; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*AbortPipe)(void *, UInt8) + * } + */ + public static final long AbortPipe$offset() { + return AbortPipe$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*AbortPipe)(void *, UInt8) + * } + */ + public static MemorySegment AbortPipe(MemorySegment struct) { + return struct.get(AbortPipe$LAYOUT, AbortPipe$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*AbortPipe)(void *, UInt8) + * } + */ + public static void AbortPipe(MemorySegment struct, MemorySegment fieldValue) { + struct.set(AbortPipe$LAYOUT, AbortPipe$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ResetPipe)(void *, UInt8) + * } + */ + public static class ResetPipe { + + ResetPipe() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ResetPipe.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ResetPipe.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ResetPipe$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ResetPipe")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ResetPipe)(void *, UInt8) + * } + */ + public static final AddressLayout ResetPipe$layout() { + return ResetPipe$LAYOUT; + } + + private static final long ResetPipe$OFFSET = 232; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ResetPipe)(void *, UInt8) + * } + */ + public static final long ResetPipe$offset() { + return ResetPipe$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ResetPipe)(void *, UInt8) + * } + */ + public static MemorySegment ResetPipe(MemorySegment struct) { + return struct.get(ResetPipe$LAYOUT, ResetPipe$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ResetPipe)(void *, UInt8) + * } + */ + public static void ResetPipe(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ResetPipe$LAYOUT, ResetPipe$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ClearPipeStall)(void *, UInt8) + * } + */ + public static class ClearPipeStall { + + ClearPipeStall() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ClearPipeStall.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ClearPipeStall.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ClearPipeStall$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ClearPipeStall")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStall)(void *, UInt8) + * } + */ + public static final AddressLayout ClearPipeStall$layout() { + return ClearPipeStall$LAYOUT; + } + + private static final long ClearPipeStall$OFFSET = 240; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStall)(void *, UInt8) + * } + */ + public static final long ClearPipeStall$offset() { + return ClearPipeStall$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStall)(void *, UInt8) + * } + */ + public static MemorySegment ClearPipeStall(MemorySegment struct) { + return struct.get(ClearPipeStall$LAYOUT, ClearPipeStall$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStall)(void *, UInt8) + * } + */ + public static void ClearPipeStall(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ClearPipeStall$LAYOUT, ClearPipeStall$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *) + * } + */ + public static class ReadPipe { + + ReadPipe() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ReadPipe.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ReadPipe.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ReadPipe$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReadPipe")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *) + * } + */ + public static final AddressLayout ReadPipe$layout() { + return ReadPipe$LAYOUT; + } + + private static final long ReadPipe$OFFSET = 248; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *) + * } + */ + public static final long ReadPipe$offset() { + return ReadPipe$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *) + * } + */ + public static MemorySegment ReadPipe(MemorySegment struct) { + return struct.get(ReadPipe$LAYOUT, ReadPipe$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ReadPipe)(void *, UInt8, void *, UInt32 *) + * } + */ + public static void ReadPipe(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ReadPipe$LAYOUT, ReadPipe$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32) + * } + */ + public static class WritePipe { + + WritePipe() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(WritePipe.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(WritePipe.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout WritePipe$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("WritePipe")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32) + * } + */ + public static final AddressLayout WritePipe$layout() { + return WritePipe$LAYOUT; + } + + private static final long WritePipe$OFFSET = 256; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32) + * } + */ + public static final long WritePipe$offset() { + return WritePipe$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32) + * } + */ + public static MemorySegment WritePipe(MemorySegment struct) { + return struct.get(WritePipe$LAYOUT, WritePipe$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*WritePipe)(void *, UInt8, void *, UInt32) + * } + */ + public static void WritePipe(MemorySegment struct, MemorySegment fieldValue) { + struct.set(WritePipe$LAYOUT, WritePipe$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static class ReadPipeAsync { + + ReadPipeAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, MemorySegment _x4, MemorySegment _x5); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ReadPipeAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ReadPipeAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, MemorySegment _x4, MemorySegment _x5) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ReadPipeAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReadPipeAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout ReadPipeAsync$layout() { + return ReadPipeAsync$LAYOUT; + } + + private static final long ReadPipeAsync$OFFSET = 264; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static final long ReadPipeAsync$offset() { + return ReadPipeAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment ReadPipeAsync(MemorySegment struct) { + return struct.get(ReadPipeAsync$LAYOUT, ReadPipeAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static void ReadPipeAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ReadPipeAsync$LAYOUT, ReadPipeAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static class WritePipeAsync { + + WritePipeAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, MemorySegment _x4, MemorySegment _x5); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(WritePipeAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(WritePipeAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, MemorySegment _x4, MemorySegment _x5) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout WritePipeAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("WritePipeAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout WritePipeAsync$layout() { + return WritePipeAsync$LAYOUT; + } + + private static final long WritePipeAsync$OFFSET = 272; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static final long WritePipeAsync$offset() { + return WritePipeAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment WritePipeAsync(MemorySegment struct) { + return struct.get(WritePipeAsync$LAYOUT, WritePipeAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsync)(void *, UInt8, void *, UInt32, IOAsyncCallback1, void *) + * } + */ + public static void WritePipeAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(WritePipeAsync$LAYOUT, WritePipeAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static class ReadIsochPipeAsync { + + ReadIsochPipeAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, long _x3, int _x4, MemorySegment _x5, MemorySegment _x6, MemorySegment _x7); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_LONG_LONG, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ReadIsochPipeAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ReadIsochPipeAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, long _x3, int _x4, MemorySegment _x5, MemorySegment _x6, MemorySegment _x7) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ReadIsochPipeAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReadIsochPipeAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout ReadIsochPipeAsync$layout() { + return ReadIsochPipeAsync$LAYOUT; + } + + private static final long ReadIsochPipeAsync$OFFSET = 280; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static final long ReadIsochPipeAsync$offset() { + return ReadIsochPipeAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment ReadIsochPipeAsync(MemorySegment struct) { + return struct.get(ReadIsochPipeAsync$LAYOUT, ReadIsochPipeAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ReadIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static void ReadIsochPipeAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ReadIsochPipeAsync$LAYOUT, ReadIsochPipeAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static class WriteIsochPipeAsync { + + WriteIsochPipeAsync() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, long _x3, int _x4, MemorySegment _x5, MemorySegment _x6, MemorySegment _x7); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_LONG_LONG, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(WriteIsochPipeAsync.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(WriteIsochPipeAsync.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, long _x3, int _x4, MemorySegment _x5, MemorySegment _x6, MemorySegment _x7) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout WriteIsochPipeAsync$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("WriteIsochPipeAsync")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout WriteIsochPipeAsync$layout() { + return WriteIsochPipeAsync$LAYOUT; + } + + private static final long WriteIsochPipeAsync$OFFSET = 288; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static final long WriteIsochPipeAsync$offset() { + return WriteIsochPipeAsync$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment WriteIsochPipeAsync(MemorySegment struct) { + return struct.get(WriteIsochPipeAsync$LAYOUT, WriteIsochPipeAsync$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*WriteIsochPipeAsync)(void *, UInt8, void *, UInt64, UInt32, IOUSBIsocFrame *, IOAsyncCallback1, void *) + * } + */ + public static void WriteIsochPipeAsync(MemorySegment struct, MemorySegment fieldValue) { + struct.set(WriteIsochPipeAsync$LAYOUT, WriteIsochPipeAsync$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *) + * } + */ + public static class ControlRequestTO { + + ControlRequestTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ControlRequestTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ControlRequestTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ControlRequestTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ControlRequestTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *) + * } + */ + public static final AddressLayout ControlRequestTO$layout() { + return ControlRequestTO$LAYOUT; + } + + private static final long ControlRequestTO$OFFSET = 296; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *) + * } + */ + public static final long ControlRequestTO$offset() { + return ControlRequestTO$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *) + * } + */ + public static MemorySegment ControlRequestTO(MemorySegment struct) { + return struct.get(ControlRequestTO$LAYOUT, ControlRequestTO$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestTO)(void *, UInt8, IOUSBDevRequestTO *) + * } + */ + public static void ControlRequestTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ControlRequestTO$LAYOUT, ControlRequestTO$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *) + * } + */ + public static class ControlRequestAsyncTO { + + ControlRequestAsyncTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ControlRequestAsyncTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ControlRequestAsyncTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, MemorySegment _x4) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ControlRequestAsyncTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ControlRequestAsyncTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout ControlRequestAsyncTO$layout() { + return ControlRequestAsyncTO$LAYOUT; + } + + private static final long ControlRequestAsyncTO$OFFSET = 304; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *) + * } + */ + public static final long ControlRequestAsyncTO$offset() { + return ControlRequestAsyncTO$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *) + * } + */ + public static MemorySegment ControlRequestAsyncTO(MemorySegment struct) { + return struct.get(ControlRequestAsyncTO$LAYOUT, ControlRequestAsyncTO$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*ControlRequestAsyncTO)(void *, UInt8, IOUSBDevRequestTO *, IOAsyncCallback1, void *) + * } + */ + public static void ControlRequestAsyncTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ControlRequestAsyncTO$LAYOUT, ControlRequestAsyncTO$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32) + * } + */ + public static class ReadPipeTO { + + ReadPipeTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, int _x4, int _x5); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ReadPipeTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ReadPipeTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, MemorySegment _x3, int _x4, int _x5) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout ReadPipeTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReadPipeTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32) + * } + */ + public static final AddressLayout ReadPipeTO$layout() { + return ReadPipeTO$LAYOUT; + } + + private static final long ReadPipeTO$OFFSET = 312; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32) + * } + */ + public static final long ReadPipeTO$offset() { + return ReadPipeTO$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32) + * } */ - public static MemorySegment WritePipe$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$32.const$3.get(seg); + public static MemorySegment ReadPipeTO(MemorySegment struct) { + return struct.get(ReadPipeTO$LAYOUT, ReadPipeTO$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*WritePipe)(void*,UInt8,void*,UInt32); + * {@snippet lang=c : + * IOReturn (*ReadPipeTO)(void *, UInt8, void *, UInt32 *, UInt32, UInt32) + * } + */ + public static void ReadPipeTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ReadPipeTO$LAYOUT, ReadPipeTO$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32) + * } + */ + public static class WritePipeTO { + + WritePipeTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(WritePipeTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(WritePipeTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout WritePipeTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("WritePipeTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32) + * } + */ + public static final AddressLayout WritePipeTO$layout() { + return WritePipeTO$LAYOUT; + } + + private static final long WritePipeTO$OFFSET = 320; + + /** + * Offset for field: + * {@snippet lang=c : + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32) * } */ - public static void WritePipe$set(MemorySegment seg, MemorySegment x) { - constants$32.const$3.set(seg, x); + public static final long WritePipeTO$offset() { + return WritePipeTO$OFFSET; } - public static MemorySegment WritePipe$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$32.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Getter for field: + * {@snippet lang=c : + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32) + * } + */ + public static MemorySegment WritePipeTO(MemorySegment struct) { + return struct.get(WritePipeTO$LAYOUT, WritePipeTO$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * IOReturn (*WritePipeTO)(void *, UInt8, void *, UInt32, UInt32, UInt32) + * } + */ + public static void WritePipeTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(WritePipeTO$LAYOUT, WritePipeTO$OFFSET, fieldValue); } - public static void WritePipe$set(MemorySegment seg, long index, MemorySegment x) { - constants$32.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * {@snippet lang=c : + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) + * } + */ + public static class ReadPipeAsyncTO { + + ReadPipeAsyncTO() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5, MemorySegment _x6, MemorySegment _x7); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ReadPipeAsyncTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ReadPipeAsyncTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5, MemorySegment _x6, MemorySegment _x7) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } - public static WritePipe WritePipe(MemorySegment segment, Arena scope) { - return WritePipe.ofAddress(WritePipe$get(segment), scope); + + private static final AddressLayout ReadPipeAsyncTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ReadPipeAsyncTO")); + + /** + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) + * } + */ + public static final AddressLayout ReadPipeAsyncTO$layout() { + return ReadPipeAsyncTO$LAYOUT; } + + private static final long ReadPipeAsyncTO$OFFSET = 328; + /** - * {@snippet : - * IOReturn (*ReadPipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public interface ReadPipeAsync { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3, java.lang.foreign.MemorySegment _x4, java.lang.foreign.MemorySegment _x5); - static MemorySegment allocate(ReadPipeAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$32.const$5, fi, constants$32.const$4, scope); - } - static ReadPipeAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3, java.lang.foreign.MemorySegment __x4, java.lang.foreign.MemorySegment __x5) -> { - try { - return (int)constants$33.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long ReadPipeAsyncTO$offset() { + return ReadPipeAsyncTO$OFFSET; } - public static VarHandle ReadPipeAsync$VH() { - return constants$33.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ReadPipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public static MemorySegment ReadPipeAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$33.const$1.get(seg); + public static MemorySegment ReadPipeAsyncTO(MemorySegment struct) { + return struct.get(ReadPipeAsyncTO$LAYOUT, ReadPipeAsyncTO$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ReadPipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*ReadPipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public static void ReadPipeAsync$set(MemorySegment seg, MemorySegment x) { - constants$33.const$1.set(seg, x); - } - public static MemorySegment ReadPipeAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$33.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ReadPipeAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$33.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ReadPipeAsync ReadPipeAsync(MemorySegment segment, Arena scope) { - return ReadPipeAsync.ofAddress(ReadPipeAsync$get(segment), scope); + public static void ReadPipeAsyncTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ReadPipeAsyncTO$LAYOUT, ReadPipeAsyncTO$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*WritePipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public interface WritePipeAsync { + public static class WritePipeAsyncTO { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3, java.lang.foreign.MemorySegment _x4, java.lang.foreign.MemorySegment _x5); - static MemorySegment allocate(WritePipeAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$33.const$2, fi, constants$32.const$4, scope); + WritePipeAsyncTO() { + // Should not be called directly } - static WritePipeAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3, java.lang.foreign.MemorySegment __x4, java.lang.foreign.MemorySegment __x5) -> { - try { - return (int)constants$33.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5, MemorySegment _x6, MemorySegment _x7); } - } - public static VarHandle WritePipeAsync$VH() { - return constants$33.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*WritePipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment WritePipeAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$33.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(WritePipeAsyncTO.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(WritePipeAsyncTO.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, MemorySegment _x2, int _x3, int _x4, int _x5, MemorySegment _x6, MemorySegment _x7) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout WritePipeAsyncTO$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("WritePipeAsyncTO")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*WritePipeAsync)(void*,UInt8,void*,UInt32,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public static void WritePipeAsync$set(MemorySegment seg, MemorySegment x) { - constants$33.const$3.set(seg, x); - } - public static MemorySegment WritePipeAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$33.const$3.get(seg.asSlice(index*sizeof())); - } - public static void WritePipeAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$33.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static WritePipeAsync WritePipeAsync(MemorySegment segment, Arena scope) { - return WritePipeAsync.ofAddress(WritePipeAsync$get(segment), scope); + public static final AddressLayout WritePipeAsyncTO$layout() { + return WritePipeAsyncTO$LAYOUT; } + + private static final long WritePipeAsyncTO$OFFSET = 336; + /** - * {@snippet : - * IOReturn (*ReadIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public interface ReadIsochPipeAsync { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, long _x3, int _x4, java.lang.foreign.MemorySegment _x5, java.lang.foreign.MemorySegment _x6, java.lang.foreign.MemorySegment _x7); - static MemorySegment allocate(ReadIsochPipeAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$33.const$5, fi, constants$33.const$4, scope); - } - static ReadIsochPipeAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, long __x3, int __x4, java.lang.foreign.MemorySegment __x5, java.lang.foreign.MemorySegment __x6, java.lang.foreign.MemorySegment __x7) -> { - try { - return (int)constants$34.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6, __x7); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long WritePipeAsyncTO$offset() { + return WritePipeAsyncTO$OFFSET; } - public static VarHandle ReadIsochPipeAsync$VH() { - return constants$34.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ReadIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public static MemorySegment ReadIsochPipeAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$34.const$1.get(seg); + public static MemorySegment WritePipeAsyncTO(MemorySegment struct) { + return struct.get(WritePipeAsyncTO$LAYOUT, WritePipeAsyncTO$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ReadIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*WritePipeAsyncTO)(void *, UInt8, void *, UInt32, UInt32, UInt32, IOAsyncCallback1, void *) * } */ - public static void ReadIsochPipeAsync$set(MemorySegment seg, MemorySegment x) { - constants$34.const$1.set(seg, x); - } - public static MemorySegment ReadIsochPipeAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$34.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ReadIsochPipeAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$34.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ReadIsochPipeAsync ReadIsochPipeAsync(MemorySegment segment, Arena scope) { - return ReadIsochPipeAsync.ofAddress(ReadIsochPipeAsync$get(segment), scope); + public static void WritePipeAsyncTO(MemorySegment struct, MemorySegment fieldValue) { + struct.set(WritePipeAsyncTO$LAYOUT, WritePipeAsyncTO$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*WriteIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *) * } */ - public interface WriteIsochPipeAsync { + public static class USBInterfaceGetStringIndex { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, long _x3, int _x4, java.lang.foreign.MemorySegment _x5, java.lang.foreign.MemorySegment _x6, java.lang.foreign.MemorySegment _x7); - static MemorySegment allocate(WriteIsochPipeAsync fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$34.const$2, fi, constants$33.const$4, scope); + USBInterfaceGetStringIndex() { + // Should not be called directly } - static WriteIsochPipeAsync ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, long __x3, int __x4, java.lang.foreign.MemorySegment __x5, java.lang.foreign.MemorySegment __x6, java.lang.foreign.MemorySegment __x7) -> { - try { - return (int)constants$34.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6, __x7); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle WriteIsochPipeAsync$VH() { - return constants$34.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*WriteIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment WriteIsochPipeAsync$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$34.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBInterfaceGetStringIndex.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBInterfaceGetStringIndex.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBInterfaceGetStringIndex$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBInterfaceGetStringIndex")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*WriteIsochPipeAsync)(void*,UInt8,void*,UInt64,UInt32,IOUSBIsocFrame*,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *) * } */ - public static void WriteIsochPipeAsync$set(MemorySegment seg, MemorySegment x) { - constants$34.const$3.set(seg, x); - } - public static MemorySegment WriteIsochPipeAsync$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$34.const$3.get(seg.asSlice(index*sizeof())); - } - public static void WriteIsochPipeAsync$set(MemorySegment seg, long index, MemorySegment x) { - constants$34.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static WriteIsochPipeAsync WriteIsochPipeAsync(MemorySegment segment, Arena scope) { - return WriteIsochPipeAsync.ofAddress(WriteIsochPipeAsync$get(segment), scope); + public static final AddressLayout USBInterfaceGetStringIndex$layout() { + return USBInterfaceGetStringIndex$LAYOUT; } + + private static final long USBInterfaceGetStringIndex$OFFSET = 344; + /** - * {@snippet : - * IOReturn (*ControlRequestTO)(void*,UInt8,IOUSBDevRequestTO*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *) * } */ - public interface ControlRequestTO { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2); - static MemorySegment allocate(ControlRequestTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$34.const$4, fi, constants$13.const$0, scope); - } - static ControlRequestTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2) -> { - try { - return (int)constants$13.const$2.invokeExact(symbol, __x0, __x1, __x2); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBInterfaceGetStringIndex$offset() { + return USBInterfaceGetStringIndex$OFFSET; } - public static VarHandle ControlRequestTO$VH() { - return constants$34.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ControlRequestTO)(void*,UInt8,IOUSBDevRequestTO*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *) * } */ - public static MemorySegment ControlRequestTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$34.const$5.get(seg); + public static MemorySegment USBInterfaceGetStringIndex(MemorySegment struct) { + return struct.get(USBInterfaceGetStringIndex$LAYOUT, USBInterfaceGetStringIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ControlRequestTO)(void*,UInt8,IOUSBDevRequestTO*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceGetStringIndex)(void *, UInt8 *) * } */ - public static void ControlRequestTO$set(MemorySegment seg, MemorySegment x) { - constants$34.const$5.set(seg, x); - } - public static MemorySegment ControlRequestTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$34.const$5.get(seg.asSlice(index*sizeof())); - } - public static void ControlRequestTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$34.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static ControlRequestTO ControlRequestTO(MemorySegment segment, Arena scope) { - return ControlRequestTO.ofAddress(ControlRequestTO$get(segment), scope); + public static void USBInterfaceGetStringIndex(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBInterfaceGetStringIndex$LAYOUT, USBInterfaceGetStringIndex$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*ControlRequestAsyncTO)(void*,UInt8,IOUSBDevRequestTO*,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpenSeize)(void *) * } */ - public interface ControlRequestAsyncTO { + public static class USBInterfaceOpenSeize { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3, java.lang.foreign.MemorySegment _x4); - static MemorySegment allocate(ControlRequestAsyncTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$35.const$0, fi, constants$28.const$4, scope); + USBInterfaceOpenSeize() { + // Should not be called directly } - static ControlRequestAsyncTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3, java.lang.foreign.MemorySegment __x4) -> { - try { - return (int)constants$29.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0); } - } - public static VarHandle ControlRequestAsyncTO$VH() { - return constants$35.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*ControlRequestAsyncTO)(void*,UInt8,IOUSBDevRequestTO*,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment ControlRequestAsyncTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$35.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(USBInterfaceOpenSeize.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(USBInterfaceOpenSeize.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout USBInterfaceOpenSeize$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("USBInterfaceOpenSeize")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*ControlRequestAsyncTO)(void*,UInt8,IOUSBDevRequestTO*,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpenSeize)(void *) * } */ - public static void ControlRequestAsyncTO$set(MemorySegment seg, MemorySegment x) { - constants$35.const$1.set(seg, x); - } - public static MemorySegment ControlRequestAsyncTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$35.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ControlRequestAsyncTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$35.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ControlRequestAsyncTO ControlRequestAsyncTO(MemorySegment segment, Arena scope) { - return ControlRequestAsyncTO.ofAddress(ControlRequestAsyncTO$get(segment), scope); + public static final AddressLayout USBInterfaceOpenSeize$layout() { + return USBInterfaceOpenSeize$LAYOUT; } + + private static final long USBInterfaceOpenSeize$OFFSET = 352; + /** - * {@snippet : - * IOReturn (*ReadPipeTO)(void*,UInt8,void*,UInt32*,UInt32,UInt32); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpenSeize)(void *) * } */ - public interface ReadPipeTO { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, java.lang.foreign.MemorySegment _x3, int _x4, int _x5); - static MemorySegment allocate(ReadPipeTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$35.const$3, fi, constants$35.const$2, scope); - } - static ReadPipeTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, java.lang.foreign.MemorySegment __x3, int __x4, int __x5) -> { - try { - return (int)constants$35.const$4.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long USBInterfaceOpenSeize$offset() { + return USBInterfaceOpenSeize$OFFSET; } - public static VarHandle ReadPipeTO$VH() { - return constants$35.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ReadPipeTO)(void*,UInt8,void*,UInt32*,UInt32,UInt32); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpenSeize)(void *) * } */ - public static MemorySegment ReadPipeTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$35.const$5.get(seg); + public static MemorySegment USBInterfaceOpenSeize(MemorySegment struct) { + return struct.get(USBInterfaceOpenSeize$LAYOUT, USBInterfaceOpenSeize$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ReadPipeTO)(void*,UInt8,void*,UInt32*,UInt32,UInt32); + * {@snippet lang=c : + * IOReturn (*USBInterfaceOpenSeize)(void *) * } */ - public static void ReadPipeTO$set(MemorySegment seg, MemorySegment x) { - constants$35.const$5.set(seg, x); - } - public static MemorySegment ReadPipeTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$35.const$5.get(seg.asSlice(index*sizeof())); - } - public static void ReadPipeTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$35.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static ReadPipeTO ReadPipeTO(MemorySegment segment, Arena scope) { - return ReadPipeTO.ofAddress(ReadPipeTO$get(segment), scope); + public static void USBInterfaceOpenSeize(MemorySegment struct, MemorySegment fieldValue) { + struct.set(USBInterfaceOpenSeize$LAYOUT, USBInterfaceOpenSeize$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*WritePipeTO)(void*,UInt8,void*,UInt32,UInt32,UInt32); + * {@snippet lang=c : + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8) * } */ - public interface WritePipeTO { + public static class ClearPipeStallBothEnds { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3, int _x4, int _x5); - static MemorySegment allocate(WritePipeTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$36.const$1, fi, constants$36.const$0, scope); + ClearPipeStallBothEnds() { + // Should not be called directly } - static WritePipeTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3, int __x4, int __x5) -> { - try { - return (int)constants$36.const$2.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1); } - } - public static VarHandle WritePipeTO$VH() { - return constants$36.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*WritePipeTO)(void*,UInt8,void*,UInt32,UInt32,UInt32); - * } - */ - public static MemorySegment WritePipeTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$36.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(ClearPipeStallBothEnds.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(ClearPipeStallBothEnds.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout ClearPipeStallBothEnds$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ClearPipeStallBothEnds")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*WritePipeTO)(void*,UInt8,void*,UInt32,UInt32,UInt32); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8) * } */ - public static void WritePipeTO$set(MemorySegment seg, MemorySegment x) { - constants$36.const$3.set(seg, x); - } - public static MemorySegment WritePipeTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$36.const$3.get(seg.asSlice(index*sizeof())); - } - public static void WritePipeTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$36.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static WritePipeTO WritePipeTO(MemorySegment segment, Arena scope) { - return WritePipeTO.ofAddress(WritePipeTO$get(segment), scope); + public static final AddressLayout ClearPipeStallBothEnds$layout() { + return ClearPipeStallBothEnds$LAYOUT; } + + private static final long ClearPipeStallBothEnds$OFFSET = 360; + /** - * {@snippet : - * IOReturn (*ReadPipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8) * } */ - public interface ReadPipeAsyncTO { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3, int _x4, int _x5, java.lang.foreign.MemorySegment _x6, java.lang.foreign.MemorySegment _x7); - static MemorySegment allocate(ReadPipeAsyncTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$36.const$5, fi, constants$36.const$4, scope); - } - static ReadPipeAsyncTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3, int __x4, int __x5, java.lang.foreign.MemorySegment __x6, java.lang.foreign.MemorySegment __x7) -> { - try { - return (int)constants$37.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6, __x7); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long ClearPipeStallBothEnds$offset() { + return ClearPipeStallBothEnds$OFFSET; } - public static VarHandle ReadPipeAsyncTO$VH() { - return constants$37.const$1; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ReadPipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8) * } */ - public static MemorySegment ReadPipeAsyncTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$37.const$1.get(seg); + public static MemorySegment ClearPipeStallBothEnds(MemorySegment struct) { + return struct.get(ClearPipeStallBothEnds$LAYOUT, ClearPipeStallBothEnds$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ReadPipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*ClearPipeStallBothEnds)(void *, UInt8) * } */ - public static void ReadPipeAsyncTO$set(MemorySegment seg, MemorySegment x) { - constants$37.const$1.set(seg, x); - } - public static MemorySegment ReadPipeAsyncTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$37.const$1.get(seg.asSlice(index*sizeof())); - } - public static void ReadPipeAsyncTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$37.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static ReadPipeAsyncTO ReadPipeAsyncTO(MemorySegment segment, Arena scope) { - return ReadPipeAsyncTO.ofAddress(ReadPipeAsyncTO$get(segment), scope); + public static void ClearPipeStallBothEnds(MemorySegment struct, MemorySegment fieldValue) { + struct.set(ClearPipeStallBothEnds$LAYOUT, ClearPipeStallBothEnds$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*WritePipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); + * {@snippet lang=c : + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8) * } */ - public interface WritePipeAsyncTO { + public static class SetPipePolicy { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, java.lang.foreign.MemorySegment _x2, int _x3, int _x4, int _x5, java.lang.foreign.MemorySegment _x6, java.lang.foreign.MemorySegment _x7); - static MemorySegment allocate(WritePipeAsyncTO fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$37.const$2, fi, constants$36.const$4, scope); + SetPipePolicy() { + // Should not be called directly } - static WritePipeAsyncTO ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, java.lang.foreign.MemorySegment __x2, int __x3, int __x4, int __x5, java.lang.foreign.MemorySegment __x6, java.lang.foreign.MemorySegment __x7) -> { - try { - return (int)constants$37.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6, __x7); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, short _x2, byte _x3); } - } - public static VarHandle WritePipeAsyncTO$VH() { - return constants$37.const$3; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*WritePipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); - * } - */ - public static MemorySegment WritePipeAsyncTO$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$37.const$3.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_SHORT, + IOKit.C_CHAR + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(SetPipePolicy.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(SetPipePolicy.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, short _x2, byte _x3) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout SetPipePolicy$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("SetPipePolicy")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*WritePipeAsyncTO)(void*,UInt8,void*,UInt32,UInt32,UInt32,IOAsyncCallback1,void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8) * } */ - public static void WritePipeAsyncTO$set(MemorySegment seg, MemorySegment x) { - constants$37.const$3.set(seg, x); - } - public static MemorySegment WritePipeAsyncTO$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$37.const$3.get(seg.asSlice(index*sizeof())); - } - public static void WritePipeAsyncTO$set(MemorySegment seg, long index, MemorySegment x) { - constants$37.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static WritePipeAsyncTO WritePipeAsyncTO(MemorySegment segment, Arena scope) { - return WritePipeAsyncTO.ofAddress(WritePipeAsyncTO$get(segment), scope); + public static final AddressLayout SetPipePolicy$layout() { + return SetPipePolicy$LAYOUT; } + + private static final long SetPipePolicy$OFFSET = 368; + /** - * {@snippet : - * IOReturn (*USBInterfaceGetStringIndex)(void*,UInt8*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8) * } */ - public interface USBInterfaceGetStringIndex { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(USBInterfaceGetStringIndex fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$37.const$4, fi, constants$6.const$5, scope); - } - static USBInterfaceGetStringIndex ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long SetPipePolicy$offset() { + return SetPipePolicy$OFFSET; } - public static VarHandle USBInterfaceGetStringIndex$VH() { - return constants$37.const$5; - } /** * Getter for field: - * {@snippet : - * IOReturn (*USBInterfaceGetStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8) * } */ - public static MemorySegment USBInterfaceGetStringIndex$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$37.const$5.get(seg); + public static MemorySegment SetPipePolicy(MemorySegment struct) { + return struct.get(SetPipePolicy$LAYOUT, SetPipePolicy$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*USBInterfaceGetStringIndex)(void*,UInt8*); + * {@snippet lang=c : + * IOReturn (*SetPipePolicy)(void *, UInt8, UInt16, UInt8) * } */ - public static void USBInterfaceGetStringIndex$set(MemorySegment seg, MemorySegment x) { - constants$37.const$5.set(seg, x); - } - public static MemorySegment USBInterfaceGetStringIndex$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$37.const$5.get(seg.asSlice(index*sizeof())); - } - public static void USBInterfaceGetStringIndex$set(MemorySegment seg, long index, MemorySegment x) { - constants$37.const$5.set(seg.asSlice(index*sizeof()), x); - } - public static USBInterfaceGetStringIndex USBInterfaceGetStringIndex(MemorySegment segment, Arena scope) { - return USBInterfaceGetStringIndex.ofAddress(USBInterfaceGetStringIndex$get(segment), scope); + public static void SetPipePolicy(MemorySegment struct, MemorySegment fieldValue) { + struct.set(SetPipePolicy$LAYOUT, SetPipePolicy$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*USBInterfaceOpenSeize)(void*); + * {@snippet lang=c : + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *) * } */ - public interface USBInterfaceOpenSeize { + public static class GetBandwidthAvailable { - int apply(java.lang.foreign.MemorySegment _x0); - static MemorySegment allocate(USBInterfaceOpenSeize fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$38.const$0, fi, constants$5.const$5, scope); + GetBandwidthAvailable() { + // Should not be called directly } - static USBInterfaceOpenSeize ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0) -> { - try { - return (int)constants$6.const$1.invokeExact(symbol, __x0); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, MemorySegment _x1); } - } - public static VarHandle USBInterfaceOpenSeize$VH() { - return constants$38.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*USBInterfaceOpenSeize)(void*); - * } - */ - public static MemorySegment USBInterfaceOpenSeize$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$38.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetBandwidthAvailable.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetBandwidthAvailable.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetBandwidthAvailable$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetBandwidthAvailable")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*USBInterfaceOpenSeize)(void*); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *) * } */ - public static void USBInterfaceOpenSeize$set(MemorySegment seg, MemorySegment x) { - constants$38.const$1.set(seg, x); - } - public static MemorySegment USBInterfaceOpenSeize$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$38.const$1.get(seg.asSlice(index*sizeof())); - } - public static void USBInterfaceOpenSeize$set(MemorySegment seg, long index, MemorySegment x) { - constants$38.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static USBInterfaceOpenSeize USBInterfaceOpenSeize(MemorySegment segment, Arena scope) { - return USBInterfaceOpenSeize.ofAddress(USBInterfaceOpenSeize$get(segment), scope); + public static final AddressLayout GetBandwidthAvailable$layout() { + return GetBandwidthAvailable$LAYOUT; } + + private static final long GetBandwidthAvailable$OFFSET = 376; + /** - * {@snippet : - * IOReturn (*ClearPipeStallBothEnds)(void*,UInt8); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *) * } */ - public interface ClearPipeStallBothEnds { - - int apply(java.lang.foreign.MemorySegment _x0, byte _x1); - static MemorySegment allocate(ClearPipeStallBothEnds fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$38.const$2, fi, constants$14.const$0, scope); - } - static ClearPipeStallBothEnds ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1) -> { - try { - return (int)constants$14.const$2.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetBandwidthAvailable$offset() { + return GetBandwidthAvailable$OFFSET; } - public static VarHandle ClearPipeStallBothEnds$VH() { - return constants$38.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*ClearPipeStallBothEnds)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *) * } */ - public static MemorySegment ClearPipeStallBothEnds$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$38.const$3.get(seg); + public static MemorySegment GetBandwidthAvailable(MemorySegment struct) { + return struct.get(GetBandwidthAvailable$LAYOUT, GetBandwidthAvailable$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*ClearPipeStallBothEnds)(void*,UInt8); + * {@snippet lang=c : + * IOReturn (*GetBandwidthAvailable)(void *, UInt32 *) * } */ - public static void ClearPipeStallBothEnds$set(MemorySegment seg, MemorySegment x) { - constants$38.const$3.set(seg, x); - } - public static MemorySegment ClearPipeStallBothEnds$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$38.const$3.get(seg.asSlice(index*sizeof())); - } - public static void ClearPipeStallBothEnds$set(MemorySegment seg, long index, MemorySegment x) { - constants$38.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static ClearPipeStallBothEnds ClearPipeStallBothEnds(MemorySegment segment, Arena scope) { - return ClearPipeStallBothEnds.ofAddress(ClearPipeStallBothEnds$get(segment), scope); + public static void GetBandwidthAvailable(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetBandwidthAvailable$LAYOUT, GetBandwidthAvailable$OFFSET, fieldValue); } + /** - * {@snippet : - * IOReturn (*SetPipePolicy)(void*,UInt8,UInt16,UInt8); + * {@snippet lang=c : + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *) * } */ - public interface SetPipePolicy { + public static class GetEndpointProperties { - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, short _x2, byte _x3); - static MemorySegment allocate(SetPipePolicy fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$38.const$5, fi, constants$38.const$4, scope); + GetEndpointProperties() { + // Should not be called directly } - static SetPipePolicy ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, short __x2, byte __x3) -> { - try { - return (int)constants$39.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, byte _x1, byte _x2, byte _x3, MemorySegment _x4, MemorySegment _x5, MemorySegment _x6); } - } - public static VarHandle SetPipePolicy$VH() { - return constants$39.const$1; - } - /** - * Getter for field: - * {@snippet : - * IOReturn (*SetPipePolicy)(void*,UInt8,UInt16,UInt8); - * } - */ - public static MemorySegment SetPipePolicy$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$39.const$1.get(seg); + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + IOKit.C_INT, + IOKit.C_POINTER, + IOKit.C_CHAR, + IOKit.C_CHAR, + IOKit.C_CHAR, + IOKit.C_POINTER, + IOKit.C_POINTER, + IOKit.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = IOKit.upcallHandle(GetEndpointProperties.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(GetEndpointProperties.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr,MemorySegment _x0, byte _x1, byte _x2, byte _x3, MemorySegment _x4, MemorySegment _x5, MemorySegment _x6) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2, _x3, _x4, _x5, _x6); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } } + + private static final AddressLayout GetEndpointProperties$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("GetEndpointProperties")); + /** - * Setter for field: - * {@snippet : - * IOReturn (*SetPipePolicy)(void*,UInt8,UInt16,UInt8); + * Layout for field: + * {@snippet lang=c : + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *) * } */ - public static void SetPipePolicy$set(MemorySegment seg, MemorySegment x) { - constants$39.const$1.set(seg, x); - } - public static MemorySegment SetPipePolicy$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$39.const$1.get(seg.asSlice(index*sizeof())); - } - public static void SetPipePolicy$set(MemorySegment seg, long index, MemorySegment x) { - constants$39.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static SetPipePolicy SetPipePolicy(MemorySegment segment, Arena scope) { - return SetPipePolicy.ofAddress(SetPipePolicy$get(segment), scope); + public static final AddressLayout GetEndpointProperties$layout() { + return GetEndpointProperties$LAYOUT; } + + private static final long GetEndpointProperties$OFFSET = 384; + /** - * {@snippet : - * IOReturn (*GetBandwidthAvailable)(void*,UInt32*); + * Offset for field: + * {@snippet lang=c : + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *) * } */ - public interface GetBandwidthAvailable { - - int apply(java.lang.foreign.MemorySegment _x0, java.lang.foreign.MemorySegment _x1); - static MemorySegment allocate(GetBandwidthAvailable fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$39.const$2, fi, constants$6.const$5, scope); - } - static GetBandwidthAvailable ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { - try { - return (int)constants$7.const$1.invokeExact(symbol, __x0, __x1); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + public static final long GetEndpointProperties$offset() { + return GetEndpointProperties$OFFSET; } - public static VarHandle GetBandwidthAvailable$VH() { - return constants$39.const$3; - } /** * Getter for field: - * {@snippet : - * IOReturn (*GetBandwidthAvailable)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *) * } */ - public static MemorySegment GetBandwidthAvailable$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$39.const$3.get(seg); + public static MemorySegment GetEndpointProperties(MemorySegment struct) { + return struct.get(GetEndpointProperties$LAYOUT, GetEndpointProperties$OFFSET); } + /** * Setter for field: - * {@snippet : - * IOReturn (*GetBandwidthAvailable)(void*,UInt32*); + * {@snippet lang=c : + * IOReturn (*GetEndpointProperties)(void *, UInt8, UInt8, UInt8, UInt8 *, UInt16 *, UInt8 *) * } */ - public static void GetBandwidthAvailable$set(MemorySegment seg, MemorySegment x) { - constants$39.const$3.set(seg, x); + public static void GetEndpointProperties(MemorySegment struct, MemorySegment fieldValue) { + struct.set(GetEndpointProperties$LAYOUT, GetEndpointProperties$OFFSET, fieldValue); } - public static MemorySegment GetBandwidthAvailable$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$39.const$3.get(seg.asSlice(index*sizeof())); - } - public static void GetBandwidthAvailable$set(MemorySegment seg, long index, MemorySegment x) { - constants$39.const$3.set(seg.asSlice(index*sizeof()), x); - } - public static GetBandwidthAvailable GetBandwidthAvailable(MemorySegment segment, Arena scope) { - return GetBandwidthAvailable.ofAddress(GetBandwidthAvailable$get(segment), scope); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } + /** - * {@snippet : - * IOReturn (*GetEndpointProperties)(void*,UInt8,UInt8,UInt8,UInt8*,UInt16*,UInt8*); - * } + * The size (in bytes) of this struct */ - public interface GetEndpointProperties { + public static long sizeof() { return layout().byteSize(); } - int apply(java.lang.foreign.MemorySegment _x0, byte _x1, byte _x2, byte _x3, java.lang.foreign.MemorySegment _x4, java.lang.foreign.MemorySegment _x5, java.lang.foreign.MemorySegment _x6); - static MemorySegment allocate(GetEndpointProperties fi, Arena scope) { - return RuntimeHelper.upcallStub(constants$39.const$5, fi, constants$39.const$4, scope); - } - static GetEndpointProperties ofAddress(MemorySegment addr, Arena arena) { - MemorySegment symbol = addr.reinterpret(arena, null); - return (java.lang.foreign.MemorySegment __x0, byte __x1, byte __x2, byte __x3, java.lang.foreign.MemorySegment __x4, java.lang.foreign.MemorySegment __x5, java.lang.foreign.MemorySegment __x6) -> { - try { - return (int)constants$40.const$0.invokeExact(symbol, __x0, __x1, __x2, __x3, __x4, __x5, __x6); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - }; - } + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static VarHandle GetEndpointProperties$VH() { - return constants$40.const$1; - } /** - * Getter for field: - * {@snippet : - * IOReturn (*GetEndpointProperties)(void*,UInt8,UInt8,UInt8,UInt8*,UInt16*,UInt8*); - * } + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. */ - public static MemorySegment GetEndpointProperties$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$40.const$1.get(seg); + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } + /** - * Setter for field: - * {@snippet : - * IOReturn (*GetEndpointProperties)(void*,UInt8,UInt8,UInt8,UInt8*,UInt16*,UInt8*); - * } + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} */ - public static void GetEndpointProperties$set(MemorySegment seg, MemorySegment x) { - constants$40.const$1.set(seg, x); - } - public static MemorySegment GetEndpointProperties$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$40.const$1.get(seg.asSlice(index*sizeof())); - } - public static void GetEndpointProperties$set(MemorySegment seg, long index, MemorySegment x) { - constants$40.const$1.set(seg.asSlice(index*sizeof()), x); - } - public static GetEndpointProperties GetEndpointProperties(MemorySegment segment, Arena scope) { - return GetEndpointProperties.ofAddress(GetEndpointProperties$get(segment), scope); + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/RuntimeHelper.java deleted file mode 100644 index 02d7840..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/RuntimeHelper.java +++ /dev/null @@ -1,228 +0,0 @@ -package net.codecrete.usb.macos.gen.iokit; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { -// System.loadLibrary("IOKit.framework"); -// SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SymbolLookup loaderLookup = SymbolLookup.libraryLookup("/System/Library/Frameworks/IOKit.framework/IOKit", Arena.global()); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$0.java deleted file mode 100644 index 0c05b25..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$0.java +++ /dev/null @@ -1,31 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_BYTE.withName("bmRequestType"), - JAVA_BYTE.withName("bRequest"), - JAVA_SHORT.withName("wValue"), - JAVA_SHORT.withName("wIndex"), - JAVA_SHORT.withName("wLength"), - RuntimeHelper.POINTER.withName("pData"), - JAVA_INT.withName("wLenDone"), - MemoryLayout.paddingLayout(4) - ).withName(""); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("bmRequestType")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("bRequest")); - static final VarHandle const$3 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wValue")); - static final VarHandle const$4 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wIndex")); - static final VarHandle const$5 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wLength")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$1.java deleted file mode 100644 index 7f197c6..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$1.java +++ /dev/null @@ -1,27 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_SHORT; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final VarHandle const$0 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("pData")); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("wLenDone")); - static final StructLayout const$2 = MemoryLayout.structLayout( - JAVA_SHORT.withName("bInterfaceClass"), - JAVA_SHORT.withName("bInterfaceSubClass"), - JAVA_SHORT.withName("bInterfaceProtocol"), - JAVA_SHORT.withName("bAlternateSetting") - ).withName(""); - static final VarHandle const$3 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("bInterfaceClass")); - static final VarHandle const$4 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("bInterfaceSubClass")); - static final VarHandle const$5 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("bInterfaceProtocol")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$10.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$10.java deleted file mode 100644 index 4587463..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$10.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$10 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$10() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceProtocol.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceProtocol")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceVendor.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceVendor")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceProduct.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceProduct")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$11.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$11.java deleted file mode 100644 index 9e28e1b..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$11.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$11 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$11() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceReleaseNumber.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceReleaseNumber")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceAddress.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceAddress")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceBusPowerAvailable.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceBusPowerAvailable")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$12.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$12.java deleted file mode 100644 index 13c8d1f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$12.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$12 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$12() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceSpeed.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceSpeed")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetNumberOfConfigurations.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetNumberOfConfigurations")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetLocationID.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetLocationID")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$13.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$13.java deleted file mode 100644 index 39624ca..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$13.java +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$13 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$13() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetConfigurationDescriptorPtr.class, "apply", constants$13.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$13.const$0 - ); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetConfigurationDescriptorPtr")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetConfiguration.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetConfiguration")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$14.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$14.java deleted file mode 100644 index f392ab2..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$14.java +++ /dev/null @@ -1,33 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$14 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$14() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.SetConfiguration.class, "apply", constants$14.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$14.const$0 - ); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("SetConfiguration")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetBusFrameNumber.class, "apply", constants$14.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$15.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$15.java deleted file mode 100644 index 79a39ca..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$15.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$15 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$15() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$14.const$4 - ); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetBusFrameNumber")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.ResetDevice.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("ResetDevice")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.DeviceRequest.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("DeviceRequest")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$16.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$16.java deleted file mode 100644 index 4aaba20..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$16.java +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$16 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$16() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.DeviceRequestAsync.class, "apply", constants$16.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$16.const$0 - ); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("DeviceRequestAsync")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.CreateInterfaceIterator.class, "apply", constants$14.const$4); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("CreateInterfaceIterator")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$17.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$17.java deleted file mode 100644 index 18fbc0e..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$17.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$17 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$17() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceOpenSeize.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceOpenSeize")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.DeviceRequestTO.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("DeviceRequestTO")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.DeviceRequestAsyncTO.class, "apply", constants$16.const$0); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("DeviceRequestAsyncTO")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$18.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$18.java deleted file mode 100644 index c5cc1d2..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$18.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$18 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$18() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceSuspend.class, "apply", constants$14.const$0); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceSuspend")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceAbortPipeZero.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceAbortPipeZero")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBGetManufacturerStringIndex.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBGetManufacturerStringIndex")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$19.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$19.java deleted file mode 100644 index a1df6f7..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$19.java +++ /dev/null @@ -1,26 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$19 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$19() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBGetProductStringIndex.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBGetProductStringIndex")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBGetSerialNumberStringIndex.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBGetSerialNumberStringIndex")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceReEnumerate.class, "apply", constants$19.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$2.java deleted file mode 100644 index 0e4c451..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$2.java +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final VarHandle const$0 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("bAlternateSetting")); - static final VarHandle const$1 = RuntimeHelper.POINTER.varHandle(); - static final MemorySegment const$2 = RuntimeHelper.lookupGlobalVariable("kCFRunLoopDefaultMode", RuntimeHelper.POINTER); - static final VarHandle const$3 = JAVA_INT.varHandle(); - static final MemorySegment const$4 = RuntimeHelper.lookupGlobalVariable("kIOMasterPortDefault", JAVA_INT); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "IONotificationPortCreate", - constants$2.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$20.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$20.java deleted file mode 100644 index a7e481c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$20.java +++ /dev/null @@ -1,73 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$20 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$20() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$19.const$4 - ); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceReEnumerate")); - static final StructLayout const$2 = MemoryLayout.structLayout( - RuntimeHelper.POINTER.withName("_reserved"), - RuntimeHelper.POINTER.withName("QueryInterface"), - RuntimeHelper.POINTER.withName("AddRef"), - RuntimeHelper.POINTER.withName("Release"), - RuntimeHelper.POINTER.withName("CreateInterfaceAsyncEventSource"), - RuntimeHelper.POINTER.withName("GetInterfaceAsyncEventSource"), - RuntimeHelper.POINTER.withName("CreateInterfaceAsyncPort"), - RuntimeHelper.POINTER.withName("GetInterfaceAsyncPort"), - RuntimeHelper.POINTER.withName("USBInterfaceOpen"), - RuntimeHelper.POINTER.withName("USBInterfaceClose"), - RuntimeHelper.POINTER.withName("GetInterfaceClass"), - RuntimeHelper.POINTER.withName("GetInterfaceSubClass"), - RuntimeHelper.POINTER.withName("GetInterfaceProtocol"), - RuntimeHelper.POINTER.withName("GetDeviceVendor"), - RuntimeHelper.POINTER.withName("GetDeviceProduct"), - RuntimeHelper.POINTER.withName("GetDeviceReleaseNumber"), - RuntimeHelper.POINTER.withName("GetConfigurationValue"), - RuntimeHelper.POINTER.withName("GetInterfaceNumber"), - RuntimeHelper.POINTER.withName("GetAlternateSetting"), - RuntimeHelper.POINTER.withName("GetNumEndpoints"), - RuntimeHelper.POINTER.withName("GetLocationID"), - RuntimeHelper.POINTER.withName("GetDevice"), - RuntimeHelper.POINTER.withName("SetAlternateInterface"), - RuntimeHelper.POINTER.withName("GetBusFrameNumber"), - RuntimeHelper.POINTER.withName("ControlRequest"), - RuntimeHelper.POINTER.withName("ControlRequestAsync"), - RuntimeHelper.POINTER.withName("GetPipeProperties"), - RuntimeHelper.POINTER.withName("GetPipeStatus"), - RuntimeHelper.POINTER.withName("AbortPipe"), - RuntimeHelper.POINTER.withName("ResetPipe"), - RuntimeHelper.POINTER.withName("ClearPipeStall"), - RuntimeHelper.POINTER.withName("ReadPipe"), - RuntimeHelper.POINTER.withName("WritePipe"), - RuntimeHelper.POINTER.withName("ReadPipeAsync"), - RuntimeHelper.POINTER.withName("WritePipeAsync"), - RuntimeHelper.POINTER.withName("ReadIsochPipeAsync"), - RuntimeHelper.POINTER.withName("WriteIsochPipeAsync"), - RuntimeHelper.POINTER.withName("ControlRequestTO"), - RuntimeHelper.POINTER.withName("ControlRequestAsyncTO"), - RuntimeHelper.POINTER.withName("ReadPipeTO"), - RuntimeHelper.POINTER.withName("WritePipeTO"), - RuntimeHelper.POINTER.withName("ReadPipeAsyncTO"), - RuntimeHelper.POINTER.withName("WritePipeAsyncTO"), - RuntimeHelper.POINTER.withName("USBInterfaceGetStringIndex"), - RuntimeHelper.POINTER.withName("USBInterfaceOpenSeize"), - RuntimeHelper.POINTER.withName("ClearPipeStallBothEnds"), - RuntimeHelper.POINTER.withName("SetPipePolicy"), - RuntimeHelper.POINTER.withName("GetBandwidthAvailable"), - RuntimeHelper.POINTER.withName("GetEndpointProperties") - ).withName("IOUSBInterfaceStruct190"); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("_reserved")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.QueryInterface.class, "apply", constants$5.const$1); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("QueryInterface")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$21.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$21.java deleted file mode 100644 index 11a65d3..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$21.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$21 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$21() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.AddRef.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("AddRef")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.Release.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("Release")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.CreateInterfaceAsyncEventSource.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("CreateInterfaceAsyncEventSource")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$22.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$22.java deleted file mode 100644 index c7b3433..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$22.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$22 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$22() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceAsyncEventSource.class, "apply", constants$3.const$0); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceAsyncEventSource")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.CreateInterfaceAsyncPort.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("CreateInterfaceAsyncPort")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceAsyncPort.class, "apply", constants$5.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceAsyncPort")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$23.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$23.java deleted file mode 100644 index 51f5726..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$23.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$23 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$23() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.USBInterfaceOpen.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("USBInterfaceOpen")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.USBInterfaceClose.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("USBInterfaceClose")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceClass.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceClass")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$24.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$24.java deleted file mode 100644 index 5f698e5..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$24.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$24 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$24() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceSubClass.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceSubClass")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceProtocol.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceProtocol")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetDeviceVendor.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceVendor")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$25.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$25.java deleted file mode 100644 index ac0ee5f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$25.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$25 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$25() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetDeviceProduct.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceProduct")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetDeviceReleaseNumber.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceReleaseNumber")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetConfigurationValue.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetConfigurationValue")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$26.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$26.java deleted file mode 100644 index 63ae0b5..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$26.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$26 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$26() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetInterfaceNumber.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetInterfaceNumber")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetAlternateSetting.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetAlternateSetting")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetNumEndpoints.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetNumEndpoints")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$27.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$27.java deleted file mode 100644 index 3623d41..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$27.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$27 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$27() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetLocationID.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetLocationID")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetDevice.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetDevice")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.SetAlternateInterface.class, "apply", constants$14.const$0); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("SetAlternateInterface")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$28.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$28.java deleted file mode 100644 index b34eb80..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$28.java +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$28 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$28() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetBusFrameNumber.class, "apply", constants$14.const$4); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetBusFrameNumber")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ControlRequest.class, "apply", constants$13.const$0); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ControlRequest")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ControlRequestAsync.class, "apply", constants$28.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$29.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$29.java deleted file mode 100644 index a546622..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$29.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$29 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$29() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$28.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ControlRequestAsync")); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetPipeProperties.class, "apply", constants$29.const$2); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - constants$29.const$2 - ); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetPipeProperties")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$3.java deleted file mode 100644 index 320ddc7..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$3.java +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$3 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$3() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "IONotificationPortGetRunLoopSource", - constants$3.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - JAVA_INT - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "IOObjectRelease", - constants$3.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "IOIteratorNext", - constants$3.const$2 - ); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "IOServiceAddMatchingNotification", - constants$3.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$30.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$30.java deleted file mode 100644 index ab553ef..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$30.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$30 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$30() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetPipeStatus.class, "apply", constants$14.const$0); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetPipeStatus")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.AbortPipe.class, "apply", constants$14.const$0); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("AbortPipe")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ResetPipe.class, "apply", constants$14.const$0); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ResetPipe")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$31.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$31.java deleted file mode 100644 index ea1c0db..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$31.java +++ /dev/null @@ -1,31 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$31 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$31() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ClearPipeStall.class, "apply", constants$14.const$0); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ClearPipeStall")); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ReadPipe.class, "apply", constants$31.const$2); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - constants$31.const$2 - ); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ReadPipe")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$32.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$32.java deleted file mode 100644 index ee057f9..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$32.java +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$32 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$32() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.WritePipe.class, "apply", constants$32.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$32.const$0 - ); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("WritePipe")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ReadPipeAsync.class, "apply", constants$32.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$33.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$33.java deleted file mode 100644 index ec15012..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$33.java +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$33 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$33() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$32.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ReadPipeAsync")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.WritePipeAsync.class, "apply", constants$32.const$4); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("WritePipeAsync")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_LONG, - JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ReadIsochPipeAsync.class, "apply", constants$33.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$34.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$34.java deleted file mode 100644 index 0dd3c4c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$34.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$34 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$34() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$33.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ReadIsochPipeAsync")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.WriteIsochPipeAsync.class, "apply", constants$33.const$4); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("WriteIsochPipeAsync")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ControlRequestTO.class, "apply", constants$13.const$0); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ControlRequestTO")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$35.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$35.java deleted file mode 100644 index 315b2f7..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$35.java +++ /dev/null @@ -1,33 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$35 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$35() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ControlRequestAsyncTO.class, "apply", constants$28.const$4); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ControlRequestAsyncTO")); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - JAVA_INT, - JAVA_INT - ); - static final MethodHandle const$3 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ReadPipeTO.class, "apply", constants$35.const$2); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - constants$35.const$2 - ); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ReadPipeTO")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$36.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$36.java deleted file mode 100644 index bd7bf06..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$36.java +++ /dev/null @@ -1,42 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$36 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$36() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_INT, - JAVA_INT, - JAVA_INT - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.WritePipeTO.class, "apply", constants$36.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$36.const$0 - ); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("WritePipeTO")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - RuntimeHelper.POINTER, - JAVA_INT, - JAVA_INT, - JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ReadPipeAsyncTO.class, "apply", constants$36.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$37.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$37.java deleted file mode 100644 index 0d52f7d..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$37.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$37 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$37() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$36.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ReadPipeAsyncTO")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.WritePipeAsyncTO.class, "apply", constants$36.const$4); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("WritePipeAsyncTO")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.USBInterfaceGetStringIndex.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("USBInterfaceGetStringIndex")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$38.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$38.java deleted file mode 100644 index ce31931..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$38.java +++ /dev/null @@ -1,28 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$38 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$38() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.USBInterfaceOpenSeize.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("USBInterfaceOpenSeize")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.ClearPipeStallBothEnds.class, "apply", constants$14.const$0); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("ClearPipeStallBothEnds")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - JAVA_SHORT, - JAVA_BYTE - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.SetPipePolicy.class, "apply", constants$38.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$39.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$39.java deleted file mode 100644 index 0aaa0f8..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$39.java +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$39 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$39() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$38.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("SetPipePolicy")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetBandwidthAvailable.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetBandwidthAvailable")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - JAVA_BYTE, - JAVA_BYTE, - JAVA_BYTE, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOUSBInterfaceStruct190.GetEndpointProperties.class, "apply", constants$39.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$4.java deleted file mode 100644 index 2118e4f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$4.java +++ /dev/null @@ -1,79 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$4 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$4() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "IORegistryEntryGetRegistryEntryID", - constants$4.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(RuntimeHelper.POINTER, - JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "IORegistryEntryCreateCFProperty", - constants$4.const$2 - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "IOServiceMatching", - constants$3.const$0 - ); - static final StructLayout const$5 = MemoryLayout.structLayout( - RuntimeHelper.POINTER.withName("_reserved"), - RuntimeHelper.POINTER.withName("QueryInterface"), - RuntimeHelper.POINTER.withName("AddRef"), - RuntimeHelper.POINTER.withName("Release"), - RuntimeHelper.POINTER.withName("CreateDeviceAsyncEventSource"), - RuntimeHelper.POINTER.withName("GetDeviceAsyncEventSource"), - RuntimeHelper.POINTER.withName("CreateDeviceAsyncPort"), - RuntimeHelper.POINTER.withName("GetDeviceAsyncPort"), - RuntimeHelper.POINTER.withName("USBDeviceOpen"), - RuntimeHelper.POINTER.withName("USBDeviceClose"), - RuntimeHelper.POINTER.withName("GetDeviceClass"), - RuntimeHelper.POINTER.withName("GetDeviceSubClass"), - RuntimeHelper.POINTER.withName("GetDeviceProtocol"), - RuntimeHelper.POINTER.withName("GetDeviceVendor"), - RuntimeHelper.POINTER.withName("GetDeviceProduct"), - RuntimeHelper.POINTER.withName("GetDeviceReleaseNumber"), - RuntimeHelper.POINTER.withName("GetDeviceAddress"), - RuntimeHelper.POINTER.withName("GetDeviceBusPowerAvailable"), - RuntimeHelper.POINTER.withName("GetDeviceSpeed"), - RuntimeHelper.POINTER.withName("GetNumberOfConfigurations"), - RuntimeHelper.POINTER.withName("GetLocationID"), - RuntimeHelper.POINTER.withName("GetConfigurationDescriptorPtr"), - RuntimeHelper.POINTER.withName("GetConfiguration"), - RuntimeHelper.POINTER.withName("SetConfiguration"), - RuntimeHelper.POINTER.withName("GetBusFrameNumber"), - RuntimeHelper.POINTER.withName("ResetDevice"), - RuntimeHelper.POINTER.withName("DeviceRequest"), - RuntimeHelper.POINTER.withName("DeviceRequestAsync"), - RuntimeHelper.POINTER.withName("CreateInterfaceIterator"), - RuntimeHelper.POINTER.withName("USBDeviceOpenSeize"), - RuntimeHelper.POINTER.withName("DeviceRequestTO"), - RuntimeHelper.POINTER.withName("DeviceRequestAsyncTO"), - RuntimeHelper.POINTER.withName("USBDeviceSuspend"), - RuntimeHelper.POINTER.withName("USBDeviceAbortPipeZero"), - RuntimeHelper.POINTER.withName("USBGetManufacturerStringIndex"), - RuntimeHelper.POINTER.withName("USBGetProductStringIndex"), - RuntimeHelper.POINTER.withName("USBGetSerialNumberStringIndex"), - RuntimeHelper.POINTER.withName("USBDeviceReEnumerate") - ).withName("IOUSBDeviceStruct187"); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$40.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$40.java deleted file mode 100644 index e5407f3..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$40.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_SHORT; -final class constants$40 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$40() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$39.const$4 - ); - static final VarHandle const$1 = constants$20.const$2.varHandle(MemoryLayout.PathElement.groupElement("GetEndpointProperties")); - static final StructLayout const$2 = MemoryLayout.structLayout( - RuntimeHelper.POINTER.withName("_reserved"), - RuntimeHelper.POINTER.withName("QueryInterface"), - RuntimeHelper.POINTER.withName("AddRef"), - RuntimeHelper.POINTER.withName("Release"), - JAVA_SHORT.withName("version"), - JAVA_SHORT.withName("revision"), - MemoryLayout.paddingLayout(4), - RuntimeHelper.POINTER.withName("Probe"), - RuntimeHelper.POINTER.withName("Start"), - RuntimeHelper.POINTER.withName("Stop") - ).withName("IOCFPlugInInterfaceStruct"); - static final VarHandle const$3 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("_reserved")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.QueryInterface.class, "apply", constants$5.const$1); - static final VarHandle const$5 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("QueryInterface")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$41.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$41.java deleted file mode 100644 index 8b77227..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$41.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$41 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$41() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.AddRef.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("AddRef")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.Release.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("Release")); - static final VarHandle const$4 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("version")); - static final VarHandle const$5 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("revision")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$42.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$42.java deleted file mode 100644 index 4ed42f8..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$42.java +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$42 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$42() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.Probe.class, "apply", constants$42.const$0); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - constants$42.const$0 - ); - static final VarHandle const$3 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("Probe")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$5 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.Start.class, "apply", constants$42.const$4); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$43.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$43.java deleted file mode 100644 index 8ad9cef..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$43.java +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$43 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$43() {} - static final MethodHandle const$0 = RuntimeHelper.downcallHandle( - constants$42.const$4 - ); - static final VarHandle const$1 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("Start")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOCFPlugInInterfaceStruct.Stop.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$40.const$2.varHandle(MemoryLayout.PathElement.groupElement("Stop")); - static final FunctionDescriptor const$4 = FunctionDescriptor.of(JAVA_INT, - JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$5 = RuntimeHelper.downcallHandle( - "IOCreatePlugInInterfaceForService", - constants$43.const$4 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$44.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$44.java deleted file mode 100644 index c074540..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$44.java +++ /dev/null @@ -1,15 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemorySegment; -final class constants$44 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$44() {} - static final MemorySegment const$0 = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("IOServiceFirstMatch"); - static final MemorySegment const$1 = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("IOServiceTerminate"); - static final MemorySegment const$2 = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("IOUSBDevice"); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$5.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$5.java deleted file mode 100644 index b604c1c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$5.java +++ /dev/null @@ -1,49 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$5 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$5() {} - static final VarHandle const$0 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("_reserved")); - static final FunctionDescriptor const$1 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - MemoryLayout.structLayout( - JAVA_BYTE.withName("byte0"), - JAVA_BYTE.withName("byte1"), - JAVA_BYTE.withName("byte2"), - JAVA_BYTE.withName("byte3"), - JAVA_BYTE.withName("byte4"), - JAVA_BYTE.withName("byte5"), - JAVA_BYTE.withName("byte6"), - JAVA_BYTE.withName("byte7"), - JAVA_BYTE.withName("byte8"), - JAVA_BYTE.withName("byte9"), - JAVA_BYTE.withName("byte10"), - JAVA_BYTE.withName("byte11"), - JAVA_BYTE.withName("byte12"), - JAVA_BYTE.withName("byte13"), - JAVA_BYTE.withName("byte14"), - JAVA_BYTE.withName("byte15") - ).withName(""), - RuntimeHelper.POINTER - ); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.QueryInterface.class, "apply", constants$5.const$1); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - constants$5.const$1 - ); - static final VarHandle const$4 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("QueryInterface")); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$6.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$6.java deleted file mode 100644 index eef323d..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$6.java +++ /dev/null @@ -1,28 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$6 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$6() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.AddRef.class, "apply", constants$5.const$5); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - constants$5.const$5 - ); - static final VarHandle const$2 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("AddRef")); - static final MethodHandle const$3 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.Release.class, "apply", constants$5.const$5); - static final VarHandle const$4 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("Release")); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$7.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$7.java deleted file mode 100644 index 5ac5bfc..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$7.java +++ /dev/null @@ -1,24 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$7 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$7() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.CreateDeviceAsyncEventSource.class, "apply", constants$6.const$5); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - constants$6.const$5 - ); - static final VarHandle const$2 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("CreateDeviceAsyncEventSource")); - static final MethodHandle const$3 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceAsyncEventSource.class, "apply", constants$3.const$0); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - constants$3.const$0 - ); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceAsyncEventSource")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$8.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$8.java deleted file mode 100644 index 9793b45..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$8.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$8 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$8() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.CreateDeviceAsyncPort.class, "apply", constants$6.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("CreateDeviceAsyncPort")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceAsyncPort.class, "apply", constants$5.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceAsyncPort")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceOpen.class, "apply", constants$5.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceOpen")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$9.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$9.java deleted file mode 100644 index fccbf56..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/constants$9.java +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.iokit; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; -final class constants$9 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$9() {} - static final MethodHandle const$0 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.USBDeviceClose.class, "apply", constants$5.const$5); - static final VarHandle const$1 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("USBDeviceClose")); - static final MethodHandle const$2 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceClass.class, "apply", constants$6.const$5); - static final VarHandle const$3 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceClass")); - static final MethodHandle const$4 = RuntimeHelper.upcallHandle(IOUSBDeviceStruct187.GetDeviceSubClass.class, "apply", constants$6.const$5); - static final VarHandle const$5 = constants$4.const$5.varHandle(MemoryLayout.PathElement.groupElement("GetDeviceSubClass")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java deleted file mode 100644 index 1f0d63c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.macos.gen.mach; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java deleted file mode 100644 index 433609e..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.macos.gen.mach; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER, - JAVA_INT - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "mach_error_string", - constants$0.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java index b53bd86..6c7ce22 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java @@ -2,37 +2,118 @@ package net.codecrete.usb.macos.gen.mach; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class mach { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfLong C_LONG = JAVA_LONG; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle mach_error_string$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"mach_error_string"); +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class mach { + + mach() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + + private static class mach_error_string { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + mach.C_POINTER, + mach.C_INT + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + mach.findOrThrow("mach_error_string"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *mach_error_string(mach_error_t error_value) + * } + */ + public static FunctionDescriptor mach_error_string$descriptor() { + return mach_error_string.DESC; + } + /** - * {@snippet : - * char* mach_error_string(mach_error_t error_value); + * Downcall method handle for: + * {@snippet lang=c : + * char *mach_error_string(mach_error_t error_value) + * } + */ + public static MethodHandle mach_error_string$handle() { + return mach_error_string.HANDLE; + } + /** + * {@snippet lang=c : + * char *mach_error_string(mach_error_t error_value) * } */ public static MemorySegment mach_error_string(int error_value) { - var mh$ = mach_error_string$MH(); + var mh$ = mach_error_string.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(error_value); + if (TRACE_DOWNCALLS) { + traceDowncall("mach_error_string", error_value); + } + return (MemorySegment)mh$.invokeExact(error_value); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/ConfigurationDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/ConfigurationDescriptor.java index 611e76f..5f65182 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/ConfigurationDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/ConfigurationDescriptor.java @@ -9,9 +9,7 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_SHORT_UNALIGNED; @@ -19,7 +17,7 @@ /** * USB configuration descriptor */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class ConfigurationDescriptor { private final MemorySegment descriptor; @@ -29,31 +27,31 @@ public ConfigurationDescriptor(MemorySegment descriptor) { } public int descriptorType() { - return 0xff & (byte) bDescriptorType$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bDescriptorType$OFFSET); } public int totalLength() { - return 0xffff & (short) wTotalLength$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, wTotalLength$OFFSET); } public int numInterfaces() { - return 0xff & (byte) bNumInterfaces$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bNumInterfaces$OFFSET); } public int configurationValue() { - return 0xff & (byte) bConfigurationValue$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bConfigurationValue$OFFSET); } public int iConfiguration() { - return 0xff & (byte) iConfiguration$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, iConfiguration$OFFSET); } public int attributes() { - return 0xff & (byte) bmAttributes$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bmAttributes$OFFSET); } public int maxPower() { - return 0xff & (byte) bMaxPower$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bMaxPower$OFFSET); } @@ -78,13 +76,13 @@ public int maxPower() { JAVA_BYTE.withName("bMaxPower") ); - private static final VarHandle bDescriptorType$VH = LAYOUT.varHandle(groupElement("bDescriptorType")); - private static final VarHandle wTotalLength$VH = LAYOUT.varHandle(groupElement("wTotalLength")); - private static final VarHandle bNumInterfaces$VH = LAYOUT.varHandle(groupElement("bNumInterfaces")); - private static final VarHandle bConfigurationValue$VH = LAYOUT.varHandle(groupElement("bConfigurationValue")); - private static final VarHandle iConfiguration$VH = LAYOUT.varHandle(groupElement("iConfiguration")); - private static final VarHandle bmAttributes$VH = LAYOUT.varHandle(groupElement("bmAttributes")); - private static final VarHandle bMaxPower$VH = LAYOUT.varHandle(groupElement("bMaxPower")); + private static final long bDescriptorType$OFFSET = 1; + private static final long wTotalLength$OFFSET = 2; + private static final long bNumInterfaces$OFFSET = 4; + private static final long bConfigurationValue$OFFSET = 5; + private static final long iConfiguration$OFFSET = 6; + private static final long bmAttributes$OFFSET = 7; + private static final long bMaxPower$OFFSET = 8; static { assert LAYOUT.byteSize() == 9; diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/DeviceDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/DeviceDescriptor.java index 686e2a1..d122711 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/DeviceDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/DeviceDescriptor.java @@ -9,9 +9,7 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_SHORT_UNALIGNED; @@ -19,7 +17,7 @@ /** * USB device descriptor */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class DeviceDescriptor { private final MemorySegment descriptor; @@ -29,43 +27,43 @@ public DeviceDescriptor(MemorySegment descriptor) { } public int usbVersion() { - return 0xffff & (short) bcdUSB$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, bcdUSB$OFFSET); } public int deviceClass() { - return 0xff & (byte) bDeviceClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bDeviceClass$OFFSET); } public int deviceSubClass() { - return 0xff & (byte) bDeviceSubClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bDeviceSubClass$OFFSET); } public int deviceProtocol() { - return 0xff & (byte) bDeviceProtocol$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bDeviceProtocol$OFFSET); } public int vendorID() { - return 0xffff & (short) idVendor$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, idVendor$OFFSET); } public int productID() { - return 0xffff & (short) idProduct$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, idProduct$OFFSET); } public int deviceVersion() { - return 0xffff & (short) bcdDevice$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, bcdDevice$OFFSET); } public int iManufacturer() { - return 0xffff & (short) iManufacturer$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, iManufacturer$OFFSET); } public int iProduct() { - return 0xffff & (short) iProduct$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, iProduct$OFFSET); } public int iSerialNumber() { - return 0xffff & (short) iSerialNumber$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, iSerialNumber$OFFSET); } // struct USBDeviceDescriptor { @@ -101,16 +99,16 @@ public int iSerialNumber() { JAVA_BYTE.withName("bNumConfigurations") ); - private static final VarHandle bcdUSB$VH = LAYOUT.varHandle(groupElement("bcdUSB")); - private static final VarHandle bDeviceClass$VH = LAYOUT.varHandle(groupElement("bDeviceClass")); - private static final VarHandle bDeviceSubClass$VH = LAYOUT.varHandle(groupElement("bDeviceSubClass")); - private static final VarHandle bDeviceProtocol$VH = LAYOUT.varHandle(groupElement("bDeviceProtocol")); - private static final VarHandle idVendor$VH = LAYOUT.varHandle(groupElement("idVendor")); - private static final VarHandle idProduct$VH = LAYOUT.varHandle(groupElement("idProduct")); - private static final VarHandle bcdDevice$VH = LAYOUT.varHandle(groupElement("bcdDevice")); - private static final VarHandle iManufacturer$VH = LAYOUT.varHandle(groupElement("iManufacturer")); - private static final VarHandle iProduct$VH = LAYOUT.varHandle(groupElement("iProduct")); - private static final VarHandle iSerialNumber$VH = LAYOUT.varHandle(groupElement("iSerialNumber")); + private static final long bcdUSB$OFFSET = 2; + private static final long bDeviceClass$OFFSET = 4; + private static final long bDeviceSubClass$OFFSET = 5; + private static final long bDeviceProtocol$OFFSET = 6; + private static final long idVendor$OFFSET = 8; + private static final long idProduct$OFFSET = 10; + private static final long bcdDevice$OFFSET = 12; + private static final long iManufacturer$OFFSET = 14; + private static final long iProduct$OFFSET = 15; + private static final long iSerialNumber$OFFSET = 16; static { diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/EndpointDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/EndpointDescriptor.java index a6d5516..c45c317 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/EndpointDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/EndpointDescriptor.java @@ -9,9 +9,7 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_SHORT_UNALIGNED; @@ -19,7 +17,7 @@ /** * USB endpoint descriptor */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class EndpointDescriptor { private final MemorySegment descriptor; @@ -33,19 +31,19 @@ public EndpointDescriptor(MemorySegment segment, long offset) { } public int endpointAddress() { - return 0xff & (byte) bEndpointAddress$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bEndpointAddress$OFFSET); } public int attributes() { - return 0xff & (byte) bmAttributes$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bmAttributes$OFFSET); } public int maxPacketSize() { - return 0xffff & (short) wMaxPacketSize$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT_UNALIGNED, wMaxPacketSize$OFFSET); } public int interval() { - return 0xff & (byte) bInterval$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterval$OFFSET); } // struct USBEndpointDescriptor { @@ -65,10 +63,10 @@ public int interval() { JAVA_BYTE.withName("bInterval") ); - private static final VarHandle bEndpointAddress$VH = LAYOUT.varHandle(groupElement("bEndpointAddress")); - private static final VarHandle bmAttributes$VH = LAYOUT.varHandle(groupElement("bmAttributes")); - private static final VarHandle wMaxPacketSize$VH = LAYOUT.varHandle(groupElement("wMaxPacketSize")); - private static final VarHandle bInterval$VH = LAYOUT.varHandle(groupElement("bInterval")); + private static final long bEndpointAddress$OFFSET = 2; + private static final long bmAttributes$OFFSET = 3; + private static final long wMaxPacketSize$OFFSET = 4; + private static final long bInterval$OFFSET = 6; static { assert LAYOUT.byteSize() == 7; diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceAssociationDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceAssociationDescriptor.java index e5f343f..b2b1435 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceAssociationDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceAssociationDescriptor.java @@ -9,16 +9,14 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; /** * USB interface association descriptor (IAD) */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class InterfaceAssociationDescriptor { private final MemorySegment descriptor; @@ -32,27 +30,27 @@ public InterfaceAssociationDescriptor(MemorySegment segment, long offset) { } public int firstInterface() { - return 0xff & (byte) bFirstInterface$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bFirstInterface$OFFSET); } public int interfaceCount() { - return 0xff & (byte) bInterfaceCount$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterfaceCount$OFFSET); } public int functionClass() { - return 0xff & (byte) bFunctionClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bFunctionClass$OFFSET); } public int functionSubClass() { - return 0xff & (byte) bFunctionSubClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bFunctionSubClass$OFFSET); } public int functionProtocol() { - return 0xff & (byte) bFunctionProtocol$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bFunctionProtocol$OFFSET); } public int function() { - return 0xff & (byte) iFunction$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, iFunction$OFFSET); } // struct USBInterfaceAssociationDescriptor { @@ -76,12 +74,12 @@ public int function() { JAVA_BYTE.withName("iFunction") ); - private static final VarHandle bFirstInterface$VH = LAYOUT.varHandle(groupElement("bFirstInterface")); - private static final VarHandle bInterfaceCount$VH = LAYOUT.varHandle(groupElement("bInterfaceCount")); - private static final VarHandle bFunctionClass$VH = LAYOUT.varHandle(groupElement("bFunctionClass")); - private static final VarHandle bFunctionSubClass$VH = LAYOUT.varHandle(groupElement("bFunctionSubClass")); - private static final VarHandle bFunctionProtocol$VH = LAYOUT.varHandle(groupElement("bFunctionProtocol")); - private static final VarHandle iFunction$VH = LAYOUT.varHandle(groupElement("iFunction")); + private static final long bFirstInterface$OFFSET = 2; + private static final long bInterfaceCount$OFFSET = 3; + private static final long bFunctionClass$OFFSET = 4; + private static final long bFunctionSubClass$OFFSET = 5; + private static final long bFunctionProtocol$OFFSET = 6; + private static final long iFunction$OFFSET = 7; static { assert LAYOUT.byteSize() == 8; diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceDescriptor.java index faf0032..2735167 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/InterfaceDescriptor.java @@ -9,16 +9,14 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; /** * USB interface descriptor */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class InterfaceDescriptor { private final MemorySegment descriptor; @@ -32,31 +30,31 @@ public InterfaceDescriptor(MemorySegment segment, long offset) { } public int interfaceNumber() { - return 0xff & (byte) bInterfaceNumber$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterfaceNumber$OFFSET); } public int alternateSetting() { - return 0xff & (byte) bAlternateSetting$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bAlternateSetting$OFFSET); } public int numEndpoints() { - return 0xff & (byte) bNumEndpoints$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bNumEndpoints$OFFSET); } public int interfaceClass() { - return 0xff & (byte) bInterfaceClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterfaceClass$OFFSET); } public int interfaceSubClass() { - return 0xff & (byte) bInterfaceSubClass$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterfaceSubClass$OFFSET); } public int interfaceProtocol() { - return 0xff & (byte) bInterfaceProtocol$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bInterfaceProtocol$OFFSET); } public int iInterface() { - return 0xff & (byte) iInterface$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, iInterface$OFFSET); } // struct USBInterfaceDescriptor { @@ -82,13 +80,13 @@ public int iInterface() { JAVA_BYTE.withName("iInterface") ); - private static final VarHandle bInterfaceNumber$VH = LAYOUT.varHandle(groupElement("bInterfaceNumber")); - private static final VarHandle bAlternateSetting$VH = LAYOUT.varHandle(groupElement("bAlternateSetting")); - private static final VarHandle bNumEndpoints$VH = LAYOUT.varHandle(groupElement("bNumEndpoints")); - private static final VarHandle bInterfaceClass$VH = LAYOUT.varHandle(groupElement("bInterfaceClass")); - private static final VarHandle bInterfaceSubClass$VH = LAYOUT.varHandle(groupElement("bInterfaceSubClass")); - private static final VarHandle bInterfaceProtocol$VH = LAYOUT.varHandle(groupElement("bInterfaceProtocol")); - private static final VarHandle iInterface$VH = LAYOUT.varHandle(groupElement("iInterface")); + private static final long bInterfaceNumber$OFFSET = 2; + private static final long bAlternateSetting$OFFSET = 3; + private static final long bNumEndpoints$OFFSET = 4; + private static final long bInterfaceClass$OFFSET = 5; + private static final long bInterfaceSubClass$OFFSET = 6; + private static final long bInterfaceProtocol$OFFSET = 7; + private static final long iInterface$OFFSET = 8; static { diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/SetupPacket.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/SetupPacket.java index c934631..e907d42 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/SetupPacket.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/SetupPacket.java @@ -3,9 +3,7 @@ import java.lang.foreign.Arena; import java.lang.foreign.GroupLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_SHORT; @@ -13,7 +11,7 @@ /** * USB setup packet. */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class SetupPacket { private final MemorySegment descriptor; @@ -46,43 +44,43 @@ public MemorySegment segment() { } public int requestType() { - return 0xff & (byte) bmRequestType$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bmRequestType$OFFSET); } public void setRequestType(int requestType) { - bmRequestType$VH.set(descriptor, (byte) requestType); + descriptor.set(JAVA_BYTE, bmRequestType$OFFSET, (byte) requestType); } public int request() { - return 0xff & (byte) bRequest$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bRequest$OFFSET); } public void setRequest(int request) { - bRequest$VH.set(descriptor, (byte) request); + descriptor.set(JAVA_BYTE, bRequest$OFFSET, (byte) request); } public int value() { - return 0xffff & (short) wValue$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT, wValue$OFFSET); } public void setValue(int value) { - wValue$VH.set(descriptor, (short) value); + descriptor.set(JAVA_SHORT, wValue$OFFSET, (short) value); } public int index() { - return 0xffff & (short) wIndex$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT, wIndex$OFFSET); } public void setIndex(int index) { - wIndex$VH.set(descriptor, (short) index); + descriptor.set(JAVA_SHORT, wIndex$OFFSET, (short) index); } public int length() { - return 0xffff & (short) wLength$VH.get(descriptor); + return 0xffff & descriptor.get(JAVA_SHORT, wLength$OFFSET); } public void setLength(int length) { - wLength$VH.set(descriptor, (short) length); + descriptor.set(JAVA_SHORT, wLength$OFFSET, (short) length); } // struct USBSetupPacket { @@ -100,11 +98,11 @@ public void setLength(int length) { JAVA_SHORT.withName("wLength") ); - private static final VarHandle bmRequestType$VH = LAYOUT.varHandle(groupElement("bmRequestType")); - private static final VarHandle bRequest$VH = LAYOUT.varHandle(groupElement("bRequest")); - private static final VarHandle wValue$VH = LAYOUT.varHandle(groupElement("wValue")); - private static final VarHandle wIndex$VH = LAYOUT.varHandle(groupElement("wIndex")); - private static final VarHandle wLength$VH = LAYOUT.varHandle(groupElement("wLength")); + private static final long bmRequestType$OFFSET = 0; + private static final long bRequest$OFFSET = 1; + private static final long wValue$OFFSET = 2; + private static final long wIndex$OFFSET = 4; + private static final long wLength$OFFSET = 6; static { assert LAYOUT.byteSize() == 8; diff --git a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/StringDescriptor.java b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/StringDescriptor.java index 4863045..6cd245a 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/StringDescriptor.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/usbstandard/StringDescriptor.java @@ -10,15 +10,15 @@ import java.lang.foreign.GroupLayout; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; -import java.lang.invoke.VarHandle; -import static java.lang.foreign.MemoryLayout.PathElement.groupElement; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_CHAR; +import static java.lang.foreign.ValueLayout.JAVA_SHORT; /** * USB string descriptor */ -@SuppressWarnings("java:S125") +@SuppressWarnings({"java:S115", "java:S125"}) public class StringDescriptor { private final MemorySegment descriptor; @@ -28,11 +28,11 @@ public StringDescriptor(MemorySegment descriptor) { } public int length() { - return 0xff & (byte) bLength$VH.get(descriptor); + return 0xff & descriptor.get(JAVA_BYTE, bLength$OFFSET); } public String string() { - var chars = descriptor.asSlice(string$offset, length() - 2L).toArray(JAVA_CHAR); + var chars = descriptor.asSlice(string$OFFSET, length() - 2L).toArray(JAVA_CHAR); return new String(chars); } @@ -47,6 +47,6 @@ public String string() { JAVA_SHORT.withName("string") ); - private static final VarHandle bLength$VH = LAYOUT.varHandle(groupElement("bLength")); - private static final long string$offset = LAYOUT.byteOffset(groupElement("string")); // NOSONAR + private static final long bLength$OFFSET = 0; + private static final long string$OFFSET = 2; } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceInfoSet.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceInfoSet.java index fbb62ab..344753c 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceInfoSet.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceInfoSet.java @@ -126,7 +126,7 @@ private DeviceInfoSet(InfoSetCreator creator) { // allocate SP_DEVINFO_DATA (will receive device details) devInfoData = _SP_DEVINFO_DATA.allocate(arena); - _SP_DEVINFO_DATA.cbSize$set(devInfoData, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize()); + _SP_DEVINFO_DATA.cbSize(devInfoData, (int) _SP_DEVINFO_DATA.layout().byteSize()); } catch (Exception e) { arena.close(); @@ -154,7 +154,7 @@ private void addDevicePath(String devicePath) { // load device information into dev info set var intfData = _SP_DEVICE_INTERFACE_DATA.allocate(arena); - _SP_DEVICE_INTERFACE_DATA.cbSize$set(intfData, (int) intfData.byteSize()); + _SP_DEVICE_INTERFACE_DATA.cbSize(intfData, (int) intfData.byteSize()); var devicePathSegment = Win.createSegmentFromString(devicePath, arena); if (SetupAPI2.SetupDiOpenDeviceInterfaceW(devInfoSet, devicePathSegment, 0, intfData, errorState) == 0) throwLastError(errorState, "internal error (SetupDiOpenDeviceInterfaceW)"); @@ -334,7 +334,7 @@ private MemorySegment getVariableLengthProperty(MemorySegment propertyKey, int p var stringLen = (requiredSizeHolder.get(JAVA_INT, 0) + 1) / 2; // allocate buffer - var propertyValueHolder = arena.allocateArray(JAVA_CHAR, stringLen); + var propertyValueHolder = arena.allocate(JAVA_CHAR, stringLen); // get property value if (SetupAPI2.SetupDiGetDevicePropertyW(devInfoSet, devInfoData, propertyKey, propertyTypeHolder, @@ -360,7 +360,7 @@ static String getDevicePath(String instanceId, MemorySegment interfaceGuid) { private String getDevicePathForGuid(MemorySegment interfaceGuid) { // retrieve first element of enumeration devIntfData = _SP_DEVICE_INTERFACE_DATA.allocate(arena); - _SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize()); + _SP_DEVICE_INTERFACE_DATA.cbSize(devIntfData, (int) devIntfData.byteSize()); if (SetupAPI2.SetupDiEnumDeviceInterfaces(devInfoSet, NULL, interfaceGuid, 0, devIntfData, errorState) == 0) throwLastError(errorState, "internal error (SetupDiEnumDeviceInterfaces)"); @@ -370,7 +370,7 @@ private String getDevicePathForGuid(MemorySegment interfaceGuid) { // the device path fits) final var devicePathOffset = 4; var intfDetailData = arena.allocate(4L + 260 * 2); - _SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$set(intfDetailData, + _SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize(intfDetailData, (int) _SP_DEVICE_INTERFACE_DETAIL_DATA_W.sizeof()); if (SetupAPI2.SetupDiGetDeviceInterfaceDetailW(devInfoSet, devIntfData, intfDetailData, (int) intfDetailData.byteSize(), NULL, NULL, errorState) == 0) diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/DevicePropertyKey.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/DevicePropertyKey.java index 72b9750..18ff46e 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/DevicePropertyKey.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/DevicePropertyKey.java @@ -68,10 +68,10 @@ private static MemorySegment createDEVPROPKEY(int data1, short data2, short data byte data4_2, byte data4_3, byte data4_4, byte data4_5, byte data4_6, byte data4_7, int pid) { @SuppressWarnings("resource") - var propKey = Arena.global().allocate(_DEVPROPKEY.$LAYOUT()); - Win.setGUID(_DEVPROPKEY.fmtid$slice(propKey), data1, data2, data3, data4_0, data4_1, data4_2, data4_3, data4_4 + var propKey = Arena.global().allocate(_DEVPROPKEY.layout()); + Win.setGUID(_DEVPROPKEY.fmtid(propKey), data1, data2, data3, data4_0, data4_1, data4_2, data4_3, data4_4 , data4_5, data4_6, data4_7); - _DEVPROPKEY.pid$set(propKey, pid); + _DEVPROPKEY.pid(propKey, pid); return propKey; } } diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java index 1bea7e6..59b64f8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java @@ -9,8 +9,12 @@ import net.codecrete.usb.windows.gen.kernel32._GUID; -import java.lang.foreign.*; +import java.lang.foreign.Arena; +import java.lang.foreign.Linker; import java.lang.foreign.MemoryLayout.PathElement; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.StructLayout; +import java.lang.foreign.ValueLayout; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.List; @@ -45,7 +49,7 @@ static MemorySegment allocateErrorState(Arena arena) { * @return the error code */ public static int getLastError(MemorySegment callState) { - return (int) callState_GetLastError$VH.get(callState); + return (int) callState_GetLastError$VH.get(callState, 0); } /** @@ -70,7 +74,7 @@ public static boolean isInvalidHandle(MemorySegment handle) { */ public static MemorySegment createSegmentFromString(String str, Arena arena) { // allocate segment (including space for terminating null) - var segment = arena.allocateArray(ValueLayout.JAVA_CHAR, str.length() + 1L); + var segment = arena.allocate(ValueLayout.JAVA_CHAR, str.length() + 1L); // copy characters segment.copyFrom(MemorySegment.ofArray(str.toCharArray())); return segment; @@ -131,12 +135,11 @@ public static List createStringListFromSegment(MemorySegment segment) { * @param data4_7 Byte 7 of group 4 * @return GUID as memory segment */ - @SuppressWarnings({"java:S117", "java:S107"}) + @SuppressWarnings({"java:S117", "java:S107", "resource"}) public static MemorySegment createGUID(int data1, short data2, short data3, byte data4_0, byte data4_1, byte data4_2, byte data4_3, byte data4_4, byte data4_5, byte data4_6, byte data4_7) { - @SuppressWarnings("resource") - var guid = Arena.global().allocate(_GUID.$LAYOUT()); + var guid = Arena.global().allocate(_GUID.layout()); setGUID(guid, data1, data2, data3, data4_0, data4_1, data4_2, data4_3, data4_4, data4_5, data4_6, data4_7); return guid; } @@ -144,10 +147,10 @@ public static MemorySegment createGUID(int data1, short data2, short data3, byte @SuppressWarnings({"java:S117", "java:S107"}) public static void setGUID(MemorySegment guid, int data1, short data2, short data3, byte data4_0, byte data4_1, byte data4_2, byte data4_3, byte data4_4, byte data4_5, byte data4_6, byte data4_7) { - _GUID.Data1$set(guid, data1); - _GUID.Data2$set(guid, data2); - _GUID.Data3$set(guid, data3); - var data4 = _GUID.Data4$slice(guid); + _GUID.Data1(guid, data1); + _GUID.Data2(guid, data2); + _GUID.Data3(guid, data3); + var data4 = _GUID.Data4(guid); data4.set(JAVA_BYTE, 0, data4_0); data4.set(JAVA_BYTE, 1, data4_1); data4.set(JAVA_BYTE, 2, data4_2); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsAsyncTask.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsAsyncTask.java index afc66e3..8150b78 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsAsyncTask.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsAsyncTask.java @@ -19,7 +19,9 @@ import java.util.Map; import static java.lang.foreign.MemorySegment.NULL; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; import static net.codecrete.usb.windows.Win.allocateErrorState; import static net.codecrete.usb.windows.WindowsUsbException.throwLastError; @@ -66,9 +68,9 @@ private void asyncCompletionTask() { try (var arena = Arena.ofConfined()) { - var overlappedHolder = arena.allocate(ADDRESS, NULL); - var numBytesHolder = arena.allocate(JAVA_INT, 0); - var completionKeyHolder = arena.allocate(JAVA_LONG, 0); + var overlappedHolder = arena.allocate(ADDRESS); + var numBytesHolder = arena.allocate(JAVA_INT); + var completionKeyHolder = arena.allocate(JAVA_LONG); var errorState = allocateErrorState(arena); while (true) { @@ -156,8 +158,8 @@ private synchronized void completeTransfer(long overlappedAddr) { if (transfer == null) return; - transfer.setResultCode((int) _OVERLAPPED.Internal$get(transfer.overlapped())); - transfer.setResultSize((int) _OVERLAPPED.InternalHigh$get(transfer.overlapped())); + transfer.setResultCode((int) _OVERLAPPED.Internal(transfer.overlapped())); + transfer.setResultSize((int) _OVERLAPPED.InternalHigh(transfer.overlapped())); availableOverlappedStructs.add(transfer.overlapped()); transfer.setOverlapped(null); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDevice.java index 28dce23..c1f3986 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDevice.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDevice.java @@ -7,7 +7,11 @@ package net.codecrete.usb.windows; -import net.codecrete.usb.*; +import net.codecrete.usb.UsbControlTransfer; +import net.codecrete.usb.UsbDirection; +import net.codecrete.usb.UsbException; +import net.codecrete.usb.UsbRecipient; +import net.codecrete.usb.UsbTransferType; import net.codecrete.usb.common.Transfer; import net.codecrete.usb.common.UsbDeviceImpl; import net.codecrete.usb.usbstandard.SetupPacket; @@ -29,7 +33,9 @@ import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.INFO; import static java.lang.foreign.MemorySegment.NULL; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_INT; import static net.codecrete.usb.common.ForeignMemory.dereference; import static net.codecrete.usb.windows.DevicePropertyKey.Children; import static net.codecrete.usb.windows.DevicePropertyKey.HardwareIds; @@ -412,12 +418,13 @@ synchronized void configureForAsyncIo(UsbDirection direction, int endpointNumber try (var arena = Arena.ofConfined()) { var errorState = allocateErrorState(arena); - var timeoutHolder = arena.allocate(JAVA_INT, 0); + var timeoutHolder = arena.allocate(JAVA_INT); if (WinUSB2.WinUsb_SetPipePolicy(intfHandle.winusbHandle, endpoint.endpointAddress(), WinUSB.PIPE_TRANSFER_TIMEOUT(), (int) timeoutHolder.byteSize(), timeoutHolder, errorState) == 0) throwLastError(errorState, "setting timeout failed"); - var rawIoHolder = arena.allocate(JAVA_BYTE, (byte) 1); + var rawIoHolder = arena.allocate(JAVA_BYTE); + rawIoHolder.setAtIndex(JAVA_BYTE, 0, (byte) 1); if (WinUSB2.WinUsb_SetPipePolicy(intfHandle.winusbHandle, endpoint.endpointAddress(), WinUSB.RAW_IO(), (int) rawIoHolder.byteSize(), rawIoHolder, errorState) == 0) throwLastError(errorState, "setting raw IO failed"); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDeviceRegistry.java index f8e5ba6..b699812 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDeviceRegistry.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUsbDeviceRegistry.java @@ -20,7 +20,11 @@ import net.codecrete.usb.windows.gen.usbioctl.USBIoctl; import net.codecrete.usb.windows.gen.usbioctl._USB_DESCRIPTOR_REQUEST; import net.codecrete.usb.windows.gen.usbioctl._USB_NODE_CONNECTION_INFORMATION_EX; -import net.codecrete.usb.windows.gen.user32.*; +import net.codecrete.usb.windows.gen.user32.User32; +import net.codecrete.usb.windows.gen.user32._DEV_BROADCAST_DEVICEINTERFACE_W; +import net.codecrete.usb.windows.gen.user32._DEV_BROADCAST_HDR; +import net.codecrete.usb.windows.gen.user32.tagMSG; +import net.codecrete.usb.windows.gen.user32.tagWNDCLASSEXW; import net.codecrete.usb.windows.winsdk.Kernel32B; import net.codecrete.usb.windows.winsdk.User32B; @@ -30,13 +34,23 @@ import java.lang.foreign.MemorySegment; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import static java.lang.System.Logger.Level.INFO; import static java.lang.foreign.MemorySegment.NULL; -import static java.lang.foreign.ValueLayout.*; -import static net.codecrete.usb.usbstandard.Constants.*; -import static net.codecrete.usb.windows.DevicePropertyKey.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; +import static java.lang.foreign.ValueLayout.PathElement; +import static net.codecrete.usb.usbstandard.Constants.CONFIGURATION_DESCRIPTOR_TYPE; +import static net.codecrete.usb.usbstandard.Constants.DEFAULT_LANGUAGE; +import static net.codecrete.usb.usbstandard.Constants.STRING_DESCRIPTOR_TYPE; +import static net.codecrete.usb.windows.DevicePropertyKey.Address; +import static net.codecrete.usb.windows.DevicePropertyKey.InstanceId; +import static net.codecrete.usb.windows.DevicePropertyKey.Parent; import static net.codecrete.usb.windows.UsbConstants.GUID_DEVINTERFACE_USB_DEVICE; import static net.codecrete.usb.windows.UsbConstants.GUID_DEVINTERFACE_USB_HUB; import static net.codecrete.usb.windows.Win.allocateErrorState; @@ -56,7 +70,7 @@ public class WindowsUsbDeviceRegistry extends UsbDeviceRegistry { private static final System.Logger LOG = System.getLogger(WindowsUsbDeviceRegistry.class.getName()); private static final long REQUEST_DATA_OFFSET - = _USB_DESCRIPTOR_REQUEST.$LAYOUT().byteOffset(PathElement.groupElement("Data")); + = _USB_DESCRIPTOR_REQUEST.layout().byteOffset(PathElement.groupElement("Data")); @Override protected void monitorDevices() { @@ -79,10 +93,10 @@ protected void monitorDevices() { // register window class var wx = tagWNDCLASSEXW.allocate(arena); - tagWNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize()); - tagWNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub); - tagWNDCLASSEXW.hInstance$set(wx, instance); - tagWNDCLASSEXW.lpszClassName$set(wx, className); + tagWNDCLASSEXW.cbSize(wx, (int) wx.byteSize()); + tagWNDCLASSEXW.lpfnWndProc(wx, handleWindowMessageStub); + tagWNDCLASSEXW.hInstance(wx, instance); + tagWNDCLASSEXW.lpszClassName(wx, className); var atom = User32B.RegisterClassExW(wx, errorState); if (atom == 0) throwLastError(errorState, "internal error (RegisterClassExW)"); @@ -95,10 +109,10 @@ protected void monitorDevices() { // configure notifications var notificationFilter = _DEV_BROADCAST_DEVICEINTERFACE_W.allocate(arena); - _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize()); - _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, + _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size(notificationFilter, (int) notificationFilter.byteSize()); + _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE()); - _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(GUID_DEVINTERFACE_USB_DEVICE); + _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid(notificationFilter).copyFrom(GUID_DEVINTERFACE_USB_DEVICE); var notifyHandle = User32B.RegisterDeviceNotificationW(hwnd, notificationFilter, User32.DEVICE_NOTIFY_WINDOW_HANDLE(), errorState); @@ -192,7 +206,7 @@ private UsbDevice createDevice(String devicePath, boolean isComposite, MemorySeg // get device descriptor var connInfo = _USB_NODE_CONNECTION_INFORMATION_EX.allocate(arena); - _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$set(connInfo, usbPortNum); + _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex(connInfo, usbPortNum); var sizeHolder = arena.allocate(JAVA_INT); var errorState = allocateErrorState(arena); if (Kernel32B.DeviceIoControl(hubHandle, USBIoctl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX(), @@ -200,7 +214,7 @@ private UsbDevice createDevice(String devicePath, boolean isComposite, MemorySeg errorState) == 0) throwLastError(errorState, "internal error (getting device descriptor failed)"); - var descriptorSegment = _USB_NODE_CONNECTION_INFORMATION_EX.DeviceDescriptor$slice(connInfo); + var descriptorSegment = _USB_NODE_CONNECTION_INFORMATION_EX.DeviceDescriptor(connInfo); var deviceDescriptor = new DeviceDescriptor(descriptorSegment); var vendorId = deviceDescriptor.vendorID(); @@ -229,8 +243,8 @@ private MemorySegment getDescriptor(MemorySegment hubHandle, int usbPortNumber, // create descriptor requests var descriptorRequest = arena.allocate(size); - _USB_DESCRIPTOR_REQUEST.ConnectionIndex$set(descriptorRequest, usbPortNumber); - var setupPacket = new SetupPacket(_USB_DESCRIPTOR_REQUEST.SetupPacket$slice(descriptorRequest)); + _USB_DESCRIPTOR_REQUEST.ConnectionIndex(descriptorRequest, usbPortNumber); + var setupPacket = new SetupPacket(_USB_DESCRIPTOR_REQUEST.SetupPacket(descriptorRequest)); setupPacket.setRequestType(0x80); // device-to-host / type standard / recipient device setupPacket.setRequest(UsbConstants.USB_REQUEST_GET_DESCRIPTOR); setupPacket.setValue((descriptorType << 8) | index); @@ -288,11 +302,11 @@ private long handleWindowMessage(MemorySegment hWnd, int uMsg, long wParam, long // check for message related to connecting/disconnecting devices if (uMsg == User32.WM_DEVICECHANGE() && (wParam == User32.DBT_DEVICEARRIVAL() || wParam == User32.DBT_DEVICEREMOVECOMPLETE())) { var data = MemorySegment.ofAddress(lParam).reinterpret(_DEV_BROADCAST_DEVICEINTERFACE_W.sizeof()); - if (_DEV_BROADCAST_HDR.dbch_devicetype$get(data) == User32.DBT_DEVTYP_DEVICEINTERFACE()) { + if (_DEV_BROADCAST_HDR.dbch_devicetype(data) == User32.DBT_DEVTYP_DEVICEINTERFACE()) { // get device path var nameSlice = - MemorySegment.ofAddress(_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_name$slice(data).address()).reinterpret(500); + MemorySegment.ofAddress(_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_name(data).address()).reinterpret(500); var devicePath = Win.createStringFromSegment(nameSlice); if (wParam == User32.DBT_DEVICEARRIVAL()) onDeviceConnected(devicePath); diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/Advapi32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/Advapi32.java index 6152d8c..aa61da8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/Advapi32.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/Advapi32.java @@ -2,61 +2,181 @@ package net.codecrete.usb.windows.gen.advapi32; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class Advapi32 { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle RegCloseKey$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"RegCloseKey"); +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class Advapi32 { + + Advapi32() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("Advapi32"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + + private static class RegCloseKey { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Advapi32.C_LONG, + Advapi32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Advapi32.findOrThrow("RegCloseKey"), + DESC); + } + /** - * {@snippet : - * LSTATUS RegCloseKey(HKEY hKey); + * Function descriptor for: + * {@snippet lang=c : + * LSTATUS RegCloseKey(HKEY hKey) + * } + */ + public static FunctionDescriptor RegCloseKey$descriptor() { + return RegCloseKey.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * LSTATUS RegCloseKey(HKEY hKey) + * } + */ + public static MethodHandle RegCloseKey$handle() { + return RegCloseKey.HANDLE; + } + /** + * {@snippet lang=c : + * LSTATUS RegCloseKey(HKEY hKey) * } */ public static int RegCloseKey(MemorySegment hKey) { - var mh$ = RegCloseKey$MH(); + var mh$ = RegCloseKey.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("RegCloseKey", hKey); + } return (int)mh$.invokeExact(hKey); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle RegQueryValueExW$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$3,"RegQueryValueExW"); + + private static class RegQueryValueExW { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Advapi32.C_LONG, + Advapi32.C_POINTER, + Advapi32.C_POINTER, + Advapi32.C_POINTER, + Advapi32.C_POINTER, + Advapi32.C_POINTER, + Advapi32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Advapi32.findOrThrow("RegQueryValueExW"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * LSTATUS RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) + * } + */ + public static FunctionDescriptor RegQueryValueExW$descriptor() { + return RegQueryValueExW.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * LSTATUS RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) + * } + */ + public static MethodHandle RegQueryValueExW$handle() { + return RegQueryValueExW.HANDLE; } /** - * {@snippet : - * LSTATUS RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); + * {@snippet lang=c : + * LSTATUS RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) * } */ public static int RegQueryValueExW(MemorySegment hKey, MemorySegment lpValueName, MemorySegment lpReserved, MemorySegment lpType, MemorySegment lpData, MemorySegment lpcbData) { - var mh$ = RegQueryValueExW$MH(); + var mh$ = RegQueryValueExW.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("RegQueryValueExW", hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); + } return (int)mh$.invokeExact(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } + private static final int KEY_READ = (int)131097L; /** - * {@snippet : + * {@snippet lang=c : * #define KEY_READ 131097 * } */ public static int KEY_READ() { - return (int)131097L; + return KEY_READ; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/RuntimeHelper.java deleted file mode 100644 index 868da38..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.advapi32; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("Advapi32"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/constants$0.java deleted file mode 100644 index ee2a9f7..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/advapi32/constants$0.java +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.advapi32; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "RegCloseKey", - constants$0.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "RegQueryValueExW", - constants$0.const$2 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java deleted file mode 100644 index 85b02bc..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.kernel32; - -/** - * {@snippet : - * typedef struct _GUID GUID; - * } - */ -public final class GUID extends _GUID { - - // Suppresses default constructor, ensuring non-instantiability. - private GUID() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java index 4561b07..fcd1d7b 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java @@ -2,237 +2,438 @@ package net.codecrete.usb.windows.gen.kernel32; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class Kernel32 { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - /** - * {@snippet : +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class Kernel32 { + + Kernel32() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("Kernel32"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int FILE_SHARE_READ = (int)1L; + /** + * {@snippet lang=c : * #define FILE_SHARE_READ 1 * } */ public static int FILE_SHARE_READ() { - return (int)1L; + return FILE_SHARE_READ; } + private static final int FILE_SHARE_WRITE = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define FILE_SHARE_WRITE 2 * } */ public static int FILE_SHARE_WRITE() { - return (int)2L; + return FILE_SHARE_WRITE; } + private static final int FILE_ATTRIBUTE_NORMAL = (int)128L; /** - * {@snippet : + * {@snippet lang=c : * #define FILE_ATTRIBUTE_NORMAL 128 * } */ public static int FILE_ATTRIBUTE_NORMAL() { - return (int)128L; + return FILE_ATTRIBUTE_NORMAL; } + private static final int OPEN_EXISTING = (int)3L; /** - * {@snippet : + * {@snippet lang=c : * #define OPEN_EXISTING 3 * } */ public static int OPEN_EXISTING() { - return (int)3L; + return OPEN_EXISTING; } + private static final int FILE_FLAG_OVERLAPPED = (int)1073741824L; /** - * {@snippet : + * {@snippet lang=c : * #define FILE_FLAG_OVERLAPPED 1073741824 * } */ public static int FILE_FLAG_OVERLAPPED() { - return (int)1073741824L; + return FILE_FLAG_OVERLAPPED; } + private static final int FORMAT_MESSAGE_ALLOCATE_BUFFER = (int)256L; /** - * {@snippet : + * {@snippet lang=c : * #define FORMAT_MESSAGE_ALLOCATE_BUFFER 256 * } */ public static int FORMAT_MESSAGE_ALLOCATE_BUFFER() { - return (int)256L; + return FORMAT_MESSAGE_ALLOCATE_BUFFER; } + private static final int FORMAT_MESSAGE_IGNORE_INSERTS = (int)512L; /** - * {@snippet : + * {@snippet lang=c : * #define FORMAT_MESSAGE_IGNORE_INSERTS 512 * } */ public static int FORMAT_MESSAGE_IGNORE_INSERTS() { - return (int)512L; + return FORMAT_MESSAGE_IGNORE_INSERTS; } + private static final int FORMAT_MESSAGE_FROM_HMODULE = (int)2048L; /** - * {@snippet : + * {@snippet lang=c : * #define FORMAT_MESSAGE_FROM_HMODULE 2048 * } */ public static int FORMAT_MESSAGE_FROM_HMODULE() { - return (int)2048L; + return FORMAT_MESSAGE_FROM_HMODULE; } + private static final int FORMAT_MESSAGE_FROM_SYSTEM = (int)4096L; /** - * {@snippet : + * {@snippet lang=c : * #define FORMAT_MESSAGE_FROM_SYSTEM 4096 * } */ public static int FORMAT_MESSAGE_FROM_SYSTEM() { - return (int)4096L; + return FORMAT_MESSAGE_FROM_SYSTEM; } - public static MethodHandle CloseHandle$MH() { - return RuntimeHelper.requireNonNull(constants$1.const$6,"CloseHandle"); + + private static class CloseHandle { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Kernel32.C_INT, + Kernel32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Kernel32.findOrThrow("CloseHandle"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BOOL CloseHandle(HANDLE hObject) + * } + */ + public static FunctionDescriptor CloseHandle$descriptor() { + return CloseHandle.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BOOL CloseHandle(HANDLE hObject) + * } + */ + public static MethodHandle CloseHandle$handle() { + return CloseHandle.HANDLE; } /** - * {@snippet : - * BOOL CloseHandle(HANDLE hObject); + * {@snippet lang=c : + * BOOL CloseHandle(HANDLE hObject) * } */ public static int CloseHandle(MemorySegment hObject) { - var mh$ = CloseHandle$MH(); + var mh$ = CloseHandle.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CloseHandle", hObject); + } return (int)mh$.invokeExact(hObject); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle GetModuleHandleW$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$1,"GetModuleHandleW"); + + private static class GetModuleHandleW { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Kernel32.C_POINTER, + Kernel32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Kernel32.findOrThrow("GetModuleHandleW"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * HMODULE GetModuleHandleW(LPCWSTR lpModuleName) + * } + */ + public static FunctionDescriptor GetModuleHandleW$descriptor() { + return GetModuleHandleW.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * HMODULE GetModuleHandleW(LPCWSTR lpModuleName) + * } + */ + public static MethodHandle GetModuleHandleW$handle() { + return GetModuleHandleW.HANDLE; } /** - * {@snippet : - * HMODULE GetModuleHandleW(LPCWSTR lpModuleName); + * {@snippet lang=c : + * HMODULE GetModuleHandleW(LPCWSTR lpModuleName) * } */ public static MemorySegment GetModuleHandleW(MemorySegment lpModuleName) { - var mh$ = GetModuleHandleW$MH(); + var mh$ = GetModuleHandleW.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(lpModuleName); + if (TRACE_DOWNCALLS) { + traceDowncall("GetModuleHandleW", lpModuleName); + } + return (MemorySegment)mh$.invokeExact(lpModuleName); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle LocalFree$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$2,"LocalFree"); + + private static class LocalFree { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Kernel32.C_POINTER, + Kernel32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Kernel32.findOrThrow("LocalFree"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * HLOCAL LocalFree(HLOCAL hMem) + * } + */ + public static FunctionDescriptor LocalFree$descriptor() { + return LocalFree.DESC; } + /** - * {@snippet : - * HLOCAL LocalFree(HLOCAL hMem); + * Downcall method handle for: + * {@snippet lang=c : + * HLOCAL LocalFree(HLOCAL hMem) + * } + */ + public static MethodHandle LocalFree$handle() { + return LocalFree.HANDLE; + } + /** + * {@snippet lang=c : + * HLOCAL LocalFree(HLOCAL hMem) * } */ public static MemorySegment LocalFree(MemorySegment hMem) { - var mh$ = LocalFree$MH(); + var mh$ = LocalFree.HANDLE; try { - return (java.lang.foreign.MemorySegment)mh$.invokeExact(hMem); + if (TRACE_DOWNCALLS) { + traceDowncall("LocalFree", hMem); + } + return (MemorySegment)mh$.invokeExact(hMem); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle FormatMessageW$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$4,"FormatMessageW"); + + private static class FormatMessageW { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Kernel32.C_LONG, + Kernel32.C_LONG, + Kernel32.C_POINTER, + Kernel32.C_LONG, + Kernel32.C_LONG, + Kernel32.C_POINTER, + Kernel32.C_LONG, + Kernel32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Kernel32.findOrThrow("FormatMessageW"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments) + * } + */ + public static FunctionDescriptor FormatMessageW$descriptor() { + return FormatMessageW.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments) + * } + */ + public static MethodHandle FormatMessageW$handle() { + return FormatMessageW.HANDLE; } /** - * {@snippet : - * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list* Arguments); + * {@snippet lang=c : + * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments) * } */ public static int FormatMessageW(int dwFlags, MemorySegment lpSource, int dwMessageId, int dwLanguageId, MemorySegment lpBuffer, int nSize, MemorySegment Arguments) { - var mh$ = FormatMessageW$MH(); + var mh$ = FormatMessageW.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("FormatMessageW", dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments); + } return (int)mh$.invokeExact(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } + private static final int GENERIC_READ = (int)2147483648L; /** - * {@snippet : + * {@snippet lang=c : * #define GENERIC_READ 2147483648 * } */ public static int GENERIC_READ() { - return (int)2147483648L; + return GENERIC_READ; } + private static final int GENERIC_WRITE = (int)1073741824L; /** - * {@snippet : + * {@snippet lang=c : * #define GENERIC_WRITE 1073741824 * } */ public static int GENERIC_WRITE() { - return (int)1073741824L; + return GENERIC_WRITE; } + private static final int INFINITE = (int)4294967295L; /** - * {@snippet : + * {@snippet lang=c : * #define INFINITE 4294967295 * } */ public static int INFINITE() { - return (int)4294967295L; + return INFINITE; } + private static final int ERROR_FILE_NOT_FOUND = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_FILE_NOT_FOUND 2 * } */ public static int ERROR_FILE_NOT_FOUND() { - return (int)2L; + return ERROR_FILE_NOT_FOUND; } + private static final int ERROR_GEN_FAILURE = (int)31L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_GEN_FAILURE 31 * } */ public static int ERROR_GEN_FAILURE() { - return (int)31L; + return ERROR_GEN_FAILURE; } + private static final int ERROR_INSUFFICIENT_BUFFER = (int)122L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_INSUFFICIENT_BUFFER 122 * } */ public static int ERROR_INSUFFICIENT_BUFFER() { - return (int)122L; + return ERROR_INSUFFICIENT_BUFFER; } + private static final int ERROR_MORE_DATA = (int)234L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_MORE_DATA 234 * } */ public static int ERROR_MORE_DATA() { - return (int)234L; + return ERROR_MORE_DATA; } + private static final int ERROR_NO_MORE_ITEMS = (int)259L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_NO_MORE_ITEMS 259 * } */ public static int ERROR_NO_MORE_ITEMS() { - return (int)259L; + return ERROR_NO_MORE_ITEMS; } + private static final int ERROR_IO_PENDING = (int)997L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_IO_PENDING 997 * } */ public static int ERROR_IO_PENDING() { - return (int)997L; + return ERROR_IO_PENDING; } + private static final int ERROR_NOT_FOUND = (int)1168L; /** - * {@snippet : + * {@snippet lang=c : * #define ERROR_NOT_FOUND 1168 * } */ public static int ERROR_NOT_FOUND() { - return (int)1168L; + return ERROR_NOT_FOUND; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/OVERLAPPED.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/OVERLAPPED.java deleted file mode 100644 index 129b989..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/OVERLAPPED.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.kernel32; - -/** - * {@snippet : - * typedef struct _OVERLAPPED OVERLAPPED; - * } - */ -public final class OVERLAPPED extends _OVERLAPPED { - - // Suppresses default constructor, ensuring non-instantiability. - private OVERLAPPED() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java deleted file mode 100644 index 2f61c11..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.kernel32; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("Kernel32"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java index ead65d4..3464e8f 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java @@ -2,116 +2,297 @@ package net.codecrete.usb.windows.gen.kernel32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _GUID { * unsigned long Data1; * unsigned short Data2; * unsigned short Data3; * unsigned char Data4[8]; - * }; + * } * } */ public class _GUID { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + _GUID() { + // Should not be called directly } - public static VarHandle Data1$VH() { - return constants$0.const$1; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + Kernel32.C_LONG.withName("Data1"), + Kernel32.C_SHORT.withName("Data2"), + Kernel32.C_SHORT.withName("Data3"), + MemoryLayout.sequenceLayout(8, Kernel32.C_CHAR).withName("Data4") + ).withName("_GUID"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt Data1$LAYOUT = (OfInt)$LAYOUT.select(groupElement("Data1")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final OfInt Data1$layout() { + return Data1$LAYOUT; + } + + private static final long Data1$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final long Data1$offset() { + return Data1$OFFSET; + } + /** * Getter for field: - * {@snippet : - * unsigned long Data1; + * {@snippet lang=c : + * unsigned long Data1 * } */ - public static int Data1$get(MemorySegment seg) { - return (int)constants$0.const$1.get(seg); + public static int Data1(MemorySegment struct) { + return struct.get(Data1$LAYOUT, Data1$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned long Data1; + * {@snippet lang=c : + * unsigned long Data1 * } */ - public static void Data1$set(MemorySegment seg, int x) { - constants$0.const$1.set(seg, x); + public static void Data1(MemorySegment struct, int fieldValue) { + struct.set(Data1$LAYOUT, Data1$OFFSET, fieldValue); } - public static int Data1$get(MemorySegment seg, long index) { - return (int)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void Data1$set(MemorySegment seg, long index, int x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort Data2$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data2")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final OfShort Data2$layout() { + return Data2$LAYOUT; } - public static VarHandle Data2$VH() { - return constants$0.const$2; + + private static final long Data2$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final long Data2$offset() { + return Data2$OFFSET; } + /** * Getter for field: - * {@snippet : - * unsigned short Data2; + * {@snippet lang=c : + * unsigned short Data2 * } */ - public static short Data2$get(MemorySegment seg) { - return (short)constants$0.const$2.get(seg); + public static short Data2(MemorySegment struct) { + return struct.get(Data2$LAYOUT, Data2$OFFSET); } + /** * Setter for field: - * {@snippet : - * unsigned short Data2; + * {@snippet lang=c : + * unsigned short Data2 * } */ - public static void Data2$set(MemorySegment seg, short x) { - constants$0.const$2.set(seg, x); + public static void Data2(MemorySegment struct, short fieldValue) { + struct.set(Data2$LAYOUT, Data2$OFFSET, fieldValue); } - public static short Data2$get(MemorySegment seg, long index) { - return (short)constants$0.const$2.get(seg.asSlice(index*sizeof())); + + private static final OfShort Data3$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data3")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final OfShort Data3$layout() { + return Data3$LAYOUT; } - public static void Data2$set(MemorySegment seg, long index, short x) { - constants$0.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final long Data3$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final long Data3$offset() { + return Data3$OFFSET; } - public static VarHandle Data3$VH() { - return constants$0.const$3; + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static short Data3(MemorySegment struct) { + return struct.get(Data3$LAYOUT, Data3$OFFSET); } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static void Data3(MemorySegment struct, short fieldValue) { + struct.set(Data3$LAYOUT, Data3$OFFSET, fieldValue); + } + + private static final SequenceLayout Data4$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("Data4")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final SequenceLayout Data4$layout() { + return Data4$LAYOUT; + } + + private static final long Data4$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final long Data4$offset() { + return Data4$OFFSET; + } + /** * Getter for field: - * {@snippet : - * unsigned short Data3; + * {@snippet lang=c : + * unsigned char Data4[8] * } */ - public static short Data3$get(MemorySegment seg) { - return (short)constants$0.const$3.get(seg); + public static MemorySegment Data4(MemorySegment struct) { + return struct.asSlice(Data4$OFFSET, Data4$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * unsigned short Data3; + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, Data4$OFFSET, Data4$LAYOUT.byteSize()); + } + + private static long[] Data4$DIMS = { 8 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static long[] Data4$dimensions() { + return Data4$DIMS; + } + private static final VarHandle Data4$ELEM_HANDLE = Data4$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * unsigned char Data4[8] * } */ - public static void Data3$set(MemorySegment seg, short x) { - constants$0.const$3.set(seg, x); + public static byte Data4(MemorySegment struct, long index0) { + return (byte)Data4$ELEM_HANDLE.get(struct, 0L, index0); } - public static short Data3$get(MemorySegment seg, long index) { - return (short)constants$0.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Indexed setter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, long index0, byte fieldValue) { + Data4$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static void Data3$set(MemorySegment seg, long index, short x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment Data4$slice(MemorySegment seg) { - return seg.asSlice(8, 8); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_OVERLAPPED.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_OVERLAPPED.java index 770014d..9bc7d1c 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_OVERLAPPED.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_OVERLAPPED.java @@ -2,13 +2,18 @@ package net.codecrete.usb.windows.gen.kernel32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _OVERLAPPED { * ULONG_PTR Internal; * ULONG_PTR InternalHigh; @@ -20,182 +25,341 @@ * PVOID Pointer; * }; * HANDLE hEvent; - * }; + * } * } */ public class _OVERLAPPED { - public static MemoryLayout $LAYOUT() { - return constants$0.const$4; + _OVERLAPPED() { + // Should not be called directly } - public static VarHandle Internal$VH() { - return constants$0.const$5; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + Kernel32.C_LONG_LONG.withName("Internal"), + Kernel32.C_LONG_LONG.withName("InternalHigh"), + MemoryLayout.unionLayout( + MemoryLayout.structLayout( + Kernel32.C_LONG.withName("Offset"), + Kernel32.C_LONG.withName("OffsetHigh") + ).withName("$anon$56:9"), + Kernel32.C_POINTER.withName("Pointer") + ).withName("$anon$55:5"), + Kernel32.C_POINTER.withName("hEvent") + ).withName("_OVERLAPPED"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfLong Internal$LAYOUT = (OfLong)$LAYOUT.select(groupElement("Internal")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG_PTR Internal + * } + */ + public static final OfLong Internal$layout() { + return Internal$LAYOUT; + } + + private static final long Internal$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG_PTR Internal + * } + */ + public static final long Internal$offset() { + return Internal$OFFSET; + } + /** * Getter for field: - * {@snippet : - * ULONG_PTR Internal; + * {@snippet lang=c : + * ULONG_PTR Internal * } */ - public static long Internal$get(MemorySegment seg) { - return (long)constants$0.const$5.get(seg); + public static long Internal(MemorySegment struct) { + return struct.get(Internal$LAYOUT, Internal$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG_PTR Internal; + * {@snippet lang=c : + * ULONG_PTR Internal * } */ - public static void Internal$set(MemorySegment seg, long x) { - constants$0.const$5.set(seg, x); + public static void Internal(MemorySegment struct, long fieldValue) { + struct.set(Internal$LAYOUT, Internal$OFFSET, fieldValue); } - public static long Internal$get(MemorySegment seg, long index) { - return (long)constants$0.const$5.get(seg.asSlice(index*sizeof())); - } - public static void Internal$set(MemorySegment seg, long index, long x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong InternalHigh$LAYOUT = (OfLong)$LAYOUT.select(groupElement("InternalHigh")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG_PTR InternalHigh + * } + */ + public static final OfLong InternalHigh$layout() { + return InternalHigh$LAYOUT; } - public static VarHandle InternalHigh$VH() { - return constants$1.const$0; + + private static final long InternalHigh$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG_PTR InternalHigh + * } + */ + public static final long InternalHigh$offset() { + return InternalHigh$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG_PTR InternalHigh; + * {@snippet lang=c : + * ULONG_PTR InternalHigh * } */ - public static long InternalHigh$get(MemorySegment seg) { - return (long)constants$1.const$0.get(seg); + public static long InternalHigh(MemorySegment struct) { + return struct.get(InternalHigh$LAYOUT, InternalHigh$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG_PTR InternalHigh; + * {@snippet lang=c : + * ULONG_PTR InternalHigh * } */ - public static void InternalHigh$set(MemorySegment seg, long x) { - constants$1.const$0.set(seg, x); + public static void InternalHigh(MemorySegment struct, long fieldValue) { + struct.set(InternalHigh$LAYOUT, InternalHigh$OFFSET, fieldValue); } - public static long InternalHigh$get(MemorySegment seg, long index) { - return (long)constants$1.const$0.get(seg.asSlice(index*sizeof())); - } - public static void InternalHigh$set(MemorySegment seg, long index, long x) { - constants$1.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt Offset$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$55:5"), groupElement("$anon$56:9"), groupElement("Offset")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD Offset + * } + */ + public static final OfInt Offset$layout() { + return Offset$LAYOUT; } - public static VarHandle Offset$VH() { - return constants$1.const$1; + + private static final long Offset$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD Offset + * } + */ + public static final long Offset$offset() { + return Offset$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD Offset; + * {@snippet lang=c : + * DWORD Offset * } */ - public static int Offset$get(MemorySegment seg) { - return (int)constants$1.const$1.get(seg); + public static int Offset(MemorySegment struct) { + return struct.get(Offset$LAYOUT, Offset$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD Offset; + * {@snippet lang=c : + * DWORD Offset * } */ - public static void Offset$set(MemorySegment seg, int x) { - constants$1.const$1.set(seg, x); - } - public static int Offset$get(MemorySegment seg, long index) { - return (int)constants$1.const$1.get(seg.asSlice(index*sizeof())); + public static void Offset(MemorySegment struct, int fieldValue) { + struct.set(Offset$LAYOUT, Offset$OFFSET, fieldValue); } - public static void Offset$set(MemorySegment seg, long index, int x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt OffsetHigh$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$55:5"), groupElement("$anon$56:9"), groupElement("OffsetHigh")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD OffsetHigh + * } + */ + public static final OfInt OffsetHigh$layout() { + return OffsetHigh$LAYOUT; } - public static VarHandle OffsetHigh$VH() { - return constants$1.const$2; + + private static final long OffsetHigh$OFFSET = 20; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD OffsetHigh + * } + */ + public static final long OffsetHigh$offset() { + return OffsetHigh$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD OffsetHigh; + * {@snippet lang=c : + * DWORD OffsetHigh * } */ - public static int OffsetHigh$get(MemorySegment seg) { - return (int)constants$1.const$2.get(seg); + public static int OffsetHigh(MemorySegment struct) { + return struct.get(OffsetHigh$LAYOUT, OffsetHigh$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD OffsetHigh; + * {@snippet lang=c : + * DWORD OffsetHigh * } */ - public static void OffsetHigh$set(MemorySegment seg, int x) { - constants$1.const$2.set(seg, x); - } - public static int OffsetHigh$get(MemorySegment seg, long index) { - return (int)constants$1.const$2.get(seg.asSlice(index*sizeof())); + public static void OffsetHigh(MemorySegment struct, int fieldValue) { + struct.set(OffsetHigh$LAYOUT, OffsetHigh$OFFSET, fieldValue); } - public static void OffsetHigh$set(MemorySegment seg, long index, int x) { - constants$1.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout Pointer$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("$anon$55:5"), groupElement("Pointer")); + + /** + * Layout for field: + * {@snippet lang=c : + * PVOID Pointer + * } + */ + public static final AddressLayout Pointer$layout() { + return Pointer$LAYOUT; } - public static VarHandle Pointer$VH() { - return constants$1.const$3; + + private static final long Pointer$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * PVOID Pointer + * } + */ + public static final long Pointer$offset() { + return Pointer$OFFSET; } + /** * Getter for field: - * {@snippet : - * PVOID Pointer; + * {@snippet lang=c : + * PVOID Pointer * } */ - public static MemorySegment Pointer$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$3.get(seg); + public static MemorySegment Pointer(MemorySegment struct) { + return struct.get(Pointer$LAYOUT, Pointer$OFFSET); } + /** * Setter for field: - * {@snippet : - * PVOID Pointer; + * {@snippet lang=c : + * PVOID Pointer * } */ - public static void Pointer$set(MemorySegment seg, MemorySegment x) { - constants$1.const$3.set(seg, x); - } - public static MemorySegment Pointer$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$3.get(seg.asSlice(index*sizeof())); + public static void Pointer(MemorySegment struct, MemorySegment fieldValue) { + struct.set(Pointer$LAYOUT, Pointer$OFFSET, fieldValue); } - public static void Pointer$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hEvent$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hEvent")); + + /** + * Layout for field: + * {@snippet lang=c : + * HANDLE hEvent + * } + */ + public static final AddressLayout hEvent$layout() { + return hEvent$LAYOUT; } - public static VarHandle hEvent$VH() { - return constants$1.const$4; + + private static final long hEvent$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * HANDLE hEvent + * } + */ + public static final long hEvent$offset() { + return hEvent$OFFSET; } + /** * Getter for field: - * {@snippet : - * HANDLE hEvent; + * {@snippet lang=c : + * HANDLE hEvent * } */ - public static MemorySegment hEvent$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$4.get(seg); + public static MemorySegment hEvent(MemorySegment struct) { + return struct.get(hEvent$LAYOUT, hEvent$OFFSET); } + /** * Setter for field: - * {@snippet : - * HANDLE hEvent; + * {@snippet lang=c : + * HANDLE hEvent * } */ - public static void hEvent$set(MemorySegment seg, MemorySegment x) { - constants$1.const$4.set(seg, x); + public static void hEvent(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hEvent$LAYOUT, hEvent$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static MemorySegment hEvent$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$4.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void hEvent$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$4.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java deleted file mode 100644 index 18b60b9..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.kernel32; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withName("Data1"), - JAVA_SHORT.withName("Data2"), - JAVA_SHORT.withName("Data3"), - MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4") - ).withName("_GUID"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("Data1")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("Data2")); - static final VarHandle const$3 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("Data3")); - static final StructLayout const$4 = MemoryLayout.structLayout( - JAVA_LONG.withName("Internal"), - JAVA_LONG.withName("InternalHigh"), - MemoryLayout.unionLayout( - MemoryLayout.structLayout( - JAVA_INT.withName("Offset"), - JAVA_INT.withName("OffsetHigh") - ).withName("$anon$0"), - RuntimeHelper.POINTER.withName("Pointer") - ).withName("$anon$0"), - RuntimeHelper.POINTER.withName("hEvent") - ).withName("_OVERLAPPED"); - static final VarHandle const$5 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("Internal")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$1.java deleted file mode 100644 index b86794f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$1.java +++ /dev/null @@ -1,29 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.kernel32; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final VarHandle const$0 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("InternalHigh")); - static final VarHandle const$1 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("Offset")); - static final VarHandle const$2 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("OffsetHigh")); - static final VarHandle const$3 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("Pointer")); - static final VarHandle const$4 = constants$0.const$4.varHandle(MemoryLayout.PathElement.groupElement("hEvent")); - static final FunctionDescriptor const$5 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$6 = RuntimeHelper.downcallHandle( - "CloseHandle", - constants$1.const$5 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$2.java deleted file mode 100644 index 0f426d9..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$2.java +++ /dev/null @@ -1,39 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.kernel32; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "GetModuleHandleW", - constants$2.const$0 - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "LocalFree", - constants$2.const$0 - ); - static final FunctionDescriptor const$3 = FunctionDescriptor.of(JAVA_INT, - JAVA_INT, - RuntimeHelper.POINTER, - JAVA_INT, - JAVA_INT, - RuntimeHelper.POINTER, - JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$4 = RuntimeHelper.downcallHandle( - "FormatMessageW", - constants$2.const$3 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/NtDll.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/NtDll.java index c7dbf69..4343408 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/NtDll.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/NtDll.java @@ -2,27 +2,81 @@ package net.codecrete.usb.windows.gen.ntdll; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class NtDll { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class NtDll { + + NtDll() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int STATUS_UNSUCCESSFUL = (int)-1073741823L; /** - * {@snippet : + * {@snippet lang=c : * #define STATUS_UNSUCCESSFUL -1073741823 * } */ public static int STATUS_UNSUCCESSFUL() { - return (int)-1073741823L; + return STATUS_UNSUCCESSFUL; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/RuntimeHelper.java deleted file mode 100644 index 45bfd22..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.ntdll; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/constants$0.java deleted file mode 100644 index 7bb245f..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ntdll/constants$0.java +++ /dev/null @@ -1,11 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.ntdll; - -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/Ole32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/Ole32.java index 15bc34d..a94f773 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/Ole32.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/Ole32.java @@ -2,37 +2,121 @@ package net.codecrete.usb.windows.gen.ole32; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class Ole32 { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; - public static MethodHandle CLSIDFromString$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"CLSIDFromString"); +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class Ole32 { + + Ole32() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("Ole32"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + + private static class CLSIDFromString { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + Ole32.C_LONG, + Ole32.C_POINTER, + Ole32.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + Ole32.findOrThrow("CLSIDFromString"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern HRESULT CLSIDFromString(LPCOLESTR lpsz, LPCLSID pclsid) + * } + */ + public static FunctionDescriptor CLSIDFromString$descriptor() { + return CLSIDFromString.DESC; + } + /** - * {@snippet : - * HRESULT CLSIDFromString(LPCOLESTR lpsz, LPCLSID pclsid); + * Downcall method handle for: + * {@snippet lang=c : + * extern HRESULT CLSIDFromString(LPCOLESTR lpsz, LPCLSID pclsid) + * } + */ + public static MethodHandle CLSIDFromString$handle() { + return CLSIDFromString.HANDLE; + } + /** + * {@snippet lang=c : + * extern HRESULT CLSIDFromString(LPCOLESTR lpsz, LPCLSID pclsid) * } */ public static int CLSIDFromString(MemorySegment lpsz, MemorySegment pclsid) { - var mh$ = CLSIDFromString$MH(); + var mh$ = CLSIDFromString.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("CLSIDFromString", lpsz, pclsid); + } return (int)mh$.invokeExact(lpsz, pclsid); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/RuntimeHelper.java deleted file mode 100644 index c58af8c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.ole32; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("Ole32"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/constants$0.java deleted file mode 100644 index bf4c2c0..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/ole32/constants$0.java +++ /dev/null @@ -1,23 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.ole32; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "CLSIDFromString", - constants$0.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/DEVPROPKEY.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/DEVPROPKEY.java deleted file mode 100644 index 8162d9a..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/DEVPROPKEY.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -/** - * {@snippet : - * typedef struct _DEVPROPKEY DEVPROPKEY; - * } - */ -public final class DEVPROPKEY extends _DEVPROPKEY { - - // Suppresses default constructor, ensuring non-instantiability. - private DEVPROPKEY() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java deleted file mode 100644 index 6a51526..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.setupapi; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("SetupAPI"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java deleted file mode 100644 index 13425fe..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -/** - * {@snippet : - * typedef struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA; - * } - */ -public final class SP_DEVICE_INTERFACE_DATA extends _SP_DEVICE_INTERFACE_DATA { - - // Suppresses default constructor, ensuring non-instantiability. - private SP_DEVICE_INTERFACE_DATA() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java deleted file mode 100644 index 7a9f76b..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -/** - * {@snippet : - * typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W; - * } - */ -public final class SP_DEVICE_INTERFACE_DETAIL_DATA_W extends _SP_DEVICE_INTERFACE_DETAIL_DATA_W { - - // Suppresses default constructor, ensuring non-instantiability. - private SP_DEVICE_INTERFACE_DETAIL_DATA_W() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java deleted file mode 100644 index ebc94bc..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -/** - * {@snippet : - * typedef struct _SP_DEVINFO_DATA SP_DEVINFO_DATA; - * } - */ -public final class SP_DEVINFO_DATA extends _SP_DEVINFO_DATA { - - // Suppresses default constructor, ensuring non-instantiability. - private SP_DEVINFO_DATA() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java index bccea11..d206dd3 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java @@ -2,109 +2,231 @@ package net.codecrete.usb.windows.gen.setupapi; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class SetupAPI { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class SetupAPI { + + SetupAPI() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("SetupAPI"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int DEVPROP_TYPEMOD_LIST = (int)8192L; /** - * {@snippet : + * {@snippet lang=c : * #define DEVPROP_TYPEMOD_LIST 8192 * } */ public static int DEVPROP_TYPEMOD_LIST() { - return (int)8192L; + return DEVPROP_TYPEMOD_LIST; } + private static final int DEVPROP_TYPE_UINT32 = (int)7L; /** - * {@snippet : + * {@snippet lang=c : * #define DEVPROP_TYPE_UINT32 7 * } */ public static int DEVPROP_TYPE_UINT32() { - return (int)7L; + return DEVPROP_TYPE_UINT32; } + private static final int DEVPROP_TYPE_STRING = (int)18L; /** - * {@snippet : + * {@snippet lang=c : * #define DEVPROP_TYPE_STRING 18 * } */ public static int DEVPROP_TYPE_STRING() { - return (int)18L; + return DEVPROP_TYPE_STRING; } + private static final int DICS_FLAG_GLOBAL = (int)1L; /** - * {@snippet : + * {@snippet lang=c : * #define DICS_FLAG_GLOBAL 1 * } */ public static int DICS_FLAG_GLOBAL() { - return (int)1L; + return DICS_FLAG_GLOBAL; } + private static final int DIGCF_PRESENT = (int)2L; /** - * {@snippet : + * {@snippet lang=c : * #define DIGCF_PRESENT 2 * } */ public static int DIGCF_PRESENT() { - return (int)2L; + return DIGCF_PRESENT; } + private static final int DIGCF_DEVICEINTERFACE = (int)16L; /** - * {@snippet : + * {@snippet lang=c : * #define DIGCF_DEVICEINTERFACE 16 * } */ public static int DIGCF_DEVICEINTERFACE() { - return (int)16L; + return DIGCF_DEVICEINTERFACE; } + private static final int DIREG_DEV = (int)1L; /** - * {@snippet : + * {@snippet lang=c : * #define DIREG_DEV 1 * } */ public static int DIREG_DEV() { - return (int)1L; + return DIREG_DEV; } - public static MethodHandle SetupDiDestroyDeviceInfoList$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$1,"SetupDiDestroyDeviceInfoList"); + + private static class SetupDiDestroyDeviceInfoList { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + SetupAPI.C_INT, + SetupAPI.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + SetupAPI.findOrThrow("SetupDiDestroyDeviceInfoList"), + DESC); } + /** - * {@snippet : - * BOOL SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet); + * Function descriptor for: + * {@snippet lang=c : + * BOOL SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) + * } + */ + public static FunctionDescriptor SetupDiDestroyDeviceInfoList$descriptor() { + return SetupDiDestroyDeviceInfoList.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BOOL SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) + * } + */ + public static MethodHandle SetupDiDestroyDeviceInfoList$handle() { + return SetupDiDestroyDeviceInfoList.HANDLE; + } + /** + * {@snippet lang=c : + * BOOL SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) * } */ public static int SetupDiDestroyDeviceInfoList(MemorySegment DeviceInfoSet) { - var mh$ = SetupDiDestroyDeviceInfoList$MH(); + var mh$ = SetupDiDestroyDeviceInfoList.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("SetupDiDestroyDeviceInfoList", DeviceInfoSet); + } return (int)mh$.invokeExact(DeviceInfoSet); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } - public static MethodHandle SetupDiDeleteDeviceInterfaceData$MH() { - return RuntimeHelper.requireNonNull(constants$2.const$3,"SetupDiDeleteDeviceInterfaceData"); + + private static class SetupDiDeleteDeviceInterfaceData { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + SetupAPI.C_INT, + SetupAPI.C_POINTER, + SetupAPI.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + SetupAPI.findOrThrow("SetupDiDeleteDeviceInterfaceData"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BOOL SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData) + * } + */ + public static FunctionDescriptor SetupDiDeleteDeviceInterfaceData$descriptor() { + return SetupDiDeleteDeviceInterfaceData.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BOOL SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData) + * } + */ + public static MethodHandle SetupDiDeleteDeviceInterfaceData$handle() { + return SetupDiDeleteDeviceInterfaceData.HANDLE; } /** - * {@snippet : - * BOOL SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData); + * {@snippet lang=c : + * BOOL SetupDiDeleteDeviceInterfaceData(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData) * } */ public static int SetupDiDeleteDeviceInterfaceData(MemorySegment DeviceInfoSet, MemorySegment DeviceInterfaceData) { - var mh$ = SetupDiDeleteDeviceInterfaceData$MH(); + var mh$ = SetupDiDeleteDeviceInterfaceData.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("SetupDiDeleteDeviceInterfaceData", DeviceInfoSet, DeviceInterfaceData); + } return (int)mh$.invokeExact(DeviceInfoSet, DeviceInterfaceData); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_DEVPROPKEY.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_DEVPROPKEY.java index 8389d24..56dae5a 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_DEVPROPKEY.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_DEVPROPKEY.java @@ -2,60 +2,172 @@ package net.codecrete.usb.windows.gen.setupapi; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _DEVPROPKEY { * DEVPROPGUID fmtid; * DEVPROPID pid; - * }; + * } * } */ public class _DEVPROPKEY { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + _DEVPROPKEY() { + // Should not be called directly } - public static MemorySegment fmtid$slice(MemorySegment seg) { - return seg.asSlice(0, 16); + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + _GUID.layout().withName("fmtid"), + SetupAPI.C_LONG.withName("pid") + ).withName("_DEVPROPKEY"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } - public static VarHandle pid$VH() { - return constants$0.const$1; + + private static final GroupLayout fmtid$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("fmtid")); + + /** + * Layout for field: + * {@snippet lang=c : + * DEVPROPGUID fmtid + * } + */ + public static final GroupLayout fmtid$layout() { + return fmtid$LAYOUT; } + + private static final long fmtid$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DEVPROPGUID fmtid + * } + */ + public static final long fmtid$offset() { + return fmtid$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DEVPROPID pid; + * {@snippet lang=c : + * DEVPROPGUID fmtid * } */ - public static int pid$get(MemorySegment seg) { - return (int)constants$0.const$1.get(seg); + public static MemorySegment fmtid(MemorySegment struct) { + return struct.asSlice(fmtid$OFFSET, fmtid$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * DEVPROPID pid; + * {@snippet lang=c : + * DEVPROPGUID fmtid * } */ - public static void pid$set(MemorySegment seg, int x) { - constants$0.const$1.set(seg, x); + public static void fmtid(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, fmtid$OFFSET, fmtid$LAYOUT.byteSize()); } - public static int pid$get(MemorySegment seg, long index) { - return (int)constants$0.const$1.get(seg.asSlice(index*sizeof())); + + private static final OfInt pid$LAYOUT = (OfInt)$LAYOUT.select(groupElement("pid")); + + /** + * Layout for field: + * {@snippet lang=c : + * DEVPROPID pid + * } + */ + public static final OfInt pid$layout() { + return pid$LAYOUT; } - public static void pid$set(MemorySegment seg, long index, int x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final long pid$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * DEVPROPID pid + * } + */ + public static final long pid$offset() { + return pid$OFFSET; } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Getter for field: + * {@snippet lang=c : + * DEVPROPID pid + * } + */ + public static int pid(MemorySegment struct) { + return struct.get(pid$LAYOUT, pid$OFFSET); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Setter for field: + * {@snippet lang=c : + * DEVPROPID pid + * } + */ + public static void pid(MemorySegment struct, int fieldValue) { + struct.set(pid$LAYOUT, pid$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_GUID.java new file mode 100644 index 0000000..019decc --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_GUID.java @@ -0,0 +1,298 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.setupapi; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct _GUID { + * unsigned long Data1; + * unsigned short Data2; + * unsigned short Data3; + * unsigned char Data4[8]; + * } + * } + */ +public class _GUID { + + _GUID() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + SetupAPI.C_LONG.withName("Data1"), + SetupAPI.C_SHORT.withName("Data2"), + SetupAPI.C_SHORT.withName("Data3"), + MemoryLayout.sequenceLayout(8, SetupAPI.C_CHAR).withName("Data4") + ).withName("_GUID"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt Data1$LAYOUT = (OfInt)$LAYOUT.select(groupElement("Data1")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final OfInt Data1$layout() { + return Data1$LAYOUT; + } + + private static final long Data1$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final long Data1$offset() { + return Data1$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static int Data1(MemorySegment struct) { + return struct.get(Data1$LAYOUT, Data1$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static void Data1(MemorySegment struct, int fieldValue) { + struct.set(Data1$LAYOUT, Data1$OFFSET, fieldValue); + } + + private static final OfShort Data2$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data2")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final OfShort Data2$layout() { + return Data2$LAYOUT; + } + + private static final long Data2$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final long Data2$offset() { + return Data2$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static short Data2(MemorySegment struct) { + return struct.get(Data2$LAYOUT, Data2$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static void Data2(MemorySegment struct, short fieldValue) { + struct.set(Data2$LAYOUT, Data2$OFFSET, fieldValue); + } + + private static final OfShort Data3$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data3")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final OfShort Data3$layout() { + return Data3$LAYOUT; + } + + private static final long Data3$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final long Data3$offset() { + return Data3$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static short Data3(MemorySegment struct) { + return struct.get(Data3$LAYOUT, Data3$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static void Data3(MemorySegment struct, short fieldValue) { + struct.set(Data3$LAYOUT, Data3$OFFSET, fieldValue); + } + + private static final SequenceLayout Data4$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("Data4")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final SequenceLayout Data4$layout() { + return Data4$LAYOUT; + } + + private static final long Data4$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final long Data4$offset() { + return Data4$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static MemorySegment Data4(MemorySegment struct) { + return struct.asSlice(Data4$OFFSET, Data4$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, Data4$OFFSET, Data4$LAYOUT.byteSize()); + } + + private static long[] Data4$DIMS = { 8 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static long[] Data4$dimensions() { + return Data4$DIMS; + } + private static final VarHandle Data4$ELEM_HANDLE = Data4$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static byte Data4(MemorySegment struct, long index0) { + return (byte)Data4$ELEM_HANDLE.get(struct, 0L, index0); + } + + /** + * Indexed setter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, long index0, byte fieldValue) { + Data4$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java index c1b5e09..b97ad0d 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java @@ -2,116 +2,264 @@ package net.codecrete.usb.windows.gen.setupapi; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _SP_DEVICE_INTERFACE_DATA { * DWORD cbSize; * GUID InterfaceClassGuid; * DWORD Flags; * ULONG_PTR Reserved; - * }; + * } * } */ public class _SP_DEVICE_INTERFACE_DATA { - public static MemoryLayout $LAYOUT() { - return constants$1.const$0; + _SP_DEVICE_INTERFACE_DATA() { + // Should not be called directly } - public static VarHandle cbSize$VH() { - return constants$1.const$1; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + SetupAPI.C_LONG.withName("cbSize"), + _GUID.layout().withName("InterfaceClassGuid"), + SetupAPI.C_LONG.withName("Flags"), + SetupAPI.C_LONG_LONG.withName("Reserved") + ).withName("_SP_DEVICE_INTERFACE_DATA"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt cbSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbSize")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final OfInt cbSize$layout() { + return cbSize$LAYOUT; + } + + private static final long cbSize$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final long cbSize$offset() { + return cbSize$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static int cbSize$get(MemorySegment seg) { - return (int)constants$1.const$1.get(seg); + public static int cbSize(MemorySegment struct) { + return struct.get(cbSize$LAYOUT, cbSize$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static void cbSize$set(MemorySegment seg, int x) { - constants$1.const$1.set(seg, x); + public static void cbSize(MemorySegment struct, int fieldValue) { + struct.set(cbSize$LAYOUT, cbSize$OFFSET, fieldValue); } - public static int cbSize$get(MemorySegment seg, long index) { - return (int)constants$1.const$1.get(seg.asSlice(index*sizeof())); + + private static final GroupLayout InterfaceClassGuid$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("InterfaceClassGuid")); + + /** + * Layout for field: + * {@snippet lang=c : + * GUID InterfaceClassGuid + * } + */ + public static final GroupLayout InterfaceClassGuid$layout() { + return InterfaceClassGuid$LAYOUT; } - public static void cbSize$set(MemorySegment seg, long index, int x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final long InterfaceClassGuid$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * GUID InterfaceClassGuid + * } + */ + public static final long InterfaceClassGuid$offset() { + return InterfaceClassGuid$OFFSET; } - public static MemorySegment InterfaceClassGuid$slice(MemorySegment seg) { - return seg.asSlice(4, 16); + + /** + * Getter for field: + * {@snippet lang=c : + * GUID InterfaceClassGuid + * } + */ + public static MemorySegment InterfaceClassGuid(MemorySegment struct) { + return struct.asSlice(InterfaceClassGuid$OFFSET, InterfaceClassGuid$LAYOUT.byteSize()); } - public static VarHandle Flags$VH() { - return constants$1.const$2; + + /** + * Setter for field: + * {@snippet lang=c : + * GUID InterfaceClassGuid + * } + */ + public static void InterfaceClassGuid(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, InterfaceClassGuid$OFFSET, InterfaceClassGuid$LAYOUT.byteSize()); } + + private static final OfInt Flags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("Flags")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD Flags + * } + */ + public static final OfInt Flags$layout() { + return Flags$LAYOUT; + } + + private static final long Flags$OFFSET = 20; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD Flags + * } + */ + public static final long Flags$offset() { + return Flags$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD Flags; + * {@snippet lang=c : + * DWORD Flags * } */ - public static int Flags$get(MemorySegment seg) { - return (int)constants$1.const$2.get(seg); + public static int Flags(MemorySegment struct) { + return struct.get(Flags$LAYOUT, Flags$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD Flags; + * {@snippet lang=c : + * DWORD Flags * } */ - public static void Flags$set(MemorySegment seg, int x) { - constants$1.const$2.set(seg, x); - } - public static int Flags$get(MemorySegment seg, long index) { - return (int)constants$1.const$2.get(seg.asSlice(index*sizeof())); + public static void Flags(MemorySegment struct, int fieldValue) { + struct.set(Flags$LAYOUT, Flags$OFFSET, fieldValue); } - public static void Flags$set(MemorySegment seg, long index, int x) { - constants$1.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong Reserved$LAYOUT = (OfLong)$LAYOUT.select(groupElement("Reserved")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG_PTR Reserved + * } + */ + public static final OfLong Reserved$layout() { + return Reserved$LAYOUT; } - public static VarHandle Reserved$VH() { - return constants$1.const$3; + + private static final long Reserved$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG_PTR Reserved + * } + */ + public static final long Reserved$offset() { + return Reserved$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG_PTR Reserved; + * {@snippet lang=c : + * ULONG_PTR Reserved * } */ - public static long Reserved$get(MemorySegment seg) { - return (long)constants$1.const$3.get(seg); + public static long Reserved(MemorySegment struct) { + return struct.get(Reserved$LAYOUT, Reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG_PTR Reserved; + * {@snippet lang=c : + * ULONG_PTR Reserved * } */ - public static void Reserved$set(MemorySegment seg, long x) { - constants$1.const$3.set(seg, x); + public static void Reserved(MemorySegment struct, long fieldValue) { + struct.set(Reserved$LAYOUT, Reserved$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long Reserved$get(MemorySegment seg, long index) { - return (long)constants$1.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void Reserved$set(MemorySegment seg, long index, long x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java index 4a837e9..7a07f13 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java @@ -2,60 +2,206 @@ package net.codecrete.usb.windows.gen.setupapi; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W { * DWORD cbSize; * WCHAR DevicePath[1]; - * }; + * } * } */ public class _SP_DEVICE_INTERFACE_DETAIL_DATA_W { - public static MemoryLayout $LAYOUT() { - return constants$1.const$4; + _SP_DEVICE_INTERFACE_DETAIL_DATA_W() { + // Should not be called directly } - public static VarHandle cbSize$VH() { - return constants$1.const$5; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + SetupAPI.C_LONG.withName("cbSize"), + MemoryLayout.sequenceLayout(1, SetupAPI.C_SHORT).withName("DevicePath"), + MemoryLayout.paddingLayout(2) + ).withName("_SP_DEVICE_INTERFACE_DETAIL_DATA_W"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt cbSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbSize")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final OfInt cbSize$layout() { + return cbSize$LAYOUT; + } + + private static final long cbSize$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final long cbSize$offset() { + return cbSize$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static int cbSize$get(MemorySegment seg) { - return (int)constants$1.const$5.get(seg); + public static int cbSize(MemorySegment struct) { + return struct.get(cbSize$LAYOUT, cbSize$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static void cbSize$set(MemorySegment seg, int x) { - constants$1.const$5.set(seg, x); + public static void cbSize(MemorySegment struct, int fieldValue) { + struct.set(cbSize$LAYOUT, cbSize$OFFSET, fieldValue); } - public static int cbSize$get(MemorySegment seg, long index) { - return (int)constants$1.const$5.get(seg.asSlice(index*sizeof())); + + private static final SequenceLayout DevicePath$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("DevicePath")); + + /** + * Layout for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static final SequenceLayout DevicePath$layout() { + return DevicePath$LAYOUT; } - public static void cbSize$set(MemorySegment seg, long index, int x) { - constants$1.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final long DevicePath$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static final long DevicePath$offset() { + return DevicePath$OFFSET; } - public static MemorySegment DevicePath$slice(MemorySegment seg) { - return seg.asSlice(4, 2); + + /** + * Getter for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static MemorySegment DevicePath(MemorySegment struct) { + return struct.asSlice(DevicePath$OFFSET, DevicePath$LAYOUT.byteSize()); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Setter for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static void DevicePath(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, DevicePath$OFFSET, DevicePath$LAYOUT.byteSize()); + } + + private static long[] DevicePath$DIMS = { 1 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static long[] DevicePath$dimensions() { + return DevicePath$DIMS; + } + private static final VarHandle DevicePath$ELEM_HANDLE = DevicePath$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static short DevicePath(MemorySegment struct, long index0) { + return (short)DevicePath$ELEM_HANDLE.get(struct, 0L, index0); + } + + /** + * Indexed setter for field: + * {@snippet lang=c : + * WCHAR DevicePath[1] + * } + */ + public static void DevicePath(MemorySegment struct, long index0, short fieldValue) { + DevicePath$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java index 8cf558b..03699c7 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java @@ -2,116 +2,264 @@ package net.codecrete.usb.windows.gen.setupapi; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _SP_DEVINFO_DATA { * DWORD cbSize; * GUID ClassGuid; * DWORD DevInst; * ULONG_PTR Reserved; - * }; + * } * } */ public class _SP_DEVINFO_DATA { - public static MemoryLayout $LAYOUT() { - return constants$0.const$2; + _SP_DEVINFO_DATA() { + // Should not be called directly } - public static VarHandle cbSize$VH() { - return constants$0.const$3; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + SetupAPI.C_LONG.withName("cbSize"), + _GUID.layout().withName("ClassGuid"), + SetupAPI.C_LONG.withName("DevInst"), + SetupAPI.C_LONG_LONG.withName("Reserved") + ).withName("_SP_DEVINFO_DATA"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt cbSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbSize")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final OfInt cbSize$layout() { + return cbSize$LAYOUT; + } + + private static final long cbSize$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD cbSize + * } + */ + public static final long cbSize$offset() { + return cbSize$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static int cbSize$get(MemorySegment seg) { - return (int)constants$0.const$3.get(seg); + public static int cbSize(MemorySegment struct) { + return struct.get(cbSize$LAYOUT, cbSize$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD cbSize; + * {@snippet lang=c : + * DWORD cbSize * } */ - public static void cbSize$set(MemorySegment seg, int x) { - constants$0.const$3.set(seg, x); + public static void cbSize(MemorySegment struct, int fieldValue) { + struct.set(cbSize$LAYOUT, cbSize$OFFSET, fieldValue); } - public static int cbSize$get(MemorySegment seg, long index) { - return (int)constants$0.const$3.get(seg.asSlice(index*sizeof())); + + private static final GroupLayout ClassGuid$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("ClassGuid")); + + /** + * Layout for field: + * {@snippet lang=c : + * GUID ClassGuid + * } + */ + public static final GroupLayout ClassGuid$layout() { + return ClassGuid$LAYOUT; } - public static void cbSize$set(MemorySegment seg, long index, int x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final long ClassGuid$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * GUID ClassGuid + * } + */ + public static final long ClassGuid$offset() { + return ClassGuid$OFFSET; } - public static MemorySegment ClassGuid$slice(MemorySegment seg) { - return seg.asSlice(4, 16); + + /** + * Getter for field: + * {@snippet lang=c : + * GUID ClassGuid + * } + */ + public static MemorySegment ClassGuid(MemorySegment struct) { + return struct.asSlice(ClassGuid$OFFSET, ClassGuid$LAYOUT.byteSize()); } - public static VarHandle DevInst$VH() { - return constants$0.const$4; + + /** + * Setter for field: + * {@snippet lang=c : + * GUID ClassGuid + * } + */ + public static void ClassGuid(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ClassGuid$OFFSET, ClassGuid$LAYOUT.byteSize()); } + + private static final OfInt DevInst$LAYOUT = (OfInt)$LAYOUT.select(groupElement("DevInst")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD DevInst + * } + */ + public static final OfInt DevInst$layout() { + return DevInst$LAYOUT; + } + + private static final long DevInst$OFFSET = 20; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD DevInst + * } + */ + public static final long DevInst$offset() { + return DevInst$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD DevInst; + * {@snippet lang=c : + * DWORD DevInst * } */ - public static int DevInst$get(MemorySegment seg) { - return (int)constants$0.const$4.get(seg); + public static int DevInst(MemorySegment struct) { + return struct.get(DevInst$LAYOUT, DevInst$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD DevInst; + * {@snippet lang=c : + * DWORD DevInst * } */ - public static void DevInst$set(MemorySegment seg, int x) { - constants$0.const$4.set(seg, x); - } - public static int DevInst$get(MemorySegment seg, long index) { - return (int)constants$0.const$4.get(seg.asSlice(index*sizeof())); + public static void DevInst(MemorySegment struct, int fieldValue) { + struct.set(DevInst$LAYOUT, DevInst$OFFSET, fieldValue); } - public static void DevInst$set(MemorySegment seg, long index, int x) { - constants$0.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong Reserved$LAYOUT = (OfLong)$LAYOUT.select(groupElement("Reserved")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG_PTR Reserved + * } + */ + public static final OfLong Reserved$layout() { + return Reserved$LAYOUT; } - public static VarHandle Reserved$VH() { - return constants$0.const$5; + + private static final long Reserved$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG_PTR Reserved + * } + */ + public static final long Reserved$offset() { + return Reserved$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG_PTR Reserved; + * {@snippet lang=c : + * ULONG_PTR Reserved * } */ - public static long Reserved$get(MemorySegment seg) { - return (long)constants$0.const$5.get(seg); + public static long Reserved(MemorySegment struct) { + return struct.get(Reserved$LAYOUT, Reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG_PTR Reserved; + * {@snippet lang=c : + * ULONG_PTR Reserved * } */ - public static void Reserved$set(MemorySegment seg, long x) { - constants$0.const$5.set(seg, x); + public static void Reserved(MemorySegment struct, long fieldValue) { + struct.set(Reserved$LAYOUT, Reserved$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long Reserved$get(MemorySegment seg, long index) { - return (long)constants$0.const$5.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void Reserved$set(MemorySegment seg, long index, long x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java deleted file mode 100644 index e5d398c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java +++ /dev/null @@ -1,40 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - MemoryLayout.structLayout( - JAVA_INT.withName("Data1"), - JAVA_SHORT.withName("Data2"), - JAVA_SHORT.withName("Data3"), - MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4") - ).withName("fmtid"), - JAVA_INT.withName("pid") - ).withName("_DEVPROPKEY"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("pid")); - static final StructLayout const$2 = MemoryLayout.structLayout( - JAVA_INT.withName("cbSize"), - MemoryLayout.structLayout( - JAVA_INT.withName("Data1"), - JAVA_SHORT.withName("Data2"), - JAVA_SHORT.withName("Data3"), - MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4") - ).withName("ClassGuid"), - JAVA_INT.withName("DevInst"), - JAVA_LONG.withName("Reserved") - ).withName("_SP_DEVINFO_DATA"); - static final VarHandle const$3 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("cbSize")); - static final VarHandle const$4 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("DevInst")); - static final VarHandle const$5 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("Reserved")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java deleted file mode 100644 index 08aa9ba..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withName("cbSize"), - MemoryLayout.structLayout( - JAVA_INT.withName("Data1"), - JAVA_SHORT.withName("Data2"), - JAVA_SHORT.withName("Data3"), - MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4") - ).withName("InterfaceClassGuid"), - JAVA_INT.withName("Flags"), - JAVA_LONG.withName("Reserved") - ).withName("_SP_DEVICE_INTERFACE_DATA"); - static final VarHandle const$1 = constants$1.const$0.varHandle(MemoryLayout.PathElement.groupElement("cbSize")); - static final VarHandle const$2 = constants$1.const$0.varHandle(MemoryLayout.PathElement.groupElement("Flags")); - static final VarHandle const$3 = constants$1.const$0.varHandle(MemoryLayout.PathElement.groupElement("Reserved")); - static final StructLayout const$4 = MemoryLayout.structLayout( - JAVA_INT.withName("cbSize"), - MemoryLayout.sequenceLayout(1, JAVA_SHORT).withName("DevicePath"), - MemoryLayout.paddingLayout(2) - ).withName("_SP_DEVICE_INTERFACE_DETAIL_DATA_W"); - static final VarHandle const$5 = constants$1.const$4.varHandle(MemoryLayout.PathElement.groupElement("cbSize")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$2.java deleted file mode 100644 index 5c778a8..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$2.java +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.setupapi; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "SetupDiDestroyDeviceInfoList", - constants$2.const$0 - ); - static final FunctionDescriptor const$2 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER, - RuntimeHelper.POINTER - ); - static final MethodHandle const$3 = RuntimeHelper.downcallHandle( - "SetupDiDeleteDeviceInterfaceData", - constants$2.const$2 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java deleted file mode 100644 index 099b08e..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.usbioctl; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java index 60c3662..3ce529c 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java @@ -2,35 +2,90 @@ package net.codecrete.usb.windows.gen.usbioctl; -import java.lang.foreign.AddressLayout; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class USBIoctl { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class USBIoctl { + + USBIoctl() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = (int)2229264L; /** - * {@snippet : + * {@snippet lang=c : * #define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 2229264 * } */ public static int IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION() { - return (int)2229264L; + return IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION; } + private static final int IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX = (int)2229320L; /** - * {@snippet : + * {@snippet lang=c : * #define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX 2229320 * } */ public static int IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX() { - return (int)2229320L; + return IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_DESCRIPTOR_REQUEST.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_DESCRIPTOR_REQUEST.java deleted file mode 100644 index 6a5de02..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_DESCRIPTOR_REQUEST.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.usbioctl; - -/** - * {@snippet : - * typedef struct _USB_DESCRIPTOR_REQUEST USB_DESCRIPTOR_REQUEST; - * } - */ -public final class USB_DESCRIPTOR_REQUEST extends _USB_DESCRIPTOR_REQUEST { - - // Suppresses default constructor, ensuring non-instantiability. - private USB_DESCRIPTOR_REQUEST() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_NODE_CONNECTION_INFORMATION_EX.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_NODE_CONNECTION_INFORMATION_EX.java deleted file mode 100644 index 9750d30..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USB_NODE_CONNECTION_INFORMATION_EX.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.usbioctl; - -/** - * {@snippet : - * typedef struct _USB_NODE_CONNECTION_INFORMATION_EX USB_NODE_CONNECTION_INFORMATION_EX; - * } - */ -public final class USB_NODE_CONNECTION_INFORMATION_EX extends _USB_NODE_CONNECTION_INFORMATION_EX { - - // Suppresses default constructor, ensuring non-instantiability. - private USB_NODE_CONNECTION_INFORMATION_EX() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DESCRIPTOR_REQUEST.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DESCRIPTOR_REQUEST.java index 38d3f92..c3e9a66 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DESCRIPTOR_REQUEST.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DESCRIPTOR_REQUEST.java @@ -2,222 +2,578 @@ package net.codecrete.usb.windows.gen.usbioctl; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _USB_DESCRIPTOR_REQUEST { * ULONG ConnectionIndex; - * struct SetupPacket; + * struct { + * UCHAR bmRequest; + * UCHAR bRequest; + * USHORT wValue; + * USHORT wIndex; + * USHORT wLength; + * } SetupPacket; * UCHAR Data[0]; - * }; + * } * } */ public class _USB_DESCRIPTOR_REQUEST { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + _USB_DESCRIPTOR_REQUEST() { + // Should not be called directly } - public static VarHandle ConnectionIndex$VH() { - return constants$0.const$1; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + USBIoctl.align(USBIoctl.C_LONG, 1).withName("ConnectionIndex"), + _USB_DESCRIPTOR_REQUEST.SetupPacket.layout().withName("SetupPacket"), + MemoryLayout.sequenceLayout(0, USBIoctl.C_CHAR).withName("Data") + ).withName("_USB_DESCRIPTOR_REQUEST"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt ConnectionIndex$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ConnectionIndex")); + /** - * Getter for field: - * {@snippet : - * ULONG ConnectionIndex; + * Layout for field: + * {@snippet lang=c : + * ULONG ConnectionIndex * } */ - public static int ConnectionIndex$get(MemorySegment seg) { - return (int)constants$0.const$1.get(seg); + public static final OfInt ConnectionIndex$layout() { + return ConnectionIndex$LAYOUT; } + + private static final long ConnectionIndex$OFFSET = 0; + /** - * Setter for field: - * {@snippet : - * ULONG ConnectionIndex; + * Offset for field: + * {@snippet lang=c : + * ULONG ConnectionIndex * } */ - public static void ConnectionIndex$set(MemorySegment seg, int x) { - constants$0.const$1.set(seg, x); + public static final long ConnectionIndex$offset() { + return ConnectionIndex$OFFSET; } - public static int ConnectionIndex$get(MemorySegment seg, long index) { - return (int)constants$0.const$1.get(seg.asSlice(index*sizeof())); + + /** + * Getter for field: + * {@snippet lang=c : + * ULONG ConnectionIndex + * } + */ + public static int ConnectionIndex(MemorySegment struct) { + return struct.get(ConnectionIndex$LAYOUT, ConnectionIndex$OFFSET); } - public static void ConnectionIndex$set(MemorySegment seg, long index, int x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + /** + * Setter for field: + * {@snippet lang=c : + * ULONG ConnectionIndex + * } + */ + public static void ConnectionIndex(MemorySegment struct, int fieldValue) { + struct.set(ConnectionIndex$LAYOUT, ConnectionIndex$OFFSET, fieldValue); } + /** - * {@snippet : + * {@snippet lang=c : * struct { * UCHAR bmRequest; * UCHAR bRequest; * USHORT wValue; * USHORT wIndex; * USHORT wLength; - * }; + * } * } */ - public static final class SetupPacket { + public static class SetupPacket { + + SetupPacket() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + USBIoctl.C_CHAR.withName("bmRequest"), + USBIoctl.C_CHAR.withName("bRequest"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("wValue"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("wIndex"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("wLength") + ).withName("$anon$971:5"); - // Suppresses default constructor, ensuring non-instantiability. - private SetupPacket() {} - public static MemoryLayout $LAYOUT() { - return constants$0.const$2; + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte bmRequest$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bmRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bmRequest + * } + */ + public static final OfByte bmRequest$layout() { + return bmRequest$LAYOUT; } - public static VarHandle bmRequest$VH() { - return constants$0.const$3; + + private static final long bmRequest$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bmRequest + * } + */ + public static final long bmRequest$offset() { + return bmRequest$OFFSET; } + /** * Getter for field: - * {@snippet : - * UCHAR bmRequest; + * {@snippet lang=c : + * UCHAR bmRequest * } */ - public static byte bmRequest$get(MemorySegment seg) { - return (byte)constants$0.const$3.get(seg); + public static byte bmRequest(MemorySegment struct) { + return struct.get(bmRequest$LAYOUT, bmRequest$OFFSET); } + /** * Setter for field: - * {@snippet : - * UCHAR bmRequest; + * {@snippet lang=c : + * UCHAR bmRequest * } */ - public static void bmRequest$set(MemorySegment seg, byte x) { - constants$0.const$3.set(seg, x); - } - public static byte bmRequest$get(MemorySegment seg, long index) { - return (byte)constants$0.const$3.get(seg.asSlice(index*sizeof())); + public static void bmRequest(MemorySegment struct, byte fieldValue) { + struct.set(bmRequest$LAYOUT, bmRequest$OFFSET, fieldValue); } - public static void bmRequest$set(MemorySegment seg, long index, byte x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte bRequest$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bRequest")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bRequest + * } + */ + public static final OfByte bRequest$layout() { + return bRequest$LAYOUT; } - public static VarHandle bRequest$VH() { - return constants$0.const$4; + + private static final long bRequest$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bRequest + * } + */ + public static final long bRequest$offset() { + return bRequest$OFFSET; } + /** * Getter for field: - * {@snippet : - * UCHAR bRequest; + * {@snippet lang=c : + * UCHAR bRequest * } */ - public static byte bRequest$get(MemorySegment seg) { - return (byte)constants$0.const$4.get(seg); + public static byte bRequest(MemorySegment struct) { + return struct.get(bRequest$LAYOUT, bRequest$OFFSET); } + /** * Setter for field: - * {@snippet : - * UCHAR bRequest; + * {@snippet lang=c : + * UCHAR bRequest * } */ - public static void bRequest$set(MemorySegment seg, byte x) { - constants$0.const$4.set(seg, x); + public static void bRequest(MemorySegment struct, byte fieldValue) { + struct.set(bRequest$LAYOUT, bRequest$OFFSET, fieldValue); } - public static byte bRequest$get(MemorySegment seg, long index) { - return (byte)constants$0.const$4.get(seg.asSlice(index*sizeof())); - } - public static void bRequest$set(MemorySegment seg, long index, byte x) { - constants$0.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wValue$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wValue")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT wValue + * } + */ + public static final OfShort wValue$layout() { + return wValue$LAYOUT; } - public static VarHandle wValue$VH() { - return constants$0.const$5; + + private static final long wValue$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT wValue + * } + */ + public static final long wValue$offset() { + return wValue$OFFSET; } + /** * Getter for field: - * {@snippet : - * USHORT wValue; + * {@snippet lang=c : + * USHORT wValue * } */ - public static short wValue$get(MemorySegment seg) { - return (short)constants$0.const$5.get(seg); + public static short wValue(MemorySegment struct) { + return struct.get(wValue$LAYOUT, wValue$OFFSET); } + /** * Setter for field: - * {@snippet : - * USHORT wValue; + * {@snippet lang=c : + * USHORT wValue * } */ - public static void wValue$set(MemorySegment seg, short x) { - constants$0.const$5.set(seg, x); - } - public static short wValue$get(MemorySegment seg, long index) { - return (short)constants$0.const$5.get(seg.asSlice(index*sizeof())); + public static void wValue(MemorySegment struct, short fieldValue) { + struct.set(wValue$LAYOUT, wValue$OFFSET, fieldValue); } - public static void wValue$set(MemorySegment seg, long index, short x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wIndex$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wIndex")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT wIndex + * } + */ + public static final OfShort wIndex$layout() { + return wIndex$LAYOUT; } - public static VarHandle wIndex$VH() { - return constants$1.const$0; + + private static final long wIndex$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT wIndex + * } + */ + public static final long wIndex$offset() { + return wIndex$OFFSET; } + /** * Getter for field: - * {@snippet : - * USHORT wIndex; + * {@snippet lang=c : + * USHORT wIndex * } */ - public static short wIndex$get(MemorySegment seg) { - return (short)constants$1.const$0.get(seg); + public static short wIndex(MemorySegment struct) { + return struct.get(wIndex$LAYOUT, wIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * USHORT wIndex; + * {@snippet lang=c : + * USHORT wIndex * } */ - public static void wIndex$set(MemorySegment seg, short x) { - constants$1.const$0.set(seg, x); - } - public static short wIndex$get(MemorySegment seg, long index) { - return (short)constants$1.const$0.get(seg.asSlice(index*sizeof())); + public static void wIndex(MemorySegment struct, short fieldValue) { + struct.set(wIndex$LAYOUT, wIndex$OFFSET, fieldValue); } - public static void wIndex$set(MemorySegment seg, long index, short x) { - constants$1.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort wLength$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wLength")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT wLength + * } + */ + public static final OfShort wLength$layout() { + return wLength$LAYOUT; } - public static VarHandle wLength$VH() { - return constants$1.const$1; + + private static final long wLength$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT wLength + * } + */ + public static final long wLength$offset() { + return wLength$OFFSET; } + /** * Getter for field: - * {@snippet : - * USHORT wLength; + * {@snippet lang=c : + * USHORT wLength * } */ - public static short wLength$get(MemorySegment seg) { - return (short)constants$1.const$1.get(seg); + public static short wLength(MemorySegment struct) { + return struct.get(wLength$LAYOUT, wLength$OFFSET); } + /** * Setter for field: - * {@snippet : - * USHORT wLength; + * {@snippet lang=c : + * USHORT wLength * } */ - public static void wLength$set(MemorySegment seg, short x) { - constants$1.const$1.set(seg, x); + public static void wLength(MemorySegment struct, short fieldValue) { + struct.set(wLength$LAYOUT, wLength$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static short wLength$get(MemorySegment seg, long index) { - return (short)constants$1.const$1.get(seg.asSlice(index*sizeof())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static void wLength$set(MemorySegment seg, long index, short x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - public static MemorySegment SetupPacket$slice(MemorySegment seg) { - return seg.asSlice(4, 8); + private static final GroupLayout SetupPacket$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("SetupPacket")); + + /** + * Layout for field: + * {@snippet lang=c : + * struct { + * UCHAR bmRequest; + * UCHAR bRequest; + * USHORT wValue; + * USHORT wIndex; + * USHORT wLength; + * } SetupPacket + * } + */ + public static final GroupLayout SetupPacket$layout() { + return SetupPacket$LAYOUT; } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + private static final long SetupPacket$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * struct { + * UCHAR bmRequest; + * UCHAR bRequest; + * USHORT wValue; + * USHORT wIndex; + * USHORT wLength; + * } SetupPacket + * } + */ + public static final long SetupPacket$offset() { + return SetupPacket$OFFSET; } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Getter for field: + * {@snippet lang=c : + * struct { + * UCHAR bmRequest; + * UCHAR bRequest; + * USHORT wValue; + * USHORT wIndex; + * USHORT wLength; + * } SetupPacket + * } + */ + public static MemorySegment SetupPacket(MemorySegment struct) { + return struct.asSlice(SetupPacket$OFFSET, SetupPacket$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * struct { + * UCHAR bmRequest; + * UCHAR bRequest; + * USHORT wValue; + * USHORT wIndex; + * USHORT wLength; + * } SetupPacket + * } + */ + public static void SetupPacket(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, SetupPacket$OFFSET, SetupPacket$LAYOUT.byteSize()); + } + + private static final SequenceLayout Data$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("Data")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static final SequenceLayout Data$layout() { + return Data$LAYOUT; + } + + private static final long Data$OFFSET = 12; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static final long Data$offset() { + return Data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static MemorySegment Data(MemorySegment struct) { + return struct.asSlice(Data$OFFSET, Data$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static void Data(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, Data$OFFSET, Data$LAYOUT.byteSize()); + } + + private static long[] Data$DIMS = { 0 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static long[] Data$dimensions() { + return Data$DIMS; + } + private static final VarHandle Data$ELEM_HANDLE = Data$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static byte Data(MemorySegment struct, long index0) { + return (byte)Data$ELEM_HANDLE.get(struct, 0L, index0); + } + + /** + * Indexed setter for field: + * {@snippet lang=c : + * UCHAR Data[0] + * } + */ + public static void Data(MemorySegment struct, long index0, byte fieldValue) { + Data$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DEVICE_DESCRIPTOR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DEVICE_DESCRIPTOR.java new file mode 100644 index 0000000..c8c41cb --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_DEVICE_DESCRIPTOR.java @@ -0,0 +1,725 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.usbioctl; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct _USB_DEVICE_DESCRIPTOR { + * UCHAR bLength; + * UCHAR bDescriptorType; + * USHORT bcdUSB; + * UCHAR bDeviceClass; + * UCHAR bDeviceSubClass; + * UCHAR bDeviceProtocol; + * UCHAR bMaxPacketSize0; + * USHORT idVendor; + * USHORT idProduct; + * USHORT bcdDevice; + * UCHAR iManufacturer; + * UCHAR iProduct; + * UCHAR iSerialNumber; + * UCHAR bNumConfigurations; + * } + * } + */ +public class _USB_DEVICE_DESCRIPTOR { + + _USB_DEVICE_DESCRIPTOR() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + USBIoctl.C_CHAR.withName("bLength"), + USBIoctl.C_CHAR.withName("bDescriptorType"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("bcdUSB"), + USBIoctl.C_CHAR.withName("bDeviceClass"), + USBIoctl.C_CHAR.withName("bDeviceSubClass"), + USBIoctl.C_CHAR.withName("bDeviceProtocol"), + USBIoctl.C_CHAR.withName("bMaxPacketSize0"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("idVendor"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("idProduct"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("bcdDevice"), + USBIoctl.C_CHAR.withName("iManufacturer"), + USBIoctl.C_CHAR.withName("iProduct"), + USBIoctl.C_CHAR.withName("iSerialNumber"), + USBIoctl.C_CHAR.withName("bNumConfigurations") + ).withName("_USB_DEVICE_DESCRIPTOR"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte bLength$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bLength")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static final OfByte bLength$layout() { + return bLength$LAYOUT; + } + + private static final long bLength$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static final long bLength$offset() { + return bLength$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static byte bLength(MemorySegment struct) { + return struct.get(bLength$LAYOUT, bLength$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static void bLength(MemorySegment struct, byte fieldValue) { + struct.set(bLength$LAYOUT, bLength$OFFSET, fieldValue); + } + + private static final OfByte bDescriptorType$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bDescriptorType")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static final OfByte bDescriptorType$layout() { + return bDescriptorType$LAYOUT; + } + + private static final long bDescriptorType$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static final long bDescriptorType$offset() { + return bDescriptorType$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static byte bDescriptorType(MemorySegment struct) { + return struct.get(bDescriptorType$LAYOUT, bDescriptorType$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static void bDescriptorType(MemorySegment struct, byte fieldValue) { + struct.set(bDescriptorType$LAYOUT, bDescriptorType$OFFSET, fieldValue); + } + + private static final OfShort bcdUSB$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bcdUSB")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT bcdUSB + * } + */ + public static final OfShort bcdUSB$layout() { + return bcdUSB$LAYOUT; + } + + private static final long bcdUSB$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT bcdUSB + * } + */ + public static final long bcdUSB$offset() { + return bcdUSB$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USHORT bcdUSB + * } + */ + public static short bcdUSB(MemorySegment struct) { + return struct.get(bcdUSB$LAYOUT, bcdUSB$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USHORT bcdUSB + * } + */ + public static void bcdUSB(MemorySegment struct, short fieldValue) { + struct.set(bcdUSB$LAYOUT, bcdUSB$OFFSET, fieldValue); + } + + private static final OfByte bDeviceClass$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bDeviceClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bDeviceClass + * } + */ + public static final OfByte bDeviceClass$layout() { + return bDeviceClass$LAYOUT; + } + + private static final long bDeviceClass$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bDeviceClass + * } + */ + public static final long bDeviceClass$offset() { + return bDeviceClass$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bDeviceClass + * } + */ + public static byte bDeviceClass(MemorySegment struct) { + return struct.get(bDeviceClass$LAYOUT, bDeviceClass$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bDeviceClass + * } + */ + public static void bDeviceClass(MemorySegment struct, byte fieldValue) { + struct.set(bDeviceClass$LAYOUT, bDeviceClass$OFFSET, fieldValue); + } + + private static final OfByte bDeviceSubClass$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bDeviceSubClass")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bDeviceSubClass + * } + */ + public static final OfByte bDeviceSubClass$layout() { + return bDeviceSubClass$LAYOUT; + } + + private static final long bDeviceSubClass$OFFSET = 5; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bDeviceSubClass + * } + */ + public static final long bDeviceSubClass$offset() { + return bDeviceSubClass$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bDeviceSubClass + * } + */ + public static byte bDeviceSubClass(MemorySegment struct) { + return struct.get(bDeviceSubClass$LAYOUT, bDeviceSubClass$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bDeviceSubClass + * } + */ + public static void bDeviceSubClass(MemorySegment struct, byte fieldValue) { + struct.set(bDeviceSubClass$LAYOUT, bDeviceSubClass$OFFSET, fieldValue); + } + + private static final OfByte bDeviceProtocol$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bDeviceProtocol")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bDeviceProtocol + * } + */ + public static final OfByte bDeviceProtocol$layout() { + return bDeviceProtocol$LAYOUT; + } + + private static final long bDeviceProtocol$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bDeviceProtocol + * } + */ + public static final long bDeviceProtocol$offset() { + return bDeviceProtocol$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bDeviceProtocol + * } + */ + public static byte bDeviceProtocol(MemorySegment struct) { + return struct.get(bDeviceProtocol$LAYOUT, bDeviceProtocol$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bDeviceProtocol + * } + */ + public static void bDeviceProtocol(MemorySegment struct, byte fieldValue) { + struct.set(bDeviceProtocol$LAYOUT, bDeviceProtocol$OFFSET, fieldValue); + } + + private static final OfByte bMaxPacketSize0$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bMaxPacketSize0")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bMaxPacketSize0 + * } + */ + public static final OfByte bMaxPacketSize0$layout() { + return bMaxPacketSize0$LAYOUT; + } + + private static final long bMaxPacketSize0$OFFSET = 7; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bMaxPacketSize0 + * } + */ + public static final long bMaxPacketSize0$offset() { + return bMaxPacketSize0$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bMaxPacketSize0 + * } + */ + public static byte bMaxPacketSize0(MemorySegment struct) { + return struct.get(bMaxPacketSize0$LAYOUT, bMaxPacketSize0$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bMaxPacketSize0 + * } + */ + public static void bMaxPacketSize0(MemorySegment struct, byte fieldValue) { + struct.set(bMaxPacketSize0$LAYOUT, bMaxPacketSize0$OFFSET, fieldValue); + } + + private static final OfShort idVendor$LAYOUT = (OfShort)$LAYOUT.select(groupElement("idVendor")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT idVendor + * } + */ + public static final OfShort idVendor$layout() { + return idVendor$LAYOUT; + } + + private static final long idVendor$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT idVendor + * } + */ + public static final long idVendor$offset() { + return idVendor$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USHORT idVendor + * } + */ + public static short idVendor(MemorySegment struct) { + return struct.get(idVendor$LAYOUT, idVendor$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USHORT idVendor + * } + */ + public static void idVendor(MemorySegment struct, short fieldValue) { + struct.set(idVendor$LAYOUT, idVendor$OFFSET, fieldValue); + } + + private static final OfShort idProduct$LAYOUT = (OfShort)$LAYOUT.select(groupElement("idProduct")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT idProduct + * } + */ + public static final OfShort idProduct$layout() { + return idProduct$LAYOUT; + } + + private static final long idProduct$OFFSET = 10; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT idProduct + * } + */ + public static final long idProduct$offset() { + return idProduct$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USHORT idProduct + * } + */ + public static short idProduct(MemorySegment struct) { + return struct.get(idProduct$LAYOUT, idProduct$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USHORT idProduct + * } + */ + public static void idProduct(MemorySegment struct, short fieldValue) { + struct.set(idProduct$LAYOUT, idProduct$OFFSET, fieldValue); + } + + private static final OfShort bcdDevice$LAYOUT = (OfShort)$LAYOUT.select(groupElement("bcdDevice")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT bcdDevice + * } + */ + public static final OfShort bcdDevice$layout() { + return bcdDevice$LAYOUT; + } + + private static final long bcdDevice$OFFSET = 12; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT bcdDevice + * } + */ + public static final long bcdDevice$offset() { + return bcdDevice$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USHORT bcdDevice + * } + */ + public static short bcdDevice(MemorySegment struct) { + return struct.get(bcdDevice$LAYOUT, bcdDevice$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USHORT bcdDevice + * } + */ + public static void bcdDevice(MemorySegment struct, short fieldValue) { + struct.set(bcdDevice$LAYOUT, bcdDevice$OFFSET, fieldValue); + } + + private static final OfByte iManufacturer$LAYOUT = (OfByte)$LAYOUT.select(groupElement("iManufacturer")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR iManufacturer + * } + */ + public static final OfByte iManufacturer$layout() { + return iManufacturer$LAYOUT; + } + + private static final long iManufacturer$OFFSET = 14; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR iManufacturer + * } + */ + public static final long iManufacturer$offset() { + return iManufacturer$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR iManufacturer + * } + */ + public static byte iManufacturer(MemorySegment struct) { + return struct.get(iManufacturer$LAYOUT, iManufacturer$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR iManufacturer + * } + */ + public static void iManufacturer(MemorySegment struct, byte fieldValue) { + struct.set(iManufacturer$LAYOUT, iManufacturer$OFFSET, fieldValue); + } + + private static final OfByte iProduct$LAYOUT = (OfByte)$LAYOUT.select(groupElement("iProduct")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR iProduct + * } + */ + public static final OfByte iProduct$layout() { + return iProduct$LAYOUT; + } + + private static final long iProduct$OFFSET = 15; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR iProduct + * } + */ + public static final long iProduct$offset() { + return iProduct$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR iProduct + * } + */ + public static byte iProduct(MemorySegment struct) { + return struct.get(iProduct$LAYOUT, iProduct$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR iProduct + * } + */ + public static void iProduct(MemorySegment struct, byte fieldValue) { + struct.set(iProduct$LAYOUT, iProduct$OFFSET, fieldValue); + } + + private static final OfByte iSerialNumber$LAYOUT = (OfByte)$LAYOUT.select(groupElement("iSerialNumber")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR iSerialNumber + * } + */ + public static final OfByte iSerialNumber$layout() { + return iSerialNumber$LAYOUT; + } + + private static final long iSerialNumber$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR iSerialNumber + * } + */ + public static final long iSerialNumber$offset() { + return iSerialNumber$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR iSerialNumber + * } + */ + public static byte iSerialNumber(MemorySegment struct) { + return struct.get(iSerialNumber$LAYOUT, iSerialNumber$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR iSerialNumber + * } + */ + public static void iSerialNumber(MemorySegment struct, byte fieldValue) { + struct.set(iSerialNumber$LAYOUT, iSerialNumber$OFFSET, fieldValue); + } + + private static final OfByte bNumConfigurations$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bNumConfigurations")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bNumConfigurations + * } + */ + public static final OfByte bNumConfigurations$layout() { + return bNumConfigurations$LAYOUT; + } + + private static final long bNumConfigurations$OFFSET = 17; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bNumConfigurations + * } + */ + public static final long bNumConfigurations$offset() { + return bNumConfigurations$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bNumConfigurations + * } + */ + public static byte bNumConfigurations(MemorySegment struct) { + return struct.get(bNumConfigurations$LAYOUT, bNumConfigurations$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bNumConfigurations + * } + */ + public static void bNumConfigurations(MemorySegment struct, byte fieldValue) { + struct.set(bNumConfigurations$LAYOUT, bNumConfigurations$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_ENDPOINT_DESCRIPTOR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_ENDPOINT_DESCRIPTOR.java new file mode 100644 index 0000000..965cedf --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_ENDPOINT_DESCRIPTOR.java @@ -0,0 +1,357 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.usbioctl; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct _USB_ENDPOINT_DESCRIPTOR { + * UCHAR bLength; + * UCHAR bDescriptorType; + * UCHAR bEndpointAddress; + * UCHAR bmAttributes; + * USHORT wMaxPacketSize; + * UCHAR bInterval; + * } + * } + */ +public class _USB_ENDPOINT_DESCRIPTOR { + + _USB_ENDPOINT_DESCRIPTOR() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + USBIoctl.C_CHAR.withName("bLength"), + USBIoctl.C_CHAR.withName("bDescriptorType"), + USBIoctl.C_CHAR.withName("bEndpointAddress"), + USBIoctl.C_CHAR.withName("bmAttributes"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("wMaxPacketSize"), + USBIoctl.C_CHAR.withName("bInterval") + ).withName("_USB_ENDPOINT_DESCRIPTOR"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte bLength$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bLength")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static final OfByte bLength$layout() { + return bLength$LAYOUT; + } + + private static final long bLength$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static final long bLength$offset() { + return bLength$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static byte bLength(MemorySegment struct) { + return struct.get(bLength$LAYOUT, bLength$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bLength + * } + */ + public static void bLength(MemorySegment struct, byte fieldValue) { + struct.set(bLength$LAYOUT, bLength$OFFSET, fieldValue); + } + + private static final OfByte bDescriptorType$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bDescriptorType")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static final OfByte bDescriptorType$layout() { + return bDescriptorType$LAYOUT; + } + + private static final long bDescriptorType$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static final long bDescriptorType$offset() { + return bDescriptorType$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static byte bDescriptorType(MemorySegment struct) { + return struct.get(bDescriptorType$LAYOUT, bDescriptorType$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bDescriptorType + * } + */ + public static void bDescriptorType(MemorySegment struct, byte fieldValue) { + struct.set(bDescriptorType$LAYOUT, bDescriptorType$OFFSET, fieldValue); + } + + private static final OfByte bEndpointAddress$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bEndpointAddress")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bEndpointAddress + * } + */ + public static final OfByte bEndpointAddress$layout() { + return bEndpointAddress$LAYOUT; + } + + private static final long bEndpointAddress$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bEndpointAddress + * } + */ + public static final long bEndpointAddress$offset() { + return bEndpointAddress$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bEndpointAddress + * } + */ + public static byte bEndpointAddress(MemorySegment struct) { + return struct.get(bEndpointAddress$LAYOUT, bEndpointAddress$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bEndpointAddress + * } + */ + public static void bEndpointAddress(MemorySegment struct, byte fieldValue) { + struct.set(bEndpointAddress$LAYOUT, bEndpointAddress$OFFSET, fieldValue); + } + + private static final OfByte bmAttributes$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bmAttributes")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bmAttributes + * } + */ + public static final OfByte bmAttributes$layout() { + return bmAttributes$LAYOUT; + } + + private static final long bmAttributes$OFFSET = 3; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bmAttributes + * } + */ + public static final long bmAttributes$offset() { + return bmAttributes$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bmAttributes + * } + */ + public static byte bmAttributes(MemorySegment struct) { + return struct.get(bmAttributes$LAYOUT, bmAttributes$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bmAttributes + * } + */ + public static void bmAttributes(MemorySegment struct, byte fieldValue) { + struct.set(bmAttributes$LAYOUT, bmAttributes$OFFSET, fieldValue); + } + + private static final OfShort wMaxPacketSize$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wMaxPacketSize")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT wMaxPacketSize + * } + */ + public static final OfShort wMaxPacketSize$layout() { + return wMaxPacketSize$LAYOUT; + } + + private static final long wMaxPacketSize$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT wMaxPacketSize + * } + */ + public static final long wMaxPacketSize$offset() { + return wMaxPacketSize$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USHORT wMaxPacketSize + * } + */ + public static short wMaxPacketSize(MemorySegment struct) { + return struct.get(wMaxPacketSize$LAYOUT, wMaxPacketSize$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USHORT wMaxPacketSize + * } + */ + public static void wMaxPacketSize(MemorySegment struct, short fieldValue) { + struct.set(wMaxPacketSize$LAYOUT, wMaxPacketSize$OFFSET, fieldValue); + } + + private static final OfByte bInterval$LAYOUT = (OfByte)$LAYOUT.select(groupElement("bInterval")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR bInterval + * } + */ + public static final OfByte bInterval$layout() { + return bInterval$LAYOUT; + } + + private static final long bInterval$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR bInterval + * } + */ + public static final long bInterval$offset() { + return bInterval$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UCHAR bInterval + * } + */ + public static byte bInterval(MemorySegment struct) { + return struct.get(bInterval$LAYOUT, bInterval$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UCHAR bInterval + * } + */ + public static void bInterval(MemorySegment struct, byte fieldValue) { + struct.set(bInterval$LAYOUT, bInterval$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java index 4527cde..199c11c 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java @@ -2,13 +2,18 @@ package net.codecrete.usb.windows.gen.usbioctl; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _USB_NODE_CONNECTION_INFORMATION_EX { * ULONG ConnectionIndex; * USB_DEVICE_DESCRIPTOR DeviceDescriptor; @@ -19,212 +24,509 @@ * ULONG NumberOfOpenPipes; * USB_CONNECTION_STATUS ConnectionStatus; * USB_PIPE_INFO PipeList[0]; - * }; + * } * } */ public class _USB_NODE_CONNECTION_INFORMATION_EX { - public static MemoryLayout $LAYOUT() { - return constants$1.const$2; + _USB_NODE_CONNECTION_INFORMATION_EX() { + // Should not be called directly } - public static VarHandle ConnectionIndex$VH() { - return constants$1.const$3; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + USBIoctl.align(USBIoctl.C_LONG, 1).withName("ConnectionIndex"), + _USB_DEVICE_DESCRIPTOR.layout().withName("DeviceDescriptor"), + USBIoctl.C_CHAR.withName("CurrentConfigurationValue"), + USBIoctl.C_CHAR.withName("Speed"), + USBIoctl.C_CHAR.withName("DeviceIsHub"), + USBIoctl.align(USBIoctl.C_SHORT, 1).withName("DeviceAddress"), + USBIoctl.align(USBIoctl.C_LONG, 1).withName("NumberOfOpenPipes"), + USBIoctl.align(USBIoctl.C_INT, 1).withName("ConnectionStatus"), + MemoryLayout.sequenceLayout(0, _USB_PIPE_INFO.layout()).withName("PipeList") + ).withName("_USB_NODE_CONNECTION_INFORMATION_EX"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final OfInt ConnectionIndex$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ConnectionIndex")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG ConnectionIndex + * } + */ + public static final OfInt ConnectionIndex$layout() { + return ConnectionIndex$LAYOUT; + } + + private static final long ConnectionIndex$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG ConnectionIndex + * } + */ + public static final long ConnectionIndex$offset() { + return ConnectionIndex$OFFSET; + } + /** * Getter for field: - * {@snippet : - * ULONG ConnectionIndex; + * {@snippet lang=c : + * ULONG ConnectionIndex * } */ - public static int ConnectionIndex$get(MemorySegment seg) { - return (int)constants$1.const$3.get(seg); + public static int ConnectionIndex(MemorySegment struct) { + return struct.get(ConnectionIndex$LAYOUT, ConnectionIndex$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG ConnectionIndex; + * {@snippet lang=c : + * ULONG ConnectionIndex * } */ - public static void ConnectionIndex$set(MemorySegment seg, int x) { - constants$1.const$3.set(seg, x); + public static void ConnectionIndex(MemorySegment struct, int fieldValue) { + struct.set(ConnectionIndex$LAYOUT, ConnectionIndex$OFFSET, fieldValue); } - public static int ConnectionIndex$get(MemorySegment seg, long index) { - return (int)constants$1.const$3.get(seg.asSlice(index*sizeof())); + + private static final GroupLayout DeviceDescriptor$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("DeviceDescriptor")); + + /** + * Layout for field: + * {@snippet lang=c : + * USB_DEVICE_DESCRIPTOR DeviceDescriptor + * } + */ + public static final GroupLayout DeviceDescriptor$layout() { + return DeviceDescriptor$LAYOUT; + } + + private static final long DeviceDescriptor$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * USB_DEVICE_DESCRIPTOR DeviceDescriptor + * } + */ + public static final long DeviceDescriptor$offset() { + return DeviceDescriptor$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USB_DEVICE_DESCRIPTOR DeviceDescriptor + * } + */ + public static MemorySegment DeviceDescriptor(MemorySegment struct) { + return struct.asSlice(DeviceDescriptor$OFFSET, DeviceDescriptor$LAYOUT.byteSize()); } - public static void ConnectionIndex$set(MemorySegment seg, long index, int x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + /** + * Setter for field: + * {@snippet lang=c : + * USB_DEVICE_DESCRIPTOR DeviceDescriptor + * } + */ + public static void DeviceDescriptor(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, DeviceDescriptor$OFFSET, DeviceDescriptor$LAYOUT.byteSize()); } - public static MemorySegment DeviceDescriptor$slice(MemorySegment seg) { - return seg.asSlice(4, 18); + + private static final OfByte CurrentConfigurationValue$LAYOUT = (OfByte)$LAYOUT.select(groupElement("CurrentConfigurationValue")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR CurrentConfigurationValue + * } + */ + public static final OfByte CurrentConfigurationValue$layout() { + return CurrentConfigurationValue$LAYOUT; } - public static VarHandle CurrentConfigurationValue$VH() { - return constants$1.const$4; + + private static final long CurrentConfigurationValue$OFFSET = 22; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR CurrentConfigurationValue + * } + */ + public static final long CurrentConfigurationValue$offset() { + return CurrentConfigurationValue$OFFSET; } + /** * Getter for field: - * {@snippet : - * UCHAR CurrentConfigurationValue; + * {@snippet lang=c : + * UCHAR CurrentConfigurationValue * } */ - public static byte CurrentConfigurationValue$get(MemorySegment seg) { - return (byte)constants$1.const$4.get(seg); + public static byte CurrentConfigurationValue(MemorySegment struct) { + return struct.get(CurrentConfigurationValue$LAYOUT, CurrentConfigurationValue$OFFSET); } + /** * Setter for field: - * {@snippet : - * UCHAR CurrentConfigurationValue; + * {@snippet lang=c : + * UCHAR CurrentConfigurationValue * } */ - public static void CurrentConfigurationValue$set(MemorySegment seg, byte x) { - constants$1.const$4.set(seg, x); - } - public static byte CurrentConfigurationValue$get(MemorySegment seg, long index) { - return (byte)constants$1.const$4.get(seg.asSlice(index*sizeof())); + public static void CurrentConfigurationValue(MemorySegment struct, byte fieldValue) { + struct.set(CurrentConfigurationValue$LAYOUT, CurrentConfigurationValue$OFFSET, fieldValue); } - public static void CurrentConfigurationValue$set(MemorySegment seg, long index, byte x) { - constants$1.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte Speed$LAYOUT = (OfByte)$LAYOUT.select(groupElement("Speed")); + + /** + * Layout for field: + * {@snippet lang=c : + * UCHAR Speed + * } + */ + public static final OfByte Speed$layout() { + return Speed$LAYOUT; } - public static VarHandle Speed$VH() { - return constants$1.const$5; + + private static final long Speed$OFFSET = 23; + + /** + * Offset for field: + * {@snippet lang=c : + * UCHAR Speed + * } + */ + public static final long Speed$offset() { + return Speed$OFFSET; } + /** * Getter for field: - * {@snippet : - * UCHAR Speed; + * {@snippet lang=c : + * UCHAR Speed * } */ - public static byte Speed$get(MemorySegment seg) { - return (byte)constants$1.const$5.get(seg); + public static byte Speed(MemorySegment struct) { + return struct.get(Speed$LAYOUT, Speed$OFFSET); } + /** * Setter for field: - * {@snippet : - * UCHAR Speed; + * {@snippet lang=c : + * UCHAR Speed * } */ - public static void Speed$set(MemorySegment seg, byte x) { - constants$1.const$5.set(seg, x); + public static void Speed(MemorySegment struct, byte fieldValue) { + struct.set(Speed$LAYOUT, Speed$OFFSET, fieldValue); } - public static byte Speed$get(MemorySegment seg, long index) { - return (byte)constants$1.const$5.get(seg.asSlice(index*sizeof())); - } - public static void Speed$set(MemorySegment seg, long index, byte x) { - constants$1.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfByte DeviceIsHub$LAYOUT = (OfByte)$LAYOUT.select(groupElement("DeviceIsHub")); + + /** + * Layout for field: + * {@snippet lang=c : + * BOOLEAN DeviceIsHub + * } + */ + public static final OfByte DeviceIsHub$layout() { + return DeviceIsHub$LAYOUT; } - public static VarHandle DeviceIsHub$VH() { - return constants$2.const$0; + + private static final long DeviceIsHub$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * BOOLEAN DeviceIsHub + * } + */ + public static final long DeviceIsHub$offset() { + return DeviceIsHub$OFFSET; } + /** * Getter for field: - * {@snippet : - * BOOLEAN DeviceIsHub; + * {@snippet lang=c : + * BOOLEAN DeviceIsHub * } */ - public static byte DeviceIsHub$get(MemorySegment seg) { - return (byte)constants$2.const$0.get(seg); + public static byte DeviceIsHub(MemorySegment struct) { + return struct.get(DeviceIsHub$LAYOUT, DeviceIsHub$OFFSET); } + /** * Setter for field: - * {@snippet : - * BOOLEAN DeviceIsHub; + * {@snippet lang=c : + * BOOLEAN DeviceIsHub * } */ - public static void DeviceIsHub$set(MemorySegment seg, byte x) { - constants$2.const$0.set(seg, x); - } - public static byte DeviceIsHub$get(MemorySegment seg, long index) { - return (byte)constants$2.const$0.get(seg.asSlice(index*sizeof())); + public static void DeviceIsHub(MemorySegment struct, byte fieldValue) { + struct.set(DeviceIsHub$LAYOUT, DeviceIsHub$OFFSET, fieldValue); } - public static void DeviceIsHub$set(MemorySegment seg, long index, byte x) { - constants$2.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final OfShort DeviceAddress$LAYOUT = (OfShort)$LAYOUT.select(groupElement("DeviceAddress")); + + /** + * Layout for field: + * {@snippet lang=c : + * USHORT DeviceAddress + * } + */ + public static final OfShort DeviceAddress$layout() { + return DeviceAddress$LAYOUT; } - public static VarHandle DeviceAddress$VH() { - return constants$2.const$1; + + private static final long DeviceAddress$OFFSET = 25; + + /** + * Offset for field: + * {@snippet lang=c : + * USHORT DeviceAddress + * } + */ + public static final long DeviceAddress$offset() { + return DeviceAddress$OFFSET; } + /** * Getter for field: - * {@snippet : - * USHORT DeviceAddress; + * {@snippet lang=c : + * USHORT DeviceAddress * } */ - public static short DeviceAddress$get(MemorySegment seg) { - return (short)constants$2.const$1.get(seg); + public static short DeviceAddress(MemorySegment struct) { + return struct.get(DeviceAddress$LAYOUT, DeviceAddress$OFFSET); } + /** * Setter for field: - * {@snippet : - * USHORT DeviceAddress; + * {@snippet lang=c : + * USHORT DeviceAddress * } */ - public static void DeviceAddress$set(MemorySegment seg, short x) { - constants$2.const$1.set(seg, x); - } - public static short DeviceAddress$get(MemorySegment seg, long index) { - return (short)constants$2.const$1.get(seg.asSlice(index*sizeof())); + public static void DeviceAddress(MemorySegment struct, short fieldValue) { + struct.set(DeviceAddress$LAYOUT, DeviceAddress$OFFSET, fieldValue); } - public static void DeviceAddress$set(MemorySegment seg, long index, short x) { - constants$2.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt NumberOfOpenPipes$LAYOUT = (OfInt)$LAYOUT.select(groupElement("NumberOfOpenPipes")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG NumberOfOpenPipes + * } + */ + public static final OfInt NumberOfOpenPipes$layout() { + return NumberOfOpenPipes$LAYOUT; } - public static VarHandle NumberOfOpenPipes$VH() { - return constants$2.const$2; + + private static final long NumberOfOpenPipes$OFFSET = 27; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG NumberOfOpenPipes + * } + */ + public static final long NumberOfOpenPipes$offset() { + return NumberOfOpenPipes$OFFSET; } + /** * Getter for field: - * {@snippet : - * ULONG NumberOfOpenPipes; + * {@snippet lang=c : + * ULONG NumberOfOpenPipes * } */ - public static int NumberOfOpenPipes$get(MemorySegment seg) { - return (int)constants$2.const$2.get(seg); + public static int NumberOfOpenPipes(MemorySegment struct) { + return struct.get(NumberOfOpenPipes$LAYOUT, NumberOfOpenPipes$OFFSET); } + /** * Setter for field: - * {@snippet : - * ULONG NumberOfOpenPipes; + * {@snippet lang=c : + * ULONG NumberOfOpenPipes * } */ - public static void NumberOfOpenPipes$set(MemorySegment seg, int x) { - constants$2.const$2.set(seg, x); + public static void NumberOfOpenPipes(MemorySegment struct, int fieldValue) { + struct.set(NumberOfOpenPipes$LAYOUT, NumberOfOpenPipes$OFFSET, fieldValue); } - public static int NumberOfOpenPipes$get(MemorySegment seg, long index) { - return (int)constants$2.const$2.get(seg.asSlice(index*sizeof())); + + private static final OfInt ConnectionStatus$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ConnectionStatus")); + + /** + * Layout for field: + * {@snippet lang=c : + * USB_CONNECTION_STATUS ConnectionStatus + * } + */ + public static final OfInt ConnectionStatus$layout() { + return ConnectionStatus$LAYOUT; } - public static void NumberOfOpenPipes$set(MemorySegment seg, long index, int x) { - constants$2.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final long ConnectionStatus$OFFSET = 31; + + /** + * Offset for field: + * {@snippet lang=c : + * USB_CONNECTION_STATUS ConnectionStatus + * } + */ + public static final long ConnectionStatus$offset() { + return ConnectionStatus$OFFSET; } - public static VarHandle ConnectionStatus$VH() { - return constants$2.const$3; + + /** + * Getter for field: + * {@snippet lang=c : + * USB_CONNECTION_STATUS ConnectionStatus + * } + */ + public static int ConnectionStatus(MemorySegment struct) { + return struct.get(ConnectionStatus$LAYOUT, ConnectionStatus$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USB_CONNECTION_STATUS ConnectionStatus + * } + */ + public static void ConnectionStatus(MemorySegment struct, int fieldValue) { + struct.set(ConnectionStatus$LAYOUT, ConnectionStatus$OFFSET, fieldValue); } + + private static final SequenceLayout PipeList$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("PipeList")); + + /** + * Layout for field: + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] + * } + */ + public static final SequenceLayout PipeList$layout() { + return PipeList$LAYOUT; + } + + private static final long PipeList$OFFSET = 35; + + /** + * Offset for field: + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] + * } + */ + public static final long PipeList$offset() { + return PipeList$OFFSET; + } + /** * Getter for field: - * {@snippet : - * USB_CONNECTION_STATUS ConnectionStatus; + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] * } */ - public static int ConnectionStatus$get(MemorySegment seg) { - return (int)constants$2.const$3.get(seg); + public static MemorySegment PipeList(MemorySegment struct) { + return struct.asSlice(PipeList$OFFSET, PipeList$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * USB_CONNECTION_STATUS ConnectionStatus; + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] * } */ - public static void ConnectionStatus$set(MemorySegment seg, int x) { - constants$2.const$3.set(seg, x); + public static void PipeList(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, PipeList$OFFSET, PipeList$LAYOUT.byteSize()); } - public static int ConnectionStatus$get(MemorySegment seg, long index) { - return (int)constants$2.const$3.get(seg.asSlice(index*sizeof())); + + private static long[] PipeList$DIMS = { 0 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] + * } + */ + public static long[] PipeList$dimensions() { + return PipeList$DIMS; } - public static void ConnectionStatus$set(MemorySegment seg, long index, int x) { - constants$2.const$3.set(seg.asSlice(index*sizeof()), x); + private static final MethodHandle PipeList$ELEM_HANDLE = PipeList$LAYOUT.sliceHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] + * } + */ + public static MemorySegment PipeList(MemorySegment struct, long index0) { + try { + return (MemorySegment)PipeList$ELEM_HANDLE.invokeExact(struct, 0L, index0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Indexed setter for field: + * {@snippet lang=c : + * USB_PIPE_INFO PipeList[0] + * } + */ + public static void PipeList(MemorySegment struct, long index0, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, PipeList(struct, index0), 0L, _USB_PIPE_INFO.layout().byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_PIPE_INFO.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_PIPE_INFO.java new file mode 100644 index 0000000..0777bc3 --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_PIPE_INFO.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.usbioctl; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct _USB_PIPE_INFO { + * USB_ENDPOINT_DESCRIPTOR EndpointDescriptor; + * ULONG ScheduleOffset; + * } + * } + */ +public class _USB_PIPE_INFO { + + _USB_PIPE_INFO() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + _USB_ENDPOINT_DESCRIPTOR.layout().withName("EndpointDescriptor"), + USBIoctl.align(USBIoctl.C_LONG, 1).withName("ScheduleOffset") + ).withName("_USB_PIPE_INFO"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout EndpointDescriptor$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("EndpointDescriptor")); + + /** + * Layout for field: + * {@snippet lang=c : + * USB_ENDPOINT_DESCRIPTOR EndpointDescriptor + * } + */ + public static final GroupLayout EndpointDescriptor$layout() { + return EndpointDescriptor$LAYOUT; + } + + private static final long EndpointDescriptor$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * USB_ENDPOINT_DESCRIPTOR EndpointDescriptor + * } + */ + public static final long EndpointDescriptor$offset() { + return EndpointDescriptor$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * USB_ENDPOINT_DESCRIPTOR EndpointDescriptor + * } + */ + public static MemorySegment EndpointDescriptor(MemorySegment struct) { + return struct.asSlice(EndpointDescriptor$OFFSET, EndpointDescriptor$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * USB_ENDPOINT_DESCRIPTOR EndpointDescriptor + * } + */ + public static void EndpointDescriptor(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, EndpointDescriptor$OFFSET, EndpointDescriptor$LAYOUT.byteSize()); + } + + private static final OfInt ScheduleOffset$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ScheduleOffset")); + + /** + * Layout for field: + * {@snippet lang=c : + * ULONG ScheduleOffset + * } + */ + public static final OfInt ScheduleOffset$layout() { + return ScheduleOffset$LAYOUT; + } + + private static final long ScheduleOffset$OFFSET = 7; + + /** + * Offset for field: + * {@snippet lang=c : + * ULONG ScheduleOffset + * } + */ + public static final long ScheduleOffset$offset() { + return ScheduleOffset$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * ULONG ScheduleOffset + * } + */ + public static int ScheduleOffset(MemorySegment struct) { + return struct.get(ScheduleOffset$LAYOUT, ScheduleOffset$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * ULONG ScheduleOffset + * } + */ + public static void ScheduleOffset(MemorySegment struct, int fieldValue) { + struct.set(ScheduleOffset$LAYOUT, ScheduleOffset$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$0.java deleted file mode 100644 index 45923e1..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$0.java +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.usbioctl; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withByteAlignment(1).withName("ConnectionIndex"), - MemoryLayout.structLayout( - JAVA_BYTE.withName("bmRequest"), - JAVA_BYTE.withName("bRequest"), - JAVA_SHORT.withByteAlignment(1).withName("wValue"), - JAVA_SHORT.withByteAlignment(1).withName("wIndex"), - JAVA_SHORT.withByteAlignment(1).withName("wLength") - ).withName("SetupPacket"), - MemoryLayout.sequenceLayout(0, JAVA_BYTE).withName("Data") - ).withName("_USB_DESCRIPTOR_REQUEST"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("ConnectionIndex")); - static final StructLayout const$2 = MemoryLayout.structLayout( - JAVA_BYTE.withName("bmRequest"), - JAVA_BYTE.withName("bRequest"), - JAVA_SHORT.withByteAlignment(1).withName("wValue"), - JAVA_SHORT.withByteAlignment(1).withName("wIndex"), - JAVA_SHORT.withByteAlignment(1).withName("wLength") - ).withName(""); - static final VarHandle const$3 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("bmRequest")); - static final VarHandle const$4 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("bRequest")); - static final VarHandle const$5 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("wValue")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$1.java deleted file mode 100644 index c650824..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$1.java +++ /dev/null @@ -1,57 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.usbioctl; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final VarHandle const$0 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("wIndex")); - static final VarHandle const$1 = constants$0.const$2.varHandle(MemoryLayout.PathElement.groupElement("wLength")); - static final StructLayout const$2 = MemoryLayout.structLayout( - JAVA_INT.withByteAlignment(1).withName("ConnectionIndex"), - MemoryLayout.structLayout( - JAVA_BYTE.withName("bLength"), - JAVA_BYTE.withName("bDescriptorType"), - JAVA_SHORT.withByteAlignment(1).withName("bcdUSB"), - JAVA_BYTE.withName("bDeviceClass"), - JAVA_BYTE.withName("bDeviceSubClass"), - JAVA_BYTE.withName("bDeviceProtocol"), - JAVA_BYTE.withName("bMaxPacketSize0"), - JAVA_SHORT.withByteAlignment(1).withName("idVendor"), - JAVA_SHORT.withByteAlignment(1).withName("idProduct"), - JAVA_SHORT.withByteAlignment(1).withName("bcdDevice"), - JAVA_BYTE.withName("iManufacturer"), - JAVA_BYTE.withName("iProduct"), - JAVA_BYTE.withName("iSerialNumber"), - JAVA_BYTE.withName("bNumConfigurations") - ).withName("DeviceDescriptor"), - JAVA_BYTE.withName("CurrentConfigurationValue"), - JAVA_BYTE.withName("Speed"), - JAVA_BYTE.withName("DeviceIsHub"), - JAVA_SHORT.withByteAlignment(1).withName("DeviceAddress"), - JAVA_INT.withByteAlignment(1).withName("NumberOfOpenPipes"), - JAVA_INT.withByteAlignment(1).withName("ConnectionStatus"), - MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout( - MemoryLayout.structLayout( - JAVA_BYTE.withName("bLength"), - JAVA_BYTE.withName("bDescriptorType"), - JAVA_BYTE.withName("bEndpointAddress"), - JAVA_BYTE.withName("bmAttributes"), - JAVA_SHORT.withByteAlignment(1).withName("wMaxPacketSize"), - JAVA_BYTE.withName("bInterval") - ).withName("EndpointDescriptor"), - JAVA_INT.withByteAlignment(1).withName("ScheduleOffset") - ).withName("_USB_PIPE_INFO")).withName("PipeList") - ).withName("_USB_NODE_CONNECTION_INFORMATION_EX"); - static final VarHandle const$3 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("ConnectionIndex")); - static final VarHandle const$4 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("CurrentConfigurationValue")); - static final VarHandle const$5 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("Speed")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$2.java deleted file mode 100644 index 5e83bb4..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/constants$2.java +++ /dev/null @@ -1,17 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.usbioctl; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final VarHandle const$0 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("DeviceIsHub")); - static final VarHandle const$1 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("DeviceAddress")); - static final VarHandle const$2 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("NumberOfOpenPipes")); - static final VarHandle const$3 = constants$1.const$2.varHandle(MemoryLayout.PathElement.groupElement("ConnectionStatus")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java deleted file mode 100644 index e13c9de..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -/** - * {@snippet : - * typedef struct _DEV_BROADCAST_DEVICEINTERFACE_W DEV_BROADCAST_DEVICEINTERFACE_W; - * } - */ -public final class DEV_BROADCAST_DEVICEINTERFACE_W extends _DEV_BROADCAST_DEVICEINTERFACE_W { - - // Suppresses default constructor, ensuring non-instantiability. - private DEV_BROADCAST_DEVICEINTERFACE_W() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java deleted file mode 100644 index 684c0ac..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -/** - * {@snippet : - * typedef struct _DEV_BROADCAST_HDR DEV_BROADCAST_HDR; - * } - */ -public final class DEV_BROADCAST_HDR extends _DEV_BROADCAST_HDR { - - // Suppresses default constructor, ensuring non-instantiability. - private DEV_BROADCAST_HDR() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java deleted file mode 100644 index 1717dd4..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -/** - * {@snippet : - * typedef struct tagMSG MSG; - * } - */ -public final class MSG extends tagMSG { - - // Suppresses default constructor, ensuring non-instantiability. - private MSG() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java deleted file mode 100644 index c2ce369..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.user32; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("User32"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java index 31903e0..f22968b 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java @@ -2,85 +2,177 @@ package net.codecrete.usb.windows.gen.user32; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class User32 { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class User32 { + + User32() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("User32"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int WM_DEVICECHANGE = (int)537L; /** - * {@snippet : + * {@snippet lang=c : * #define WM_DEVICECHANGE 537 * } */ public static int WM_DEVICECHANGE() { - return (int)537L; + return WM_DEVICECHANGE; } + private static final int DEVICE_NOTIFY_WINDOW_HANDLE = (int)0L; /** - * {@snippet : + * {@snippet lang=c : * #define DEVICE_NOTIFY_WINDOW_HANDLE 0 * } */ public static int DEVICE_NOTIFY_WINDOW_HANDLE() { - return (int)0L; + return DEVICE_NOTIFY_WINDOW_HANDLE; } + private static final int DBT_DEVICEARRIVAL = (int)32768L; /** - * {@snippet : + * {@snippet lang=c : * #define DBT_DEVICEARRIVAL 32768 * } */ public static int DBT_DEVICEARRIVAL() { - return (int)32768L; + return DBT_DEVICEARRIVAL; } + private static final int DBT_DEVICEREMOVECOMPLETE = (int)32772L; /** - * {@snippet : + * {@snippet lang=c : * #define DBT_DEVICEREMOVECOMPLETE 32772 * } */ public static int DBT_DEVICEREMOVECOMPLETE() { - return (int)32772L; + return DBT_DEVICEREMOVECOMPLETE; } + private static final int DBT_DEVTYP_DEVICEINTERFACE = (int)5L; /** - * {@snippet : + * {@snippet lang=c : * #define DBT_DEVTYP_DEVICEINTERFACE 5 * } */ public static int DBT_DEVTYP_DEVICEINTERFACE() { - return (int)5L; + return DBT_DEVTYP_DEVICEINTERFACE; + } + + private static class DefWindowProcW { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + User32.C_LONG_LONG, + User32.C_POINTER, + User32.C_INT, + User32.C_LONG_LONG, + User32.C_LONG_LONG + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + User32.findOrThrow("DefWindowProcW"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * LRESULT DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) + * } + */ + public static FunctionDescriptor DefWindowProcW$descriptor() { + return DefWindowProcW.DESC; } - public static MethodHandle DefWindowProcW$MH() { - return RuntimeHelper.requireNonNull(constants$3.const$2,"DefWindowProcW"); + + /** + * Downcall method handle for: + * {@snippet lang=c : + * LRESULT DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) + * } + */ + public static MethodHandle DefWindowProcW$handle() { + return DefWindowProcW.HANDLE; } /** - * {@snippet : - * LRESULT DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); + * {@snippet lang=c : + * LRESULT DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) * } */ public static long DefWindowProcW(MemorySegment hWnd, int Msg, long wParam, long lParam) { - var mh$ = DefWindowProcW$MH(); + var mh$ = DefWindowProcW.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("DefWindowProcW", hWnd, Msg, wParam, lParam); + } return (long)mh$.invokeExact(hWnd, Msg, wParam, lParam); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } + private static final MemorySegment HWND_MESSAGE = MemorySegment.ofAddress(-3L); /** - * {@snippet : - * #define HWND_MESSAGE -3 + * {@snippet lang=c : + * #define HWND_MESSAGE (void*) -3 * } */ public static MemorySegment HWND_MESSAGE() { - return constants$4.const$5; + return HWND_MESSAGE; } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java deleted file mode 100644 index aa336e4..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -/** - * {@snippet : - * typedef struct tagWNDCLASSEXW WNDCLASSEXW; - * } - */ -public final class WNDCLASSEXW extends tagWNDCLASSEXW { - - // Suppresses default constructor, ensuring non-instantiability. - private WNDCLASSEXW() {} -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java index ff9172c..67bbb28 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java @@ -2,120 +2,344 @@ package net.codecrete.usb.windows.gen.user32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _DEV_BROADCAST_DEVICEINTERFACE_W { * DWORD dbcc_size; * DWORD dbcc_devicetype; * DWORD dbcc_reserved; * GUID dbcc_classguid; * wchar_t dbcc_name[1]; - * }; + * } * } */ public class _DEV_BROADCAST_DEVICEINTERFACE_W { - public static MemoryLayout $LAYOUT() { - return constants$4.const$1; + _DEV_BROADCAST_DEVICEINTERFACE_W() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_LONG.withName("dbcc_size"), + User32.C_LONG.withName("dbcc_devicetype"), + User32.C_LONG.withName("dbcc_reserved"), + _GUID.layout().withName("dbcc_classguid"), + MemoryLayout.sequenceLayout(1, User32.C_SHORT).withName("dbcc_name"), + MemoryLayout.paddingLayout(2) + ).withName("_DEV_BROADCAST_DEVICEINTERFACE_W"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt dbcc_size$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbcc_size")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbcc_size + * } + */ + public static final OfInt dbcc_size$layout() { + return dbcc_size$LAYOUT; } - public static VarHandle dbcc_size$VH() { - return constants$4.const$2; + + private static final long dbcc_size$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbcc_size + * } + */ + public static final long dbcc_size$offset() { + return dbcc_size$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD dbcc_size; + * {@snippet lang=c : + * DWORD dbcc_size * } */ - public static int dbcc_size$get(MemorySegment seg) { - return (int)constants$4.const$2.get(seg); + public static int dbcc_size(MemorySegment struct) { + return struct.get(dbcc_size$LAYOUT, dbcc_size$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD dbcc_size; + * {@snippet lang=c : + * DWORD dbcc_size * } */ - public static void dbcc_size$set(MemorySegment seg, int x) { - constants$4.const$2.set(seg, x); + public static void dbcc_size(MemorySegment struct, int fieldValue) { + struct.set(dbcc_size$LAYOUT, dbcc_size$OFFSET, fieldValue); } - public static int dbcc_size$get(MemorySegment seg, long index) { - return (int)constants$4.const$2.get(seg.asSlice(index*sizeof())); + + private static final OfInt dbcc_devicetype$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbcc_devicetype")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbcc_devicetype + * } + */ + public static final OfInt dbcc_devicetype$layout() { + return dbcc_devicetype$LAYOUT; } - public static void dbcc_size$set(MemorySegment seg, long index, int x) { - constants$4.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final long dbcc_devicetype$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbcc_devicetype + * } + */ + public static final long dbcc_devicetype$offset() { + return dbcc_devicetype$OFFSET; } - public static VarHandle dbcc_devicetype$VH() { - return constants$4.const$3; + + /** + * Getter for field: + * {@snippet lang=c : + * DWORD dbcc_devicetype + * } + */ + public static int dbcc_devicetype(MemorySegment struct) { + return struct.get(dbcc_devicetype$LAYOUT, dbcc_devicetype$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DWORD dbcc_devicetype + * } + */ + public static void dbcc_devicetype(MemorySegment struct, int fieldValue) { + struct.set(dbcc_devicetype$LAYOUT, dbcc_devicetype$OFFSET, fieldValue); } + + private static final OfInt dbcc_reserved$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbcc_reserved")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbcc_reserved + * } + */ + public static final OfInt dbcc_reserved$layout() { + return dbcc_reserved$LAYOUT; + } + + private static final long dbcc_reserved$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbcc_reserved + * } + */ + public static final long dbcc_reserved$offset() { + return dbcc_reserved$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD dbcc_devicetype; + * {@snippet lang=c : + * DWORD dbcc_reserved * } */ - public static int dbcc_devicetype$get(MemorySegment seg) { - return (int)constants$4.const$3.get(seg); + public static int dbcc_reserved(MemorySegment struct) { + return struct.get(dbcc_reserved$LAYOUT, dbcc_reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD dbcc_devicetype; + * {@snippet lang=c : + * DWORD dbcc_reserved + * } + */ + public static void dbcc_reserved(MemorySegment struct, int fieldValue) { + struct.set(dbcc_reserved$LAYOUT, dbcc_reserved$OFFSET, fieldValue); + } + + private static final GroupLayout dbcc_classguid$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("dbcc_classguid")); + + /** + * Layout for field: + * {@snippet lang=c : + * GUID dbcc_classguid + * } + */ + public static final GroupLayout dbcc_classguid$layout() { + return dbcc_classguid$LAYOUT; + } + + private static final long dbcc_classguid$OFFSET = 12; + + /** + * Offset for field: + * {@snippet lang=c : + * GUID dbcc_classguid + * } + */ + public static final long dbcc_classguid$offset() { + return dbcc_classguid$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * GUID dbcc_classguid * } */ - public static void dbcc_devicetype$set(MemorySegment seg, int x) { - constants$4.const$3.set(seg, x); + public static MemorySegment dbcc_classguid(MemorySegment struct) { + return struct.asSlice(dbcc_classguid$OFFSET, dbcc_classguid$LAYOUT.byteSize()); } - public static int dbcc_devicetype$get(MemorySegment seg, long index) { - return (int)constants$4.const$3.get(seg.asSlice(index*sizeof())); + + /** + * Setter for field: + * {@snippet lang=c : + * GUID dbcc_classguid + * } + */ + public static void dbcc_classguid(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, dbcc_classguid$OFFSET, dbcc_classguid$LAYOUT.byteSize()); } - public static void dbcc_devicetype$set(MemorySegment seg, long index, int x) { - constants$4.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final SequenceLayout dbcc_name$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("dbcc_name")); + + /** + * Layout for field: + * {@snippet lang=c : + * wchar_t dbcc_name[1] + * } + */ + public static final SequenceLayout dbcc_name$layout() { + return dbcc_name$LAYOUT; } - public static VarHandle dbcc_reserved$VH() { - return constants$4.const$4; + + private static final long dbcc_name$OFFSET = 28; + + /** + * Offset for field: + * {@snippet lang=c : + * wchar_t dbcc_name[1] + * } + */ + public static final long dbcc_name$offset() { + return dbcc_name$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD dbcc_reserved; + * {@snippet lang=c : + * wchar_t dbcc_name[1] * } */ - public static int dbcc_reserved$get(MemorySegment seg) { - return (int)constants$4.const$4.get(seg); + public static MemorySegment dbcc_name(MemorySegment struct) { + return struct.asSlice(dbcc_name$OFFSET, dbcc_name$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * DWORD dbcc_reserved; + * {@snippet lang=c : + * wchar_t dbcc_name[1] * } */ - public static void dbcc_reserved$set(MemorySegment seg, int x) { - constants$4.const$4.set(seg, x); + public static void dbcc_name(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, dbcc_name$OFFSET, dbcc_name$LAYOUT.byteSize()); } - public static int dbcc_reserved$get(MemorySegment seg, long index) { - return (int)constants$4.const$4.get(seg.asSlice(index*sizeof())); + + private static long[] dbcc_name$DIMS = { 1 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * wchar_t dbcc_name[1] + * } + */ + public static long[] dbcc_name$dimensions() { + return dbcc_name$DIMS; } - public static void dbcc_reserved$set(MemorySegment seg, long index, int x) { - constants$4.const$4.set(seg.asSlice(index*sizeof()), x); + private static final VarHandle dbcc_name$ELEM_HANDLE = dbcc_name$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * wchar_t dbcc_name[1] + * } + */ + public static short dbcc_name(MemorySegment struct, long index0) { + return (short)dbcc_name$ELEM_HANDLE.get(struct, 0L, index0); } - public static MemorySegment dbcc_classguid$slice(MemorySegment seg) { - return seg.asSlice(12, 16); + + /** + * Indexed setter for field: + * {@snippet lang=c : + * wchar_t dbcc_name[1] + * } + */ + public static void dbcc_name(MemorySegment struct, long index0, short fieldValue) { + dbcc_name$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); } - public static MemorySegment dbcc_name$slice(MemorySegment seg) { - return seg.asSlice(28, 2); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java index 06d1ef7..c672335 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java @@ -2,112 +2,218 @@ package net.codecrete.usb.windows.gen.user32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct _DEV_BROADCAST_HDR { * DWORD dbch_size; * DWORD dbch_devicetype; * DWORD dbch_reserved; - * }; + * } * } */ public class _DEV_BROADCAST_HDR { - public static MemoryLayout $LAYOUT() { - return constants$3.const$3; + _DEV_BROADCAST_HDR() { + // Should not be called directly } - public static VarHandle dbch_size$VH() { - return constants$3.const$4; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_LONG.withName("dbch_size"), + User32.C_LONG.withName("dbch_devicetype"), + User32.C_LONG.withName("dbch_reserved") + ).withName("_DEV_BROADCAST_HDR"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt dbch_size$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbch_size")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbch_size + * } + */ + public static final OfInt dbch_size$layout() { + return dbch_size$LAYOUT; + } + + private static final long dbch_size$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbch_size + * } + */ + public static final long dbch_size$offset() { + return dbch_size$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD dbch_size; + * {@snippet lang=c : + * DWORD dbch_size * } */ - public static int dbch_size$get(MemorySegment seg) { - return (int)constants$3.const$4.get(seg); + public static int dbch_size(MemorySegment struct) { + return struct.get(dbch_size$LAYOUT, dbch_size$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD dbch_size; + * {@snippet lang=c : + * DWORD dbch_size * } */ - public static void dbch_size$set(MemorySegment seg, int x) { - constants$3.const$4.set(seg, x); - } - public static int dbch_size$get(MemorySegment seg, long index) { - return (int)constants$3.const$4.get(seg.asSlice(index*sizeof())); + public static void dbch_size(MemorySegment struct, int fieldValue) { + struct.set(dbch_size$LAYOUT, dbch_size$OFFSET, fieldValue); } - public static void dbch_size$set(MemorySegment seg, long index, int x) { - constants$3.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt dbch_devicetype$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbch_devicetype")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbch_devicetype + * } + */ + public static final OfInt dbch_devicetype$layout() { + return dbch_devicetype$LAYOUT; } - public static VarHandle dbch_devicetype$VH() { - return constants$3.const$5; + + private static final long dbch_devicetype$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbch_devicetype + * } + */ + public static final long dbch_devicetype$offset() { + return dbch_devicetype$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD dbch_devicetype; + * {@snippet lang=c : + * DWORD dbch_devicetype * } */ - public static int dbch_devicetype$get(MemorySegment seg) { - return (int)constants$3.const$5.get(seg); + public static int dbch_devicetype(MemorySegment struct) { + return struct.get(dbch_devicetype$LAYOUT, dbch_devicetype$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD dbch_devicetype; + * {@snippet lang=c : + * DWORD dbch_devicetype * } */ - public static void dbch_devicetype$set(MemorySegment seg, int x) { - constants$3.const$5.set(seg, x); + public static void dbch_devicetype(MemorySegment struct, int fieldValue) { + struct.set(dbch_devicetype$LAYOUT, dbch_devicetype$OFFSET, fieldValue); } - public static int dbch_devicetype$get(MemorySegment seg, long index) { - return (int)constants$3.const$5.get(seg.asSlice(index*sizeof())); - } - public static void dbch_devicetype$set(MemorySegment seg, long index, int x) { - constants$3.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt dbch_reserved$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dbch_reserved")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD dbch_reserved + * } + */ + public static final OfInt dbch_reserved$layout() { + return dbch_reserved$LAYOUT; } - public static VarHandle dbch_reserved$VH() { - return constants$4.const$0; + + private static final long dbch_reserved$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD dbch_reserved + * } + */ + public static final long dbch_reserved$offset() { + return dbch_reserved$OFFSET; } + /** * Getter for field: - * {@snippet : - * DWORD dbch_reserved; + * {@snippet lang=c : + * DWORD dbch_reserved * } */ - public static int dbch_reserved$get(MemorySegment seg) { - return (int)constants$4.const$0.get(seg); + public static int dbch_reserved(MemorySegment struct) { + return struct.get(dbch_reserved$LAYOUT, dbch_reserved$OFFSET); } + /** * Setter for field: - * {@snippet : - * DWORD dbch_reserved; + * {@snippet lang=c : + * DWORD dbch_reserved * } */ - public static void dbch_reserved$set(MemorySegment seg, int x) { - constants$4.const$0.set(seg, x); + public static void dbch_reserved(MemorySegment struct, int fieldValue) { + struct.set(dbch_reserved$LAYOUT, dbch_reserved$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static int dbch_reserved$get(MemorySegment seg, long index) { - return (int)constants$4.const$0.get(seg.asSlice(index*sizeof())); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static void dbch_reserved$set(MemorySegment seg, long index, int x) { - constants$4.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_GUID.java new file mode 100644 index 0000000..ecef1ab --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_GUID.java @@ -0,0 +1,298 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.user32; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct _GUID { + * unsigned long Data1; + * unsigned short Data2; + * unsigned short Data3; + * unsigned char Data4[8]; + * } + * } + */ +public class _GUID { + + _GUID() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_LONG.withName("Data1"), + User32.C_SHORT.withName("Data2"), + User32.C_SHORT.withName("Data3"), + MemoryLayout.sequenceLayout(8, User32.C_CHAR).withName("Data4") + ).withName("_GUID"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt Data1$LAYOUT = (OfInt)$LAYOUT.select(groupElement("Data1")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final OfInt Data1$layout() { + return Data1$LAYOUT; + } + + private static final long Data1$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static final long Data1$offset() { + return Data1$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static int Data1(MemorySegment struct) { + return struct.get(Data1$LAYOUT, Data1$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned long Data1 + * } + */ + public static void Data1(MemorySegment struct, int fieldValue) { + struct.set(Data1$LAYOUT, Data1$OFFSET, fieldValue); + } + + private static final OfShort Data2$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data2")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final OfShort Data2$layout() { + return Data2$LAYOUT; + } + + private static final long Data2$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static final long Data2$offset() { + return Data2$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static short Data2(MemorySegment struct) { + return struct.get(Data2$LAYOUT, Data2$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned short Data2 + * } + */ + public static void Data2(MemorySegment struct, short fieldValue) { + struct.set(Data2$LAYOUT, Data2$OFFSET, fieldValue); + } + + private static final OfShort Data3$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Data3")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final OfShort Data3$layout() { + return Data3$LAYOUT; + } + + private static final long Data3$OFFSET = 6; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static final long Data3$offset() { + return Data3$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static short Data3(MemorySegment struct) { + return struct.get(Data3$LAYOUT, Data3$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned short Data3 + * } + */ + public static void Data3(MemorySegment struct, short fieldValue) { + struct.set(Data3$LAYOUT, Data3$OFFSET, fieldValue); + } + + private static final SequenceLayout Data4$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("Data4")); + + /** + * Layout for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final SequenceLayout Data4$layout() { + return Data4$LAYOUT; + } + + private static final long Data4$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static final long Data4$offset() { + return Data4$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static MemorySegment Data4(MemorySegment struct) { + return struct.asSlice(Data4$OFFSET, Data4$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, Data4$OFFSET, Data4$LAYOUT.byteSize()); + } + + private static long[] Data4$DIMS = { 8 }; + + /** + * Dimensions for array field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static long[] Data4$dimensions() { + return Data4$DIMS; + } + private static final VarHandle Data4$ELEM_HANDLE = Data4$LAYOUT.varHandle(sequenceElement()); + + /** + * Indexed getter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static byte Data4(MemorySegment struct, long index0) { + return (byte)Data4$ELEM_HANDLE.get(struct, 0L, index0); + } + + /** + * Indexed setter for field: + * {@snippet lang=c : + * unsigned char Data4[8] + * } + */ + public static void Data4(MemorySegment struct, long index0, byte fieldValue) { + Data4$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java deleted file mode 100644 index c4377aa..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final StructLayout const$0 = MemoryLayout.structLayout( - JAVA_INT.withName("cbSize"), - JAVA_INT.withName("style"), - RuntimeHelper.POINTER.withName("lpfnWndProc"), - JAVA_INT.withName("cbClsExtra"), - JAVA_INT.withName("cbWndExtra"), - RuntimeHelper.POINTER.withName("hInstance"), - RuntimeHelper.POINTER.withName("hIcon"), - RuntimeHelper.POINTER.withName("hCursor"), - RuntimeHelper.POINTER.withName("hbrBackground"), - RuntimeHelper.POINTER.withName("lpszMenuName"), - RuntimeHelper.POINTER.withName("lpszClassName"), - RuntimeHelper.POINTER.withName("hIconSm") - ).withName("tagWNDCLASSEXW"); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("cbSize")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("style")); - static final VarHandle const$3 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("lpfnWndProc")); - static final VarHandle const$4 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("cbClsExtra")); - static final VarHandle const$5 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("cbWndExtra")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$1.java deleted file mode 100644 index 1836e3c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$1.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -import java.lang.foreign.MemoryLayout; -import java.lang.invoke.VarHandle; -final class constants$1 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$1() {} - static final VarHandle const$0 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("hInstance")); - static final VarHandle const$1 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("hIcon")); - static final VarHandle const$2 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("hCursor")); - static final VarHandle const$3 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("hbrBackground")); - static final VarHandle const$4 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("lpszMenuName")); - static final VarHandle const$5 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("lpszClassName")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$2.java deleted file mode 100644 index 7fba5be..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$2.java +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$2 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$2() {} - static final VarHandle const$0 = constants$0.const$0.varHandle(MemoryLayout.PathElement.groupElement("hIconSm")); - static final StructLayout const$1 = MemoryLayout.structLayout( - RuntimeHelper.POINTER.withName("hwnd"), - JAVA_INT.withName("message"), - MemoryLayout.paddingLayout(4), - JAVA_LONG.withName("wParam"), - JAVA_LONG.withName("lParam"), - JAVA_INT.withName("time"), - MemoryLayout.structLayout( - JAVA_INT.withName("x"), - JAVA_INT.withName("y") - ).withName("pt"), - MemoryLayout.paddingLayout(4) - ).withName("tagMSG"); - static final VarHandle const$2 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("hwnd")); - static final VarHandle const$3 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("message")); - static final VarHandle const$4 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("wParam")); - static final VarHandle const$5 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("lParam")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$3.java deleted file mode 100644 index 1ab0947..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$3.java +++ /dev/null @@ -1,37 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.StructLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -import static java.lang.foreign.ValueLayout.JAVA_LONG; -final class constants$3 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$3() {} - static final VarHandle const$0 = constants$2.const$1.varHandle(MemoryLayout.PathElement.groupElement("time")); - static final FunctionDescriptor const$1 = FunctionDescriptor.of(JAVA_LONG, - RuntimeHelper.POINTER, - JAVA_INT, - JAVA_LONG, - JAVA_LONG - ); - static final MethodHandle const$2 = RuntimeHelper.downcallHandle( - "DefWindowProcW", - constants$3.const$1 - ); - static final StructLayout const$3 = MemoryLayout.structLayout( - JAVA_INT.withName("dbch_size"), - JAVA_INT.withName("dbch_devicetype"), - JAVA_INT.withName("dbch_reserved") - ).withName("_DEV_BROADCAST_HDR"); - static final VarHandle const$4 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("dbch_size")); - static final VarHandle const$5 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("dbch_devicetype")); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$4.java deleted file mode 100644 index 441a40c..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$4.java +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.user32; - -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; -final class constants$4 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$4() {} - static final VarHandle const$0 = constants$3.const$3.varHandle(MemoryLayout.PathElement.groupElement("dbch_reserved")); - static final StructLayout const$1 = MemoryLayout.structLayout( - JAVA_INT.withName("dbcc_size"), - JAVA_INT.withName("dbcc_devicetype"), - JAVA_INT.withName("dbcc_reserved"), - MemoryLayout.structLayout( - JAVA_INT.withName("Data1"), - JAVA_SHORT.withName("Data2"), - JAVA_SHORT.withName("Data3"), - MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4") - ).withName("dbcc_classguid"), - MemoryLayout.sequenceLayout(1, JAVA_SHORT).withName("dbcc_name"), - MemoryLayout.paddingLayout(2) - ).withName("_DEV_BROADCAST_DEVICEINTERFACE_W"); - static final VarHandle const$2 = constants$4.const$1.varHandle(MemoryLayout.PathElement.groupElement("dbcc_size")); - static final VarHandle const$3 = constants$4.const$1.varHandle(MemoryLayout.PathElement.groupElement("dbcc_devicetype")); - static final VarHandle const$4 = constants$4.const$1.varHandle(MemoryLayout.PathElement.groupElement("dbcc_reserved")); - static final MemorySegment const$5 = MemorySegment.ofAddress(-3L); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java index 98724ca..b75ef83 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java @@ -2,13 +2,18 @@ package net.codecrete.usb.windows.gen.user32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct tagMSG { * HWND hwnd; * UINT message; @@ -16,158 +21,339 @@ * LPARAM lParam; * DWORD time; * POINT pt; - * }; + * } * } */ public class tagMSG { - public static MemoryLayout $LAYOUT() { - return constants$2.const$1; + tagMSG() { + // Should not be called directly } - public static VarHandle hwnd$VH() { - return constants$2.const$2; + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_POINTER.withName("hwnd"), + User32.C_INT.withName("message"), + MemoryLayout.paddingLayout(4), + User32.C_LONG_LONG.withName("wParam"), + User32.C_LONG_LONG.withName("lParam"), + User32.C_LONG.withName("time"), + tagPOINT.layout().withName("pt"), + MemoryLayout.paddingLayout(4) + ).withName("tagMSG"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; } + + private static final AddressLayout hwnd$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hwnd")); + + /** + * Layout for field: + * {@snippet lang=c : + * HWND hwnd + * } + */ + public static final AddressLayout hwnd$layout() { + return hwnd$LAYOUT; + } + + private static final long hwnd$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * HWND hwnd + * } + */ + public static final long hwnd$offset() { + return hwnd$OFFSET; + } + /** * Getter for field: - * {@snippet : - * HWND hwnd; + * {@snippet lang=c : + * HWND hwnd * } */ - public static MemorySegment hwnd$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$2.const$2.get(seg); + public static MemorySegment hwnd(MemorySegment struct) { + return struct.get(hwnd$LAYOUT, hwnd$OFFSET); } + /** * Setter for field: - * {@snippet : - * HWND hwnd; + * {@snippet lang=c : + * HWND hwnd * } */ - public static void hwnd$set(MemorySegment seg, MemorySegment x) { - constants$2.const$2.set(seg, x); - } - public static MemorySegment hwnd$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$2.const$2.get(seg.asSlice(index*sizeof())); + public static void hwnd(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hwnd$LAYOUT, hwnd$OFFSET, fieldValue); } - public static void hwnd$set(MemorySegment seg, long index, MemorySegment x) { - constants$2.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt message$LAYOUT = (OfInt)$LAYOUT.select(groupElement("message")); + + /** + * Layout for field: + * {@snippet lang=c : + * UINT message + * } + */ + public static final OfInt message$layout() { + return message$LAYOUT; } - public static VarHandle message$VH() { - return constants$2.const$3; + + private static final long message$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * UINT message + * } + */ + public static final long message$offset() { + return message$OFFSET; } + /** * Getter for field: - * {@snippet : - * UINT message; + * {@snippet lang=c : + * UINT message * } */ - public static int message$get(MemorySegment seg) { - return (int)constants$2.const$3.get(seg); + public static int message(MemorySegment struct) { + return struct.get(message$LAYOUT, message$OFFSET); } + /** * Setter for field: - * {@snippet : - * UINT message; + * {@snippet lang=c : + * UINT message * } */ - public static void message$set(MemorySegment seg, int x) { - constants$2.const$3.set(seg, x); - } - public static int message$get(MemorySegment seg, long index) { - return (int)constants$2.const$3.get(seg.asSlice(index*sizeof())); + public static void message(MemorySegment struct, int fieldValue) { + struct.set(message$LAYOUT, message$OFFSET, fieldValue); } - public static void message$set(MemorySegment seg, long index, int x) { - constants$2.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong wParam$LAYOUT = (OfLong)$LAYOUT.select(groupElement("wParam")); + + /** + * Layout for field: + * {@snippet lang=c : + * WPARAM wParam + * } + */ + public static final OfLong wParam$layout() { + return wParam$LAYOUT; } - public static VarHandle wParam$VH() { - return constants$2.const$4; + + private static final long wParam$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * WPARAM wParam + * } + */ + public static final long wParam$offset() { + return wParam$OFFSET; } + /** * Getter for field: - * {@snippet : - * WPARAM wParam; + * {@snippet lang=c : + * WPARAM wParam * } */ - public static long wParam$get(MemorySegment seg) { - return (long)constants$2.const$4.get(seg); + public static long wParam(MemorySegment struct) { + return struct.get(wParam$LAYOUT, wParam$OFFSET); } + /** * Setter for field: - * {@snippet : - * WPARAM wParam; + * {@snippet lang=c : + * WPARAM wParam * } */ - public static void wParam$set(MemorySegment seg, long x) { - constants$2.const$4.set(seg, x); - } - public static long wParam$get(MemorySegment seg, long index) { - return (long)constants$2.const$4.get(seg.asSlice(index*sizeof())); + public static void wParam(MemorySegment struct, long fieldValue) { + struct.set(wParam$LAYOUT, wParam$OFFSET, fieldValue); } - public static void wParam$set(MemorySegment seg, long index, long x) { - constants$2.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfLong lParam$LAYOUT = (OfLong)$LAYOUT.select(groupElement("lParam")); + + /** + * Layout for field: + * {@snippet lang=c : + * LPARAM lParam + * } + */ + public static final OfLong lParam$layout() { + return lParam$LAYOUT; } - public static VarHandle lParam$VH() { - return constants$2.const$5; + + private static final long lParam$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * LPARAM lParam + * } + */ + public static final long lParam$offset() { + return lParam$OFFSET; } + /** * Getter for field: - * {@snippet : - * LPARAM lParam; + * {@snippet lang=c : + * LPARAM lParam * } */ - public static long lParam$get(MemorySegment seg) { - return (long)constants$2.const$5.get(seg); + public static long lParam(MemorySegment struct) { + return struct.get(lParam$LAYOUT, lParam$OFFSET); } + /** * Setter for field: - * {@snippet : - * LPARAM lParam; + * {@snippet lang=c : + * LPARAM lParam * } */ - public static void lParam$set(MemorySegment seg, long x) { - constants$2.const$5.set(seg, x); + public static void lParam(MemorySegment struct, long fieldValue) { + struct.set(lParam$LAYOUT, lParam$OFFSET, fieldValue); } - public static long lParam$get(MemorySegment seg, long index) { - return (long)constants$2.const$5.get(seg.asSlice(index*sizeof())); + + private static final OfInt time$LAYOUT = (OfInt)$LAYOUT.select(groupElement("time")); + + /** + * Layout for field: + * {@snippet lang=c : + * DWORD time + * } + */ + public static final OfInt time$layout() { + return time$LAYOUT; } - public static void lParam$set(MemorySegment seg, long index, long x) { - constants$2.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final long time$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * DWORD time + * } + */ + public static final long time$offset() { + return time$OFFSET; } - public static VarHandle time$VH() { - return constants$3.const$0; + + /** + * Getter for field: + * {@snippet lang=c : + * DWORD time + * } + */ + public static int time(MemorySegment struct) { + return struct.get(time$LAYOUT, time$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DWORD time + * } + */ + public static void time(MemorySegment struct, int fieldValue) { + struct.set(time$LAYOUT, time$OFFSET, fieldValue); } + + private static final GroupLayout pt$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("pt")); + + /** + * Layout for field: + * {@snippet lang=c : + * POINT pt + * } + */ + public static final GroupLayout pt$layout() { + return pt$LAYOUT; + } + + private static final long pt$OFFSET = 36; + + /** + * Offset for field: + * {@snippet lang=c : + * POINT pt + * } + */ + public static final long pt$offset() { + return pt$OFFSET; + } + /** * Getter for field: - * {@snippet : - * DWORD time; + * {@snippet lang=c : + * POINT pt * } */ - public static int time$get(MemorySegment seg) { - return (int)constants$3.const$0.get(seg); + public static MemorySegment pt(MemorySegment struct) { + return struct.asSlice(pt$OFFSET, pt$LAYOUT.byteSize()); } + /** * Setter for field: - * {@snippet : - * DWORD time; + * {@snippet lang=c : + * POINT pt * } */ - public static void time$set(MemorySegment seg, int x) { - constants$3.const$0.set(seg, x); + public static void pt(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, pt$OFFSET, pt$LAYOUT.byteSize()); } - public static int time$get(MemorySegment seg, long index) { - return (int)constants$3.const$0.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static void time$set(MemorySegment seg, long index, int x) { - constants$3.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment pt$slice(MemorySegment seg) { - return seg.asSlice(36, 8); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagPOINT.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagPOINT.java new file mode 100644 index 0000000..54888fc --- /dev/null +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagPOINT.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package net.codecrete.usb.windows.gen.user32; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct tagPOINT { + * LONG x; + * LONG y; + * } + * } + */ +public class tagPOINT { + + tagPOINT() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_LONG.withName("x"), + User32.C_LONG.withName("y") + ).withName("tagPOINT"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt x$LAYOUT = (OfInt)$LAYOUT.select(groupElement("x")); + + /** + * Layout for field: + * {@snippet lang=c : + * LONG x + * } + */ + public static final OfInt x$layout() { + return x$LAYOUT; + } + + private static final long x$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * LONG x + * } + */ + public static final long x$offset() { + return x$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * LONG x + * } + */ + public static int x(MemorySegment struct) { + return struct.get(x$LAYOUT, x$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * LONG x + * } + */ + public static void x(MemorySegment struct, int fieldValue) { + struct.set(x$LAYOUT, x$OFFSET, fieldValue); + } + + private static final OfInt y$LAYOUT = (OfInt)$LAYOUT.select(groupElement("y")); + + /** + * Layout for field: + * {@snippet lang=c : + * LONG y + * } + */ + public static final OfInt y$layout() { + return y$LAYOUT; + } + + private static final long y$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * LONG y + * } + */ + public static final long y$offset() { + return y$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * LONG y + * } + */ + public static int y(MemorySegment struct) { + return struct.get(y$LAYOUT, y$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * LONG y + * } + */ + public static void y(MemorySegment struct, int fieldValue) { + struct.set(y$LAYOUT, y$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java index 6f6c334..525ff27 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java @@ -2,13 +2,18 @@ package net.codecrete.usb.windows.gen.user32; -import java.lang.foreign.Arena; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.invoke.VarHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + /** - * {@snippet : + * {@snippet lang=c : * struct tagWNDCLASSEXW { * UINT cbSize; * UINT style; @@ -22,344 +27,607 @@ * LPCWSTR lpszMenuName; * LPCWSTR lpszClassName; * HICON hIconSm; - * }; + * } * } */ public class tagWNDCLASSEXW { - public static MemoryLayout $LAYOUT() { - return constants$0.const$0; + tagWNDCLASSEXW() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + User32.C_INT.withName("cbSize"), + User32.C_INT.withName("style"), + User32.C_POINTER.withName("lpfnWndProc"), + User32.C_INT.withName("cbClsExtra"), + User32.C_INT.withName("cbWndExtra"), + User32.C_POINTER.withName("hInstance"), + User32.C_POINTER.withName("hIcon"), + User32.C_POINTER.withName("hCursor"), + User32.C_POINTER.withName("hbrBackground"), + User32.C_POINTER.withName("lpszMenuName"), + User32.C_POINTER.withName("lpszClassName"), + User32.C_POINTER.withName("hIconSm") + ).withName("tagWNDCLASSEXW"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt cbSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbSize")); + + /** + * Layout for field: + * {@snippet lang=c : + * UINT cbSize + * } + */ + public static final OfInt cbSize$layout() { + return cbSize$LAYOUT; } - public static VarHandle cbSize$VH() { - return constants$0.const$1; + + private static final long cbSize$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UINT cbSize + * } + */ + public static final long cbSize$offset() { + return cbSize$OFFSET; } + /** * Getter for field: - * {@snippet : - * UINT cbSize; + * {@snippet lang=c : + * UINT cbSize * } */ - public static int cbSize$get(MemorySegment seg) { - return (int)constants$0.const$1.get(seg); + public static int cbSize(MemorySegment struct) { + return struct.get(cbSize$LAYOUT, cbSize$OFFSET); } + /** * Setter for field: - * {@snippet : - * UINT cbSize; + * {@snippet lang=c : + * UINT cbSize * } */ - public static void cbSize$set(MemorySegment seg, int x) { - constants$0.const$1.set(seg, x); + public static void cbSize(MemorySegment struct, int fieldValue) { + struct.set(cbSize$LAYOUT, cbSize$OFFSET, fieldValue); } - public static int cbSize$get(MemorySegment seg, long index) { - return (int)constants$0.const$1.get(seg.asSlice(index*sizeof())); - } - public static void cbSize$set(MemorySegment seg, long index, int x) { - constants$0.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt style$LAYOUT = (OfInt)$LAYOUT.select(groupElement("style")); + + /** + * Layout for field: + * {@snippet lang=c : + * UINT style + * } + */ + public static final OfInt style$layout() { + return style$LAYOUT; } - public static VarHandle style$VH() { - return constants$0.const$2; + + private static final long style$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * UINT style + * } + */ + public static final long style$offset() { + return style$OFFSET; } + /** * Getter for field: - * {@snippet : - * UINT style; + * {@snippet lang=c : + * UINT style * } */ - public static int style$get(MemorySegment seg) { - return (int)constants$0.const$2.get(seg); + public static int style(MemorySegment struct) { + return struct.get(style$LAYOUT, style$OFFSET); } + /** * Setter for field: - * {@snippet : - * UINT style; + * {@snippet lang=c : + * UINT style * } */ - public static void style$set(MemorySegment seg, int x) { - constants$0.const$2.set(seg, x); - } - public static int style$get(MemorySegment seg, long index) { - return (int)constants$0.const$2.get(seg.asSlice(index*sizeof())); + public static void style(MemorySegment struct, int fieldValue) { + struct.set(style$LAYOUT, style$OFFSET, fieldValue); } - public static void style$set(MemorySegment seg, long index, int x) { - constants$0.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout lpfnWndProc$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpfnWndProc")); + + /** + * Layout for field: + * {@snippet lang=c : + * WNDPROC lpfnWndProc + * } + */ + public static final AddressLayout lpfnWndProc$layout() { + return lpfnWndProc$LAYOUT; } - public static VarHandle lpfnWndProc$VH() { - return constants$0.const$3; + + private static final long lpfnWndProc$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * WNDPROC lpfnWndProc + * } + */ + public static final long lpfnWndProc$offset() { + return lpfnWndProc$OFFSET; } + /** * Getter for field: - * {@snippet : - * WNDPROC lpfnWndProc; + * {@snippet lang=c : + * WNDPROC lpfnWndProc * } */ - public static MemorySegment lpfnWndProc$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$0.const$3.get(seg); + public static MemorySegment lpfnWndProc(MemorySegment struct) { + return struct.get(lpfnWndProc$LAYOUT, lpfnWndProc$OFFSET); } + /** * Setter for field: - * {@snippet : - * WNDPROC lpfnWndProc; + * {@snippet lang=c : + * WNDPROC lpfnWndProc * } */ - public static void lpfnWndProc$set(MemorySegment seg, MemorySegment x) { - constants$0.const$3.set(seg, x); + public static void lpfnWndProc(MemorySegment struct, MemorySegment fieldValue) { + struct.set(lpfnWndProc$LAYOUT, lpfnWndProc$OFFSET, fieldValue); } - public static MemorySegment lpfnWndProc$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$0.const$3.get(seg.asSlice(index*sizeof())); - } - public static void lpfnWndProc$set(MemorySegment seg, long index, MemorySegment x) { - constants$0.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt cbClsExtra$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbClsExtra")); + + /** + * Layout for field: + * {@snippet lang=c : + * int cbClsExtra + * } + */ + public static final OfInt cbClsExtra$layout() { + return cbClsExtra$LAYOUT; } - public static VarHandle cbClsExtra$VH() { - return constants$0.const$4; + + private static final long cbClsExtra$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * int cbClsExtra + * } + */ + public static final long cbClsExtra$offset() { + return cbClsExtra$OFFSET; } + /** * Getter for field: - * {@snippet : - * int cbClsExtra; + * {@snippet lang=c : + * int cbClsExtra * } */ - public static int cbClsExtra$get(MemorySegment seg) { - return (int)constants$0.const$4.get(seg); + public static int cbClsExtra(MemorySegment struct) { + return struct.get(cbClsExtra$LAYOUT, cbClsExtra$OFFSET); } + /** * Setter for field: - * {@snippet : - * int cbClsExtra; + * {@snippet lang=c : + * int cbClsExtra * } */ - public static void cbClsExtra$set(MemorySegment seg, int x) { - constants$0.const$4.set(seg, x); - } - public static int cbClsExtra$get(MemorySegment seg, long index) { - return (int)constants$0.const$4.get(seg.asSlice(index*sizeof())); + public static void cbClsExtra(MemorySegment struct, int fieldValue) { + struct.set(cbClsExtra$LAYOUT, cbClsExtra$OFFSET, fieldValue); } - public static void cbClsExtra$set(MemorySegment seg, long index, int x) { - constants$0.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final OfInt cbWndExtra$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cbWndExtra")); + + /** + * Layout for field: + * {@snippet lang=c : + * int cbWndExtra + * } + */ + public static final OfInt cbWndExtra$layout() { + return cbWndExtra$LAYOUT; } - public static VarHandle cbWndExtra$VH() { - return constants$0.const$5; + + private static final long cbWndExtra$OFFSET = 20; + + /** + * Offset for field: + * {@snippet lang=c : + * int cbWndExtra + * } + */ + public static final long cbWndExtra$offset() { + return cbWndExtra$OFFSET; } + /** * Getter for field: - * {@snippet : - * int cbWndExtra; + * {@snippet lang=c : + * int cbWndExtra * } */ - public static int cbWndExtra$get(MemorySegment seg) { - return (int)constants$0.const$5.get(seg); + public static int cbWndExtra(MemorySegment struct) { + return struct.get(cbWndExtra$LAYOUT, cbWndExtra$OFFSET); } + /** * Setter for field: - * {@snippet : - * int cbWndExtra; + * {@snippet lang=c : + * int cbWndExtra * } */ - public static void cbWndExtra$set(MemorySegment seg, int x) { - constants$0.const$5.set(seg, x); + public static void cbWndExtra(MemorySegment struct, int fieldValue) { + struct.set(cbWndExtra$LAYOUT, cbWndExtra$OFFSET, fieldValue); } - public static int cbWndExtra$get(MemorySegment seg, long index) { - return (int)constants$0.const$5.get(seg.asSlice(index*sizeof())); - } - public static void cbWndExtra$set(MemorySegment seg, long index, int x) { - constants$0.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hInstance$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hInstance")); + + /** + * Layout for field: + * {@snippet lang=c : + * HINSTANCE hInstance + * } + */ + public static final AddressLayout hInstance$layout() { + return hInstance$LAYOUT; } - public static VarHandle hInstance$VH() { - return constants$1.const$0; + + private static final long hInstance$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * HINSTANCE hInstance + * } + */ + public static final long hInstance$offset() { + return hInstance$OFFSET; } + /** * Getter for field: - * {@snippet : - * HINSTANCE hInstance; + * {@snippet lang=c : + * HINSTANCE hInstance * } */ - public static MemorySegment hInstance$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$0.get(seg); + public static MemorySegment hInstance(MemorySegment struct) { + return struct.get(hInstance$LAYOUT, hInstance$OFFSET); } + /** * Setter for field: - * {@snippet : - * HINSTANCE hInstance; + * {@snippet lang=c : + * HINSTANCE hInstance * } */ - public static void hInstance$set(MemorySegment seg, MemorySegment x) { - constants$1.const$0.set(seg, x); - } - public static MemorySegment hInstance$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$0.get(seg.asSlice(index*sizeof())); + public static void hInstance(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hInstance$LAYOUT, hInstance$OFFSET, fieldValue); } - public static void hInstance$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$0.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hIcon$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hIcon")); + + /** + * Layout for field: + * {@snippet lang=c : + * HICON hIcon + * } + */ + public static final AddressLayout hIcon$layout() { + return hIcon$LAYOUT; } - public static VarHandle hIcon$VH() { - return constants$1.const$1; + + private static final long hIcon$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * HICON hIcon + * } + */ + public static final long hIcon$offset() { + return hIcon$OFFSET; } + /** * Getter for field: - * {@snippet : - * HICON hIcon; + * {@snippet lang=c : + * HICON hIcon * } */ - public static MemorySegment hIcon$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$1.get(seg); + public static MemorySegment hIcon(MemorySegment struct) { + return struct.get(hIcon$LAYOUT, hIcon$OFFSET); } + /** * Setter for field: - * {@snippet : - * HICON hIcon; + * {@snippet lang=c : + * HICON hIcon * } */ - public static void hIcon$set(MemorySegment seg, MemorySegment x) { - constants$1.const$1.set(seg, x); + public static void hIcon(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hIcon$LAYOUT, hIcon$OFFSET, fieldValue); } - public static MemorySegment hIcon$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$1.get(seg.asSlice(index*sizeof())); - } - public static void hIcon$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$1.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hCursor$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hCursor")); + + /** + * Layout for field: + * {@snippet lang=c : + * HCURSOR hCursor + * } + */ + public static final AddressLayout hCursor$layout() { + return hCursor$LAYOUT; } - public static VarHandle hCursor$VH() { - return constants$1.const$2; + + private static final long hCursor$OFFSET = 40; + + /** + * Offset for field: + * {@snippet lang=c : + * HCURSOR hCursor + * } + */ + public static final long hCursor$offset() { + return hCursor$OFFSET; } + /** * Getter for field: - * {@snippet : - * HCURSOR hCursor; + * {@snippet lang=c : + * HCURSOR hCursor * } */ - public static MemorySegment hCursor$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$2.get(seg); + public static MemorySegment hCursor(MemorySegment struct) { + return struct.get(hCursor$LAYOUT, hCursor$OFFSET); } + /** * Setter for field: - * {@snippet : - * HCURSOR hCursor; + * {@snippet lang=c : + * HCURSOR hCursor * } */ - public static void hCursor$set(MemorySegment seg, MemorySegment x) { - constants$1.const$2.set(seg, x); - } - public static MemorySegment hCursor$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$2.get(seg.asSlice(index*sizeof())); + public static void hCursor(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hCursor$LAYOUT, hCursor$OFFSET, fieldValue); } - public static void hCursor$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$2.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hbrBackground$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hbrBackground")); + + /** + * Layout for field: + * {@snippet lang=c : + * HBRUSH hbrBackground + * } + */ + public static final AddressLayout hbrBackground$layout() { + return hbrBackground$LAYOUT; } - public static VarHandle hbrBackground$VH() { - return constants$1.const$3; + + private static final long hbrBackground$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * HBRUSH hbrBackground + * } + */ + public static final long hbrBackground$offset() { + return hbrBackground$OFFSET; } + /** * Getter for field: - * {@snippet : - * HBRUSH hbrBackground; + * {@snippet lang=c : + * HBRUSH hbrBackground * } */ - public static MemorySegment hbrBackground$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$3.get(seg); + public static MemorySegment hbrBackground(MemorySegment struct) { + return struct.get(hbrBackground$LAYOUT, hbrBackground$OFFSET); } + /** * Setter for field: - * {@snippet : - * HBRUSH hbrBackground; + * {@snippet lang=c : + * HBRUSH hbrBackground * } */ - public static void hbrBackground$set(MemorySegment seg, MemorySegment x) { - constants$1.const$3.set(seg, x); + public static void hbrBackground(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hbrBackground$LAYOUT, hbrBackground$OFFSET, fieldValue); } - public static MemorySegment hbrBackground$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$3.get(seg.asSlice(index*sizeof())); - } - public static void hbrBackground$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$3.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout lpszMenuName$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpszMenuName")); + + /** + * Layout for field: + * {@snippet lang=c : + * LPCWSTR lpszMenuName + * } + */ + public static final AddressLayout lpszMenuName$layout() { + return lpszMenuName$LAYOUT; } - public static VarHandle lpszMenuName$VH() { - return constants$1.const$4; + + private static final long lpszMenuName$OFFSET = 56; + + /** + * Offset for field: + * {@snippet lang=c : + * LPCWSTR lpszMenuName + * } + */ + public static final long lpszMenuName$offset() { + return lpszMenuName$OFFSET; } + /** * Getter for field: - * {@snippet : - * LPCWSTR lpszMenuName; + * {@snippet lang=c : + * LPCWSTR lpszMenuName * } */ - public static MemorySegment lpszMenuName$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$4.get(seg); + public static MemorySegment lpszMenuName(MemorySegment struct) { + return struct.get(lpszMenuName$LAYOUT, lpszMenuName$OFFSET); } + /** * Setter for field: - * {@snippet : - * LPCWSTR lpszMenuName; + * {@snippet lang=c : + * LPCWSTR lpszMenuName * } */ - public static void lpszMenuName$set(MemorySegment seg, MemorySegment x) { - constants$1.const$4.set(seg, x); - } - public static MemorySegment lpszMenuName$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$4.get(seg.asSlice(index*sizeof())); + public static void lpszMenuName(MemorySegment struct, MemorySegment fieldValue) { + struct.set(lpszMenuName$LAYOUT, lpszMenuName$OFFSET, fieldValue); } - public static void lpszMenuName$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$4.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout lpszClassName$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpszClassName")); + + /** + * Layout for field: + * {@snippet lang=c : + * LPCWSTR lpszClassName + * } + */ + public static final AddressLayout lpszClassName$layout() { + return lpszClassName$LAYOUT; } - public static VarHandle lpszClassName$VH() { - return constants$1.const$5; + + private static final long lpszClassName$OFFSET = 64; + + /** + * Offset for field: + * {@snippet lang=c : + * LPCWSTR lpszClassName + * } + */ + public static final long lpszClassName$offset() { + return lpszClassName$OFFSET; } + /** * Getter for field: - * {@snippet : - * LPCWSTR lpszClassName; + * {@snippet lang=c : + * LPCWSTR lpszClassName * } */ - public static MemorySegment lpszClassName$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$1.const$5.get(seg); + public static MemorySegment lpszClassName(MemorySegment struct) { + return struct.get(lpszClassName$LAYOUT, lpszClassName$OFFSET); } + /** * Setter for field: - * {@snippet : - * LPCWSTR lpszClassName; + * {@snippet lang=c : + * LPCWSTR lpszClassName * } */ - public static void lpszClassName$set(MemorySegment seg, MemorySegment x) { - constants$1.const$5.set(seg, x); + public static void lpszClassName(MemorySegment struct, MemorySegment fieldValue) { + struct.set(lpszClassName$LAYOUT, lpszClassName$OFFSET, fieldValue); } - public static MemorySegment lpszClassName$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$1.const$5.get(seg.asSlice(index*sizeof())); - } - public static void lpszClassName$set(MemorySegment seg, long index, MemorySegment x) { - constants$1.const$5.set(seg.asSlice(index*sizeof()), x); + + private static final AddressLayout hIconSm$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hIconSm")); + + /** + * Layout for field: + * {@snippet lang=c : + * HICON hIconSm + * } + */ + public static final AddressLayout hIconSm$layout() { + return hIconSm$LAYOUT; } - public static VarHandle hIconSm$VH() { - return constants$2.const$0; + + private static final long hIconSm$OFFSET = 72; + + /** + * Offset for field: + * {@snippet lang=c : + * HICON hIconSm + * } + */ + public static final long hIconSm$offset() { + return hIconSm$OFFSET; } + /** * Getter for field: - * {@snippet : - * HICON hIconSm; + * {@snippet lang=c : + * HICON hIconSm * } */ - public static MemorySegment hIconSm$get(MemorySegment seg) { - return (java.lang.foreign.MemorySegment)constants$2.const$0.get(seg); + public static MemorySegment hIconSm(MemorySegment struct) { + return struct.get(hIconSm$LAYOUT, hIconSm$OFFSET); } + /** * Setter for field: - * {@snippet : - * HICON hIconSm; + * {@snippet lang=c : + * HICON hIconSm * } */ - public static void hIconSm$set(MemorySegment seg, MemorySegment x) { - constants$2.const$0.set(seg, x); + public static void hIconSm(MemorySegment struct, MemorySegment fieldValue) { + struct.set(hIconSm$LAYOUT, hIconSm$OFFSET, fieldValue); } - public static MemorySegment hIconSm$get(MemorySegment seg, long index) { - return (java.lang.foreign.MemorySegment)constants$2.const$0.get(seg.asSlice(index*sizeof())); + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); } - public static void hIconSm$set(MemorySegment seg, long index, MemorySegment x) { - constants$2.const$0.set(seg.asSlice(index*sizeof()), x); + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); } - public static long sizeof() { return $LAYOUT().byteSize(); } - public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); } - public static MemorySegment allocateArray(long len, SegmentAllocator allocator) { - return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT())); + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); } - public static MemorySegment ofAddress(MemorySegment addr, Arena scope) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, scope); } -} + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java deleted file mode 100644 index c9ab3d5..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java +++ /dev/null @@ -1,227 +0,0 @@ -package net.codecrete.usb.windows.gen.winusb; -// Generated by jextract - -import java.lang.foreign.*; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.*; - -final class RuntimeHelper { - - private static final Linker LINKER = Linker.nativeLinker(); - private static final ClassLoader LOADER = RuntimeHelper.class.getClassLoader(); - private static final MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup(); - private static final SymbolLookup SYMBOL_LOOKUP; - private static final SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); }; - static final AddressLayout POINTER = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE)); - - final static SegmentAllocator CONSTANT_ALLOCATOR = - (size, align) -> Arena.ofAuto().allocate(size, align); - - static { - System.loadLibrary("Winusb"); - SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); - SYMBOL_LOOKUP = name -> loaderLookup.find(name).or(() -> LINKER.defaultLookup().find(name)); - } - - // Suppresses default constructor, ensuring non-instantiability. - private RuntimeHelper() {} - - static T requireNonNull(T obj, String symbolName) { - if (obj == null) { - throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName); - } - return obj; - } - - static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { - return SYMBOL_LOOKUP.find(name) - .map(s -> s.reinterpret(layout.byteSize())) - .orElse(null); - } - - static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> LINKER.downcallHandle(addr, fdesc)). - orElse(null); - } - - static MethodHandle downcallHandle(FunctionDescriptor fdesc) { - return LINKER.downcallHandle(fdesc); - } - - static MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) { - return SYMBOL_LOOKUP.find(name). - map(addr -> VarargsInvoker.make(addr, fdesc)). - orElse(null); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MH_LOOKUP.findVirtual(fi, name, fdesc.toMethodType()); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment upcallStub(MethodHandle fiHandle, Z z, FunctionDescriptor fdesc, Arena scope) { - try { - fiHandle = fiHandle.bindTo(z); - return LINKER.upcallStub(fiHandle, fdesc, scope); - } catch (Throwable ex) { - throw new AssertionError(ex); - } - } - - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { - return addr.reinterpret(numElements * layout.byteSize(), arena, null); - } - - // Internals only below this point - - private static final class VarargsInvoker { - private static final MethodHandle INVOKE_MH; - private final MemorySegment symbol; - private final FunctionDescriptor function; - - private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) { - this.symbol = symbol; - this.function = function; - } - - static { - try { - INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) { - VarargsInvoker invoker = new VarargsInvoker(symbol, function); - MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1); - MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class); - for (MemoryLayout layout : function.argumentLayouts()) { - mtype = mtype.appendParameterTypes(carrier(layout, false)); - } - mtype = mtype.appendParameterTypes(Object[].class); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mtype = mtype.insertParameterTypes(0, SegmentAllocator.class); - } else { - handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR); - } - return handle.asType(mtype); - } - - static Class carrier(MemoryLayout layout, boolean ret) { - if (layout instanceof ValueLayout valueLayout) { - return valueLayout.carrier(); - } else if (layout instanceof GroupLayout) { - return MemorySegment.class; - } else { - throw new AssertionError("Cannot get here!"); - } - } - - private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable { - // one trailing Object[] - int nNamedArgs = function.argumentLayouts().size(); - assert(args.length == nNamedArgs + 1); - // The last argument is the array of vararg collector - Object[] unnamedArgs = (Object[]) args[args.length - 1]; - - int argsCount = nNamedArgs + unnamedArgs.length; - Class[] argTypes = new Class[argsCount]; - MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length]; - - int pos = 0; - for (pos = 0; pos < nNamedArgs; pos++) { - argLayouts[pos] = function.argumentLayouts().get(pos); - } - - assert pos == nNamedArgs; - for (Object o: unnamedArgs) { - argLayouts[pos] = variadicLayout(normalize(o.getClass())); - pos++; - } - assert pos == argsCount; - - FunctionDescriptor f = (function.returnLayout().isEmpty()) ? - FunctionDescriptor.ofVoid(argLayouts) : - FunctionDescriptor.of(function.returnLayout().get(), argLayouts); - MethodHandle mh = LINKER.downcallHandle(symbol, f); - boolean needsAllocator = function.returnLayout().isPresent() && - function.returnLayout().get() instanceof GroupLayout; - if (needsAllocator) { - mh = mh.bindTo(allocator); - } - // flatten argument list so that it can be passed to an asSpreader MH - Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length]; - System.arraycopy(args, 0, allArgs, 0, nNamedArgs); - System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length); - - return mh.asSpreader(Object[].class, argsCount).invoke(allArgs); - } - - private static Class unboxIfNeeded(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Void.class) { - return void.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } - } - - private Class promote(Class c) { - if (c == byte.class || c == char.class || c == short.class || c == int.class) { - return long.class; - } else if (c == float.class) { - return double.class; - } else { - return c; - } - } - - private Class normalize(Class c) { - c = unboxIfNeeded(c); - if (c.isPrimitive()) { - return promote(c); - } - if (c == MemorySegment.class) { - return MemorySegment.class; - } - throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName()); - } - - private MemoryLayout variadicLayout(Class c) { - if (c == long.class) { - return JAVA_LONG; - } else if (c == double.class) { - return JAVA_DOUBLE; - } else if (c == MemorySegment.class) { - return ADDRESS; - } else { - throw new IllegalArgumentException("Unhandled variadic argument class: " + c); - } - } - } -} diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java index a35ff11..5d9a82f 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java @@ -2,53 +2,138 @@ package net.codecrete.usb.windows.gen.winusb; -import java.lang.foreign.AddressLayout; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; import static java.lang.foreign.ValueLayout.*; -public class WinUSB { - - public static final OfByte C_CHAR = JAVA_BYTE; - public static final OfShort C_SHORT = JAVA_SHORT; - public static final OfInt C_INT = JAVA_INT; - public static final OfInt C_LONG = JAVA_INT; - public static final OfLong C_LONG_LONG = JAVA_LONG; - public static final OfFloat C_FLOAT = JAVA_FLOAT; - public static final OfDouble C_DOUBLE = JAVA_DOUBLE; - public static final AddressLayout C_POINTER = RuntimeHelper.POINTER; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class WinUSB { + + WinUSB() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("Winusb"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT; + public static final ValueLayout.OfDouble C_LONG_DOUBLE = ValueLayout.JAVA_DOUBLE; + private static final int PIPE_TRANSFER_TIMEOUT = (int)3L; /** - * {@snippet : + * {@snippet lang=c : * #define PIPE_TRANSFER_TIMEOUT 3 * } */ public static int PIPE_TRANSFER_TIMEOUT() { - return (int)3L; + return PIPE_TRANSFER_TIMEOUT; } + private static final int RAW_IO = (int)7L; /** - * {@snippet : + * {@snippet lang=c : * #define RAW_IO 7 * } */ public static int RAW_IO() { - return (int)7L; + return RAW_IO; + } + + private static class WinUsb_Free { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + WinUSB.C_INT, + WinUSB.C_POINTER + ); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( + WinUSB.findOrThrow("WinUsb_Free"), + DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BOOL WinUsb_Free(WINUSB_INTERFACE_HANDLE InterfaceHandle) + * } + */ + public static FunctionDescriptor WinUsb_Free$descriptor() { + return WinUsb_Free.DESC; } - public static MethodHandle WinUsb_Free$MH() { - return RuntimeHelper.requireNonNull(constants$0.const$1,"WinUsb_Free"); + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BOOL WinUsb_Free(WINUSB_INTERFACE_HANDLE InterfaceHandle) + * } + */ + public static MethodHandle WinUsb_Free$handle() { + return WinUsb_Free.HANDLE; } /** - * {@snippet : - * BOOL WinUsb_Free(WINUSB_INTERFACE_HANDLE InterfaceHandle); + * {@snippet lang=c : + * BOOL WinUsb_Free(WINUSB_INTERFACE_HANDLE InterfaceHandle) * } */ public static int WinUsb_Free(MemorySegment InterfaceHandle) { - var mh$ = WinUsb_Free$MH(); + var mh$ = WinUsb_Free.HANDLE; try { + if (TRACE_DOWNCALLS) { + traceDowncall("WinUsb_Free", InterfaceHandle); + } return (int)mh$.invokeExact(InterfaceHandle); } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); + throw new AssertionError("should not reach here", ex$); } } } - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java deleted file mode 100644 index 90f3902..0000000 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by jextract - -package net.codecrete.usb.windows.gen.winusb; - -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; - -import static java.lang.foreign.ValueLayout.JAVA_INT; -final class constants$0 { - - // Suppresses default constructor, ensuring non-instantiability. - private constants$0() {} - static final FunctionDescriptor const$0 = FunctionDescriptor.of(JAVA_INT, - RuntimeHelper.POINTER - ); - static final MethodHandle const$1 = RuntimeHelper.downcallHandle( - "WinUsb_Free", - constants$0.const$0 - ); -} - - diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/Kernel32B.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/Kernel32B.java index 4de451f..f177955 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/Kernel32B.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/Kernel32B.java @@ -14,7 +14,9 @@ import java.lang.foreign.SymbolLookup; import java.lang.invoke.MethodHandle; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_LONG; /** * Native function calls for Kernel32. diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/User32B.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/User32B.java index 05caa2f..3d71892 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/User32B.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/User32B.java @@ -14,7 +14,9 @@ import java.lang.foreign.SymbolLookup; import java.lang.invoke.MethodHandle; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_INT; +import static java.lang.foreign.ValueLayout.JAVA_SHORT; /** * Native function calls for User32. diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/WinUSB2.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/WinUSB2.java index 940ae40..f8d6cd8 100644 --- a/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/WinUSB2.java +++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/winsdk/WinUSB2.java @@ -15,7 +15,9 @@ import java.lang.foreign.SymbolLookup; import java.lang.invoke.MethodHandle; -import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.ValueLayout.ADDRESS; +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_INT; /** * Native function calls for WinUSB. diff --git a/java-does-usb/src/test/java/net/codecrete/usb/AlternateInterfaceTest.java b/java-does-usb/src/test/java/net/codecrete/usb/AlternateInterfaceTest.java index 12f05dc..e268725 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/AlternateInterfaceTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/AlternateInterfaceTest.java @@ -13,7 +13,10 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; class AlternateInterfaceTest extends TestDeviceBase { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/BulkTransferTest.java b/java-does-usb/src/test/java/net/codecrete/usb/BulkTransferTest.java index 08e80e4..582fca2 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/BulkTransferTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/BulkTransferTest.java @@ -15,7 +15,9 @@ import java.util.Arrays; import java.util.concurrent.CompletableFuture; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; class BulkTransferTest extends TestDeviceBase { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/ConfigurationParserTest.java b/java-does-usb/src/test/java/net/codecrete/usb/ConfigurationParserTest.java index ee3a091..2117df2 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/ConfigurationParserTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/ConfigurationParserTest.java @@ -6,7 +6,9 @@ import java.lang.foreign.MemorySegment; -import static net.codecrete.usb.ConfigurationDescriptors.*; +import static net.codecrete.usb.ConfigurationDescriptors.COMPOSITE_LARGE; +import static net.codecrete.usb.ConfigurationDescriptors.COMPOSITE_TEST_DEVICE; +import static net.codecrete.usb.ConfigurationDescriptors.SIMPLE; import static org.assertj.core.api.Assertions.assertThatThrownBy; class ConfigurationParserTest { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/ControlTransferTest.java b/java-does-usb/src/test/java/net/codecrete/usb/ControlTransferTest.java index 9d09d4e..8a65367 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/ControlTransferTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/ControlTransferTest.java @@ -11,7 +11,9 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests control transfers diff --git a/java-does-usb/src/test/java/net/codecrete/usb/DescriptionTest.java b/java-does-usb/src/test/java/net/codecrete/usb/DescriptionTest.java index 801f68f..42097c2 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/DescriptionTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/DescriptionTest.java @@ -11,7 +11,11 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the interface, alternate settings and endpoint descriptions. diff --git a/java-does-usb/src/test/java/net/codecrete/usb/DeviceLifecycleTest.java b/java-does-usb/src/test/java/net/codecrete/usb/DeviceLifecycleTest.java index 69ba293..da9b6ee 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/DeviceLifecycleTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/DeviceLifecycleTest.java @@ -12,7 +12,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; class DeviceLifecycleTest { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/SpeedTest.java b/java-does-usb/src/test/java/net/codecrete/usb/SpeedTest.java index 33d0b82..1733b58 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/SpeedTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/SpeedTest.java @@ -14,7 +14,8 @@ import java.io.IOException; import java.util.concurrent.CompletableFuture; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class SpeedTest extends TestDeviceBase { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/special/Continuous.java b/java-does-usb/src/test/java/net/codecrete/usb/special/Continuous.java new file mode 100644 index 0000000..d9c6ad4 --- /dev/null +++ b/java-does-usb/src/test/java/net/codecrete/usb/special/Continuous.java @@ -0,0 +1,61 @@ +package net.codecrete.usb.special; + +import net.codecrete.usb.Usb; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbException; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Random; + +public class Continuous { + + @SuppressWarnings("ResultOfMethodCallIgnored") + public static void main(String[] args) throws IOException { + var device = Usb.findDevice(0xcafe, 0xceaf) + .or(() -> Usb.findDevice(0xcafe, 0xcea0)) + .orElseThrow(() -> new IllegalStateException("No test device connected")); + var interfaceNumber = device.getProductId() == 0xceaf ? 0 : 3; + + device.open(); + device.claimInterface(interfaceNumber); + + new Thread(() -> readData(device)).start(); + new Thread(() -> sendData(device)).start(); + + System.out.println("Press RETURN to exit"); + System.in.read(); + device.close(); + } + + @SuppressWarnings({"java:S2925", "BusyWait"}) + private static void sendData(UsbDevice device) { + var random = new Random(); + var buffer = new byte[40]; + + while (true) { + random.nextBytes(buffer); + try { + device.transferOut(1, buffer); + Thread.sleep(3000); + } catch (UsbException e) { + return; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + + private static void readData(UsbDevice device) { + var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + while (true) { + try { + var packet = device.transferIn(2); + System.out.printf("%s packet of %d bytes received\n", LocalDateTime.now().format(formatter), packet.length); + } catch (UsbException e) { + return; + } + } + } +} diff --git a/java-does-usb/src/test/java/net/codecrete/usb/special/LogicAnalyzer.java b/java-does-usb/src/test/java/net/codecrete/usb/special/LogicAnalyzer.java index c50b04e..12b9b6e 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/special/LogicAnalyzer.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/special/LogicAnalyzer.java @@ -10,7 +10,13 @@ package net.codecrete.usb.special; -import net.codecrete.usb.*; +import net.codecrete.usb.Usb; +import net.codecrete.usb.UsbControlTransfer; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbDirection; +import net.codecrete.usb.UsbException; +import net.codecrete.usb.UsbRecipient; +import net.codecrete.usb.UsbRequestType; import java.io.Closeable; import java.io.IOException; diff --git a/java-does-usb/src/test/java/net/codecrete/usb/special/MonitorDevices.java b/java-does-usb/src/test/java/net/codecrete/usb/special/MonitorDevices.java index fd7fdc5..cc31826 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/special/MonitorDevices.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/special/MonitorDevices.java @@ -7,7 +7,11 @@ package net.codecrete.usb.special; -import net.codecrete.usb.*; +import net.codecrete.usb.Usb; +import net.codecrete.usb.UsbControlTransfer; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbRecipient; +import net.codecrete.usb.UsbRequestType; import java.io.IOException; @@ -21,13 +25,13 @@ public class MonitorDevices { public static void main(String[] args) throws IOException { Usb.setOnDeviceConnected((device) -> { - System.out.println(STR."Connected: \{device.toString()}"); + System.out.println("Connected: " + device.toString()); talkToTestDevice(device); }); - Usb.setOnDeviceDisconnected((device) -> System.out.println(STR."Disconnected: \{device.toString()}")); + Usb.setOnDeviceDisconnected((device) -> System.out.println("Disconnected: " + device.toString())); for (var device : Usb.getDevices()) { - System.out.println(STR."Present: \{device.toString()}"); + System.out.println("Present: " + device.toString()); talkToTestDevice(device); } System.out.println("Monitoring..."); diff --git a/java-does-usb/src/test/java/net/codecrete/usb/special/USBSerialTest.java b/java-does-usb/src/test/java/net/codecrete/usb/special/USBSerial.java similarity index 92% rename from java-does-usb/src/test/java/net/codecrete/usb/special/USBSerialTest.java rename to java-does-usb/src/test/java/net/codecrete/usb/special/USBSerial.java index 04964ba..efaaaf4 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/special/USBSerialTest.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/special/USBSerial.java @@ -7,7 +7,12 @@ package net.codecrete.usb.special; -import net.codecrete.usb.*; +import net.codecrete.usb.Usb; +import net.codecrete.usb.UsbControlTransfer; +import net.codecrete.usb.UsbDevice; +import net.codecrete.usb.UsbDirection; +import net.codecrete.usb.UsbRecipient; +import net.codecrete.usb.UsbRequestType; /** * Interacts with a USB CDC device (serial device) directly, without using the @@ -26,7 +31,7 @@ * apply for this test. *

*/ -public class USBSerialTest { +public class USBSerial { public static void main(String[] args) { for (var device : Usb.getDevices()) { diff --git a/java-does-usb/src/test/java/net/codecrete/usb/special/Unplug.java b/java-does-usb/src/test/java/net/codecrete/usb/special/Unplug.java index a4ea7ee..87a0463 100644 --- a/java-does-usb/src/test/java/net/codecrete/usb/special/Unplug.java +++ b/java-does-usb/src/test/java/net/codecrete/usb/special/Unplug.java @@ -15,7 +15,7 @@ import java.io.IOException; import java.util.HashMap; -import static java.time.Duration.*; +import static java.time.Duration.ofSeconds; /** * Test for robustness when USB devices is unplugged during operation. diff --git a/reference/README.md b/reference/README.md index 6b5c71d..a8d4b96 100644 --- a/reference/README.md +++ b/reference/README.md @@ -6,4 +6,4 @@ The C++ code contains less error checking, less test cases and does not cover al - [MacOS](macos) (for use with Xcode) - [Windows](windows) (for use with Visual Studio) -- [LInux](linux) (for use with CMake) +- [Linux](linux) (for use with CMake) diff --git a/test-devices/composite-stm32/README.md b/test-devices/composite-stm32/README.md index 931eef4..bdea208 100644 --- a/test-devices/composite-stm32/README.md +++ b/test-devices/composite-stm32/README.md @@ -75,7 +75,7 @@ To upload using the BlackPill's built-in bootloader: 2. Press the *Boot* button while connecting the board via USB to your computer. By pressing the *Boot* button, the device enters bootloader mode. 3. Verify with `dfu-util --list` that the bootloader is available via USB. If not unplug the device and repeat step 2. 4. Run the below command from the project directory. -5. Unplug and reconnect the board from your computer. The LED should now blink about twice a second. +5. Unplug and reconnect the board from your computer. Both the power and user LED should be lit and the device should appear as a serial device (aka as COM port on Windows). ``` dfu-util --device 0483:df11 --alt 0 --dfuse-address 0x08000000 --reset --download bin/blackpill-fxxx.bin diff --git a/test-devices/composite-stm32/bin/blackpill-f401cc.bin b/test-devices/composite-stm32/bin/blackpill-f401cc.bin index 1df99e2..81f2e06 100755 Binary files a/test-devices/composite-stm32/bin/blackpill-f401cc.bin and b/test-devices/composite-stm32/bin/blackpill-f401cc.bin differ diff --git a/test-devices/composite-stm32/bin/blackpill-f411ce.bin b/test-devices/composite-stm32/bin/blackpill-f411ce.bin index c92dcc7..1f9993c 100755 Binary files a/test-devices/composite-stm32/bin/blackpill-f411ce.bin and b/test-devices/composite-stm32/bin/blackpill-f411ce.bin differ diff --git a/test-devices/composite-stm32/bin/bluepill-f103c8.bin b/test-devices/composite-stm32/bin/bluepill-f103c8.bin index 84a8557..70d232b 100755 Binary files a/test-devices/composite-stm32/bin/bluepill-f103c8.bin and b/test-devices/composite-stm32/bin/bluepill-f103c8.bin differ diff --git a/test-devices/composite-stm32/src/board_f1.c b/test-devices/composite-stm32/src/board_f1.c index e3dc0eb..344cae6 100644 --- a/test-devices/composite-stm32/src/board_f1.c +++ b/test-devices/composite-stm32/src/board_f1.c @@ -188,20 +188,16 @@ uint32_t board_millis(void) { void board_led_write(bool on) { if (on) - gpio_set(GPIOB, 12); - else gpio_clear(GPIOB, 12); + else + gpio_set(GPIOB, 12); } // --- Interrupt handlers --- void SysTick_Handler (void) { - millis_count++; -} - -void USBWakeUp_IRQHandler(void) { - tud_int_handler(0); + millis_count++; } void USB_HP_IRQHandler(void) { diff --git a/test-devices/composite-stm32/src/board_f4.c b/test-devices/composite-stm32/src/board_f4.c index 6f83803..927320d 100644 --- a/test-devices/composite-stm32/src/board_f4.c +++ b/test-devices/composite-stm32/src/board_f4.c @@ -262,16 +262,16 @@ uint32_t board_millis(void) { void board_led_write(bool on) { if (on) - gpio_set(GPIOC, 13); - else gpio_clear(GPIOC, 13); + else + gpio_set(GPIOC, 13); } // --- Interrupt handlers --- void SysTick_Handler (void) { - millis_count++; + millis_count++; } void OTG_FS_IRQHandler(void) { diff --git a/test-devices/composite-stm32/src/main.c b/test-devices/composite-stm32/src/main.c index 034a371..0ae69a2 100644 --- a/test-devices/composite-stm32/src/main.c +++ b/test-devices/composite-stm32/src/main.c @@ -25,15 +25,16 @@ uint8_t loopback_buffer[512]; // RX buffer for loopback uint8_t loopback_rx_buffer[64]; -// Blink durations -enum { - BLINK_NOT_MOUNTED = 250, - BLINK_MOUNTED = 1000, - BLINK_SUSPENDED = 2500, -}; +static bool is_blinking = true; +static uint32_t led_on_until = 0; +static uint32_t blink_toogle_at = 0; +static bool is_blink_on = true; -static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; +static inline bool has_expired(uint32_t deadline, uint32_t now) { + return (int32_t)(now - deadline) >= 0; +} +static void led_busy(void); static void led_blinking_task(void); static void cdc_task(void); static void loopback_init(void); @@ -82,6 +83,7 @@ void loopback_check_tx(void) { n = 128; cust_vendor_start_transmit(EP_LOOPBACK_TX, info.ptr_lin, n); + led_busy(); } } @@ -105,6 +107,7 @@ void cdc_task(void) { tud_cdc_write(buf, n); tud_cdc_write_flush(); + led_busy(); } @@ -115,6 +118,7 @@ void cust_vendor_rx_cb(uint8_t ep_addr, uint32_t recv_bytes) { tu_fifo_write_n(&loopback_fifo, loopback_rx_buffer, recv_bytes); loopback_check_rx(); loopback_check_tx(); + led_busy(); } // Invoked when last tx transfer finished @@ -134,11 +138,14 @@ void cust_vendor_tx_cb(uint8_t ep_addr, uint32_t sent_bytes) { if ((sent_bytes & (BULK_MAX_PACKET_SIZE - 1)) == 0 && !cust_vendor_is_transmitting(ep_addr)) cust_vendor_start_transmit(EP_LOOPBACK_TX, NULL, 0); + + led_busy(); } // Invoked when interface has been opened void cust_vendor_intf_open_cb(uint8_t intf) { loopback_check_rx(); + led_busy(); } void cust_vendor_halt_cleared_cb(uint8_t ep_addr) { @@ -152,6 +159,7 @@ void cust_vendor_halt_cleared_cb(uint8_t ep_addr) { default: break; } + led_busy(); } @@ -176,6 +184,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_SAVE_VALUE: if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 0) { + led_busy(); // save value from wValue saved_value = request->wValue; return tud_control_status(rhport, request); @@ -184,6 +193,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_SAVE_DATA: if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 4) { + led_busy(); // receive into `saved_value` return tud_control_xfer(rhport, request, &saved_value, 4); } @@ -191,6 +201,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_SEND_DATA: if (request->bmRequestType_bit.direction == TUSB_DIR_IN && request->wLength == 4) { + led_busy(); // transmit from `saved_value` return tud_control_xfer(rhport, request, &saved_value, 4); } @@ -198,6 +209,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_RESET_BUFFERS: if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 0) { + led_busy(); reset_buffers(); return tud_control_status(rhport, request); } @@ -207,6 +219,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ if (request->bmRequestType_bit.direction == TUSB_DIR_IN && request->wLength == 1) { uint8_t intf_num = request->wIndex & 0xff; if (intf_num < 4) { + led_busy(); // return inteface number return tud_control_xfer(rhport, request, &intf_num, 1); } @@ -247,38 +260,27 @@ usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) { // Invoked when device is mounted void tud_mount_cb(void) { - blink_interval_ms = BLINK_MOUNTED; + is_blinking = false; } -// Invoked when device is unmounted -void tud_umount_cb(void) { - blink_interval_ms = BLINK_NOT_MOUNTED; -} -// Invoked when usb bus is suspended -// remote_wakeup_en: if host allow us to perform remote wakeup -// Within 7ms, device must draw an average of current less than 2.5 mA from bus -void tud_suspend_cb(bool remote_wakeup_en) { - (void) remote_wakeup_en; - blink_interval_ms = BLINK_SUSPENDED; -} +// --- LED blinking --- -// Invoked when usb bus is resumed -void tud_resume_cb(void) { - blink_interval_ms = BLINK_MOUNTED; +void led_busy(void) { + led_on_until = board_millis() + 100; + board_led_write(true); } -// --- LED blinking --- - void led_blinking_task(void) { - static uint32_t start_ms = 0; - static bool led_state = false; - - // Blink every interval ms - if ( board_millis() - start_ms < blink_interval_ms) - return; // not enough time - start_ms += blink_interval_ms; - - board_led_write(led_state); - led_state = 1 - led_state; // toggle + uint32_t now = board_millis(); + if (is_blinking) { + if (has_expired(blink_toogle_at, now)) { + is_blink_on = !is_blink_on; + blink_toogle_at = now + 250; + } + board_led_write(is_blink_on && (now & 7) == 0); + + } else if (has_expired(led_on_until, now)) { + board_led_write((now & 3) == 0); + } } diff --git a/test-devices/loopback-stm32/.vscode/settings.json b/test-devices/loopback-stm32/.vscode/settings.json index a92d133..1a7c2ee 100644 --- a/test-devices/loopback-stm32/.vscode/settings.json +++ b/test-devices/loopback-stm32/.vscode/settings.json @@ -3,6 +3,9 @@ "usbd.h": "c", "usbd_pvt.h": "c", "dwc2_stm32.h": "c", - "stm32f7xx.h": "c" + "stm32f7xx.h": "c", + "stm32f4xx.h": "c", + "stm32f401xc.h": "c", + "stm32f401xe.h": "c" } } \ No newline at end of file diff --git a/test-devices/loopback-stm32/README.md b/test-devices/loopback-stm32/README.md index b485a64..4533209 100644 --- a/test-devices/loopback-stm32/README.md +++ b/test-devices/loopback-stm32/README.md @@ -7,8 +7,9 @@ For testing the *Java Does USB* library, a dedicated USB test device is needed. - BlackPill with STM32F401CC microcontroller - BlackPill with STM32F411CE microcontroller - BluePill with STM32F103C8 microcontroller +- STM32F723 Discovery board -To upload the firmware, the STM32F4x microcontroller have a built-in USB bootloader. The STM32F1x microcontrollers need an ST-Link debug adapter (or a USB-to-serial converter). +To upload the firmware, the STM32F4x microcontroller have a built-in USB bootloader. The STM32F1x microcontrollers need an ST-Link debug adapter (or a USB-to-serial converter). The STM32F723 Discovery board has a built-in ST-Link programmer. ## Test features @@ -45,6 +46,18 @@ Two alternate interfaces are implemented: - Alternate 1: only the control endpoint and the bulk endpoints (0x01 and 0x82) are available +### Suspend / resume + +The device can be put into suspend mode by the host. It will go into a low-power mode. This is indicated by the user LED turning off. The power LED will stay on. The device can be woken up by the host. + +To put the device into suspended mode, put the host computer to sleep or supended mode. To wake it up, wake up the host computer. + +NOTE: *Due to a limitation of TinyUSB, the device will only go into suspended mode if the host has set a USB configuration. Usually it means that an application has communicated with the device after it was plugged in. The LED blinks as long as no USB configuration has been set.* + +NOTE: *Suspend/resume has not been implemented for the STM32F723 Discovery board.* + + + ## Building the firmware This project requires [PlatformIO](https://platformio.org/). The easiest way to get up and running is to use Visual Studio Code and then install the [PlatformIO IDE extension](https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide). @@ -69,6 +82,7 @@ The directory `bin` contains a pre-built firmware: - `blackpill-f401cc.bin`: Firmware for BlackPill with STM32F401CC microcontroller - `blackpill-f411ce.bin`: Firmware for BlackPill with STM32F411CE microcontroller - `bluepill-f103c8.bin`: Firmware for BluePill with STM32F103C8 microcontroller +- `disco_f723ie.bin`: Firmware for STM32F723 Discovery board ### Upload using built-in bootloader diff --git a/test-devices/loopback-stm32/bin/blackpill-f401cc.bin b/test-devices/loopback-stm32/bin/blackpill-f401cc.bin index fd044b6..bb69371 100755 Binary files a/test-devices/loopback-stm32/bin/blackpill-f401cc.bin and b/test-devices/loopback-stm32/bin/blackpill-f401cc.bin differ diff --git a/test-devices/loopback-stm32/bin/blackpill-f411ce.bin b/test-devices/loopback-stm32/bin/blackpill-f411ce.bin index ad2b198..8f478d2 100755 Binary files a/test-devices/loopback-stm32/bin/blackpill-f411ce.bin and b/test-devices/loopback-stm32/bin/blackpill-f411ce.bin differ diff --git a/test-devices/loopback-stm32/bin/bluepill-f103c8.bin b/test-devices/loopback-stm32/bin/bluepill-f103c8.bin index 0d10a31..d123d88 100755 Binary files a/test-devices/loopback-stm32/bin/bluepill-f103c8.bin and b/test-devices/loopback-stm32/bin/bluepill-f103c8.bin differ diff --git a/test-devices/loopback-stm32/bin/disco_f723ie.bin b/test-devices/loopback-stm32/bin/disco_f723ie.bin index 5154fd6..da78a59 100755 Binary files a/test-devices/loopback-stm32/bin/disco_f723ie.bin and b/test-devices/loopback-stm32/bin/disco_f723ie.bin differ diff --git a/test-devices/loopback-stm32/src/board.h b/test-devices/loopback-stm32/src/board.h index 4e032fd..8d07340 100644 --- a/test-devices/loopback-stm32/src/board.h +++ b/test-devices/loopback-stm32/src/board.h @@ -28,6 +28,9 @@ void board_led_write(bool on); // Return the number of milliseconds since a time in the past uint32_t board_millis(void); +// Enter sleep or stop mode and wake up on USB resume +void board_sleep(void); + // USB serial number extern char board_serial_num[13]; diff --git a/test-devices/loopback-stm32/src/board_f1.c b/test-devices/loopback-stm32/src/board_f1.c index ac547f6..d0690d8 100644 --- a/test-devices/loopback-stm32/src/board_f1.c +++ b/test-devices/loopback-stm32/src/board_f1.c @@ -15,6 +15,8 @@ #include "stm32f1xx.h" #include "device/usbd.h" +#define EXTI_USBWakeUp_Line EXTI_IMR_IM18 + extern uint32_t SystemCoreClock; void SystemCoreClockUpdate(void); @@ -180,6 +182,12 @@ void board_init(void) { gpio_set_mode(GPIOB, 12, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSH_PULL); usb_init_serial_num(); + + // Wake up event is only available as interrupt, not as an event. + // See product errata sheet + set_reg(&EXTI->RTSR, EXTI_USBWakeUp_Line, EXTI_USBWakeUp_Line); + set_reg(&EXTI->IMR, EXTI_USBWakeUp_Line, EXTI_USBWakeUp_Line); + NVIC_EnableIRQ(USBWakeUp_IRQn); } uint32_t board_millis(void) { @@ -188,9 +196,38 @@ uint32_t board_millis(void) { void board_led_write(bool on) { if (on) - gpio_set(GPIOB, 12); - else gpio_clear(GPIOB, 12); + else + gpio_set(GPIOB, 12); +} + +void board_sleep(void) { + + // turn off LED + board_led_write(false); + + // pause systick interrupts + set_reg(&SysTick->CTRL, 0, SysTick_CTRL_TICKINT_Msk); + + // enter Stop mode when the CPU enters deep sleep + set_reg(&PWR->CR, 0, PWR_CR_PDDS_Msk | PWR_CR_LPDS_Msk); + + set_reg(&SCB->SCR, SCB_SCR_SLEEPDEEP_Msk, SCB_SCR_SLEEPDEEP_Msk); + + // sleep until an interrupt occurs + __WFI(); + + // reset SLEEPDEEP bit + set_reg(&SCB->SCR, 0, SCB_SCR_SLEEPDEEP_Msk); + + // after wakeup, re-enable PLL as clock source + rcc_clock_setup_in_hse_8mhz_out_72mhz(); + + // resume systick interrupts + set_reg(&SysTick->CTRL, SysTick_CTRL_TICKINT_Msk, SysTick_CTRL_TICKINT_Msk); + + // turn on LED + board_led_write(true); } @@ -201,7 +238,8 @@ void SysTick_Handler (void) { } void USBWakeUp_IRQHandler(void) { - tud_int_handler(0); + // clear interrupt + EXTI->PR = EXTI_USBWakeUp_Line; } void USB_HP_IRQHandler(void) { diff --git a/test-devices/loopback-stm32/src/board_f4.c b/test-devices/loopback-stm32/src/board_f4.c index 4499e8c..dfb887e 100644 --- a/test-devices/loopback-stm32/src/board_f4.c +++ b/test-devices/loopback-stm32/src/board_f4.c @@ -15,6 +15,9 @@ #include "stm32f4xx.h" #include "device/usbd.h" +#define EXTI_USBWakeUp_Line EXTI_IMR_IM18 + + extern uint32_t SystemCoreClock; void SystemCoreClockUpdate(void); @@ -85,6 +88,11 @@ const rcc_clock_setup_t clock_setup_hse_value_out_84mhz_3v3 = { #define GPIO_OSPEED_HIGH 3 +// --- additional USB register +#define PCGCCTL ((volatile uint32_t *)((uint32_t)USB_OTG_FS + USB_OTG_PCGCCTL_BASE)) + + + static inline void rcc_wait_for_osc_ready(uint32_t rcc_cr_clk_rdy) { while (get_reg(&RCC->CR, rcc_cr_clk_rdy) == 0) ; @@ -254,6 +262,13 @@ void board_init(void) { gpio_mode_setup(GPIOC, 13, GPIO_MODE_OUTPUT, GPIO_PUPD_NO_PULL); usb_init_serial_num(); + + // enable USB wakeup interrupt + EXTI->PR = EXTI_USBWakeUp_Line; + EXTI->RTSR |= EXTI_USBWakeUp_Line; + EXTI->IMR |= EXTI_USBWakeUp_Line; + NVIC_SetPriority(OTG_FS_WKUP_IRQn, 0); + NVIC_EnableIRQ(OTG_FS_WKUP_IRQn); } uint32_t board_millis(void) { @@ -262,9 +277,44 @@ uint32_t board_millis(void) { void board_led_write(bool on) { if (on) - gpio_set(GPIOC, 13); - else gpio_clear(GPIOC, 13); + else + gpio_set(GPIOC, 13); +} + +void board_sleep(void) { + + // turn off LED + board_led_write(false); + + // stop PCLK to USB + set_reg(PCGCCTL, USB_OTG_PCGCCTL_STOPCLK, USB_OTG_PCGCCTL_STOPCLK_Msk); + + // pause systick interrupts + set_reg(&SysTick->CTRL, 0, SysTick_CTRL_TICKINT_Msk); + + // enter stop mode when the CPU enters deep sleep + set_reg(&PWR->CR, 0, PWR_CR_PDDS_Msk | PWR_CR_LPDS_Msk); + + // use deep sleep mode + set_reg(&SCB->SCR, SCB_SCR_SLEEPDEEP_Msk, SCB_SCR_SLEEPDEEP_Msk); + + __WFI(); + + // reset to regular sleep mode + set_reg(&SCB->SCR, 0, SCB_SCR_SLEEPDEEP_Msk); + + // after wakeup, re-enable PLL as clock source + rcc_clock_setup_pll(&clock_setup_hse_value_out_84mhz_3v3); + + // resume systick interrupts + set_reg(&SysTick->CTRL, SysTick_CTRL_TICKINT_Msk, SysTick_CTRL_TICKINT_Msk); + + // restart PCLK to USB + set_reg(PCGCCTL, 0, USB_OTG_PCGCCTL_STOPCLK_Msk); + + // turn on LED + board_led_write(true); } @@ -278,4 +328,9 @@ void OTG_FS_IRQHandler(void) { tud_int_handler(0); } +void OTG_FS_WKUP_IRQHandler(void) { + // clear interrupt + EXTI->PR = EXTI_USBWakeUp_Line; +} + #endif diff --git a/test-devices/loopback-stm32/src/board_f7.c b/test-devices/loopback-stm32/src/board_f7.c index bdff30b..34d40bf 100644 --- a/test-devices/loopback-stm32/src/board_f7.c +++ b/test-devices/loopback-stm32/src/board_f7.c @@ -284,6 +284,10 @@ void board_init(void) { usb_init_serial_num(); } +void board_sleep(void) { + // not implemented yet +} + uint32_t board_millis(void) { return millis_count; } diff --git a/test-devices/loopback-stm32/src/main.c b/test-devices/loopback-stm32/src/main.c index 31d9cca..9449565 100644 --- a/test-devices/loopback-stm32/src/main.c +++ b/test-devices/loopback-stm32/src/main.c @@ -38,15 +38,16 @@ int echo_buffer_len; int num_echos; -// Blink durations -enum { - BLINK_NOT_MOUNTED = 250, - BLINK_MOUNTED = 1000, - BLINK_SUSPENDED = 2500, -}; +static bool is_blinking = true; +static uint32_t led_on_until = 0; +static uint32_t blink_toogle_at = 0; +static bool is_blink_on = true; -static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; +static inline bool has_expired(uint32_t deadline, uint32_t now) { + return (int32_t)(now - deadline) >= 0; +} +static void led_busy(void); static void led_blinking_task(void); static void loopback_init(void); static void loopback_check_rx(void); @@ -94,6 +95,7 @@ void loopback_check_tx(void) { n = max_size; cust_vendor_start_transmit_fifo(EP_LOOPBACK_TX, &loopback_fifo, n); + led_busy(); } } @@ -111,6 +113,7 @@ void loopback_check_rx(void) { void echo_update_state(void) { if (num_echos > 0) { cust_vendor_start_transmit(EP_ECHO_TX, echo_buffer, echo_buffer_len); + led_busy(); } else { cust_vendor_prepare_recv(EP_ECHO_RX, echo_buffer, sizeof(echo_buffer)); } @@ -130,6 +133,7 @@ void cust_vendor_rx_cb(uint8_t ep_addr, uint32_t recv_bytes) { echo_buffer_len = recv_bytes; echo_update_state(); } + led_busy(); } // Invoked when last tx transfer finished @@ -140,8 +144,10 @@ void cust_vendor_tx_cb(uint8_t ep_addr, uint32_t sent_bytes) { // check ZLP if ((sent_bytes & (bulk_packet_size - 1)) == 0 - && !cust_vendor_is_transmitting(ep_addr)) + && !cust_vendor_is_transmitting(ep_addr)) { cust_vendor_start_transmit(EP_LOOPBACK_TX, NULL, 0); + led_busy(); + } } else if (ep_addr == EP_ECHO_TX) { num_echos--; @@ -154,6 +160,7 @@ void cust_vendor_intf_open_cb(uint8_t intf) { bulk_packet_size = cust_vendor_packet_size(EP_LOOPBACK_RX); loopback_check_rx(); echo_update_state(); + led_busy(); } // Invoked when an alternate interface has been selected @@ -163,6 +170,7 @@ void cust_vendor_alt_intf_selected_cb(uint8_t intf, uint8_t alt) { loopback_check_rx(); if (alt == 0) echo_update_state(); + led_busy(); } void cust_vendor_halt_cleared_cb(uint8_t ep_addr) { @@ -184,6 +192,7 @@ void cust_vendor_halt_cleared_cb(uint8_t ep_addr) { default: break; } + led_busy(); } @@ -210,6 +219,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 0) { // save value from wValue saved_value = request->wValue; + led_busy(); return tud_control_status(rhport, request); } break; @@ -217,6 +227,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_SAVE_DATA: if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 4) { // receive into `saved_value` + led_busy(); return tud_control_xfer(rhport, request, &saved_value, 4); } break; @@ -224,6 +235,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_SEND_DATA: if (request->bmRequestType_bit.direction == TUSB_DIR_IN && request->wLength == 4) { // transmit from `saved_value` + led_busy(); return tud_control_xfer(rhport, request, &saved_value, 4); } break; @@ -231,6 +243,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ case REQUEST_RESET_BUFFERS: if (request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->wLength == 0) { reset_buffers(); + led_busy(); return tud_control_status(rhport, request); } break; @@ -239,6 +252,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ if (request->bmRequestType_bit.direction == TUSB_DIR_IN && request->wLength == 1) { uint8_t intf_num = request->wIndex & 0xff; if (intf_num < 4) { + led_busy(); // return inteface number return tud_control_xfer(rhport, request, &intf_num, 1); } @@ -248,6 +262,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ // Microsoft WCID descriptor (for automatic WinUSB installation) case WCID_VENDOR_CODE: if (request->bmRequestType_bit.direction == TUSB_DIR_IN && request->wIndex == 0x0004) { + led_busy(); // transmit WCID feature descriptor int len = sizeof(wcid_feature_desc); if (len >= request->wLength) @@ -275,12 +290,7 @@ usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) { // Invoked when device is mounted void tud_mount_cb(void) { - blink_interval_ms = BLINK_MOUNTED; -} - -// Invoked when device is unmounted -void tud_umount_cb(void) { - blink_interval_ms = BLINK_NOT_MOUNTED; + is_blinking = false; } // Invoked when usb bus is suspended @@ -288,26 +298,27 @@ void tud_umount_cb(void) { // Within 7ms, device must draw an average of current less than 2.5 mA from bus void tud_suspend_cb(bool remote_wakeup_en) { (void) remote_wakeup_en; - blink_interval_ms = BLINK_SUSPENDED; -} - -// Invoked when usb bus is resumed -void tud_resume_cb(void) { - blink_interval_ms = BLINK_MOUNTED; + board_sleep(); } // --- LED blinking --- -void led_blinking_task(void) { - static uint32_t start_ms = 0; - static bool led_state = false; - - // Blink every interval ms - if ( board_millis() - start_ms < blink_interval_ms) - return; // not enough time - start_ms += blink_interval_ms; +void led_busy(void) { + led_on_until = board_millis() + 100; + board_led_write(true); +} - board_led_write(led_state); - led_state = 1 - led_state; // toggle +void led_blinking_task(void) { + uint32_t now = board_millis(); + if (is_blinking) { + if (has_expired(blink_toogle_at, now)) { + is_blink_on = !is_blink_on; + blink_toogle_at = now + 250; + } + board_led_write(is_blink_on && (now & 7) == 0); + + } else if (has_expired(led_on_until, now)) { + board_led_write((now & 3) == 0); + } } diff --git a/test-devices/loopback-stm32/src/usb_descriptors.c b/test-devices/loopback-stm32/src/usb_descriptors.c index 4989398..9aa5028 100644 --- a/test-devices/loopback-stm32/src/usb_descriptors.c +++ b/test-devices/loopback-stm32/src/usb_descriptors.c @@ -57,7 +57,7 @@ enum { uint8_t const desc_fs_configuration[] = { // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(1, INTF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 500), + TUD_CONFIG_DESCRIPTOR(1, INTF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x80, 500), // Loopback interface (alternate 0) CUSTOM_VENDOR_INTERFACE(0, 4), // Loopback endpoint OUT