jni取得変数

1844 ワード

#define JINT "I"
#define JLONG "J"
#define JFLOAT "F"
#define JSTR "Ljava/lang/String;"
#define JBOOL "Z"
#define JBYTES "[B"
///    ID
jfieldID GetFieldID_(int line,
                     JNIEnv* jni,
                     jclass c,
                     const char* name,
                     const char* signature);
///    ID
jfieldID GetFieldID_(int line,
                     JNIEnv* jni,
                     jclass c,
                     const char* name,
                     const char* signature) {
  jfieldID f = jni->GetFieldID(c, name, signature);
  CHECK_EXCEPTION(jni) << "error during GetFieldID"
                       << " line: " << line;
  CHECK(f) << name << ", " << signature << " line: " << line;
  return f;
}

///    ID
#define _GetFieldID(_jni_, _c_, _name_, _signature_) \
  GetFieldID_(__LINE__, _jni_, _c_, _name_, _signature_)


///      
jint GetIntField_(int line,
                  JNIEnv* jni,
                  jobject object,
                  jclass cls,
                  const char* name);
///      
jint GetIntField_(int line,
                  JNIEnv* jni,
                  jobject object,
                  jclass cls,
                  const char* name) {
 //        ,             , :GetLongField....
  jint i = jni->GetIntField(object, _GetFieldID(jni, cls, name, JINT));
  CHECK_EXCEPTION(jni) << "error during GetIntField"
                       << " line: " << line;
  return i;
}

#define _GetIntField(_jni_, _obj_, _cls_, _name_) \
  GetIntField_(__LINE__, _jni_, _obj_, _cls_, _name_)
  • は、1つのオブジェクトの整形変数
  • を取得するために使用する.
    jint sn  = _GetIntField(env, msg, cls, "sn");