blob: 6741443ac4e31b55081671824cf8d4311f0912d2 [file] [log] [blame]
Ken Wakasace9e52a2011-06-18 13:09:55 +09001/*
2**
3** Copyright 2011, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef LATINIME_JNI_COMMON_H
19#define LATINIME_JNI_COMMON_H
20
Yusuke Nojimade2f8422011-09-27 11:15:18 +090021#include <stdlib.h>
22
Ken Wakasace9e52a2011-06-18 13:09:55 +090023#include "jni.h"
24
25namespace latinime {
26
Yusuke Nojimade2f8422011-09-27 11:15:18 +090027int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090028 int numMethods);
29
Yusuke Nojimade2f8422011-09-27 11:15:18 +090030inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
31 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090032 return env->GetIntArrayElements(jArray, 0);
Yusuke Nojimade2f8422011-09-27 11:15:18 +090033 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090034 return 0;
Yusuke Nojimade2f8422011-09-27 11:15:18 +090035 }
36}
37
Yusuke Nojimaad358352011-09-29 16:44:54 +090038inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
39 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090040 return env->GetFloatArrayElements(jArray, 0);
Yusuke Nojimaad358352011-09-29 16:44:54 +090041 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090042 return 0;
Yusuke Nojimaad358352011-09-29 16:44:54 +090043 }
44}
45
Yusuke Nojimade2f8422011-09-27 11:15:18 +090046inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
47 if (jArray) {
48 env->ReleaseIntArrayElements(jArray, cArray, 0);
49 }
50}
51
Yusuke Nojimaad358352011-09-29 16:44:54 +090052inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) {
53 if (jArray) {
54 env->ReleaseFloatArrayElements(jArray, cArray, 0);
55 }
56}
57
Ken Wakasace9e52a2011-06-18 13:09:55 +090058} // namespace latinime
59
60#endif // LATINIME_JNI_COMMON_H