jnilib.h File Reference

Descripes the JNILIB structures and functions. More...

#include "jni.h"
#include <stdlib.h>
#include <string.h>

Include dependency graph for jnilib.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Jvm_
 A structure for C, which descripes the Jvm. More...
struct  JvmCPP_
 A structure for C++, which descripes the Jvm. More...
struct  JvmData
 This structure holds the data needed for the Jvm for C and C++. More...

Typedefs

typedef Jvm_ Jvm
 Defines which structure is used as Jvm.
typedef Jvm_ Jvm_
 A structure for C, which descripes the Jvm.
typedef JvmCPP_ JvmCPP_
 A structure for C++, which descripes the Jvm.
typedef JvmData JvmData
 This structure holds the data needed for the Jvm for C and C++.

Functions

jboolean callBooleanMethod (jobject obj, jmethodID mid,...)
 Calls a boolean method.
jboolean callBooleanMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a boolean method.
jbyte callByteMethod (jobject obj, jmethodID mid,...)
 Calls a byte method.
jbyte callByteMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a byte method.
jchar callCharMethod (jobject obj, jmethodID mid,...)
 Calls a char method.
jchar callCharMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a char method.
jdouble callDoubleMethod (jobject obj, jmethodID mid,...)
 Calls a double method.
jdouble callDoubleMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a double method.
jfloat callFloatMethod (jobject obj, jmethodID mid,...)
 Calls a float method.
jfloat callFloatMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a float method.
jint callIntMethod (jobject obj, jmethodID mid,...)
 Calls an int method.
jint callIntMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls an int method.
jlong callLongMethod (jobject obj, jmethodID mid,...)
 Calls a long method.
jlong callLongMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a long method.
jobject callObjectMethod (jobject obj, jmethodID mid,...)
 Calls a object method.
jobject callObjectMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a object method.
jshort callShortMethod (jobject obj, jmethodID mid,...)
 Calls a short method.
jshort callShortMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a short method.
jint callStaticIntMethod (jclass cls, jmethodID mid,...)
 Calls a static int method.
jobject callStaticObjectMethod (jclass cls, jmethodID mid,...)
 Calls a static object method.
void callStaticVoidMethod (jclass cls, jmethodID mid,...)
 Calls a static void method.
void callVoidMethod (jobject obj, jmethodID mid,...)
 Calls a void method.
void callVoidMethodByName (jobject obj, const char *method, const char *signature,...)
 Calls a void method.
char * convertJString (jstring jstr)
 Creates a native char* from a jstring.
jobject createGlobalReference (jobject obj)
 Creates a global reference of a Java-Object and deletes the local reference.
jstring createJString (const char *str)
 Creates a jstring from a native char*.
void deleteGlobalReference (jobject obj)
 Deletes a global reference.
void deleteLocalReference (jobject)
 Deletes a local reference.
jboolean exception ()
 Tests if an exception was thrown and prints the exception.
jclass findClass (const char *strclass)
 Finds the Java class specified by strclass.
jmethodID findMethod (jclass cls, const char *method, const char *signature)
 Finds a method of a Java class.
jfieldID findStaticField (jclass cls, const char *field, const char *signature)
 Finds a static field of a Java class.
jmethodID findStaticMethod (jclass cls, const char *method, const char *signature)
 Finds a static method of a Java class.
JavaVM * getJavaVM ()
 Gets a Pointer to the current JavaVM structure.
JNIEnv * getJNIEnv ()
 Gets a Pointer to the actual JNIEnv structure.
jclass getObjectClass (jobject obj)
 Gets the Class of the Java-Object.
jint getStaticIntFieldByName (const char *strclass, const char *strfield)
 Gets the value of a class field.
jobject getStaticObjectFieldByName (const char *strclass, const char *strfield, const char *signature)
 Gets the value of a class field.
void initJvm (Jvm *jvm, const char *classpath)
 Initializes and creates the Jvm.
jboolean isSameObject (jobject obj1, jobject obj2)
 Compares 2 objects if they are the same or not.
void jnisleep (jint ms)
 Sleeps for ms milliseconds.
jobject newObject (jclass cls, jmethodID mid,...)
 Creates a new Object of a Class.
jobject newObjectBySignature (jclass cls, const char *signature,...)
 Creates a new Object of a Class.
jint registerNatives (jclass cls, const JNINativeMethod *nm, jint nMethods)
 Resgisters a native function pointer as native function in a Java-Class.
void throwByName (const char *name, const char *msg)
 Throws an Throwable by name.


Detailed Description

Descripes the JNILIB structures and functions.

These functions and structures provide access to a JVM. You can initialize a JVM instance and create objects and call methods by using these functions. Also some helper functions can be found here.

