satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +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 | * |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 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 | b68e734 | 2013-04-08 17:08:19 +0900 | [diff] [blame] | 19 | #include "jni_common.h" |
| 20 | |
Jean Chalard | e7870a2 | 2013-08-12 12:44:04 +0900 | [diff] [blame] | 21 | #ifndef HOST_TOOL |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 22 | #include "com_android_inputmethod_keyboard_ProximityInfo.h" |
| 23 | #include "com_android_inputmethod_latin_BinaryDictionary.h" |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 24 | #include "com_android_inputmethod_latin_DicTraverseSession.h" |
Jean Chalard | e7870a2 | 2013-08-12 12:44:04 +0900 | [diff] [blame] | 25 | #endif |
Yuichiro Hanada | 112257e | 2013-08-20 15:48:16 +0900 | [diff] [blame] | 26 | #include "com_android_inputmethod_latin_makedict_Ver3DictDecoder.h" |
Ken Wakasa | 3b088a2 | 2012-05-16 23:05:32 +0900 | [diff] [blame] | 27 | #include "defines.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 28 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 29 | /* |
| 30 | * Returns the JNI version on success, -1 on failure. |
| 31 | */ |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 32 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 33 | JNIEnv *env = 0; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 34 | |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 35 | if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 36 | AKLOGE("ERROR: GetEnv failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 37 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 38 | } |
Ken Wakasa | ccebd5c | 2013-01-09 15:21:44 +0900 | [diff] [blame] | 39 | ASSERT(env); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 40 | if (!env) { |
| 41 | AKLOGE("ERROR: JNIEnv is invalid"); |
| 42 | return -1; |
| 43 | } |
Jean Chalard | e7870a2 | 2013-08-12 12:44:04 +0900 | [diff] [blame] | 44 | #ifndef HOST_TOOL |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 45 | if (!latinime::register_BinaryDictionary(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 46 | AKLOGE("ERROR: BinaryDictionary native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 47 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 48 | } |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 49 | if (!latinime::register_DicTraverseSession(env)) { |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 50 | AKLOGE("ERROR: DicTraverseSession native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 51 | return -1; |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 52 | } |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 53 | if (!latinime::register_ProximityInfo(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 54 | AKLOGE("ERROR: ProximityInfo native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 55 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 56 | } |
Jean Chalard | e7870a2 | 2013-08-12 12:44:04 +0900 | [diff] [blame] | 57 | #endif |
Yuichiro Hanada | 112257e | 2013-08-20 15:48:16 +0900 | [diff] [blame] | 58 | if (!latinime::register_Ver3DictDecoder(env)) { |
| 59 | AKLOGE("ERROR: Ver3DictDecoder native registration failed"); |
Jean Chalard | e7870a2 | 2013-08-12 12:44:04 +0900 | [diff] [blame] | 60 | return -1; |
| 61 | } |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 62 | /* success -- return valid version number */ |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 63 | return JNI_VERSION_1_6; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 64 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 65 | |
| 66 | namespace latinime { |
Ken Wakasa | ad0c6d7 | 2013-06-04 19:16:47 +0900 | [diff] [blame] | 67 | int registerNativeMethods(JNIEnv *env, const char *const className, const JNINativeMethod *methods, |
| 68 | const int numMethods) { |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 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 |