Get "com/termux/shared/jni/models/JniResult" object that can be returned as result for a JNI call. */
| 162 | |
| 163 | /* Get "com/termux/shared/jni/models/JniResult" object that can be returned as result for a JNI call. */ |
| 164 | jobject getJniResult(JNIEnv *env, jstring title, const int retvalParam, const int errnoParam, |
| 165 | string errmsgParam, const int intDataParam) { |
| 166 | jclass clazz = env->FindClass("com/termux/shared/jni/models/JniResult"); |
| 167 | if (checkJniException(env)) return NULL; |
| 168 | if (!clazz) { |
| 169 | log_error(get_title_and_message(env, title, |
| 170 | "Failed to find JniResult class to create object for " + |
| 171 | getJniResultString(retvalParam, errnoParam, errmsgParam, intDataParam))); |
| 172 | return NULL; |
| 173 | } |
| 174 | |
| 175 | jmethodID constructor = env->GetMethodID(clazz, "<init>", "(IILjava/lang/String;I)V"); |
| 176 | if (checkJniException(env)) return NULL; |
| 177 | if (!constructor) { |
| 178 | log_error(get_title_and_message(env, title, |
| 179 | "Failed to get constructor for JniResult class to create object for " + |
| 180 | getJniResultString(retvalParam, errnoParam, errmsgParam, intDataParam))); |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | if (!errmsgParam.empty()) |
| 185 | errmsgParam = get_title_and_message(env, title, string(errmsgParam)); |
| 186 | |
| 187 | jobject obj = env->NewObject(clazz, constructor, retvalParam, errnoParam, env->NewStringUTF(errmsgParam.c_str()), intDataParam); |
| 188 | if (checkJniException(env)) return NULL; |
| 189 | if (obj == NULL) { |
| 190 | log_error(get_title_and_message(env, title, |
| 191 | "Failed to get JniResult object for " + |
| 192 | getJniResultString(retvalParam, errnoParam, errmsgParam, intDataParam))); |
| 193 | return NULL; |
| 194 | } |
| 195 | |
| 196 | return obj; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | jobject getJniResult(JNIEnv *env, jstring title, const int retvalParam, const int errnoParam) { |
no test coverage detected