public final class Library
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Library.DefaultLibrary
A handle to the current process
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.ref.WeakReference<Library>> |
cache
A cache of opened libraries
|
private Foreign |
foreign
A handle to the foreign interface to keep it alive as long as this object is alive
|
static int |
GLOBAL
All symbols in the library are made available to other libraries
|
private long |
handle
The native dl/LoadLibrary handle
|
private static java.lang.ThreadLocal<java.lang.String> |
lastError
Stores the last error returned by a dlopen or dlsym call
|
static int |
LAZY
Perform lazy binding.
|
static int |
LOCAL
Symbols in this library are not made available to other libraries
|
private static java.lang.Object |
lock
A lock used to serialize all dlopen/dlsym calls
|
private java.lang.String |
name
The name of this Library
|
static int |
NOW
Resolve all symbols when loading the library
|
Modifier | Constructor and Description |
---|---|
private |
Library(Foreign foreign,
java.lang.String name,
long address) |
Modifier and Type | Method and Description |
---|---|
private static long |
dlopen(Foreign foreign,
java.lang.String name,
int flags)
Internal wrapper around dlopen.
|
protected void |
finalize() |
static Library |
getCachedInstance(java.lang.String name,
int flags)
Gets a handle for the named library.
|
static Library |
getDefault()
Gets a handle to the default library.
|
static java.lang.String |
getLastError()
Gets the current error string from dlopen/LoadLibrary.
|
long |
getSymbolAddress(java.lang.String name)
Gets the address of a symbol within the Library.
|
static Library |
openLibrary(java.lang.String name,
int flags)
Gets a handle for the named library.
|
private static final java.util.Map<java.lang.String,java.lang.ref.WeakReference<Library>> cache
private static final java.lang.Object lock
private static final java.lang.ThreadLocal<java.lang.String> lastError
public static final int LAZY
public static final int NOW
public static final int LOCAL
public static final int GLOBAL
private final long handle
private final java.lang.String name
private final Foreign foreign
private Library(Foreign foreign, java.lang.String name, long address)
private static long dlopen(Foreign foreign, java.lang.String name, int flags)
name
- The name of the library to openflags
- The flags to pass to dlopenpublic static final Library getDefault()
public static final Library getCachedInstance(java.lang.String name, int flags)
name
- The name or path of the library to open.flags
- The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)public static final Library openLibrary(java.lang.String name, int flags)
name
- The name or path of the library to open.flags
- The library flags (e.g. LAZY, NOW, LOCAL, GLOBAL)public final long getSymbolAddress(java.lang.String name)
name
- The name of the symbol to locate.public static final java.lang.String getLastError()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable