• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012, The Android Open Source Project
3  *
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  */
16 
17 #define LOG_TAG "LatinIME: jni: Session"
18 
19 #include "com_android_inputmethod_latin_DicTraverseSession.h"
20 #include "dic_traverse_wrapper.h"
21 #include "jni.h"
22 #include "jni_common.h"
23 
24 namespace latinime {
25 class Dictionary;
latinime_setDicTraverseSession(JNIEnv * env,jobject object,jstring localeJStr)26 static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object, jstring localeJStr) {
27     void *traverseSession = DicTraverseWrapper::getDicTraverseSession(env, localeJStr);
28     return reinterpret_cast<jlong>(traverseSession);
29 }
30 
latinime_initDicTraverseSession(JNIEnv * env,jobject object,jlong traverseSession,jlong dictionary,jintArray previousWord,jint previousWordLength)31 static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession,
32         jlong dictionary, jintArray previousWord, jint previousWordLength) {
33     void *ts = reinterpret_cast<void *>(traverseSession);
34     Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
35     if (!previousWord) {
36         DicTraverseWrapper::initDicTraverseSession(ts, dict, 0, 0);
37         return;
38     }
39     int prevWord[previousWordLength];
40     env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
41     DicTraverseWrapper::initDicTraverseSession(ts, dict, prevWord, previousWordLength);
42 }
43 
latinime_releaseDicTraverseSession(JNIEnv * env,jobject object,jlong traverseSession)44 static void latinime_releaseDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession) {
45     void *ts = reinterpret_cast<void *>(traverseSession);
46     DicTraverseWrapper::releaseDicTraverseSession(ts);
47 }
48 
49 static JNINativeMethod sMethods[] = {
50     {"setDicTraverseSessionNative", "(Ljava/lang/String;)J",
51             reinterpret_cast<void *>(latinime_setDicTraverseSession)},
52     {"initDicTraverseSessionNative", "(JJ[II)V",
53             reinterpret_cast<void *>(latinime_initDicTraverseSession)},
54     {"releaseDicTraverseSessionNative", "(J)V",
55             reinterpret_cast<void *>(latinime_releaseDicTraverseSession)}
56 };
57 
register_DicTraverseSession(JNIEnv * env)58 int register_DicTraverseSession(JNIEnv *env) {
59     const char *const kClassPathName = "com/android/inputmethod/latin/DicTraverseSession";
60     return registerNativeMethods(env, kClassPathName, sMethods,
61             sizeof(sMethods) / sizeof(sMethods[0]));
62 }
63 } // namespace latinime
64