/** * 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); } }
private boolean initializeOpenVRLibrary() { if (initialized) { return true; } logger.info("Adding OpenVR search path: " + NativeHelper.getOpenVRLibPath()); NativeLibrary.addSearchPath("openvr_api", NativeHelper.getOpenVRLibPath()); if (jopenvr.JOpenVRLibrary.VR_IsHmdPresent() != 1) { logger.info("VR Headset not detected."); return false; } logger.info("VR Headset detected."); return true; }
/** * 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); }
library = new NativeLibrary("<process>", null, Native.open(null, openFlags(options)), options); library = loadLibrary(libraryName, options); libraries.put(library.getName() + options, ref); File file = library.getFile(); if (file != null) { libraries.put(file.getAbsolutePath() + options, ref);
public static ID getGlobal(String libraryName, String globalVarName) { return new ID(NativeLibrary.getInstance(libraryName).getGlobalVariableAddress(globalVarName).getNativeLong(0).longValue()); } }
/** * 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()); }
/** * Create a new {@link Function} that is linked with a native * function that follows a given calling flags. * * @param functionName * Name of the native function to be linked with * @param callFlags * Flags affecting the function invocation * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName, int callFlags) { return getFunction(functionName, callFlags, encoding); }
private static void disposeLibrary(Library lib, String name) { if(lib != null) { NativeLibrary.getInstance(name).dispose(); } }
boolean isAbsolutePath = new File(libraryName).isAbsolute(); List<String> searchPath = new ArrayList<String>(); int openFlags = openFlags(options); searchPath.addAll(initPaths("jna.library.path")); String libraryPath = findLibraryPath(libraryName, searchPath); long handle = 0; libraryPath = findLibraryPath(libraryName, searchPath); LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath); handle = Native.open(libraryPath, openFlags); libraryPath = matchLibrary(libraryName, searchPath); if (libraryPath != null) { LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath); libraryPath = matchFramework(libraryName); if (libraryPath != null) { try { libraryPath = findLibraryPath("lib" + libraryName, searchPath); if (libraryPath != null) { LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath); addSuppressedReflected(res, t); return new NativeLibrary(libraryName, libraryPath, handle, options);
Method[] methods = cls.getDeclaredMethods(); List<Method> mlist = new ArrayList<Method>(); Map<String, ?> options = lib.getOptions(); TypeMapper mapper = (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER); boolean allowObjects = Boolean.TRUE.equals(options.get(Library.OPTION_ALLOW_OBJECTS)); Function f = lib.getFunction(method.getName(), method); try { handles[i] = registerMethod(cls, method.getName(),
protected Pointer getPointer() { if (pointer == null) for (String symbol : symbols) if ((pointer = library.getGlobalVariableAddress(symbol)) != null) break; return pointer; } }
libraryPath = matchLibrary(libraryName, searchPath); if (libraryPath != null) { try { handle = open(libraryPath); } catch(UnsatisfiedLinkError e2) { e = e2; } + ".framework/" + libraryName; if (new File(libraryPath).exists()) { try { handle = open(libraryPath); } catch(UnsatisfiedLinkError e2) { e = e2; } return new NativeLibrary(libraryName, libraryPath, handle);
/** Close the library when it is no longer referenced. */ @Override protected void finalize() { dispose(); }
public static WinscardLibInfo openLib() { String libraryName = Platform.isWindows() ? WINDOWS_PATH : Platform.isMac() ? MAC_PATH : PCSC_PATH; HashMap<String, Object> options = new HashMap<String, Object>(); if (Platform.isWindows()) { options.put(Library.OPTION_FUNCTION_MAPPER, new WindowsFunctionMapper()); } else if (Platform.isMac()) { options.put(Library.OPTION_FUNCTION_MAPPER, new MacFunctionMapper()); } WinscardLibrary lib = (WinscardLibrary) Native.loadLibrary(libraryName, WinscardLibrary.class, options); NativeLibrary nativeLibrary = NativeLibrary.getInstance(libraryName); // SCARD_PCI_* is #defined to the following symbols (both pcsclite and winscard) ScardIoRequest SCARD_PCI_T0 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT0Pci")); ScardIoRequest SCARD_PCI_T1 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT1Pci")); ScardIoRequest SCARD_PCI_RAW = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardRawPci")); SCARD_PCI_T0.read(); SCARD_PCI_T1.read(); SCARD_PCI_RAW.read(); SCARD_PCI_T0.setAutoSynch(false); SCARD_PCI_T1.setAutoSynch(false); SCARD_PCI_RAW.setAutoSynch(false); return new WinscardLibInfo(lib, SCARD_PCI_T0, SCARD_PCI_T1, SCARD_PCI_RAW); } }
/** * Create a new {@link Function} that is linked with a native * function that follows the NativeLibrary's calling convention. * * <p>The allocated instance represents a pointer to the named native * function from the library. * * @param functionName * Name of the native function to be linked with * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName) { return getFunction(functionName, callFlags); }
int openFlags = openFlags(options); searchPath.addAll(initPaths("jna.library.path")); String libraryPath = findLibraryPath(libraryName, searchPath); long handle = 0; libraryPath = findLibraryPath(libraryName, searchPath); if (Native.DEBUG_LOAD) { System.out.println("Trying " + libraryPath); System.out.println("Looking for version variants"); libraryPath = matchLibrary(libraryName, searchPath); if (libraryPath != null) { if (Native.DEBUG_LOAD) { System.out.println("Looking for matching frameworks"); libraryPath = matchFramework(libraryName); if (libraryPath != null) { try { libraryPath = findLibraryPath("lib" + libraryName, searchPath); if (libraryPath != null) { if (Native.DEBUG_LOAD) { return new NativeLibrary(libraryName, libraryPath, handle, options);
library = new NativeLibrary("<process>", null, Native.open(null, openFlags(options)), options); library = loadLibrary(libraryName, options); libraries.put(library.getName() + options, ref); File file = library.getFile(); if (file != null) { libraries.put(file.getAbsolutePath() + options, ref);
Method[] methods = cls.getDeclaredMethods(); List<Method> mlist = new ArrayList<Method>(); Map<String, ?> options = lib.getOptions(); TypeMapper mapper = (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER); boolean allowObjects = Boolean.TRUE.equals(options.get(Library.OPTION_ALLOW_OBJECTS)); Function f = lib.getFunction(method.getName(), method); try { handles[i] = registerMethod(cls, method.getName(),
protected Pointer getPointer() { if (pointer == null) for (String symbol : symbols) if ((pointer = library.getGlobalVariableAddress(symbol)) != null) break; return pointer; } }
/** Close all open native libraries. */ static void disposeAll() { Set<Reference<NativeLibrary>> values; synchronized(libraries) { values = new LinkedHashSet<Reference<NativeLibrary>>(libraries.values()); } for (Reference<NativeLibrary> ref : values) { NativeLibrary lib = ref.get(); if (lib != null) { lib.dispose(); } } }