Repository navigation
Add CUPS printing system bindings to c.s.j.p.unix - #1718
Conversation
9730d3f to
2e49a2e
Compare
matthiasblaesing
left a comment
There was a problem hiding this comment.
Looks sane to me. For the documentation references people need to be careful. I noticed for example for CupsJob the structure definition in the documentation did not match the header file. The mapping is sane with respect to the header, so is good.
You might want to consider this change:
--- a/contrib/platform/test/com/sun/jna/platform/CupsTest.java
+++ b/contrib/platform/test/com/sun/jna/platform/CupsTest.java
@@ -27,6 +27,9 @@
import com.sun.jna.platform.unix.Cups;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
@@ -88,7 +91,8 @@
assertNotNull("Destinations pointer should not be null", destsPtr);
// Read the first destination
- Cups.CupsDest dest = new Cups.CupsDest(destsPtr);
+ Cups.CupsDest[] dests = (Cups.CupsDest[]) new Cups.CupsDest(destsPtr).toArray(numDests);
+ Cups.CupsDest dest = dests[0];
assertNotNull("First destination name should not be null", dest.name);
System.out.println("First destination: " + dest.name
+ (dest.is_default != 0 ? " (default)" : ""));
@@ -106,7 +110,7 @@
String printerType = Cups.INSTANCE.cupsGetOption(
"printer-type", dest.num_options, dest.options);
- System.out.println(" printer-type: " + printerType);
+ System.out.println(" printer-type: " + printerType + " " + mapPrinterTypeEnumNames(printerType).toString());
}
}
} finally {
@@ -116,6 +120,28 @@
}
}
+ public List<String> mapPrinterTypeEnumNames(String printerType) throws RuntimeException, NumberFormatException {
+ try {
+ List<String> result = new ArrayList<>();
+
+ int printerTypeInt = Integer.parseInt(printerType);
+
+ for (Field f : Cups.class.getFields()) {
+ String fieldName = f.getName();
+ if (fieldName.startsWith("CUPS_PRINTER_")) {
+ int val = f.getInt(null);
+ if (((printerTypeInt & val) == val)) {
+ result.add(fieldName);
+ }
+ }
+ }
+
+ return result;
+ } catch (IllegalAccessException | IllegalArgumentException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
public void testGetDefault() {
if (!cupsAvailable) {
return;
@@ -144,7 +170,8 @@
Pointer jobsPtr = jobsRef.getValue();
assertNotNull("Jobs pointer should not be null", jobsPtr);
- Cups.CupsJob job = new Cups.CupsJob(jobsPtr);
+ Cups.CupsJob[] jobs = (Cups.CupsJob[]) new Cups.CupsJob(jobsPtr).toArray(numJobs);
+ Cups.CupsJob job = jobs[0];
assertTrue("Job ID should be positive", job.id > 0);
assertNotNull("Job destination should not be null", job.dest);
System.out.println("First job: id=" + job.id + " dest=" + job.dest
Both cupsGetDests and cupsGetJobs2 return an array of values and this demonstrates decoding. The code in mapPrinterTypeEnumNames was more for me to test what I get for my default printer.
Closes java-native-access#1710 Add Cups interface providing JNA bindings for libcups, the Common UNIX Printing System library. Includes structures (CupsDest, CupsOption, CupsJob), printer state/type constants, job state constants, and functions for destination enumeration, job management, option handling, and server/user configuration.
2e49a2e to
801734b
Compare
Yeah, I've seen that a lot in manpage docs as well, where they tell you what elements are in the structure (assuming you'll fetch via Applied your suggested changes, will merge when CI passes. |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` |  |  | --- ### Release Notes <details> <summary>java-native-access/jna (net.java.dev.jna:jna)</summary> ### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191) [Compare Source](java-native-access/jna@5.19.0...5.19.1) \============== ## Bug Fixes - [#​1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@​matthiasblaesing](https://github.com/matthiasblaesing). ### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190) [Compare Source](java-native-access/jna@5.18.1...5.19.0) \============== ## Features - [#​1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@​baier233](https://github.com/baier233). - [#​1697](java-native-access/jna#1697): Add WlanApi module - [@​eranl](https://github.com/eranl). - [#​1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@​dbwiddis](https://github.com/dbwiddis). - [#​1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@​dbwiddis](https://github.com/dbwiddis). - [#​1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@​dbwiddis](https://github.com/dbwiddis). ## Bug Fixes - [#​1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@​lwahonen](https://github.com/lwahonen) - [#​1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@​dbwiddis](https://github.com/dbwiddis). - [#​1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@​dbwiddis](https://github.com/dbwiddis). - [#​1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@​dbwiddis](https://github.com/dbwiddis). - [#​1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@​matthiasblaesing](https://github.com/matthiasblaesing). </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820 Reviewed-by: Mark Harding <[email protected]>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` |  |  | --- ### Release Notes <details> <summary>java-native-access/jna (net.java.dev.jna:jna)</summary> ### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191) [Compare Source](java-native-access/jna@5.19.0...5.19.1) \============== ## Bug Fixes - [#​1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@​matthiasblaesing](https://github.com/matthiasblaesing). ### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190) [Compare Source](java-native-access/jna@5.18.1...5.19.0) \============== ## Features - [#​1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@​baier233](https://github.com/baier233). - [#​1697](java-native-access/jna#1697): Add WlanApi module - [@​eranl](https://github.com/eranl). - [#​1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@​dbwiddis](https://github.com/dbwiddis). - [#​1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@​dbwiddis](https://github.com/dbwiddis). - [#​1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@​dbwiddis](https://github.com/dbwiddis). ## Bug Fixes - [#​1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@​lwahonen](https://github.com/lwahonen) - [#​1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@​dbwiddis](https://github.com/dbwiddis). - [#​1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@​dbwiddis](https://github.com/dbwiddis). - [#​1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@​dbwiddis](https://github.com/dbwiddis). - [#​1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@​matthiasblaesing](https://github.com/matthiasblaesing). </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820 Reviewed-by: Mark Harding <[email protected]>
Adds
Cupsinterface toc.s.j.p.unixproviding JNA bindings for libcups, the Common UNIX Printing System library available on Linux, macOS, and other UNIX platforms.Structures
CupsDestcups_dest_tCupsOptioncups_option_tCupsJobcups_job_tFunctions
cupsGetDests/cupsGetDests2cupsFreeDestscupsGetDestcupsGetNamedDestcupsGetDefaultcupsGetOptioncupsAddOptioncupsFreeOptionscupsGetJobs2cupsFreeJobscupsCancelJobcupsServer/cupsSetServercupsUser/cupsSetUsercupsLastError/cupsLastErrorStringConstants
IPP_PRINTER_IDLE,IPP_PRINTER_PROCESSING,IPP_PRINTER_STOPPEDCUPS_PRINTER_CLASS,CUPS_PRINTER_COLOR,CUPS_PRINTER_DUPLEX, etc.IPP_JSTATE_PENDINGthroughIPP_JSTATE_COMPLETEDCUPS_WHICHJOBS_ALL,CUPS_WHICHJOBS_ACTIVE,CUPS_WHICHJOBS_COMPLETEDCloses #1710
Test Output
On my local mac with actual printers: