|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cinvoke.CInvoke
Provides interfaces and related utility methods for calling C libraries. The CInvoke class is the main public class in the C/Invoke Java binding. In addition to the load() methods, which connect Java interfaces to native shared libraries, it contains methods which can marshal parameters or return values in situations where the library cannot determine the correct marshaling behavior on its own.
Nested Class Summary | |
class |
CInvoke.CC
An enumeration of values representing different calling conventions. |
class |
CInvoke.ENC
An enumeration which determines the encoding to use when marshalling strings. |
Constructor Summary | |
CInvoke()
|
Method Summary | |
static int |
getSize(java.lang.Class type)
Utility method which returns the number of bytes required to hold an instance of the given marshalable type. |
static int |
getSize(java.lang.Object obj)
Utility method which returns the number of bytes required to hold the given marshalable value. |
static java.lang.Object |
load(java.lang.String libname,
java.lang.Class iface)
Loads a native C library and attaches it to the given Java interface. |
static java.lang.Object |
load(java.lang.String libname,
java.lang.Class iface,
int callconv)
Loads a native C library and attaches it to the given Java interface. |
static java.lang.Object |
load(java.lang.String libname,
java.lang.Class iface,
int callconv,
int encoding)
Loads a native C library and attaches it to the given Java interface. |
static java.lang.Object[] |
ptrToArray(Ptr ptr,
java.lang.Class eltype,
int num)
Converts a pointer to a native array to a Java array value. |
static java.lang.String |
ptrToString(Ptr ptr,
int numchars,
int encoding)
Converts a pointer to an unmanaged buffer to a Java string value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CInvoke()
Method Detail |
public static java.lang.Object load(java.lang.String libname, java.lang.Class iface)
load(String, Class, int, int)
overload for more information. Using this overload calls functions
with the default calling convention and the UTF-8 string encoding.
libname
- The platform-specific name of the library to load.iface
- The interface to attach to the library.
public static java.lang.Object load(java.lang.String libname, java.lang.Class iface, int callconv)
load(String, Class, int, int)
overload for more information. Using this overload calls functions
with the UTF-8 string encoding.
libname
- The platform-specific name of the library to load.iface
- The interface to attach to the library.callconv
- The calling convention to use on functions in this
library, from the CInvoke.CC
enumeration.
public static java.lang.Object load(java.lang.String libname, java.lang.Class iface, int callconv, int encoding)
NativeShort
: Marshaled as a C 'short' type.
NativeInt
: Marshaled as a C 'int' type.
NativeLong
: Marshaled as a C 'long' type.
NativeLongLong
: Marshaled as a C 'long long' type.
Ptr
: Marshaled a C pointer value (i.e. a void*, or
any other pointer of the same size).
ptrToString
or ptrToArray
instead).
struct st { short mys; int myi float myfl; };the Java class should be declared:
class st { public NativeShort a_mys; public NativeInt b_myi; public float c_myf; }The prefixes on the members ensure that the alphabetic order of the class fields corresponds to the C structure member order.
Structures cannot contain members
that are arrays, Strings, or interfaces. Members which have class types
are treated as embedded structure values. Structures can never be
passed or returned by value, only inside arrays. To pass a pointer to
a structure to a function, pass an array with a length of 1. To return
a pointer to a function, return a Ptr value and convert it to an array
of structures with ptrToArray
.
libname
- The platform-specific name of the library to load.
This is usually the name of a file containing the shared object file,
i.e. mylib.dll or /lib/libmylib.so. The search path for library files
is also implementation and system-defined; specifying the full path to
a library file usually yields the most portable behavior.iface
- The interface to attach to the library. The returned
object implements this interface.callconv
- The calling convention to use on functions in this
library, from the CInvoke.CC
enumeration.encoding
- The encoding to use when marshaling strings in and out
of this library, from the CInvoke.ENC
enumeration.
public static java.lang.String ptrToString(Ptr ptr, int numchars, int encoding)
ptr
- A pointer value which points to an array of bytes or
Unicode characters.numchars
- The number of characters in the string. Specify a
negative value
to stop conversion at the first 0 character. This parameter is ignored
when using the UTF-8 encoding, which always stops at the first 0 byte.encoding
- The encoding to use, must be one of the values from the
CInvoke.ENC
enumeration.
public static java.lang.Object[] ptrToArray(Ptr ptr, java.lang.Class eltype, int num)
ptr
- A pointer value which points to a contiguous array of
unmanaged values.eltype
- The type of the elements of the array to create. Must
be either a class with public fields (marshalled as a C structure) or
a "basic" type (Byte, Short, Int, Long, Float, Double, NativeShort,
NativeInt, NativeLong, NativeLongLong, or Ptr).num
- The number of elements in the array.
public static int getSize(java.lang.Class type)
type
- The type to retrieve the size of.
public static int getSize(java.lang.Object obj)
obj
- The object to retrieve the size of.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |