org.bridj
Class BridJ

java.lang.Object
  extended by org.bridj.BridJ

public class BridJ
extends Object

BridJ's central class.

Author:
ochafik

Field Summary
static boolean debug
           
static boolean debugNeverFree
           
static boolean debugPointers
           
static boolean enableDestructors
           
static boolean logCalls
           
static boolean protectedMode
           
static boolean verbose
           
static boolean veryVerbose
           
 
Constructor Summary
BridJ()
           
 
Method Summary
static void addLibraryPath(String path)
           
static void addNativeLibraryAlias(String name, String alias)
          Add a possible alias for a library.
static
<O extends NativeObject>
void
copyNativeObjectToAddress(O value, Type type, Pointer<O> ptr)
           
static
<O extends NativeObject>
O
createNativeObjectFromPointer(Pointer<? super O> pointer, Type type)
           
static
<O extends NativeObject>
O
createNativeObjectFromReturnValuePointer(Pointer<? super O> pointer, Type type)
           
static void delete(NativeObject nativeObject)
           
static String describe(NativeObject instance)
          Creates a string that describes the provided native object, printing generally-relevant internal data (for instance for structures, this will typically display the fields values).
static String describe(Type nativeObjectType)
          Creates a string that describes the provided native object type, printing generally-relevant internal data (for instance for structures, this will typically display name of the fields, their offsets and lengths...).
static Object getJavaObjectFromNativePeer(long peer)
           
static NativeEntities getNativeEntities(AnnotatedElement type)
           
static NativeLibrary getNativeLibrary(AnnotatedElement type)
           
static NativeLibrary getNativeLibrary(String name)
          Loads the library with the name provided in argument (see getNativeLibraryFile(String))
static NativeLibrary getNativeLibrary(String name, File f)
          Loads the shared library file under the provided name.
