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