Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 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 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 23 | #include "jni.h" |
| 24 | |
| 25 | namespace latinime { |
| 26 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 27 | int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 28 | int numMethods); |
| 29 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 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 | |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 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 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 46 | inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) { |
| 47 | if (jArray) { |
| 48 | env->ReleaseIntArrayElements(jArray, cArray, 0); |
| 49 | } |
| 50 | } |
| 51 | |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 52 | inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) { |
| 53 | if (jArray) { |
| 54 | env->ReleaseFloatArrayElements(jArray, cArray, 0); |
| 55 | } |
| 56 | } |
| 57 | |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 58 | } // namespace latinime |
| 59 | |
| 60 | #endif // LATINIME_JNI_COMMON_H |