blob: 658ff18b91aceb5093cbf97b115ee9e2b560e054 [file] [log] [blame]
Ken Wakasace9e52a2011-06-18 13:09:55 +09001/*
Ken Wakasa5460ea32012-07-30 16:27:44 +09002 * Copyright (C) 2011, The Android Open Source Project
Ken Wakasa0bbb9172012-07-25 17:51:43 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ken Wakasace9e52a2011-06-18 13:09:55 +090016
17#ifndef LATINIME_JNI_COMMON_H
18#define LATINIME_JNI_COMMON_H
19
20#include "jni.h"
21
22namespace latinime {
23
Yusuke Nojimade2f8422011-09-27 11:15:18 +090024int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090025 int numMethods);
26
Yusuke Nojimade2f8422011-09-27 11:15:18 +090027inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
28 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090029 return env->GetIntArrayElements(jArray, 0);
Yusuke Nojimade2f8422011-09-27 11:15:18 +090030 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090031 return 0;
Yusuke Nojimade2f8422011-09-27 11:15:18 +090032 }
33}
34
Yusuke Nojimaad358352011-09-29 16:44:54 +090035inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
36 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090037 return env->GetFloatArrayElements(jArray, 0);
Yusuke Nojimaad358352011-09-29 16:44:54 +090038 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090039 return 0;
Yusuke Nojimaad358352011-09-29 16:44:54 +090040 }
41}
42
Yusuke Nojimade2f8422011-09-27 11:15:18 +090043inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
44 if (jArray) {
45 env->ReleaseIntArrayElements(jArray, cArray, 0);
46 }
47}
48
Yusuke Nojimaad358352011-09-29 16:44:54 +090049inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) {
50 if (jArray) {
51 env->ReleaseFloatArrayElements(jArray, cArray, 0);
52 }
53}
Ken Wakasace9e52a2011-06-18 13:09:55 +090054} // namespace latinime
Ken Wakasace9e52a2011-06-18 13:09:55 +090055#endif // LATINIME_JNI_COMMON_H