2011-02-22 08:28:55 +00:00
|
|
|
/*
|
2012-07-30 07:27:44 +00:00
|
|
|
* Copyright (C) 2011, The Android Open Source Project
|
2012-07-25 08:51:43 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
#define LOG_TAG "LatinIME: jni"
|
|
|
|
|
2012-08-08 07:46:16 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
|
|
|
|
#include "com_android_inputmethod_latin_BinaryDictionary.h"
|
2012-08-08 10:40:44 +00:00
|
|
|
#include "com_android_inputmethod_latin_DicTraverseSession.h"
|
2012-06-08 10:05:47 +00:00
|
|
|
#include "com_android_inputmethod_latin_NativeUtils.h"
|
2012-05-16 14:05:32 +00:00
|
|
|
#include "defines.h"
|
2011-02-22 08:28:55 +00:00
|
|
|
#include "jni.h"
|
2012-08-01 09:03:55 +00:00
|
|
|
#include "jni_common.h"
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
using namespace latinime;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the JNI version on success, -1 on failure.
|
|
|
|
*/
|
2012-07-25 08:51:43 +00:00
|
|
|
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
|
|
JNIEnv *env = 0;
|
2011-02-22 08:28:55 +00:00
|
|
|
jint result = -1;
|
|
|
|
|
2012-07-30 07:27:44 +00:00
|
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: GetEnv failed");
|
2011-02-22 08:28:55 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
2012-07-30 07:27:44 +00:00
|
|
|
assert(env);
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
if (!register_BinaryDictionary(env)) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: BinaryDictionary native registration failed");
|
2011-02-22 08:28:55 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2012-08-08 10:40:44 +00:00
|
|
|
if (!register_DicTraverseSession(env)) {
|
|
|
|
AKLOGE("ERROR: DicTraverseSession native registration failed");
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
if (!register_ProximityInfo(env)) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: ProximityInfo native registration failed");
|
2011-02-22 08:28:55 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2012-06-08 10:05:47 +00:00
|
|
|
if (!register_NativeUtils(env)) {
|
|
|
|
AKLOGE("ERROR: NativeUtils native registration failed");
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
/* success -- return valid version number */
|
2012-07-30 07:27:44 +00:00
|
|
|
result = JNI_VERSION_1_6;
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
bail:
|
|
|
|
return result;
|
|
|
|
}
|
2011-06-18 04:09:55 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
2012-07-25 08:51:43 +00:00
|
|
|
int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
|
2011-06-18 04:09:55 +00:00
|
|
|
int numMethods) {
|
|
|
|
jclass clazz = env->FindClass(className);
|
2012-07-30 07:27:44 +00:00
|
|
|
if (!clazz) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("Native registration unable to find class '%s'", className);
|
2011-06-18 04:09:55 +00:00
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("RegisterNatives failed for '%s'", className);
|
2011-06-18 04:09:55 +00:00
|
|
|
env->DeleteLocalRef(clazz);
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
env->DeleteLocalRef(clazz);
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
} // namespace latinime
|