If you define the symbol DEBUG you get Java JNI debug information.

Author:
Stefan Gruber
Date:
11.01.2005

Definition in file jnilib.h.


Typedef Documentation

typedef struct Jvm_ Jvm
 

Defines which structure is used as Jvm.

Definition at line 35 of file jnilib.h.

typedef struct Jvm_ Jvm_
 

A structure for C, which descripes the Jvm.

typedef struct JvmCPP_ JvmCPP_
 

A structure for C++, which descripes the Jvm.

typedef struct JvmData JvmData
 

This structure holds the data needed for the Jvm for C and C++.


Function Documentation

jboolean callBooleanMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a boolean method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 614 of file jnilib.c.

jboolean callBooleanMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a boolean method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 870 of file jnilib.c.

jbyte callByteMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a byte method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 635 of file jnilib.c.

jbyte callByteMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a byte method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 898 of file jnilib.c.

jchar callCharMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a char method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 656 of file jnilib.c.

jchar callCharMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a char method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 926 of file jnilib.c.

jdouble callDoubleMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a double method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 782 of file jnilib.c.

jdouble callDoubleMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a double method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 1066 of file jnilib.c.

jfloat callFloatMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a float method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 761 of file jnilib.c.

jfloat callFloatMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a float method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 1038 of file jnilib.c.

jint callIntMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls an int method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 719 of file jnilib.c.

jint callIntMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls an int method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 982 of file jnilib.c.

jlong callLongMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a long method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 740 of file jnilib.c.

jlong callLongMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a long method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 1010 of file jnilib.c.

jobject callObjectMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a object method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 824 of file jnilib.c.

jobject callObjectMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a object method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 1094 of file jnilib.c.

jshort callShortMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a short method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 677 of file jnilib.c.

jshort callShortMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a short method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 954 of file jnilib.c.

jint callStaticIntMethod jclass  cls,
jmethodID  mid,
  ...
 

Calls a static int method.

Parameters:
cls - A Java-Class.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 698 of file jnilib.c.

jobject callStaticObjectMethod jclass  cls,
jmethodID  mid,
  ...
 

Calls a static object method.

Parameters:
cls - A Java-Class.
mid - The methodID of the method.
... - The parameters the method needs.
Returns:
the result of the called method.

Definition at line 803 of file jnilib.c.

void callStaticVoidMethod jclass  cls,
jmethodID  mid,
  ...
 

Calls a static void method.

Parameters:
cls - A Java-Class.
mid - The methodID of the method.
... - The parameters the method needs.

Definition at line 578 of file jnilib.c.

void callVoidMethod jobject  obj,
jmethodID  mid,
  ...
 

Calls a void method.

Parameters:
obj - A Java-Object.
mid - The methodID of the method.
... - The parameters the method needs.

Definition at line 595 of file jnilib.c.

void callVoidMethodByName jobject  obj,
const char *  method,
const char *  signature,
  ...
 

Calls a void method.

Parameters:
obj - A Java-Object.
method - The name of the method.
signature - The signature of the method.
... - The parameters the method needs.

Definition at line 844 of file jnilib.c.

char* convertJString jstring  jstr  ) 
 

Creates a native char* from a jstring.

Parameters:
jstr - A JString.
Returns:
a native character string.
Warning:
You have to free the memory of the native character string yourself with free()!
See also:
createJString(const char* str)

Definition at line 455 of file jnilib.c.

jobject createGlobalReference jobject  obj  ) 
 

Creates a global reference of a Java-Object and deletes the local reference.

Parameters:
obj - The object reference to create the global reference of.
Returns:
The global reference.

Definition at line 371 of file jnilib.c.

jstring createJString const char *  str  ) 
 

Creates a jstring from a native char*.

Parameters:
str - A native character string.
Returns:
a JString.
See also:
convertJString(jstring jstr)

Definition at line 418 of file jnilib.c.

void deleteGlobalReference jobject  obj  ) 
 

Deletes a global reference.

Parameters:
obj - The reference to be deleted.

Definition at line 360 of file jnilib.c.

void deleteLocalReference jobject  obj  ) 
 

Deletes a local reference.

Parameters:
obj - The reference to be deleted.

Definition at line 351 of file jnilib.c.

jboolean exception  ) 
 

Tests if an exception was thrown and prints the exception.

Returns:
JNI_TRUE if an exception was thrown, otherwise JNI_FALSE.

Definition at line 395 of file jnilib.c.

jclass findClass const char *  strclass  ) 
 

Finds the Java class specified by strclass.

Parameters:
strclass - Full name of the class.
Returns:
A global reference to the class.
See also:
getObjectClass(jobject obj)

Definition at line 236 of file jnilib.c.

