• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "defines.h"
23 #include "jni.h"
24 #include "proximity_info.h"
25 
26 #include <assert.h>
27 #include <errno.h>
28 #include <stdio.h>
29 
30 using namespace latinime;
31 
32 /*
33  * Returns the JNI version on success, -1 on failure.
34  */
JNI_OnLoad(JavaVM * vm,void * reserved)35 jint JNI_OnLoad(JavaVM* vm, void* reserved) {
36     JNIEnv* env = 0;
37     jint result = -1;
38 
39     if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
40         AKLOGE("ERROR: GetEnv failed");
41         goto bail;
42     }
43     assert(env != 0);
44 
45     if (!register_BinaryDictionary(env)) {
46         AKLOGE("ERROR: BinaryDictionary native registration failed");
47         goto bail;
48     }
49 
50     if (!register_ProximityInfo(env)) {
51         AKLOGE("ERROR: ProximityInfo native registration failed");
52         goto bail;
53     }
54 
55     /* success -- return valid version number */
56     result = JNI_VERSION_1_4;
57 
58 bail:
59     return result;
60 }
61 
62 namespace latinime {
63 
registerNativeMethods(JNIEnv * env,const char * className,JNINativeMethod * methods,int numMethods)64 int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* methods,
65         int numMethods) {
66     jclass clazz = env->FindClass(className);
67     if (clazz == 0) {
68         AKLOGE("Native registration unable to find class '%s'", className);
69         return JNI_FALSE;
70     }
71     if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
72         AKLOGE("RegisterNatives failed for '%s'", className);
73         env->DeleteLocalRef(clazz);
74         return JNI_FALSE;
75     }
76     env->DeleteLocalRef(clazz);
77     return JNI_TRUE;
78 }
79 
80 } // namespace latinime
81