Purge DicTraverseWrapper

bug: 8550444

Change-Id: Iad017e66ac579c6727b9f60ad9cda64e478200e5
This commit is contained in:
Satoshi Kataoka 2013-06-03 16:12:20 +09:00
parent 0e66ab7433
commit 7c92b421ee
9 changed files with 37 additions and 148 deletions

View file

@ -47,7 +47,6 @@ LATIN_IME_JNI_SRC_FILES := \
LATIN_IME_CORE_SRC_FILES := \
correction.cpp \
dic_traverse_wrapper.cpp \
unigram_dictionary.cpp \
words_priority_queue.cpp \
suggest/core/suggest.cpp \

View file

@ -137,7 +137,8 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return 0;
ProximityInfo *pInfo = reinterpret_cast<ProximityInfo *>(proximityInfo);
void *traverseSession = reinterpret_cast<void *>(dicTraverseSession);
DicTraverseSession *traverseSession =
reinterpret_cast<DicTraverseSession *>(dicTraverseSession);
// Input values
int xCoordinates[inputSize];

View file

@ -17,36 +17,37 @@
#define LOG_TAG "LatinIME: jni: Session"
#include "com_android_inputmethod_latin_DicTraverseSession.h"
#include "defines.h"
#include "dic_traverse_wrapper.h"
#include "jni.h"
#include "jni_common.h"
#include "suggest/core/session/dic_traverse_session.h"
namespace latinime {
class Dictionary;
static jlong latinime_setDicTraverseSession(JNIEnv *env, jclass clazz, jstring localeJStr) {
void *traverseSession = DicTraverseWrapper::getDicTraverseSession(env, localeJStr);
void *traverseSession = DicTraverseSession::getSessionInstance(env, localeJStr);
return reinterpret_cast<jlong>(traverseSession);
}
static void latinime_initDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession,
jlong dictionary, jintArray previousWord, jint previousWordLength) {
void *ts = reinterpret_cast<void *>(traverseSession);
DicTraverseSession *ts = reinterpret_cast<DicTraverseSession *>(traverseSession);
Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
if (!previousWord) {
DicTraverseWrapper::initDicTraverseSession(
DicTraverseSession::initSessionInstance(
ts, dict, 0 /* prevWord */, 0 /* prevWordLength*/, 0 /* suggestOptions */);
return;
}
int prevWord[previousWordLength];
env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
DicTraverseWrapper::initDicTraverseSession(
DicTraverseSession::initSessionInstance(
ts, dict, prevWord, previousWordLength, 0 /* suggestOptions */);
}
static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) {
void *ts = reinterpret_cast<void *>(traverseSession);
DicTraverseWrapper::releaseDicTraverseSession(ts);
DicTraverseSession *ts = reinterpret_cast<DicTraverseSession *>(traverseSession);
DicTraverseSession::releaseSessionInstance(ts);
}
static JNINativeMethod sMethods[] = {

View file

@ -1,26 +0,0 @@
/*
* Copyright (C) 2012, The Android Open Source Project
*
* 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.
*/
#define LOG_TAG "LatinIME: jni: Session"
#include "dic_traverse_wrapper.h"
namespace latinime {
void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring) = 0;
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
void *, const Dictionary *const, const int *, const int, const SuggestOptions *const) = 0;
} // namespace latinime

View file

@ -1,68 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.
*/
#ifndef LATINIME_DIC_TRAVERSE_WRAPPER_H
#define LATINIME_DIC_TRAVERSE_WRAPPER_H
#include "defines.h"
#include "jni.h"
namespace latinime {
class Dictionary;
class SuggestOptions;
// TODO: Remove
class DicTraverseWrapper {
public:
static void *getDicTraverseSession(JNIEnv *env, jstring locale) {
if (sDicTraverseSessionFactoryMethod) {
return sDicTraverseSessionFactoryMethod(env, locale);
}
return 0;
}
static void initDicTraverseSession(void *traverseSession, const Dictionary *const dictionary,
const int *prevWord, const int prevWordLength,
const SuggestOptions *const suggestOptions) {
if (sDicTraverseSessionInitMethod) {
sDicTraverseSessionInitMethod(
traverseSession, dictionary, prevWord, prevWordLength, suggestOptions);
}
}
static void releaseDicTraverseSession(void *traverseSession) {
if (sDicTraverseSessionReleaseMethod) {
sDicTraverseSessionReleaseMethod(traverseSession);
}
}
static void setTraverseSessionFactoryMethod(void *(*factoryMethod)(JNIEnv *, jstring)) {
sDicTraverseSessionFactoryMethod = factoryMethod;
}
static void setTraverseSessionInitMethod(
void (*initMethod)(void *, const Dictionary *const, const int *, const int,
const SuggestOptions *const)) {
sDicTraverseSessionInitMethod = initMethod;
}
static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) {
sDicTraverseSessionReleaseMethod = releaseMethod;
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring);
static void (*sDicTraverseSessionInitMethod)(
void *, const Dictionary *const, const int *, const int, const SuggestOptions *const);
static void (*sDicTraverseSessionReleaseMethod)(void *);
};
} // namespace latinime
#endif // LATINIME_DIC_TRAVERSE_WRAPPER_H

View file

@ -22,9 +22,9 @@
#include <stdint.h>
#include "defines.h"
#include "dic_traverse_wrapper.h"
#include "suggest/core/dictionary/bigram_dictionary.h"
#include "suggest/core/dictionary/binary_format.h"
#include "suggest/core/session/dic_traverse_session.h"
#include "suggest/core/suggest.h"
#include "suggest/core/suggest_options.h"
#include "suggest/policyimpl/gesture/gesture_suggest_policy_factory.h"
@ -50,14 +50,14 @@ Dictionary::~Dictionary() {
delete mTypingSuggest;
}
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession,
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
int *spaceIndices, int *outputTypes) const {
int result = 0;
if (suggestOptions->isGesture()) {
DicTraverseWrapper::initDicTraverseSession(
DicTraverseSession::initSessionInstance(
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
@ -68,7 +68,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi
return result;
} else {
if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
DicTraverseWrapper::initDicTraverseSession(
DicTraverseSession::initSessionInstance(
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,

View file

@ -25,6 +25,7 @@
namespace latinime {
class BigramDictionary;
class DicTraverseSession;
class ProximityInfo;
class SuggestInterface;
class SuggestOptions;
@ -54,9 +55,9 @@ class Dictionary {
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust);
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
int *prevWordCodePoints, int prevWordLength, int commitPoint,
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
int *spaceIndices, int *outputTypes) const;

View file

@ -17,7 +17,6 @@
#include "suggest/core/session/dic_traverse_session.h"
#include "defines.h"
#include "dic_traverse_wrapper.h"
#include "jni.h"
#include "suggest/core/dicnode/dic_node_utils.h"
#include "suggest/core/dictionary/binary_dictionary_info.h"
@ -26,43 +25,6 @@
namespace latinime {
const int DicTraverseSession::CACHE_START_INPUT_LENGTH_THRESHOLD = 20;
// A factory method for DicTraverseSession
static void *getSessionInstance(JNIEnv *env, jstring localeStr) {
return new DicTraverseSession(env, localeStr);
}
// TODO: Pass "DicTraverseSession *traverseSession" when the source code structure settles down.
static void initSessionInstance(void *traverseSession, const Dictionary *const dictionary,
const int *prevWord, const int prevWordLength,
const SuggestOptions *const suggestOptions) {
if (traverseSession) {
DicTraverseSession *tSession = static_cast<DicTraverseSession *>(traverseSession);
tSession->init(dictionary, prevWord, prevWordLength, suggestOptions);
}
}
// TODO: Pass "DicTraverseSession *traverseSession" when the source code structure settles down.
static void releaseSessionInstance(void *traverseSession) {
delete static_cast<DicTraverseSession *>(traverseSession);
}
// An ad-hoc internal class to register the factory method defined above
class TraverseSessionFactoryRegisterer {
public:
TraverseSessionFactoryRegisterer() {
DicTraverseWrapper::setTraverseSessionFactoryMethod(getSessionInstance);
DicTraverseWrapper::setTraverseSessionInitMethod(initSessionInstance);
DicTraverseWrapper::setTraverseSessionReleaseMethod(releaseSessionInstance);
}
private:
DISALLOW_COPY_AND_ASSIGN(TraverseSessionFactoryRegisterer);
};
// To invoke the TraverseSessionFactoryRegisterer constructor in the global constructor.
static TraverseSessionFactoryRegisterer traverseSessionFactoryRegisterer;
void DicTraverseSession::init(const Dictionary *const dictionary, const int *prevWord,
int prevWordLength, const SuggestOptions *const suggestOptions) {
mDictionary = dictionary;

View file

@ -35,6 +35,25 @@ class SuggestOptions;
class DicTraverseSession {
public:
// A factory method for DicTraverseSession
static AK_FORCE_INLINE void *getSessionInstance(JNIEnv *env, jstring localeStr) {
return new DicTraverseSession(env, localeStr);
}
static AK_FORCE_INLINE void initSessionInstance(DicTraverseSession *traverseSession,
const Dictionary *const dictionary, const int *prevWord, const int prevWordLength,
const SuggestOptions *const suggestOptions) {
if (traverseSession) {
DicTraverseSession *tSession = static_cast<DicTraverseSession *>(traverseSession);
tSession->init(dictionary, prevWord, prevWordLength, suggestOptions);
}
}
static AK_FORCE_INLINE void releaseSessionInstance(DicTraverseSession *traverseSession) {
delete traverseSession;
}
AK_FORCE_INLINE DicTraverseSession(JNIEnv *env, jstring localeStr)
: mPrevWordPos(NOT_VALID_WORD), mProximityInfo(0),
mDictionary(0), mSuggestOptions(0), mDicNodesCache(), mMultiBigramMap(),