Package com.kenai.jffi
Class Library
java.lang.Object
com.kenai.jffi.Library
Represents a native library
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
A handle to the current process -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<String,
WeakReference<Library>> A cache of opened librariesprivate int
Indicates whether this library has been disposed of.private final Foreign
A handle to the foreign interface to keep it alive as long as this object is alivestatic final int
All symbols in the library are made available to other librariesprivate final long
The native dl/LoadLibrary handleprivate static final ThreadLocal<String>
Stores the last error returned by a dlopen or dlsym callstatic final int
Perform lazy binding.static final int
Symbols in this library are not made available to other librariesprivate static final Object
A lock used to serialize all dlopen/dlsym callsprivate final String
The name of thisLibrary
static final int
Resolve all symbols when loading the libraryprivate static final AtomicIntegerFieldUpdater<Library>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static long
Internal wrapper around dlopen.protected void
finalize()
static final Library
getCachedInstance
(String name, int flags) Gets a handle for the named library.static final Library
Gets a handle to the default library.static final String
Gets the current error string from dlopen/LoadLibrary.final long
getSymbolAddress
(String name) Gets the address of a symbol within theLibrary
.static final Library
openLibrary
(String name, int flags) Gets a handle for the named library.
-
Field Details
-
cache
A cache of opened libraries -
lock
A lock used to serialize all dlopen/dlsym calls -
lastError
Stores the last error returned by a dlopen or dlsym call -
LAZY
public static final int LAZYPerform lazy binding. Only resolve symbols as needed- See Also:
-
NOW
public static final int NOWResolve all symbols when loading the library- See Also:
-
LOCAL
public static final int LOCALSymbols in this library are not made available to other libraries- See Also:
-
GLOBAL
public static final int GLOBALAll symbols in the library are made available to other libraries- See Also:
-
handle
private final long handleThe native dl/LoadLibrary handle -
name
The name of thisLibrary
-
foreign
A handle to the foreign interface to keep it alive as long as this object is alive -
disposed
private volatile int disposedIndicates whether this library has been disposed of. -
UPDATER
-
-
Constructor Details
-
Library
-
-
Method Details
-
dlopen
Internal wrapper around dlopen. If the library open fails, then this stores the native error in a thread local variable for later retrieval.- Parameters:
name
- The name of the library to openflags
- The flags to pass to dlopen- Returns:
- The native handle for the opened library, or 0 if it failed to open.
-
getDefault
Gets a handle to the default library.- Returns:
- A
Library
instance representing the default library.
-
getCachedInstance
Gets a handle for the named library.- Parameters:
name
- The name or path of the library to open.flags
- The library flags (e.g.LAZY, NOW, LOCAL, GLOBAL
)- Returns:
- A
Library
instance representing the named library, ornull
if the library could not be opened.
-
openLibrary
Gets a handle for the named library. Note This will not cache the instance, nor will it return a cached instance. Only use when you really need a new handle for the library.- Parameters:
name
- The name or path of the library to open.flags
- The library flags (e.g.LAZY, NOW, LOCAL, GLOBAL
)- Returns:
- A
Library
instance representing the named library, or null if the library cannot be opened.
-
getSymbolAddress
Gets the address of a symbol within theLibrary
.- Parameters:
name
- The name of the symbol to locate.- Returns:
- The address of the symbol within the current address space.
-
getLastError
Gets the current error string from dlopen/LoadLibrary.- Returns:
- A
String
describing the last error.
-
finalize
-