blob: 4eeda1d4e0904a9726be1cdf2c59ad12f0edc85d [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"
Ken Wakasae7b34b92012-06-08 19:05:47 +090021#include "com_android_inputmethod_latin_NativeUtils.h"
Ken Wakasa3b088a22012-05-16 23:05:32 +090022#include "defines.h"
satok8fbd5522011-02-22 17:28:55 +090023#include "jni.h"
24#include "proximity_info.h"
25
26#include <assert.h>
27#include <errno.h>
28#include <stdio.h>
29
satok8fbd5522011-02-22 17:28:55 +090030using namespace latinime;
31
satok8fbd5522011-02-22 17:28:55 +090032/*
33 * Returns the JNI version on success, -1 on failure.
34 */
Ken Wakasa0bbb9172012-07-25 17:51:43 +090035jint JNI_OnLoad(JavaVM *vm, void *reserved) {
36 JNIEnv *env = 0;
satok8fbd5522011-02-22 17:28:55 +090037 jint result = -1;
38
Ken Wakasa5460ea32012-07-30 16:27:44 +090039 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
satok9fb6f472012-01-13 18:01:22 +090040 AKLOGE("ERROR: GetEnv failed");
satok8fbd5522011-02-22 17:28:55 +090041 goto bail;
42 }
Ken Wakasa5460ea32012-07-30 16:27:44 +090043 assert(env);
satok8fbd5522011-02-22 17:28:55 +090044
45 if (!register_BinaryDictionary(env)) {
satok9fb6f472012-01-13 18:01:22 +090046 AKLOGE("ERROR: BinaryDictionary native registration failed");
satok8fbd5522011-02-22 17:28:55 +090047 goto bail;
48 }
49
50 if (!register_ProximityInfo(env)) {
satok9fb6f472012-01-13 18:01:22 +090051 AKLOGE("ERROR: ProximityInfo native registration failed");
satok8fbd5522011-02-22 17:28:55 +090052 goto bail;
53 }
54
Ken Wakasae7b34b92012-06-08 19:05:47 +090055 if (!register_NativeUtils(env)) {
56 AKLOGE("ERROR: NativeUtils native registration failed");
57 goto bail;
58 }
59
satok8fbd5522011-02-22 17:28:55 +090060 /* success -- return valid version number */
Ken Wakasa5460ea32012-07-30 16:27:44 +090061 result = JNI_VERSION_1_6;
satok8fbd5522011-02-22 17:28:55 +090062
63bail:
64 return result;
65}
Ken Wakasace9e52a2011-06-18 13:09:55 +090066
67namespace latinime {
68
Ken Wakasa0bbb9172012-07-25 17:51:43 +090069int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Ken Wakasace9e52a2011-06-18 13:09:55 +090070 int numMethods) {
71 jclass clazz = env->FindClass(className);
Ken Wakasa5460ea32012-07-30 16:27:44 +090072 if (!clazz) {
satok9fb6f472012-01-13 18:01:22 +090073 AKLOGE("Native registration unable to find class '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090074 return JNI_FALSE;
75 }
76 if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
satok9fb6f472012-01-13 18:01:22 +090077 AKLOGE("RegisterNatives failed for '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090078 env->DeleteLocalRef(clazz);
79 return JNI_FALSE;
80 }
81 env->DeleteLocalRef(clazz);
82 return JNI_TRUE;
83}
Ken Wakasace9e52a2011-06-18 13:09:55 +090084} // namespace latinime