blob: 9548e1b3f5ec93cd4e20a672361b5e4784a0f204 [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) {
32 return env->GetIntArrayElements(jArray, NULL);
33 } else {
34 return NULL;
35 }
36}
37
Yusuke Nojimaad358352011-09-29 16:44:54 +090038inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
39 if (jArray) {
40 return env->GetFloatArrayElements(jArray, NULL);
41 } else {
42 return NULL;
43 }
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