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