1 /*
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
21 #include <stdlib.h>
22
23 #include "jni.h"
24
25 namespace latinime {
26
27 int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
28 int numMethods);
29
safeGetIntArrayElements(JNIEnv * env,jintArray jArray)30 inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
31 if (jArray) {
32 return env->GetIntArrayElements(jArray, NULL);
33 } else {
34 return NULL;
35 }
36 }
37
safeGetFloatArrayElements(JNIEnv * env,jfloatArray jArray)38 inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
39 if (jArray) {
40 return env->GetFloatArrayElements(jArray, NULL);
41 } else {
42 return NULL;
43 }
44 }
45
safeReleaseIntArrayElements(JNIEnv * env,jintArray jArray,jint * cArray)46 inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
47 if (jArray) {
48 env->ReleaseIntArrayElements(jArray, cArray, 0);
49 }
50 }
51
safeReleaseFloatArrayElements(JNIEnv * env,jfloatArray jArray,jfloat * cArray)52 inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) {
53 if (jArray) {
54 env->ReleaseFloatArrayElements(jArray, cArray, 0);
55 }
56 }
57
58 } // namespace latinime
59
60 #endif // LATINIME_JNI_COMMON_H
61