|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjnr.ffi.LibraryLoader<T>
public abstract class LibraryLoader<T>
Loads a native library and maps it to a java interface.
Example usage
public interface LibC {
int puts(String str);
}
LibC libc = LibraryLoader.create(LibC.class).load("c");
libc.puts("Hello, World");
| Constructor Summary | |
|---|---|
protected |
LibraryLoader(Class<T> interfaceClass)
|
| Method Summary | ||
|---|---|---|
LibraryLoader<T> |
convention(CallingConvention convention)
Sets the native function calling convention. |
|
static
|
create(Class<T> interfaceClass)
Creates a new LibraryLoader instance. |
|
LibraryLoader<T> |
failImmediately()
Turns off lazy propagation of load failures. |
|
LibraryLoader<T> |
library(String libraryName)
Adds a library to be loaded. |
|
T |
load()
Loads a native library and links the methods defined in interfaceClass
to native methods in the library. |
|
T |
load(String libraryName)
Loads a native library and links the methods defined in interfaceClass
to native methods in the library. |
|
protected abstract T |
loadLibrary(Class<T> interfaceClass,
Collection<String> libraryNames,
Collection<String> searchPaths,
Map<LibraryOption,Object> options)
Implemented by FFI providers to load the actual library. |
|
LibraryLoader<T> |
mapper(FunctionMapper typeMapper)
Adds a function mapper to use when resolving symbols in this library. |
|
LibraryLoader<T> |
mapper(SignatureTypeMapper typeMapper)
Adds a type mapper to use when resolving method parameter and result types. |
|
LibraryLoader<T> |
mapper(TypeMapper typeMapper)
Adds a type mapper to use when resolving method parameter and result types. |
|
LibraryLoader<T> |
option(LibraryOption option,
Object value)
Sets an option when loading libraries. |
|
LibraryLoader<T> |
search(String path)
Adds a path to search for libraries. |
|
LibraryLoader<T> |
stdcall()
Sets the calling convention of the library to the Windows stdcall calling convention |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected LibraryLoader(Class<T> interfaceClass)
| Method Detail |
|---|
public static <T> LibraryLoader<T> create(Class<T> interfaceClass)
LibraryLoader instance.
interfaceClass - the interface that describes the native library functions
LibraryLoader instance.public LibraryLoader<T> library(String libraryName)
libraryName - The name or path of library to load.
LibraryLoader instance.public LibraryLoader<T> search(String path)
path - A directory to search.
LibraryLoader instance.
public LibraryLoader<T> option(LibraryOption option,
Object value)
option - The option to setvalue - The value for the option.
LibraryLoader instance.LibraryOptionpublic LibraryLoader<T> mapper(TypeMapper typeMapper)
typeMapper - The type mapper to use.
LibraryLoader instance.public LibraryLoader<T> mapper(SignatureTypeMapper typeMapper)
typeMapper - The type mapper to use.
LibraryLoader instance.public LibraryLoader<T> mapper(FunctionMapper typeMapper)
typeMapper - The function mapper to use.
LibraryLoader instance.public LibraryLoader<T> convention(CallingConvention convention)
This is only needed on windows platforms - unless explicitly specified, all platforms assume
CallingConvention.DEFAULT as the calling convention.
LibraryLoader instance.public final LibraryLoader<T> stdcall()
LibraryLoader instance.public final LibraryLoader<T> failImmediately()
load() will not fail
immediately if any libraries cannot be loaded - instead, it will create an instance of the library interface
that re-throws any load errors when invoked.
Calling this method will make load() throw errors immediately.
LibraryLoader instance.public T load(String libraryName)
interfaceClass
to native methods in the library.
libraryName - The name or path of library to load.
create(Class) that will call the native methods.public T load()
interfaceClass
to native methods in the library.
create(Class) that will call the native methods.
protected abstract T loadLibrary(Class<T> interfaceClass,
Collection<String> libraryNames,
Collection<String> searchPaths,
Map<LibraryOption,Object> options)
interfaceClass - The java class that describes the functions to be mapped.libraryNames - A list of libraries to load & search for symbolssearchPaths - The paths to search for libraries to be loadedoptions - The options to apply when loading the library
interfaceClass that will call the native methods.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||