blob: 771361d5e9ea8f6e2448002f0a426f710d07255d [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
Yusuke Nojimade2f8422011-09-27 11:15:18 +090020#include <stdlib.h>
21
Ken Wakasace9e52a2011-06-18 13:09:55 +090022#include "jni.h"
23
24namespace latinime {
25
Yusuke Nojimade2f8422011-09-27 11:15:18 +090026int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090027 int numMethods);
28
Yusuke Nojimade2f8422011-09-27 11:15:18 +090029inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
30 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090031 return env->GetIntArrayElements(jArray, 0);
Yusuke Nojimade2f8422011-09-27 11:15:18 +090032 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090033 return 0;
Yusuke Nojimade2f8422011-09-27 11:15:18 +090034 }
35}
36
Yusuke Nojimaad358352011-09-29 16:44:54 +090037inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
38 if (jArray) {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090039 return env->GetFloatArrayElements(jArray, 0);
Yusuke Nojimaad358352011-09-29 16:44:54 +090040 } else {
Tadashi G. Takaoka94810de2011-10-28 17:06:58 +090041 return 0;
Yusuke Nojimaad358352011-09-29 16:44:54 +090042 }
43}
44
Yusuke Nojimade2f8422011-09-27 11:15:18 +090045inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
46 if (jArray) {
47 env->ReleaseIntArrayElements(jArray, cArray, 0);
48 }
49}
50
Yusuke Nojimaad358352011-09-29 16:44:54 +090051inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) {
52 if (jArray) {
53 env->ReleaseFloatArrayElements(jArray, cArray, 0);
54 }
55}
Ken Wakasace9e52a2011-06-18 13:09:55 +090056} // namespace latinime
Ken Wakasace9e52a2011-06-18 13:09:55 +090057#endif // LATINIME_JNI_COMMON_H