Package com.jogamp.common.os
Class NativeLibrary
java.lang.Object
com.jogamp.common.os.NativeLibrary
- All Implemented Interfaces:
DynamicLookupHelper
Provides low-level, relatively platform-independent access to
shared ("native") libraries. The core library routines
System.load() and System.loadLibrary()
in general provide suitable functionality for applications using
native code, but are not flexible enough to support certain kinds
of glue code generation and deployment strategies. This class
supports direct linking of native libraries to other shared
objects not necessarily installed on the system (in particular,
via the use of dlopen(RTLD_GLOBAL) on Unix platforms) as well as
manual lookup of function names to support e.g. GlueGen's
ProcAddressTable glue code generation style without additional
supporting code needed in the generated library.-
Field Summary
Fields inherited from interface com.jogamp.common.os.DynamicLookupHelper
DEBUG, DEBUG_LOOKUP -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal voidclose()Closes this native library.final longdynamicLookupFunction(String funcName) Returns the function handle for function 'funcName'.final longdynamicLookupFunctionGlobal(String funcName) Looks up the given function name in all loaded libraries.enumerateLibraryPaths(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader) Given the base library names (no prefixes/suffixes) for the various platforms, enumerate the possible locations and names of the indicated native library on the system using the system path.enumerateLibraryPaths(String windowsLibName, String unixLibName, String macOSXLibName, ClassLoader loader) Given the base library names (no prefixes/suffixes) for the various platforms, enumerate the possible locations and names of the indicated native library on the system not using the system path.static final StringfindLibrary(String libName, ClassLoader loader) final longRetrieves the low-level library handle from this NativeLibrary object.final StringRetrieves the path under which this library was opened.final booleanisFunctionAvailable(String funcName) Queries whether function 'funcName' is available.static final StringisValidNativeLibraryName(String libName, boolean isLowerCaseAlready) Comparison of prefix and suffix of the given libName's basename is performed case insensitivestatic final NativeLibraryopen(String libName, ClassLoader loader) Opens the given native library, assuming it has the same base name on all platforms, looking first in the system's search path, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g.static final NativeLibraryopen(String libName, ClassLoader loader, boolean global) Opens the given native library, assuming it has the same base name on all platforms, looking first in the system's search path, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g.static final NativeLibraryopen(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader) Opens the given native library, assuming it has the given base names (no "lib" prefix or ".dll/.so/.dylib" suffix) on the Windows, Unix and Mac OS X platforms, respectively, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g.static final NativeLibraryopen(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader, boolean global) final voidfinal StringtoString()
-
Method Details
-
toString
-
open
Opens the given native library, assuming it has the same base name on all platforms, looking first in the system's search path, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g. Java Web Start.- Throws:
SecurityException- if user is not granted access for the named library.
-
open
public static final NativeLibrary open(String libName, ClassLoader loader, boolean global) throws SecurityException Opens the given native library, assuming it has the same base name on all platforms, looking first in the system's search path, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g. Java Web Start.- Throws:
SecurityException- if user is not granted access for the named library.
-
open
public static final NativeLibrary open(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader) throws SecurityException Opens the given native library, assuming it has the given base names (no "lib" prefix or ".dll/.so/.dylib" suffix) on the Windows, Unix and Mac OS X platforms, respectively, and in the context of the specified ClassLoader, which is used to help find the library in the case of e.g. Java Web Start.The
Note that we do not currently handle DSO versioning on Unix. Experience with JOAL and OpenAL has shown that it is extremely problematic to rely on a specific .so version (for one thing, ClassLoader.findLibrary on Unix doesn't work with files not ending in .so, for example .so.0), and in general if this dynamic loading facility is used correctly the version number will be irrelevant.searchSystemPathFirstargument changes the behavior to first search the default system path rather than searching it last.- Throws:
SecurityException- if user is not granted access for the named library.
-
open
public static final NativeLibrary open(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader, boolean global) throws SecurityException - Throws:
SecurityException- if user is not granted access for the named library.
-
claimAllLinkPermission
- Specified by:
claimAllLinkPermissionin interfaceDynamicLookupHelper- Throws:
SecurityException- if user is not granted access for the library set.
-
releaseAllLinkPermission
- Specified by:
releaseAllLinkPermissionin interfaceDynamicLookupHelper- Throws:
SecurityException- if user is not granted access for the library set.
-
dynamicLookupFunction
Description copied from interface:DynamicLookupHelperReturns the function handle for function 'funcName'.- Specified by:
dynamicLookupFunctionin interfaceDynamicLookupHelper- Throws:
SecurityException- if user is not granted access for the library set.
-
isFunctionAvailable
Description copied from interface:DynamicLookupHelperQueries whether function 'funcName' is available.- Specified by:
isFunctionAvailablein interfaceDynamicLookupHelper- Throws:
SecurityException- if user is not granted access for the library set.
-
dynamicLookupFunctionGlobal
Looks up the given function name in all loaded libraries.- Throws:
SecurityException- if user is not granted access for the named library.
-
getLibraryHandle
public final long getLibraryHandle()Retrieves the low-level library handle from this NativeLibrary object. On the Windows platform this is an HMODULE, and on Unix and Mac OS X platforms the void* result of calling dlopen(). -
getLibraryPath
Retrieves the path under which this library was opened. -
close
Closes this native library. Further lookup operations are not allowed after calling this method.- Throws:
SecurityException- if user is not granted access for the named library.
-
isValidNativeLibraryName
Comparison of prefix and suffix of the given libName's basename is performed case insensitive- Parameters:
libName- the full path library name with prefix and suffixisLowerCaseAlready- indicates if libName is already lower-case- Returns:
- basename of libName w/o path, ie. /usr/lib/libDrinkBeer.so -> DrinkBeer on Unix systems, but null on Windows.
-
enumerateLibraryPaths
public static final List<String> enumerateLibraryPaths(String windowsLibName, String unixLibName, String macOSXLibName, ClassLoader loader) Given the base library names (no prefixes/suffixes) for the various platforms, enumerate the possible locations and names of the indicated native library on the system not using the system path. -
enumerateLibraryPaths
public static final List<String> enumerateLibraryPaths(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, ClassLoader loader) Given the base library names (no prefixes/suffixes) for the various platforms, enumerate the possible locations and names of the indicated native library on the system using the system path. -
findLibrary
-