Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsJNI.cpp File Reference
#include "jni.h"
#include "nsISecureJNI2.h"
#include "nsHashtable.h"
#include "nsVoidArray.h"
#include "plstr.h"

Go to the source code of this file.

Classes

class  JNIHashKey
struct  JNIMember
struct  JNIField
struct  JNIMethod
class  MarshalledArgs
 Marshalls a va_list into a jvalue array, and destructor automatically deletes when the args go out of scope. More...
class  nsJNIEnv

Defines

#define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField)
#define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField)
#define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)
#define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)
#define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField)
#define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)
#define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)
#define IMPLEMENT_NEW_ARRAY(methodName, type)
#define IMPLEMENT_GET_ARRAY_ELEMENTS(methodName, type)
#define IMPLEMENT_RELEASE_ARRAY_ELEMENTS(methodName, type)
#define IMPLEMENT_GET_ARRAY_REGION(methodName, type)
#define IMPLEMENT_SET_ARRAY_REGION(methodName, type)
#define REFERENCE_METHOD_FAMILY(methodName)   &methodName, &methodName##V, &methodName##A,

Functions

static jni_type get_jni_type (char sig)
static PRBool get_method_type (const char *sig, PRUint32 &arg_count, jni_type *&arg_types, jni_type &return_type)

Define Documentation

#define IMPLEMENT_GET_ARRAY_ELEMENTS (   methodName,
  type 
)
Value:
static type* JNICALL methodName(JNIEnv *env, type##Array array, jboolean *isCopy)                                      \
       {                                                                                                                                                                                     \
		type* outElements = NULL;                                                                                                                               \
		nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                          \
		nsresult result = secureEnv->GetArrayElements(type##_type, array, isCopy, &outElements);               \
              return outElements;                                                                                                                                              \
       }                                                                                                                                                                                     \

Definition at line 969 of file nsJNI.cpp.

#define IMPLEMENT_GET_ARRAY_REGION (   methodName,
  type 
)
Value:
static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)        \
       {                                                                                                                                                                                     \
		nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                          \
		nsresult result = secureEnv->GetArrayRegion(type##_type, array, start, len, buf);                             \
       }                                                                                                                                                                                     \

Definition at line 1007 of file nsJNI.cpp.

#define IMPLEMENT_GET_FIELD (   methodName,
  returnType,
  jvalueField 
)
Value:
static returnType JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID)           \
       {                                                                                                                                                         \
              return GetField(env, obj, (JNIField*)fieldID).jvalueField;                                               \
       }                                                                                                                                                         \

Definition at line 815 of file nsJNI.cpp.

#define IMPLEMENT_GET_FIELD (   methodName,
  returnType,
  jvalueField 
)
Value:
static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID)          \
       {                                                                                                                                                         \
              return GetStaticField(env, clazz, (JNIField*)fieldID).jvalueField;                                \
       }                                                                                                                                                         \

Definition at line 815 of file nsJNI.cpp.

#define IMPLEMENT_METHOD_FAMILY (   methodName,
  returnType,
  jvalueField 
)
Value:
static returnType JNICALL methodName(JNIEnv *env, jobject obj, jmethodID methodID, ...)                                \
       {                                                                                                                                                                                     \
              va_list args; va_start(args, methodID);                                                                                                            \
              returnType result = InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                             \
              va_end(args);                                                                                                                                                    \
              return result;                                                                                                                                                          \
       }                                                                                                                                                                                     \
                                                                                                                                                                                             \
       static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)             \
       {                                                                                                                                                                                     \
              return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                                                        \
       }                                                                                                                                                                                     \
                                                                                                                                                                                             \
       static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)     \
       {                                                                                                                                                                                     \
              return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                                                        \
       }                                                                                                                                                                                     \

Definition at line 740 of file nsJNI.cpp.

#define IMPLEMENT_METHOD_FAMILY (   methodName,
  returnType,
  jvalueField 
)
Value:
static returnType JNICALL methodName(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)                         \
       {                                                                                                                                                                                                          \
              va_list args; va_start(args, methodID);                                                                                                                                 \
              returnType result = InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                   \
              va_end(args);                                                                                                                                                                         \
              return result;                                                                                                                                                                               \
       }                                                                                                                                                                                                          \
                                                                                                                                                                                                                  \
       static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)      \
       {                                                                                                                                                                                                          \
              return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                                              \
       }                                                                                                                                                                                                          \
                                                                                                                                                                                                                  \
       static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)     \
       {                                                                                                                                                                                                          \
              return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                                              \
       }                                                                                                                                                                                                          \

Definition at line 740 of file nsJNI.cpp.

