public interface NativeInterface
This class provides some utilities to implement simulated natives.
StopListener and the stop() method| Modifier and Type | Method and Description |
|---|---|
void |
addStopListener(StopListener stopListener)
Register a stop listener.
The stop listeners will be notified when the simulation stops. |
void |
flushContent(java.lang.Object array)
Flush fully an array.
Equivalent to call flushContent(Object, int, int) with the full array range. |
void |
flushContent(java.lang.Object array,
int offset,
int length)
Flush the content of an array.
Only range [offset, offset + length - 1] is flushed. |
void |
flushImmortalContent(java.lang.Object array)
Flush fully an immortal array.
Equivalent to call flushImmortalContent(Object, int, int) with the full array range. |
void |
flushImmortalContent(java.lang.Object array,
int offset,
int length)
Flush content of an immortal array.
Only range [offset, offset + length - 1] is flushed. |
NativeResource |
getNativeResource(int resourceId)
Returns the registered
NativeResource for the given resource ID. |
int |
getNativeResourceCloseFunctionId()
Returns an integer that can be passed by the application to the method
SNI.closeOnGC() as
the closeFunction argument. |
byte[] |
getResourceContent(java.lang.String resourceName)
Get full content of a resource.
|
boolean |
isImmortal(java.lang.Object obj)
Tells whether an object is an immortal array or not.
|
void |
notifySuspendEnd()
Notifies the simulator that the current native is no more suspended.
|
void |
notifySuspendStart()
Notifies the simulator that the current native is suspended so it can schedule a thread with
a lower priority.
|
void |
refreshContent(java.lang.Object array)
Refresh full content of array if it is immortal.
Does nothing if the given object is not an immortal array. Equivalent to call refreshImmortalContent(Object) assuming that the array is immortal. |
void |
refreshContent(java.lang.Object array,
int offset,
int length)
Refresh content of array if it is immortal.
Does nothing if the given object is not an immortal array. |
void |
refreshImmortalContent(java.lang.Object array)
Refresh fully an immortal array.
Equivalent to call refreshImmortalContent(Object, int, int) with the full array range. |
void |
refreshImmortalContent(java.lang.Object array,
int offset,
int length)
Refresh content of an immortal array.
Only range [offset, offset + length - 1] is refreshed. |
NativeResource |
registerNativeResource(java.io.Closeable resource)
Registers a native resource that will be closed automatically when the simulator will stop or when
the native resource will be unregistered (see
unregisterNativeResource(int)). |
void |
stop()
Allows to request the simulation stop.
|
void |
toCString(java.lang.String javaString,
byte[] cString)
Transforms a Java String into a C String.
The platform default encoding is used to transform Java characters into C characters. The created C String is a NULL terminated String (ends with '\0'). |
java.lang.String |
toJavaString(byte[] cString)
Transforms a C String into a Java String, using platform default encoding.
|
NativeResource |
unregisterNativeResource(int resourceId)
Unregisters the given resource.
|
boolean isImmortal(java.lang.Object obj)
obj - the object to test.true if the given object is an immortal array, false otherwise.void refreshContent(java.lang.Object array)
refreshImmortalContent(Object) assuming that the array is immortal.isImmortal(Object)void refreshContent(java.lang.Object array,
int offset,
int length)
refreshImmortalContent(Object, int, int) assuming that the array is immortal.void refreshImmortalContent(java.lang.Object array)
refreshImmortalContent(Object, int, int) with the full array range.void refreshImmortalContent(java.lang.Object array,
int offset,
int length)
[offset, offset + length - 1] is refreshed.array - the immortal array to refresh.offset - the start index of the range.length - the length of the range.java.lang.IllegalArgumentException - if the given array is not an array or is not immortal.java.lang.ArrayIndexOutOfBoundsException - if the given range is invalid.BrokenConnection - if the array cannot be refreshed.void flushContent(java.lang.Object array)
flushContent(Object, int, int) with the full array range.void flushContent(java.lang.Object array,
int offset,
int length)
[offset, offset + length - 1] is flushed. If array is immortal, this method calls
flushImmortalContent(Object, int, int). Otherwise, if array has been passed as argument of an invoke
method, the content of the array is marked to be flushed when method returns. This method may be called many
times to extend the range to flush (union of intervals).array - the immortal array to flush.offset - the start index of the range.length - the length of the range.java.lang.IllegalArgumentException - if the given array is not an array or is not immortal.java.lang.ArrayIndexOutOfBoundsException - if the given range is invalid.BrokenConnection - if the array cannot be flushed.void flushImmortalContent(java.lang.Object array)
flushImmortalContent(Object, int, int) with the full array range.void flushImmortalContent(java.lang.Object array,
int offset,
int length)
[offset, offset + length - 1] is flushed.array - the immortal array to flush.offset - the start index of the range.length - the length of the range.java.lang.IllegalArgumentException - if the given array is not an array or is not immortal.java.lang.ArrayIndexOutOfBoundsException - if the given range is invalid.BrokenConnection - if the array cannot be flushed.byte[] getResourceContent(java.lang.String resourceName)
resourceName - as described in Class.getResourceAsStream(String).null if not found.java.lang.IllegalArgumentException - if the given resource name is not absolute.BrokenConnection - if the resource could not be retrieved.void addStopListener(StopListener stopListener)
stopListener - the listener to register.void stop()
void toCString(java.lang.String javaString,
byte[] cString)
cString array length
must be at least javaString.length()+1.cString array is automatically flushed with the method flushContent(Object, int, int).
Only javaString.length() bytes are flushed.javaString - the Java StringcString - byte array which contains the C String.java.lang.IllegalArgumentException - if javaString or cString is nulljava.lang.ArrayIndexOutOfBoundsException - if cString is too small to contain the stringjava.lang.String toJavaString(byte[] cString)
cString is automatically refreshed with
the method refreshContent(Object).cString - byte array which contains the C Stringjava.lang.IllegalArgumentException - if cString is null or its length is 1java.lang.IllegalArgumentException - if cString is not NULL terminated.NativeResource registerNativeResource(java.io.Closeable resource)
unregisterNativeResource(int)).
When the native resource is closed, the close() method is called on the given Closeable.
The native resource can also be closed if the application calls the SNI method NativeResource.closeOnGC()
and if the object linked to the native resource is reclaimed by the application garbage collector.
resource - the resource to register.NativeResource for the resource.NativeResource unregisterNativeResource(int resourceId) throws java.lang.IllegalArgumentException
NativeResource.
The given resourceId must be a value returned by NativeResource.getResourceId().resourceId - ID of the resource.NativeResource that has been unregistered.java.lang.IllegalArgumentException - if no native resource is registered with the given ID.NativeResource getNativeResource(int resourceId) throws java.lang.IllegalArgumentException
NativeResource for the given resource ID.
The given resource ID must be a value returned by NativeResource.getResourceId().resourceId - ID of the resource.java.lang.IllegalArgumentException - if no native resource is registered with the given ID.int getNativeResourceCloseFunctionId()
SNI.closeOnGC() as
the closeFunction argument.void notifySuspendStart()
This method must be called before a wait or a sleep to simulate that a native has been suspended in SNI.
void notifySuspendEnd()
This method must be called after a wait or a sleep to simulate that a native has been resumed in SNI.