| 18 | JavaF2Function(ScopedJavaGlobalRef<jobject> *_handle) : func::F2Function(), handle_(_handle) {} |
| 19 | |
| 20 | const std::string Execute(const std::string &functionId, const std::string ¶m) override { |
| 21 | JNIEnv *env = GetJniEnvSafe(); |
| 22 | if(nExecuteMethod_ == nullptr) { |
| 23 | jclass functionClass = env->GetObjectClass(handle_->obj()); |
| 24 | nExecuteMethod_ = env->GetMethodID(functionClass, "nExecute", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"); |
| 25 | } |
| 26 | |
| 27 | // double check nExecuteMethod_. |
| 28 | if(nExecuteMethod_ == nullptr || jni::HasException(env)) { |
| 29 | jni::ClearException(env); |
| 30 | F2_LOG_E("JavaF2Function", "Get nExecute Method failed. functionId: %s", functionId.data()); |
| 31 | return "{}"; |
| 32 | } |
| 33 | |
| 34 | jstring jfunctionId = StringToJString(env, functionId); |
| 35 | jstring jparam = StringToJString(env, param); |
| 36 | jstring jrst = (jstring)env->CallObjectMethod(handle_->obj(), nExecuteMethod_, jfunctionId, jparam); |
| 37 | |
| 38 | if(jni::HasException(env)) { |
| 39 | jni::ClearException(env); |
| 40 | F2_LOG_E("JavaF2Function", "execute nExecute Method failed. functionId: %s", functionId.data()); |
| 41 | return "{}"; |
| 42 | } |
| 43 | |
| 44 | std::string result = JavaStringToString(env, jrst); |
| 45 | jni::ClearException(env); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | ~JavaF2Function() override { |
| 50 | handle_->Reset(); |
nothing calls this directly
no test coverage detected