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