blob: 0da166903987202fa772111ee1a50e0ec411ab04 [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
Ken Wakasa5460ea32012-07-30 16:27:44 +09002 * Copyright (C) 2011, The Android Open Source Project
Ken Wakasa0bbb9172012-07-25 17:51:43 +09003 *
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 */
satok8fbd5522011-02-22 17:28:55 +090016
17#define LOG_TAG "LatinIME: jni"
18
Ken Wakasa9b392362012-08-08 16:46:16 +090019#include <cassert>
20
satok8fbd5522011-02-22 17:28:55 +090021#include "com_android_inputmethod_keyboard_ProximityInfo.h"
22#include "com_android_inputmethod_latin_BinaryDictionary.h"
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090023#include "com_android_inputmethod_latin_DicTraverseSession.h"
Ken Wakasa3b088a22012-05-16 23:05:32 +090024#include "defines.h"
satok8fbd5522011-02-22 17:28:55 +090025#include "jni.h"
Ken Wakasa74fb9572012-08-01 18:03:55 +090026#include "jni_common.h"
satok8fbd5522011-02-22 17:28:55 +090027
satok8fbd5522011-02-22 17:28:55 +090028using namespace latinime;
29
satok8fbd5522011-02-22 17:28:55 +090030/*
31 * Returns the JNI version on success, -1 on failure.
32 */
Ken Wakasa0bbb9172012-07-25 17:51:43 +090033jint JNI_OnLoad(JavaVM *vm, void *reserved) {
34 JNIEnv *env = 0;
satok8fbd5522011-02-22 17:28:55 +090035 jint result = -1;
36
Ken Wakasa34710b02012-08-14 14:22:27 +090037 if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
satok9fb6f472012-01-13 18:01:22 +090038 AKLOGE("ERROR: GetEnv failed");
satok8fbd5522011-02-22 17:28:55 +090039 goto bail;
40 }
Ken Wakasa5460ea32012-07-30 16:27:44 +090041 assert(env);
satok8fbd5522011-02-22 17:28:55 +090042
43 if (!register_BinaryDictionary(env)) {
satok9fb6f472012-01-13 18:01:22 +090044 AKLOGE("ERROR: BinaryDictionary native registration failed");
satok8fbd5522011-02-22 17:28:55 +090045 goto bail;
46 }
47
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090048 if (!register_DicTraverseSession(env)) {
49 AKLOGE("ERROR: DicTraverseSession native registration failed");
50 goto bail;
51 }
52
satok8fbd5522011-02-22 17:28:55 +090053 if (!register_ProximityInfo(env)) {
satok9fb6f472012-01-13 18:01:22 +090054 AKLOGE("ERROR: ProximityInfo native registration failed");
satok8fbd5522011-02-22 17:28:55 +090055 goto bail;
56 }
57
58 /* success -- return valid version number */
Ken Wakasa5460ea32012-07-30 16:27:44 +090059 result = JNI_VERSION_1_6;
satok8fbd5522011-02-22 17:28:55 +090060
61bail:
62 return result;
63}
Ken Wakasace9e52a2011-06-18 13:09:55 +090064
65namespace latinime {
66
Ken Wakasa0bbb9172012-07-25 17:51:43 +090067int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090068 int numMethods) {
69 jclass clazz = env->FindClass(className);
Ken Wakasa5460ea32012-07-30 16:27:44 +090070 if (!clazz) {
satok9fb6f472012-01-13 18:01:22 +090071 AKLOGE("Native registration unable to find class '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090072 return JNI_FALSE;
73 }
74 if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
satok9fb6f472012-01-13 18:01:22 +090075 AKLOGE("RegisterNatives failed for '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090076 env->DeleteLocalRef(clazz);
77 return JNI_FALSE;
78 }
79 env->DeleteLocalRef(clazz);
80 return JNI_TRUE;
81}
Ken Wakasace9e52a2011-06-18 13:09:55 +090082} // namespace latinime