/** * Init the native binding to the underlying system library. * @return <code>true</code> if the link is effective and <code>false</code> otherwise. */ public static void init() throws UnsatisfiedLinkError { Native.unregister(JOpenVRLibrary.class); String path = System.getProperty(JNA_OPENVR_LIBRARY_PATH); if (path != null){ JNA_LIBRARY_NAME = path; logger.config("Using OpenVR implementation located at "+JNA_LIBRARY_NAME); JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME); Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB); } else { JNA_LIBRARY_NAME = "openvr_api"; logger.config("Using embedded OpenVR implementation "+JOpenVRLibrary.JNA_LIBRARY_NAME); JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME); Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB); } }
public static void lockMemory() { try { Native.register(Platform.C_LIBRARY_NAME); int result = mlockall(1); if (result == 0) { return; } } catch (Throwable t) { throw new IllegalStateException("Error trying to lock memory", t); } int lastError = Native.getLastError(); String message = "mlockall failed: " + lastError; if (lastError == 1 || lastError == 12) { // EPERM || ENOMEM message = "Unable to lock memory due to insufficient free space or privileges. " + "Please check the RLIMIT_MEMLOCK soft resource limit (ulimit -l) and " + "increase the available memory if needed"; } throw new IllegalStateException(message); }
private JNAKernel32Library() { if (Constants.WINDOWS) { try { Native.register("kernel32"); logger.debug("windows/Kernel32 library loaded"); } catch (NoClassDefFoundError e) { logger.warn("JNA not found. native methods and handlers will be disabled."); } catch (UnsatisfiedLinkError e) { logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); } } }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. Uses the class loader of the given class to search for the * native library in the resource path if it is not found in the system * library load path or <code>jna.library.path</code>. * @param cls Class with native methods to register * @param libName name of or path to native library to which functions * should be bound */ public static void register(Class<?> cls, String libName) { NativeLibrary library = NativeLibrary.getInstance(libName, Collections.singletonMap(Library.OPTION_CLASSLOADER, cls.getClassLoader())); register(cls, library); }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. * @param lib native library to which functions should be bound */ public static void register(NativeLibrary lib) { register(findDirectMappedClass(getCallingClass()), lib); }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. * @param libName library name to which functions should be bound */ public static void register(String libName) { register(findDirectMappedClass(getCallingClass()), libName); }
public NativeLibc() { synchronized (NativeLibc.class) { if (!initialized) { try { Native.register(Platform.C_LIBRARY_NAME); initialized = true; } catch (Exception e) { throw new IllegalArgumentException("native libc load failed", e); } } } }
Native.register((String)null);
Native.register((String)null);
private JNAKernel32Library() { if (Constants.WINDOWS) { try { Native.register("kernel32"); logger.debug("windows/Kernel32 library loaded"); } catch (NoClassDefFoundError e) { logger.warn("JNA not found. native methods and handlers will be disabled."); } catch (UnsatisfiedLinkError e) { logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); } } }
private JNAKernel32Library() { if (Constants.WINDOWS) { try { Native.register("kernel32"); logger.debug("windows/Kernel32 library loaded"); } catch (NoClassDefFoundError e) { logger.warn("JNA not found. native methods and handlers will be disabled."); } catch (UnsatisfiedLinkError e) { logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); } } }
private JNAKernel32Library() { if (Constants.WINDOWS) { try { Native.register("kernel32"); logger.debug("windows/Kernel32 library loaded"); } catch (NoClassDefFoundError e) { logger.warn("JNA not found. native methods and handlers will be disabled."); } catch (UnsatisfiedLinkError e) { logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); } } }
/** * Please note that the libsodium.so * file HAS to be built for the platform this program will run on. * * @param path Absolute path to libsodium.so. */ public SodiumJava(String path) { Native.register(SodiumJava.class, path); onRegistered(); }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. Uses the class loader of the given class to search for the * native library in the resource path if it is not found in the system * library load path or <code>jna.library.path</code>. * @param cls Class with native methods to register * @param libName name of or path to native library to which functions * should be bound */ public static void register(Class<?> cls, String libName) { NativeLibrary library = NativeLibrary.getInstance(libName, Collections.singletonMap(Library.OPTION_CLASSLOADER, cls.getClassLoader())); register(cls, library); }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. * @param lib native library to which functions should be bound */ public static void register(NativeLibrary lib) { register(findDirectMappedClass(getCallingClass()), lib); }
/** * When called from a class static initializer, maps all native methods * found within that class to native libraries via the JNA raw calling * interface. * @param libName library name to which functions should be bound */ public static void register(String libName) { register(findDirectMappedClass(getCallingClass()), libName); }
public static void lockMemory() { int result = 0; try { Native.register(Platform.C_LIBRARY_NAME); result = mlockall(1); if (result == 0) { return; } } catch (Throwable t) { throw new IllegalStateException("Error trying to lock memory", t); } int errno = Native.getLastError(); String msg = "mlockall failed: " + errno; if (errno == 1 || errno == 12) { // EPERM || ENOMEM msg = "Unable to lock memory due to insufficient free space or privileges. " + "Please check the RLIMIT_MEMLOCK soft resource limit (ulimit -l) and " + "increase the available memory if needed"; } throw new IllegalStateException(msg); }
private JNAKernel32Library() { if (Constants.WINDOWS) { try { Native.register("kernel32"); logger.debug("windows/Kernel32 library loaded"); } catch (NoClassDefFoundError e) { logger.warn("JNA not found. native methods and handlers will be disabled."); } catch (UnsatisfiedLinkError e) { logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); } } }