Class CupsFunctions

java.lang.Object
oshi.ffm.ForeignFunctions
oshi.ffm.unix.CupsFunctions

public final class CupsFunctions extends ForeignFunctions
FFM bindings for the CUPS (Common Unix Printing System) library.

CUPS is available as libcups on Linux and macOS (via the dyld shared cache as libcups.dylib).

  • Field Details

    • IPP_PRINTER_IDLE

      public static final int IPP_PRINTER_IDLE
      IPP printer state: idle.
      See Also:
    • IPP_PRINTER_PROCESSING

      public static final int IPP_PRINTER_PROCESSING
      IPP printer state: processing (printing).
      See Also:
    • IPP_PRINTER_STOPPED

      public static final int IPP_PRINTER_STOPPED
      IPP printer state: stopped.
      See Also:
    • CUPS_PRINTER_REMOTE

      public static final int CUPS_PRINTER_REMOTE
      Printer type bit flag indicating a remote (network) printer.
      See Also:
    • CUPS_DEST_T

      public static final StructLayout CUPS_DEST_T
      Layout of cups_dest_t:
      typedef struct {
          char          *name;        // Printer or class name
          char          *instance;    // Local instance name or NULL
          int           is_default;   // Is this printer the default?
          int           num_options;  // Number of options
          cups_option_t *options;     // Options
      } cups_dest_t;
      
    • CUPS_DEST_NAME

      public static final VarHandle CUPS_DEST_NAME
      VarHandle for the name field of cups_dest_t.
    • CUPS_DEST_IS_DEFAULT

      public static final VarHandle CUPS_DEST_IS_DEFAULT
      VarHandle for the is_default field of cups_dest_t.
    • CUPS_DEST_NUM_OPTIONS

      public static final VarHandle CUPS_DEST_NUM_OPTIONS
      VarHandle for the num_options field of cups_dest_t.
    • CUPS_DEST_OPTIONS

      public static final VarHandle CUPS_DEST_OPTIONS
      VarHandle for the options field of cups_dest_t.
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Returns whether the CUPS library was successfully loaded and all symbols bound.
      Returns:
      true if libcups is available
    • cupsGetDests

      public static int cupsGetDests(MemorySegment dests) throws Throwable
      Gets all available CUPS destinations (printers and classes).
      Parameters:
      dests - a pointer-to-pointer that will be set to the allocated destination array
      Returns:
      the number of destinations, or 0 on failure
      Throws:
      Throwable - if the native call fails
    • cupsFreeDests

      public static void cupsFreeDests(int numDests, MemorySegment dests) throws Throwable
      Frees the memory allocated by cupsGetDests.
      Parameters:
      numDests - the number of destinations returned by cupsGetDests
      dests - the destination array pointer
      Throws:
      Throwable - if the native call fails
    • cupsGetOption

      public static MemorySegment cupsGetOption(MemorySegment name, int numOptions, MemorySegment options) throws Throwable
      Gets the value of a named option from a destination's options array.
      Parameters:
      name - the option name as a native string segment
      numOptions - the number of options
      options - pointer to the options array
      Returns:
      a native segment pointing to the option value string, or a NULL segment if not found
      Throws:
      Throwable - if the native call fails
    • cupsGetDefault

      public static MemorySegment cupsGetDefault() throws Throwable
      Gets the default printer name.
      Returns:
      a native segment pointing to the default printer name, or a NULL segment if none is set
      Throws:
      Throwable - if the native call fails
    • getOption

      public static String getOption(String optionName, int numOptions, MemorySegment options, Arena arena)
      Convenience method to read a named option value from a destination's options segment.
      Parameters:
      optionName - the option name
      numOptions - the number of options in the array
      options - the native options pointer
      arena - the arena to allocate the name string in
      Returns:
      the option value, or an empty string if not found