/** * 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); } }
/** * Returns an instance of NativeLibrary which refers to the current * process. This is useful for accessing functions which were already * mapped by some other mechanism, without having to reference or even * know the exact name of the native library. */ public static synchronized final NativeLibrary getProcess() { return getInstance(null); }
/** * Returns an instance of NativeLibrary which refers to the current * process. This is useful for accessing functions which were already * mapped by some other mechanism, without having to reference or even * know the exact name of the native library. */ public static synchronized final NativeLibrary getProcess(Map<String, ?> options) { return getInstance(null, options); }
/** * Returns an instance of NativeLibrary for the specified name. * The library is loaded if not already loaded. If already loaded, the * existing instance is returned.<p> * More than one name may map to the same NativeLibrary instance; only * a single instance will be provided for any given unique file path. * * @param libraryName The library name to load. * This can be short form (e.g. "c"), * an explicit version (e.g. "libc.so.6"), or * the full path to the library (e.g. "/lib/libc.so.6"). */ public static final NativeLibrary getInstance(String libraryName) { return getInstance(libraryName, Collections.<String, Object>emptyMap()); }
/** * Returns an instance of NativeLibrary for the specified name. * The library is loaded if not already loaded. If already loaded, the * existing instance is returned.<p> * More than one name may map to the same NativeLibrary instance; only * a single instance will be provided for any given unique file path. * * @param libraryName The library name to load. * This can be short form (e.g. "c"), * an explicit version (e.g. "libc.so.6"), or * the full path to the library (e.g. "/lib/libc.so.6"). * @param classLoader The class loader to use to load the native library. * This only affects library loading when the native library is * included somewhere in the classpath, either bundled in a jar file * or as a plain file within the classpath. */ public static final NativeLibrary getInstance(String libraryName, ClassLoader classLoader) { return getInstance(libraryName, Collections.singletonMap(Library.OPTION_CLASSLOADER, classLoader)); }
/** * 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); }
public Handler(String libname, Class<?> interfaceClass, Map<String, ?> options) { if (libname != null && "".equals(libname.trim())) { throw new IllegalArgumentException("Invalid library name \"" + libname + "\""); } if (!interfaceClass.isInterface()) { throw new IllegalArgumentException(libname + " does not implement an interface: " + interfaceClass.getName()); } this.interfaceClass = interfaceClass; this.options = new HashMap<String, Object>(options); int callingConvention = AltCallingConvention.class.isAssignableFrom(interfaceClass) ? Function.ALT_CONVENTION : Function.C_CONVENTION; if (this.options.get(OPTION_CALLING_CONVENTION) == null) { this.options.put(OPTION_CALLING_CONVENTION, Integer.valueOf(callingConvention)); } if (this.options.get(OPTION_CLASSLOADER) == null) { this.options.put(OPTION_CLASSLOADER, interfaceClass.getClassLoader()); } this.nativeLibrary = NativeLibrary.getInstance(libname, this.options); invocationMapper = (InvocationMapper)this.options.get(OPTION_INVOCATION_MAPPER); }
/** * Obtain a <code>Function</code> representing a native * function that follows the standard "C" calling convention. * * <p>The allocated instance represents a pointer to the named native * function from the named library, called with the standard "C" calling * convention. * * @param libraryName * Library in which to find the native function * @param functionName * Name of the native function to be linked with * @throws UnsatisfiedLinkError if the library is not found or * the given function name is not found within the library. */ public static Function getFunction(String libraryName, String functionName) { return NativeLibrary.getInstance(libraryName).getFunction(functionName); }
/** * Obtain a <code>Function</code> representing a native * function. * * <p>The allocated instance represents a pointer to the named native * function from the named library. * * @param libraryName * Library in which to find the function * @param functionName * Name of the native function to be linked with * @param callFlags * Function <a href="#callflags">call flags</a> * * @throws UnsatisfiedLinkError if the library is not found or * the given function name is not found within the library. */ public static Function getFunction(String libraryName, String functionName, int callFlags) { return NativeLibrary.getInstance(libraryName).getFunction(functionName, callFlags, null); }
/** * Obtain a <code>Function</code> representing a native * function. * * <p>The allocated instance represents a pointer to the named native * function from the named library. * * @param libraryName * Library in which to find the function * @param functionName * Name of the native function to be linked with * @param callFlags * Function <a href="#callflags">call flags</a> * @param encoding * Encoding to use for conversion between Java and native * strings. * * @throws UnsatisfiedLinkError if the library is not found or * the given function name is not found within the library. */ public static Function getFunction(String libraryName, String functionName, int callFlags, String encoding) { return NativeLibrary.getInstance(libraryName).getFunction(functionName, callFlags, encoding); }
/** * Returns an instance of NativeLibrary which refers to the current * process. This is useful for accessing functions which were already * mapped by some other mechanism, without having to reference or even * know the exact name of the native library. */ public static synchronized final NativeLibrary getProcess() { return getInstance(null); }
private static NativeLibrary tryLoadLibrary(String libName) { try { return NativeLibrary.getInstance(libName); } catch (UnsatisfiedLinkError e) { return null; } }
/** * Returns an instance of NativeLibrary which refers to the current * process. This is useful for accessing functions which were already * mapped by some other mechanism, without having to reference or even * know the exact name of the native library. */ public static synchronized final NativeLibrary getProcess(Map<String, ?> options) { return getInstance(null, options); }
public static synchronized NativeLibrary getNativeLibrary(String name) { for (String format : nameFormats) try { return NativeLibrary.getInstance(String.format(format, name)); } catch (UnsatisfiedLinkError ex) { continue; } throw new UnsatisfiedLinkError("Could not load library: " + name); }
public static synchronized NativeLibrary getNativeLibrary(String name) { if (!Platform.isWindows()) return NativeLibrary.getInstance(name); for (String format : windowsNameFormats) try { return NativeLibrary.getInstance(String.format(format, name)); } catch (UnsatisfiedLinkError ex) { continue; } throw new UnsatisfiedLinkError("Could not load library: " + name); }
private static void disposeLibrary(Library lib, String name) { if(lib != null) { NativeLibrary.getInstance(name).dispose(); } }
private static void load(String name) { NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader()); Native.register(LibGmp.class, library); Native.register(SIZE_T_CLASS, library); }
private static void load(String name) { NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader()); Native.register(LibGmp.class, library); Native.register(SIZE_T_CLASS, library); }
@Override public final Invoker createInvoker(Ruby runtime, String libraryName, String functionName, NativeType returnType, NativeType[] parameterTypes, String convention) { Function function = NativeLibrary.getInstance(libraryName).getFunction(functionName, "stdcall".equals(convention) ? Function.ALT_CONVENTION : Function.C_CONVENTION); FunctionInvoker functionInvoker = getFunctionInvoker(returnType); Marshaller[] marshallers = new Marshaller[parameterTypes.length]; for (int i = 0; i < marshallers.length; ++i) { marshallers[i] = getMarshaller(parameterTypes[i]); } return new JNAInvoker(runtime, function, functionInvoker, marshallers); }
/** * On later versions of OSX, it is necessary to force-load libvlccore before libvlc, otherwise libvlc will fail to * load. * * @param path */ private void forceLoadLibVlcCore(String path) { NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcCoreLibraryName(), path); NativeLibrary.getInstance(RuntimeUtil.getLibVlcCoreLibraryName()); }