#define IMPLEMENT_METHOD_FAMILY (   methodName,
  returnType,
  jvalueField 
)
Value:
static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jmethodID methodID, ...)                        \
       {                                                                                                                                                                                     \
              va_list args; va_start(args, methodID);                                                                                                            \
              returnType result = InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                     \
              va_end(args);                                                                                                                                                    \
              return result;                                                                                                                                                          \
       }                                                                                                                                                                                     \
                                                                                                                                                                                             \
       static returnType JNICALL methodName##V(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)     \
       {                                                                                                                                                                                     \
              return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                                         \
       }                                                                                                                                                                                     \
                                                                                                                                                                                             \
       static returnType JNICALL methodName##A(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)    \
       {                                                                                                                                                                                     \
              return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                                         \
       }                                                                                                                                                                                     \

Definition at line 740 of file nsJNI.cpp.

#define IMPLEMENT_NEW_ARRAY (   methodName,
  type 
)
Value:
static type##Array JNICALL methodName(JNIEnv *env, jsize len)                                                          \
       {                                                                                                                                                                       \
		type##Array outArray = NULL;                                                                                                              \
		nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                            \
		nsresult result = secureEnv->NewArray(type##_type, len, (jarray*)&outArray);                           \
              return outArray;                                                                                                                                   \
       }                                                                                                                                                                       \

Definition at line 949 of file nsJNI.cpp.

#define IMPLEMENT_RELEASE_ARRAY_ELEMENTS (   methodName,
  type 
)
Value:
static void JNICALL methodName(JNIEnv *env, type##Array array, type* elems, jint mode)                                 \
       {                                                                                                                                                                                     \
		nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                          \
		nsresult result = secureEnv->ReleaseArrayElements(type##_type, array, elems, mode);                                  \
       }                                                                                                                                                                                     \

Definition at line 989 of file nsJNI.cpp.

#define IMPLEMENT_SET_ARRAY_REGION (   methodName,
  type 
)
Value:
static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)        \
       {                                                                                                                                                                                     \
		nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                          \
		nsresult result = secureEnv->SetArrayRegion(type##_type, array, start, len, buf);                             \
       }                                                                                                                                                                                     \

Definition at line 1025 of file nsJNI.cpp.

#define IMPLEMENT_SET_FIELD (   methodName,
  fieldType,
  jvalueField 
)
Value:
static void JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID, fieldType value)              \
       {                                                                                                                                                                       \
		jvalue fieldValue;                                                                                                                               \
              fieldValue.jvalueField = value;                                                                                                             \
              SetField(env, obj, (JNIField*)fieldID, fieldValue);                                                                           \
       }                                                                                                                                                                       \

Definition at line 839 of file nsJNI.cpp.

#define IMPLEMENT_SET_FIELD (   methodName,
  fieldType,
  jvalueField 
)
Value:
static void JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID, fieldType value)      \
       {                                                                                                                                                                       \
		jvalue fieldValue;                                                                                                                               \
              fieldValue.jvalueField = value;                                                                                                             \
              SetStaticField(env, clazz, (JNIField*)fieldID, fieldValue);                                                            \
       }                                                                                                                                                                       \

Definition at line 839 of file nsJNI.cpp.

#define REFERENCE_METHOD_FAMILY (   methodName)    &methodName, &methodName##V, &methodName##A,

Function Documentation

static jni_type get_jni_type ( char  sig) [static]

Definition at line 50 of file nsJNI.cpp.

{
       switch (sig) {
       case 'L':
       case '[':
              return jobject_type;
       case 'Z':
              return jboolean_type;
       case 'B':
              return jbyte_type;
       case 'C':
              return jchar_type;
       case 'S':
              return jshort_type;
       case 'I':
              return jint_type;
       case 'J':
              return jlong_type;
       case 'F':
              return jfloat_type;
       case 'D':
              return jdouble_type;
       case 'V':
              return jvoid_type;
       }
       return jvoid_type;
}

Here is the caller graph for this function:

static PRBool get_method_type ( const char *  sig,
PRUint32 arg_count,
jni_type *&  arg_types,
jni_type return_type 
) [static]

Definition at line 78 of file nsJNI.cpp.

{
       arg_count = 0;
       if (sig[0] == '(') {
              nsVoidArray vec;
              ++sig;
              while (*sig != ')' && *sig) {
                     char arg_sig = *sig++;
                     jni_type arg_type = get_jni_type(arg_sig);
                     if (arg_type == jobject_type) {
                            // could be an array or an object.
                            while (*sig == '[') ++sig;
                            if (*sig == 'L') {
                                   // skip over "className;"
                                   ++sig;
                                   while (*sig != ';') ++sig;
                            }
                            // skip over scalar or ';'.
                            ++sig;
                     }
                     vec.AppendElement((void*)arg_type);
              }
              arg_count = vec.Count();
              arg_types = new jni_type[arg_count];
              for (int index = arg_count - 1; index >= 0; --index)
                     arg_types[index] = jni_type(vec.ElementAt(index));
              if (*sig == ')') {
                     char return_sig = *++sig;
                     return_type = get_jni_type(return_sig);
              }
       }
       return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function: