am 73fc766e: am 9d298716: Add reset method for dic travserse session

* commit '73fc766e8c03a84cad5a049d7c9a93a476097277':
  Add reset method for dic travserse session
main
Satoshi Kataoka 2012-08-09 02:21:10 -07:00 committed by Android Git Automerger
commit b481b045f3
3 changed files with 30 additions and 5 deletions

View File

@ -22,20 +22,30 @@ public class DicTraverseSession {
static { static {
JniUtils.loadNativeLibrary(); JniUtils.loadNativeLibrary();
} }
private native long setDicTraverseSessionNative(String locale);
private native void initDicTraverseSessionNative(
long nativeDicTraverseSession, int[] previousWord, int previwousWordLength);
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
private long mNativeDicTraverseSession; private long mNativeDicTraverseSession;
public DicTraverseSession(Locale locale) { public DicTraverseSession(Locale locale) {
mNativeDicTraverseSession = createNativeDicTraverseSession( mNativeDicTraverseSession = createNativeDicTraverseSession(
locale != null ? locale.toString() : ""); locale != null ? locale.toString() : "");
initSession();
} }
public long getSession() { public long getSession() {
return mNativeDicTraverseSession; return mNativeDicTraverseSession;
} }
private native long setDicTraverseSessionNative(String locale); public void initSession() {
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession); initSession(null, 0);
}
public void initSession(int[] previousWord, int previousWordLength) {
initDicTraverseSessionNative(mNativeDicTraverseSession, previousWord, previousWordLength);
}
private final long createNativeDicTraverseSession(String locale) { private final long createNativeDicTraverseSession(String locale) {
return setDicTraverseSessionNative(locale); return setDicTraverseSessionNative(locale);

View File

@ -23,6 +23,8 @@
namespace latinime { namespace latinime {
void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)() = 0; void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)() = 0;
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0; void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
JNIEnv *, void *, const jintArray, const jint) = 0;
static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object, static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
jstring localejStr) { jstring localejStr) {
@ -30,15 +32,21 @@ static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
return reinterpret_cast<jlong>(traverseSession); return reinterpret_cast<jlong>(traverseSession);
} }
static void latinime_initDicTraverseSession(JNIEnv *env, jlong traverseSession,
jintArray previousWord, jint previousWordLength) {
void *ts = reinterpret_cast<void*>(traverseSession);
DicTraverseWrapper::initDicTraverseSession(env, ts, previousWord, previousWordLength);
}
static void latinime_DicTraverseSession_release( static void latinime_DicTraverseSession_release(
JNIEnv *env, jobject object, jlong traverseSession) { JNIEnv *env, jobject object, jlong traverseSession) {
void *pi = reinterpret_cast<void*>(traverseSession); void *ts = reinterpret_cast<void*>(traverseSession);
if (!pi) return; DicTraverseWrapper::releaseDicTraverseSession(ts);
DicTraverseWrapper::releaseDicTraverseSession(pi);
} }
static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = {
{"setDicTraverseSessionNative", "(Ljava/lang/String;)J", (void*)latinime_setDicTraverseSession}, {"setDicTraverseSessionNative", "(Ljava/lang/String;)J", (void*)latinime_setDicTraverseSession},
{"initDicTraverseSessionNative", "(J[II)V", (void*)latinime_initDicTraverseSession},
{"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_DicTraverseSession_release} {"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_DicTraverseSession_release}
}; };

View File

@ -31,6 +31,12 @@ class DicTraverseWrapper {
} }
return 0; return 0;
} }
static void initDicTraverseSession(JNIEnv *env, void *traverseSession,
const jintArray prevWord, const jint prevWordLength) {
if (sDicTraverseSessionInitMethod) {
sDicTraverseSessionInitMethod(env, traverseSession, prevWord, prevWordLength);
}
}
static void releaseDicTraverseSession(void *traverseSession) { static void releaseDicTraverseSession(void *traverseSession) {
if (sDicTraverseSessionReleaseMethod) { if (sDicTraverseSessionReleaseMethod) {
sDicTraverseSessionReleaseMethod(traverseSession); sDicTraverseSessionReleaseMethod(traverseSession);
@ -39,6 +45,7 @@ class DicTraverseWrapper {
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper); DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
static void *(*sDicTraverseSessionFactoryMethod)(); static void *(*sDicTraverseSessionFactoryMethod)();
static void (*sDicTraverseSessionInitMethod)(JNIEnv *, void *, const jintArray, const jint);
static void (*sDicTraverseSessionReleaseMethod)(void *); static void (*sDicTraverseSessionReleaseMethod)(void *);
}; };
int register_DicTraverseSession(JNIEnv *env); int register_DicTraverseSession(JNIEnv *env);