Class StubEngine
- java.lang.Object
-
- com.jstatcom.engine.stub.StubEngine
-
- All Implemented Interfaces:
- Engine
public final class StubEngine extends java.lang.Object implements Engine
AStubEnginemanages calls to methods defined in arbitrary system libraries. It works on Win32, Linux (i386), and Solaris. It uses the "Shared Stubs" example by Sheng Liang to dispatch method calls without the need to create a distinguished JNI wrapper for every library to be used.The methods defined in the system library can take certain types as arguments and returns, which are
The argument and return types must be compatible with the- int, &int
- double, &double
- float, &float
- int*
- double*
- float*
- int**
- double**
- float**
- char*
- char**
- char***
JSCDataobjects defined in thecallmethod.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidcall(java.lang.String procName, JSCData[] args, JSCData[] retData)Makes a call toprocNamein the native library that was loaded before.java.lang.StringgetCurrentSysLib()Gets the system library that is currently used by this engine.static StubEnginegetInstance()Returns an instance of theStubEnginethat is a Singleton.booleanisValid(JSCTypes type)Gets whethertypecan be handled by this engine.voidload(java.lang.String module, LoadTypes loadType, JSCData... args)Sets the name of the native library to be used.voidshutdown()Does nothing.voidstop()Throws an Exception, because the task cannot be stopped.
-
-
-
Method Detail
-
getInstance
public static StubEngine getInstance()
Returns an instance of theStubEnginethat is a Singleton.- Returns:
- an engine instance
-
call
public void call(java.lang.String procName, JSCData[] args, JSCData[] retData)Makes a call toprocNamein the native library that was loaded before. The method signature is created from the specified input and return parameters. TheCSignTypescan be used to set certain properties (FLOAT, VECTOR, BYREF) on the corresponding data objects. This can be used to conform to a wide range of different method signatures. The following C-types correspond toJSCTypes:double - JSCNumberfloat - JSCNumberwithFLOAT == trueint - JSCInt&double - JSCNumberwithBYREF == true&float - JSCNumberwithFLOAT == true && BYREF == true&int - JSCIntwithBYREF == truechar* - JSCStringchar** - JSCSArraywithVECTOR == truechar*** - JSCSArraywithVECTOR == falsedouble* - JSCNArraywithVECTOR == truedouble** - JSCSNrraywithVECTOR == falsefloat* - JSCNArraywithVECTOR == true && FLOAT == truefloat** - JSCSNrraywithVECTOR == false && FLOAT == true
Input specification
If a type corresponds to a C-pointer type (instead of a value), then the memory is allocated according to the rows and columns of the respectiveJSCDataobject. All input arguments are filled with the values of the corresponding pointers after the procedure call, which means that it is possible to use an argument that holds the results. Value arguments must not be empty.Return specification
IfretData == nullor has zero length, then the procedure is assumed to returnvoid. If the return type (retData[0].tpye()) is a pointer type, then it is assumed, that the returned pointer from the procedure call has the same dimensions asretData[0], because is not possible to retrieve the size from the returned pointer.Vectors
Often C-functions have input arguments that correspond to a one dimensional array. To call functions with these types, the vector property ofJSCSArrayandJSCNArraymust be set totrue. The data object is then vectorized (similar toUMatrix.vec). After the function call the pointer is indirected to the data object again, the array elements are filled with the values from the pointer columnwise, keeping the original array dimension.- Specified by:
callin interfaceEngine- Parameters:
procName- name of the procedure to call, must be defined in the currently loaded libraryargs- arguments for the procedure, the method signature is derived from itretData- return type, can contain at most 1 element,voidif empty ornull, if type is an array, it has to be set to the rows and cols of the returned pointer- Throws:
java.lang.IllegalArgumentException-- if
argsorretDatacontainnullelements or unsupported types - if
retDatacontains more than 1 element -
if (procName == null || procName.length() == 0) - if an element of
argsrepresentsINT, NUMBER or STRINGbut is empty andBYREF == false - if an element of
argsrepresentsSARRAYand containsnullstrings
- if
java.lang.RuntimeException- ifprocNameadress could not be found in the loaded libraryjava.lang.IllegalStateException- if no system library was loaded before
-
isValid
public boolean isValid(JSCTypes type)
Description copied from interface:EngineGets whethertypecan be handled by this engine.- Specified by:
isValidin interfaceEngine- Parameters:
type- the data type to be checked- Returns:
trueif ok,falseiftypecannot be handled by this engine- See Also:
Engine.isValid(com.jstatcom.model.JSCTypes)
-
load
public void load(java.lang.String module, LoadTypes loadType, JSCData... args)Sets the name of the native library to be used. The library is then used in the next call to a function.Usage Note:
if (loadType == StubLoadTypes.USERLIB)then the library is searched in thejstubsubdirectory. No system specific extension (.dll/.so) is required but will be appended automatically according to the running OS.if (loadType == StubLoadTypes.SYSLIB)then the library is searched in the library search path. The library name must be fully qualified with extension, because not all system libraries have a default suffix (e.g. libc.so.6).- Specified by:
loadin interfaceEngine- Parameters:
module- the name of the system library to load with/without the system specific extension (SYSLIB/USERLIB)loadType- the load typeargs- always ignored- Throws:
java.lang.IllegalArgumentException-if (loadName == null || loadType == null)orif (module.length() == 0)or if no user library with that name exists in thejstubsubdirjava.lang.RuntimeException- if operating system is not supported or if the system library with the given name cannot be found- See Also:
Engine.load(String, com.jstatcom.engine.LoadTypes, com.jstatcom.model.JSCData[])
-
getCurrentSysLib
public java.lang.String getCurrentSysLib()
Gets the system library that is currently used by this engine. It can be changed via theloadmethod.- Returns:
- the absolute path of the current system library or null if
nonehas been loaded so far
-
stop
public void stop()
Throws an Exception, because the task cannot be stopped.- Specified by:
stopin interfaceEngine- Throws:
java.lang.UnsupportedOperationException- See Also:
Engine.stop()
-
shutdown
public void shutdown()
Does nothing.- Specified by:
shutdownin interfaceEngine- See Also:
Engine.shutdown()
-
-
DMelt 3.0 © DataMelt by jWork.ORG