jmethodID findMethod jclass  cls,
const char *  method,
const char *  signature
 

Finds a method of a Java class.

Parameters:
cls - A Java-Class.
method - The name of the method.
signature - The signature of the method.
Returns:
The methodID of the function.
See also:
findStaticMethod(jclass cls, const char* method, const char* signature)

Definition at line 319 of file jnilib.c.

jfieldID findStaticField jclass  cls,
const char *  field,
const char *  signature
 

Finds a static field of a Java class.

Parameters:
cls - A Java-Class.
field - The name of the field.
signature - The signature of the field.
Returns:
The methodID of the function.

Definition at line 299 of file jnilib.c.

jmethodID findStaticMethod jclass  cls,
const char *  method,
const char *  signature
 

Finds a static method of a Java class.

Note:
To get the signature of a function run the javap tool with the Parameters -s and -p. The "-s" flag tells javap to output signatures. The "-p" flag lets javap include private members.

Usage: javap -s -p {PACKAGE}.{CLASSNAME}
Parameters:
cls - A Java-Class.
method - The name of the method.
signature - The signature of the method.
Returns:
The methodID of the function.
See also:
findMethod(jclass cls, const char* method, const char* signature)

Definition at line 281 of file jnilib.c.

JavaVM* getJavaVM  ) 
 

Gets a Pointer to the current JavaVM structure.

Returns:
Pointer to a JavaVM structure.

Definition at line 86 of file jnilib.c.

JNIEnv* getJNIEnv  ) 
 

Gets a Pointer to the actual JNIEnv structure.

Attention:
To get the right JNIEnv call AttachCurrentThread. It returns the JNIEnv of the current thread. If the Thread is already attached, it only returns the JNIEnv.
Returns:
Pointer to a JNIEnv structure.

Definition at line 104 of file jnilib.c.

jclass getObjectClass jobject  obj  ) 
 

Gets the Class of the Java-Object.

Parameters:
obj - A Java object.
Returns:
A global reference to the class.
See also:
findClass(const char* strclass)

Definition at line 260 of file jnilib.c.

jint getStaticIntFieldByName const char *  strclass,
const char *  strfield
 

Gets the value of a class field.

Parameters:
strclass - The Name of the Java Class.
strfield - The name of the field.
Returns:
the value of the class field.

Definition at line 1120 of file jnilib.c.

jobject getStaticObjectFieldByName const char *  strclass,
const char *  strfield,
const char *  signature
 

Gets the value of a class field.

Parameters:
strclass - The Name of the Java Class.
strfield - The name of the field.
signature - The signature of the field.
Returns:
the value of the class field.

Definition at line 1144 of file jnilib.c.

void initJvm Jvm jvm,
const char *  classpath
 

Initializes and creates the Jvm.

Parameters:
jvm - Pointer to a Jvm struct.
classpath - The classpath for the Jvm.

Definition at line 75 of file jnilib.c.

jboolean isSameObject jobject  obj1,
jobject  obj2
 

Compares 2 objects if they are the same or not.

Parameters:
obj1 - The first object to compare.
obj2 - The second object to ccompare.
Returns:
JNI_TRUE if they are the same, otherwise JNI_FALSE;

Definition at line 386 of file jnilib.c.

void jnisleep jint  ms  ) 
 

Sleeps for ms milliseconds.

Parameters:
ms - Milliseconds to sleep for.

Definition at line 512 of file jnilib.c.

jobject newObject jclass  cls,
jmethodID  mid,
  ...
 

Creates a new Object of a Class.

Parameters:
cls - A Java-Class.
mid - The methodID of the Constructor.
... - The parameters the Constructor needs.
Returns:
a global reference of the object.

Definition at line 532 of file jnilib.c.

jobject newObjectBySignature jclass  cls,
const char *  signature,
  ...
 

Creates a new Object of a Class.

Parameters:
cls - A Java-Class.
signature - The signature of the method.
... - The parameters the Constructor needs.
Returns:
a global reference of the object.

Definition at line 555 of file jnilib.c.

jint registerNatives jclass  cls,
const JNINativeMethod *  nm,
jint  nMethods
 

Resgisters a native function pointer as native function in a Java-Class.

Parameters:
cls - A Java-Class.
nm - Pointer to the JNINativeMethod structs.
nMethods - Number of methods to register.
Returns:
0 on success, otherwise a negative number.

Definition at line 337 of file jnilib.c.

void throwByName const char *  name,
const char *  msg
 

Throws an Throwable by name.

Parameters:
name - Name of the Throwable.
msg - The Message for the Throwable.

Definition at line 497 of file jnilib.c.


Generated on Sat Nov 19 14:11:13 2005 for GrubC by  doxygen 1.4.4