jni関数名の取得

1756 ワード

取得した関数名をカプセル化
///  
jmethodID GetMethodID_(int line,
                       JNIEnv* jni,
                       jclass c,
                       const char* name,
                       const char* signature);

///      ,    ,JNIEnv ,jclass ,   ,    .
jmethodID GetMethodID_(int line,JNIEnv* jni, jclass c,
                      const char* name,const char* signature) {
 // jni   GetMethodID      
  jmethodID m = jni->GetMethodID(c, name, signature);
 //           .
  CHECK_EXCEPTION(jni) << "error during GetMethodID: " << name << ", "
                       << signature << " line: " << line;
  CHECK(m) << name << ", " << signature << " line: " << line;
  return m;
}

///            ,JNIEnv ,jclass ,   ,    .
jmethodID GetStaticMethodID_(int line,
                             JNIEnv* jni,
                             jclass c,
                             const char* name,
                             const char* signature) {
  jmethodID m = jni->GetStaticMethodID(c, name, signature);
  CHECK_EXCEPTION(jni) << "error during GetStaticMethodID: " << name << ", "
                       << signature << " line: " << line;
  CHECK(m) << name << ", " << signature << " line: " << line;
  return m;
}

///      (        )
#define _GET_METHOD_ID(_jni_, _c_, _name_, _signature_) \
  GetMethodID_(__LINE__, _jni_, _c_, _name_, _signature_)
  • 使用形態
  •  jmethodID methodID =
          _GET_METHOD_ID(env, jnicb.jcbCls, "OnRobotGetMultiDataRsp","(JLjava/lang/Object;)V");