com.jniwrapper
Class Function

java.lang.Object
  extended by com.jniwrapper.Function

public class Function
extends java.lang.Object

The Function class allows to call a specified function from a native code library.


Field Summary
static byte CDECL_CALLING_CONVENTION
          Indicates cdecl calling convention.
static byte DEFAULT_CALLING_CONVENTION
          Default calling convention for native platform.
static com.jniwrapper.NullLibrary NULL_LIBRARY
           
static byte STDCALL_CALLING_CONVENTION
          Indicates stdcall calling convention.
 
Method Summary
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue)
          Convenience method that invokes a native code function, which has no parameters.
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue, Parameter parameter)
          Convenience method that invokes a native code function with a single parameter.
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue, Parameter[] parameters)
          Invokes the specified function from a specified native library.
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue, Parameter param1, Parameter param2)
          Convenience method that invokes a native code function, which has two parameters.
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue, Parameter param1, Parameter param2, Parameter param3)
          Convenience method that invokes a native function with three parameters.
static long call(java.lang.String libraryName, java.lang.String functionName, Parameter returnValue, Parameter param1, Parameter param2, Parameter param3, Parameter param4)
          Convenience method that invokes a native function with four parameters.
 byte getCallingConvention()
          Returns calling convention used for calling this function.
 java.lang.String getName()
          Returns function name.
 long invoke(Parameter returnValue)
          Convenience method for calling a native function without parameters.
 long invoke(Parameter returnValue, Parameter parameter)
          Convenience method for calling a native function with a single parameter.
 long invoke(Parameter returnValue, Parameter[] parameters)
          Invokes the function with the passed parameters.
 long invoke(Parameter returnValue, Parameter param1, Parameter param2)
          Convenience method for calling native function with two parameters.
 long invoke(Parameter returnValue, Parameter param1, Parameter param2, Parameter param3)
          Convenience method for calling a native function with three parameters.
 long invoke(Parameter returnValue, Parameter param1, Parameter param2, Parameter param3, Parameter param4)
          Convenience method for calling native function with four parameters.
 void setCallingConvention(byte callingConvention)
          Sets calling convention for this function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CALLING_CONVENTION

public static final byte DEFAULT_CALLING_CONVENTION
Default calling convention for native platform.

See Also:
Constant Field Values

CDECL_CALLING_CONVENTION

public static final byte CDECL_CALLING_CONVENTION
Indicates cdecl calling convention. Caller cleans stack in this convention.

See Also:
Constant Field Values

STDCALL_CALLING_CONVENTION

public static final byte STDCALL_CALLING_CONVENTION
Indicates stdcall calling convention. Caller cleans stack in this convention.

See Also:
Constant Field Values

NULL_LIBRARY

public static final com.jniwrapper.NullLibrary NULL_LIBRARY
Method Detail

setCallingConvention

public final void setCallingConvention(byte callingConvention)
Sets calling convention for this function. This setting is remembered in the current Function object only - it is not mapped to the function name. Most of the time users do not need to use this method.


getCallingConvention

public byte getCallingConvention()
Returns calling convention used for calling this function. This method does not return the DEFAULT_CALLING_CONVENTION value.


getName

public java.lang.String getName()
Returns function name.


invoke

public long invoke(Parameter returnValue,
                   Parameter[] parameters)
            throws FunctionExecutionException
Invokes the function with the passed parameters. A type of the return value and parameter types should correspond to types of the native code function.

Parameters:
returnValue - reference to return value
parameters - array of parameters of called function
Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException

invoke

public final long invoke(Parameter returnValue)
                  throws FunctionExecutionException
Convenience method for calling a native function without parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
invoke(Parameter, Parameter[])

invoke

public final long invoke(Parameter returnValue,
                         Parameter parameter)
                  throws FunctionExecutionException
Convenience method for calling a native function with a single parameter.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
invoke(Parameter, Parameter[])

invoke

public final long invoke(Parameter returnValue,
                         Parameter param1,
                         Parameter param2)
                  throws FunctionExecutionException
Convenience method for calling native function with two parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
invoke(Parameter, Parameter[])

invoke

public final long invoke(Parameter returnValue,
                         Parameter param1,
                         Parameter param2,
                         Parameter param3)
                  throws FunctionExecutionException
Convenience method for calling a native function with three parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
invoke(Parameter, Parameter[])

invoke

public final long invoke(Parameter returnValue,
                         Parameter param1,
                         Parameter param2,
                         Parameter param3,
                         Parameter param4)
                  throws FunctionExecutionException
Convenience method for calling native function with four parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
invoke(Parameter, Parameter[])

call

public static long call(java.lang.String libraryName,
                        java.lang.String functionName,
                        Parameter returnValue,
                        Parameter[] parameters)
                 throws FunctionExecutionException
Invokes the specified function from a specified native library. A type of the return value and parameter types should correspond to types of the native code function.

Since this method creates instances of Library and Function, it should be used when the number of calls is minimal.

Parameters:
libraryName - filename of the library containing a called function
functionName - name of the called function
returnValue - reference to a return value
parameters - array of parameters of the called function
Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException

call

public static final long call(java.lang.String libraryName,
                              java.lang.String functionName,
                              Parameter returnValue)
                       throws FunctionExecutionException
Convenience method that invokes a native code function, which has no parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
call(String, String, Parameter, Parameter[])

call

public static final long call(java.lang.String libraryName,
                              java.lang.String functionName,
                              Parameter returnValue,
                              Parameter parameter)
                       throws FunctionExecutionException
Convenience method that invokes a native code function with a single parameter.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
call(String, String, Parameter, Parameter[])

call

public static final long call(java.lang.String libraryName,
                              java.lang.String functionName,
                              Parameter returnValue,
                              Parameter param1,
                              Parameter param2)
                       throws FunctionExecutionException
Convenience method that invokes a native code function, which has two parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
call(String, String, Parameter, Parameter[])

call

public static final long call(java.lang.String libraryName,
                              java.lang.String functionName,
                              Parameter returnValue,
                              Parameter param1,
                              Parameter param2,
                              Parameter param3)
                       throws FunctionExecutionException
Convenience method that invokes a native function with three parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
call(String, String, Parameter, Parameter[])

call

public static final long call(java.lang.String libraryName,
                              java.lang.String functionName,
                              Parameter returnValue,
                              Parameter param1,
                              Parameter param2,
                              Parameter param3,
                              Parameter param4)
                       throws FunctionExecutionException
Convenience method that invokes a native function with four parameters.

Returns:
Last error code. NOTE: For Windows platform only. For all other platforms the result is 0.
Throws:
FunctionExecutionException
See Also:
call(String, String, Parameter, Parameter[])