static File getNativeLibraryFile(String libraryName)
          Given a library name (e.g.
static String getNativeLibraryName(AnnotatedElement m)
          Gets the name of the library declared for an annotated element.
static NativeEntities getOrphanEntities()
           
static BridJRuntime getRuntime(Class<?> type)
          Get the runtime associated with a class (using the Runtime annotation, if any, looking up parents and defaulting to CRuntime).
static
<R extends BridJRuntime>
R
getRuntimeByRuntimeClass(Class<R> runtimeClass)
           
static Class<? extends BridJRuntime> getRuntimeClass(Class<?> type)
          Get the runtime class associated with a class (using the Runtime annotation, if any, looking up parents and defaulting to CRuntime).
static Demangler.Symbol getSymbolByAddress(long peer)
           
static boolean isCastingNativeObjectInCurrentThread()
          Deprecated. 
static boolean isCastingNativeObjectReturnTypeInCurrentThread()
          Deprecated. 
static boolean isDirectModeEnabled()
          Query direct mode.
static boolean log(Level level, String message)
           
static boolean log(Level level, String message, Throwable ex)
           
static void main(String[] args)
           
static
<T extends NativeObject>
T
protectFromGC(T ob)
          Keep a hard reference to a native object to avoid its garbage collection.
static
<T extends NativeObject>
T
readFromNative(T instance)
          Some native object need manual synchronization between Java fields and native memory.
static void register()
          Registers the native methods of the caller class and all its inner types.
static BridJRuntime register(Class<?> type)
          Registers the native method of a type (and all its inner types).
static void releaseAll()
          Reclaims all the memory allocated by BridJ in the JVM and on the native side.
static void releaseLibrary(File library)
           
static void releaseLibrary(String name)
           
static
<O extends NativeObject>
void
setJavaObjectFromNativePeer(long peer, O object)
           
static void setMinLogLevel(Level level)
           
static void setNativeLibraryActualName(String name, String actualName)
          Define the actual name of a library.
static void setNativeLibraryFile(String libraryName, File nativeLibraryFile)
          Associate a library name (e.g.
static void setOrphanEntities(NativeEntities orphanEntities)
           
static long sizeOf(Type type)
           
static
<T extends NativeObject>
T
unprotectFromGC(T ob)
          Drop the hard reference created with protectFromGC(NativeObject).
static void unregister(Class<?> type)
           
static
<T extends NativeObject>
T
writeToNative(T instance)
          Some native object need manual synchronization between Java fields and native memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static final boolean debug

debugNeverFree

public static final boolean debugNeverFree

debugPointers

public static final boolean debugPointers

veryVerbose

public static final boolean veryVerbose

verbose

public static final boolean verbose

logCalls

public static final boolean logCalls

protectedMode

public static final boolean protectedMode

enableDestructors

public static final boolean enableDestructors
Constructor Detail

BridJ

public BridJ()
Method Detail

sizeOf

public static long sizeOf(Type type)

protectFromGC

public static <T extends NativeObject> T protectFromGC(T ob)
Keep a hard reference to a native object to avoid its garbage collection.
See unprotectFromGC(NativeObject) to remove the GC protection.


unprotectFromGC

public static <T extends NativeObject> T unprotectFromGC(T ob)
Drop the hard reference created with protectFromGC(NativeObject).


delete

public static void delete(NativeObject nativeObject)

register

public static void register()
Registers the native methods of the caller class and all its inner types.
\@Library("mylib")
                public class MyLib {
                        static {
                                BridJ.register();
                        }
                        public static native void someFunc();
                }
                


isCastingNativeObjectInCurrentThread

@Deprecated
public static boolean isCastingNativeObjectInCurrentThread()
Deprecated. 


isCastingNativeObjectReturnTypeInCurrentThread

@Deprecated
public static boolean isCastingNativeObjectReturnTypeInCurrentThread()
Deprecated. 


setJavaObjectFromNativePeer

public static <O extends NativeObject> void setJavaObjectFromNativePeer(long peer,
                                                                        O object)

getJavaObjectFromNativePeer

public static Object getJavaObjectFromNativePeer(long peer)

copyNativeObjectToAddress

public static <O extends NativeObject> void copyNativeObjectToAddress(O value,
                                                                      Type type,
                                                                      Pointer<O> ptr)

createNativeObjectFromPointer

public static <O extends NativeObject> O createNativeObjectFromPointer(Pointer<? super O> pointer,
                                                                       Type type)

createNativeObjectFromReturnValuePointer

public static <O extends NativeObject> O createNativeObjectFromReturnValuePointer(Pointer<? super O> pointer,
                                                                                  Type type)

getRuntimeByRuntimeClass

public static <R extends BridJRuntime> R getRuntimeByRuntimeClass(Class<R> runtimeClass)

getRuntimeClass

public static Class<? extends BridJRuntime> getRuntimeClass(Class<?> type)
Get the runtime class associated with a class (using the Runtime annotation, if any, looking up parents and defaulting to CRuntime).


getRuntime

public static BridJRuntime getRuntime(Class<?> type)
Get the runtime associated with a class (using the Runtime annotation, if any, looking up parents and defaulting to CRuntime).


register

public static BridJRuntime register(Class<?> type)
Registers the native method of a type (and all its inner types).
\@Library("mylib")
                public class MyLib {
                        static {
                                BridJ.register(MyLib.class);
                        }
                        public static native void someFunc();
                }
                


unregister

public static void unregister(Class<?> type)

setMinLogLevel

public static void setMinLogLevel(Level level)

log

public static boolean log(Level level,
                          String message,
                          Throwable ex)

log

public static boolean log(Level level,
                          String message)

getNativeEntities

public static NativeEntities getNativeEntities(AnnotatedElement type)
                                        throws IOException
Throws:
IOException

getNativeLibrary

public static NativeLibrary getNativeLibrary(AnnotatedElement type)
                                      throws IOException
Throws:
IOException

releaseAll

public static void releaseAll()
Reclaims all the memory allocated by BridJ in the JVM and on the native side. This is automatically called at shutdown time.


releaseLibrary

public static void releaseLibrary(String name)

releaseLibrary

public static void releaseLibrary(File library)

addLibraryPath

public static void addLibraryPath(String path)

setNativeLibraryActualName

public static void setNativeLibraryActualName(String name,
                                              String actualName)
Define the actual name of a library.
Works only before the library is loaded.
For instance, library "OpenGL" is actually named "OpenGL32" on Windows : BridJ.setNativeLibraryActualName("OpenGL", "OpenGL32");

Parameters:
name -
actualName -

addNativeLibraryAlias

public static void addNativeLibraryAlias(String name,
                                         String alias)
Add a possible alias for a library.
Aliases are prioritary over the library (or its actual name, see setNativeLibraryActualName(String, String)), in the order they are defined.
Works only before the library is loaded.

Parameters:
name -
alias -

getNativeLibraryFile

public static File getNativeLibraryFile(String libraryName)
Given a library name (e.g. "test"), finds the shared library file in the system-specific path ("/usr/bin/libtest.so", "./libtest.dylib", "c:\\windows\\system\\test.dll"...)


setNativeLibraryFile

public static void setNativeLibraryFile(String libraryName,
                                        File nativeLibraryFile)
Associate a library name (e.g. "test"), to its shared library file.


isDirectModeEnabled

public static boolean isDirectModeEnabled()
Query direct mode.
In direct mode, BridJ will attempt to optimize calls with assembler code, so that the overhead of each call is about the same as with plain JNI.
Set -Dbridj.direct=false in the command line (or setProperty("bridj.direct", "false")) or environment var BRIDJ_DIRECT=0 to disable


getNativeLibrary

public static NativeLibrary getNativeLibrary(String name)
                                      throws IOException
Loads the library with the name provided in argument (see getNativeLibraryFile(String))

Throws:
IOException

getNativeLibrary

public static NativeLibrary getNativeLibrary(String name,
                                             File f)
                                      throws IOException
Loads the shared library file under the provided name. Any subsequent call to getNativeLibrary(String) will return this library.

Throws:
IOException

getNativeLibraryName

public static String getNativeLibraryName(AnnotatedElement m)
Gets the name of the library declared for an annotated element. Recurses up to parents of the element (class, enclosing classes) to find any Library annotation.


getSymbolByAddress

public static Demangler.Symbol getSymbolByAddress(long peer)

setOrphanEntities

public static void setOrphanEntities(NativeEntities orphanEntities)

getOrphanEntities

public static NativeEntities getOrphanEntities()

readFromNative

public static <T extends NativeObject> T readFromNative(T instance)
Some native object need manual synchronization between Java fields and native memory.
An example is JNA-style structures.


writeToNative

public static <T extends NativeObject> T writeToNative(T instance)
Some native object need manual synchronization between Java fields and native memory.
An example is JNA-style structures.


describe

public static String describe(NativeObject instance)
Creates a string that describes the provided native object, printing generally-relevant internal data (for instance for structures, this will typically display the fields values).
This is primarily useful for debugging purposes.


describe

public static String describe(Type nativeObjectType)
Creates a string that describes the provided native object type, printing generally-relevant internal data (for instance for structures, this will typically display name of the fields, their offsets and lengths...).
This is primarily useful for debugging purposes.


main

public static void main(String[] args)


Copyright © 2009-2012. All Rights Reserved.