satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 2 | * Copyright (C) 2011, The Android Open Source Project |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 3 | * |
| 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 | */ |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 16 | |
| 17 | #define LOG_TAG "LatinIME: jni" |
| 18 | |
| 19 | #include "com_android_inputmethod_keyboard_ProximityInfo.h" |
| 20 | #include "com_android_inputmethod_latin_BinaryDictionary.h" |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame^] | 21 | #include "com_android_inputmethod_latin_DicTraverseSession.h" |
Ken Wakasa | e7b34b9 | 2012-06-08 19:05:47 +0900 | [diff] [blame] | 22 | #include "com_android_inputmethod_latin_NativeUtils.h" |
Ken Wakasa | 3b088a2 | 2012-05-16 23:05:32 +0900 | [diff] [blame] | 23 | #include "defines.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 24 | #include "jni.h" |
Ken Wakasa | 74fb957 | 2012-08-01 18:03:55 +0900 | [diff] [blame] | 25 | #include "jni_common.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 26 | |
Ken Wakasa | f1008c5 | 2012-07-31 17:56:40 +0900 | [diff] [blame] | 27 | #include <cassert> |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 28 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 29 | using namespace latinime; |
| 30 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 31 | /* |
| 32 | * Returns the JNI version on success, -1 on failure. |
| 33 | */ |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 34 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 35 | JNIEnv *env = 0; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 36 | jint result = -1; |
| 37 | |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 38 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 39 | AKLOGE("ERROR: GetEnv failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 40 | goto bail; |
| 41 | } |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 42 | assert(env); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 43 | |
| 44 | if (!register_BinaryDictionary(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 45 | AKLOGE("ERROR: BinaryDictionary native registration failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 46 | goto bail; |
| 47 | } |
| 48 | |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame^] | 49 | if (!register_DicTraverseSession(env)) { |
| 50 | AKLOGE("ERROR: DicTraverseSession native registration failed"); |
| 51 | goto bail; |
| 52 | } |
| 53 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 54 | if (!register_ProximityInfo(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 55 | AKLOGE("ERROR: ProximityInfo native registration failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 56 | goto bail; |
| 57 | } |
| 58 | |
Ken Wakasa | e7b34b9 | 2012-06-08 19:05:47 +0900 | [diff] [blame] | 59 | if (!register_NativeUtils(env)) { |
| 60 | AKLOGE("ERROR: NativeUtils native registration failed"); |
| 61 | goto bail; |
| 62 | } |
| 63 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 64 | /* success -- return valid version number */ |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 65 | result = JNI_VERSION_1_6; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 66 | |
| 67 | bail: |
| 68 | return result; |
| 69 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 70 | |
| 71 | namespace latinime { |
| 72 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 73 | int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 74 | int numMethods) { |
| 75 | jclass clazz = env->FindClass(className); |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 76 | if (!clazz) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 77 | AKLOGE("Native registration unable to find class '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 78 | return JNI_FALSE; |
| 79 | } |
| 80 | if (env->RegisterNatives(clazz, methods, numMethods) < 0) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 81 | AKLOGE("RegisterNatives failed for '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 82 | env->DeleteLocalRef(clazz); |
| 83 | return JNI_FALSE; |
| 84 | } |
| 85 | env->DeleteLocalRef(clazz); |
| 86 | return JNI_TRUE; |
| 87 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 88 | } // namespace latinime |