blob: dde5f644ec8598bad6c00606c008c9201761b0e8 [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
19#include "com_android_inputmethod_keyboard_ProximityInfo.h"
20#include "com_android_inputmethod_latin_BinaryDictionary.h"
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090021#include "com_android_inputmethod_latin_DicTraverseSession.h"
Ken Wakasae7b34b92012-06-08 19:05:47 +090022#include "com_android_inputmethod_latin_NativeUtils.h"
Ken Wakasa3b088a22012-05-16 23:05:32 +090023#include "defines.h"
satok8fbd5522011-02-22 17:28:55 +090024#include "jni.h"
Ken Wakasa74fb9572012-08-01 18:03:55 +090025#include "jni_common.h"
satok8fbd5522011-02-22 17:28:55 +090026
Ken Wakasaf1008c52012-07-31 17:56:40 +090027#include <cassert>
satok8fbd5522011-02-22 17:28:55 +090028
satok8fbd5522011-02-22 17:28:55 +090029using namespace latinime;
30
satok8fbd5522011-02-22 17:28:55 +090031/*
32 * Returns the JNI version on success, -1 on failure.
33 */
Ken Wakasa0bbb9172012-07-25 17:51:43 +090034jint JNI_OnLoad(JavaVM *vm, void *reserved) {
35 JNIEnv *env = 0;
satok8fbd5522011-02-22 17:28:55 +090036 jint result = -1;
37
Ken Wakasa5460ea32012-07-30 16:27:44 +090038 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
satok9fb6f472012-01-13 18:01:22 +090039 AKLOGE("ERROR: GetEnv failed");
satok8fbd5522011-02-22 17:28:55 +090040 goto bail;
41 }
Ken Wakasa5460ea32012-07-30 16:27:44 +090042 assert(env);
satok8fbd5522011-02-22 17:28:55 +090043
44 if (!register_BinaryDictionary(env)) {
satok9fb6f472012-01-13 18:01:22 +090045 AKLOGE("ERROR: BinaryDictionary native registration failed");
satok8fbd5522011-02-22 17:28:55 +090046 goto bail;
47 }
48
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090049 if (!register_DicTraverseSession(env)) {
50 AKLOGE("ERROR: DicTraverseSession native registration failed");
51 goto bail;
52 }
53
satok8fbd5522011-02-22 17:28:55 +090054 if (!register_ProximityInfo(env)) {
satok9fb6f472012-01-13 18:01:22 +090055 AKLOGE("ERROR: ProximityInfo native registration failed");
satok8fbd5522011-02-22 17:28:55 +090056 goto bail;
57 }
58
Ken Wakasae7b34b92012-06-08 19:05:47 +090059 if (!register_NativeUtils(env)) {
60 AKLOGE("ERROR: NativeUtils native registration failed");
61 goto bail;
62 }
63
satok8fbd5522011-02-22 17:28:55 +090064 /* success -- return valid version number */
Ken Wakasa5460ea32012-07-30 16:27:44 +090065 result = JNI_VERSION_1_6;
satok8fbd5522011-02-22 17:28:55 +090066
67bail:
68 return result;
69}
Ken Wakasace9e52a2011-06-18 13:09:55 +090070
71namespace latinime {
72
Ken Wakasa0bbb9172012-07-25 17:51:43 +090073int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090074 int numMethods) {
75 jclass clazz = env->FindClass(className);
Ken Wakasa5460ea32012-07-30 16:27:44 +090076 if (!clazz) {
satok9fb6f472012-01-13 18:01:22 +090077 AKLOGE("Native registration unable to find class '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090078 return JNI_FALSE;
79 }
80 if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
satok9fb6f472012-01-13 18:01:22 +090081 AKLOGE("RegisterNatives failed for '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090082 env->DeleteLocalRef(clazz);
83 return JNI_FALSE;
84 }
85 env->DeleteLocalRef(clazz);
86 return JNI_TRUE;
87}
Ken Wakasace9e52a2011-06-18 13:09:55 +090088} // namespace latinime