report counts/values using language rather than dictionary name. To

support that, pass lang name from java into jni.
This commit is contained in:
Andy2 2011-04-11 18:55:42 -07:00
parent 40116d792f
commit 002bb40a09
12 changed files with 79 additions and 39 deletions

View file

@ -388,9 +388,8 @@ and_dictionary_destroy( DictionaryCtxt* dict )
XP_FREE( ctxt->super.mpool, ctxt->super.faces );
XP_FREE( ctxt->super.mpool, ctxt->super.facePtrs );
XP_FREE( ctxt->super.mpool, ctxt->super.countsAndValues );
if ( NULL != ctxt->super.name ) {
XP_FREE( ctxt->super.mpool, ctxt->super.name );
}
XP_FREEP( ctxt->super.mpool, &ctxt->super.name );
XP_FREEP( ctxt->super.mpool, &ctxt->super.langName );
(*env)->ReleaseByteArrayElements( env, ctxt->byteArray, ctxt->bytes, 0 );
(*env)->DeleteGlobalRef( env, ctxt->byteArray );
@ -424,7 +423,7 @@ and_dictionary_make_empty( MPFORMAL JNIEnv* env, JNIUtilCtxt* jniutil )
void
makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
jobjectArray jdicts, jobjectArray jnames )
jobjectArray jdicts, jobjectArray jnames, jstring jlang )
{
LOG_FUNC();
int ii;
@ -436,7 +435,7 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
if ( ii < len ) {
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname );
dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang );
XP_ASSERT( !!dict );
(*env)->DeleteLocalRef( env, jdict );
(*env)->DeleteLocalRef( env, jname );
@ -448,7 +447,7 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
DictionaryCtxt*
makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
jstring jname )
jstring jname, jstring jlangname )
{
AndDictionaryCtxt* anddict = (AndDictionaryCtxt*)
and_dictionary_make_empty( MPPARM(mpool) env, jniutil );
@ -463,13 +462,8 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
parseDict( anddict, (XP_U8*)anddict->bytes, len );
/* copy the name */
if ( NULL != jname ) {
len = 1 + (*env)->GetStringUTFLength( env, jname );
const char* chars = (*env)->GetStringUTFChars( env, jname, NULL );
anddict->super.name = XP_MALLOC( mpool, len );
XP_MEMCPY( anddict->super.name, chars, len );
(*env)->ReleaseStringUTFChars( env, jname, chars );
}
anddict->super.name = getStringCopy( MPPARM(mpool) env, jname );
anddict->super.langName = getStringCopy( MPPARM(mpool) env, jlangname );
return (DictionaryCtxt*)anddict;
}

View file

@ -1,3 +1,4 @@
/* -*-mode: C; compile-command: "../../scripts/ndkbuild.sh"; -*- */
/*
* Copyright © 2009-2010 by Eric House (xwords@eehouse.org). All
* rights reserved.
@ -29,10 +30,10 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes,
XP_U16 nBytes, XP_U16 nFaces );
DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
jbyteArray bytes, jstring jname );
jbyteArray bytes, jstring jname, jstring jlang );
void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts,
jobjectArray jdicts, jobjectArray jnames );
jobjectArray jdicts, jobjectArray jnames, jstring jlang );
void destroyDicts( PlayerDicts* dicts );

View file

@ -151,6 +151,20 @@ getString( JNIEnv* env, jobject obj, const char* name, XP_UCHAR* buf,
(*env)->DeleteLocalRef( env, cls );
}
XP_UCHAR*
getStringCopy( MPFORMAL JNIEnv* env, jstring jstr )
{
XP_UCHAR* result = NULL;
if ( NULL != jstr ) {
jsize len = 1 + (*env)->GetStringUTFLength( env, jstr );
const char* chars = (*env)->GetStringUTFChars( env, jstr, NULL );
result = XP_MALLOC( mpool, len );
XP_MEMCPY( result, chars, len );
(*env)->ReleaseStringUTFChars( env, jstr, chars );
}
return result;
}
bool
getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
jobject* ret )

View file

@ -40,6 +40,7 @@ bool setBool( JNIEnv* env, jobject obj, const char* name, bool value );
bool setString( JNIEnv* env, jobject obj, const char* name, const XP_UCHAR* value );
void getString( JNIEnv* env, jobject jlp, const char* name, XP_UCHAR* buf,
int bufLen );
XP_UCHAR* getStringCopy( MPFORMAL JNIEnv* env, jstring jname );
void setObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
jobject val );
bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,

View file

@ -270,7 +270,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
#endif
JNIUtilCtxt* jniutil = makeJNIUtil( MPPARM(mpool) &env, jniu );
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil,
jDictBytes, NULL );
jDictBytes, NULL, NULL );
jint code = dict_getLangCode( dict );
jint nWords = dict_getWordCount( dict );
dict_destroy( dict );
@ -380,7 +380,7 @@ JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
( JNIEnv* env, jclass C, jint gamePtr, jobject j_gi, jobject j_util,
jobject jniu, jobject j_draw, jobject j_cp, jobject j_procs,
jobjectArray j_dicts, jobjectArray j_names )
jobjectArray j_dicts, jobjectArray j_names, jstring j_lang )
{
XWJNI_START_GLOBALS();
CurGameInfo* gi = makeGI( MPPARM(mpool) env, j_gi );
@ -399,7 +399,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
globals->xportProcs );
PlayerDicts dicts;
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, j_dicts, j_names );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, j_dicts, j_names,
j_lang );
#ifdef STUBBED_DICT
if ( !dict ) {
XP_LOGF( "falling back to stubbed dict" );
@ -439,8 +440,8 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
( JNIEnv* env, jclass C, jint gamePtr, jbyteArray jstream, jobject /*out*/jgi,
jobjectArray jdicts, jobjectArray jdictNames, jobject jutil, jobject jniu,
jobject jdraw, jobject jcp, jobject jprocs )
jobjectArray jdicts, jobjectArray jdictNames, jstring jlang,
jobject jutil, jobject jniu, jobject jdraw, jobject jcp, jobject jprocs )
{
jboolean result;
PlayerDicts dicts;
@ -450,7 +451,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
globals->util = makeUtil( MPPARM(mpool) &state->env,
jutil, globals->gi, globals );
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, jdicts, jdictNames );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, jdicts, jdictNames,
jlang );
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );

View file

@ -997,6 +997,7 @@ public class BoardActivity extends XWActivity
Utils.logf( "loadGame: dict name: %s", m_gi.dictName );
String[] dictNames = m_gi.dictNames();
byte[][] dictBytes = GameUtils.openDicts( this, dictNames );
String langName = m_gi.langName();
m_jniGamePtr = XwJNI.initJNI();
if ( m_gi.serverRole != DeviceRole.SERVER_STANDALONE ) {
@ -1008,11 +1009,11 @@ public class BoardActivity extends XWActivity
if ( null == stream ||
! XwJNI.game_makeFromStream( m_jniGamePtr, stream,
m_gi, dictBytes, dictNames,
m_utils, m_jniu,
langName, m_utils, m_jniu,
m_view, cp, m_xport ) ) {
XwJNI.game_makeNewGame( m_jniGamePtr, m_gi, m_utils, m_jniu,
m_view, cp, m_xport,
dictBytes, dictNames );
dictBytes, dictNames, langName );
}
m_jniThread = new

View file

@ -191,7 +191,8 @@ public class GameUtils {
gamePtr = XwJNI.initJNI();
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
CommonPrefs.get( context ), dictBytes,
dictNames );
dictNames, gi.langName() );
if ( null != addr ) {
XwJNI.comms_setAddr( gamePtr, addr );
}
@ -288,16 +289,17 @@ public class GameUtils {
XwJNI.gi_from_stream( gi, stream );
String[] dictNames = gi.dictNames();
byte[][] dictBytes = openDicts( context, dictNames );
String langName = gi.langName();
boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
JNIUtilsImpl.get(), gi,
dictBytes, dictNames,
util,
langName, util,
CommonPrefs.get(context));
if ( !madeGame ) {
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
CommonPrefs.get(context), dictBytes,
dictNames );
dictNames, langName );
}
}
@ -666,6 +668,7 @@ public class GameUtils {
// games?
String[] dictNames = gi.dictNames();
byte[][] dictBytes = openDicts( context, dictNames );
String langName = gi.langName();
int gamePtr = XwJNI.initJNI();
boolean madeGame = false;
CommonPrefs cp = CommonPrefs.get( context );
@ -678,13 +681,14 @@ public class GameUtils {
madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
JNIUtilsImpl.get(),
new CurGameInfo(context),
dictBytes, dictNames, cp );
dictBytes, dictNames,
langName, cp );
}
if ( forceNew || !madeGame ) {
gi.setInProgress( false );
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
cp, dictBytes, dictNames );
cp, dictBytes, dictNames, langName );
}
if ( null != car ) {

View file

@ -246,6 +246,11 @@ public class CurGameInfo {
return result;
}
public String langName()
{
return DictLangCache.getLangName( m_context, dictLang );
}
public boolean addPlayer()
{
boolean added = nPlayers < MAX_NUM_PLAYERS;

View file

@ -59,13 +59,16 @@ public class XwJNI {
JNIUtils jniu,
DrawCtx draw, CommonPrefs cp,
TransportProcs procs,
byte[][] dicts, String[] dictNames );
byte[][] dicts,
String[] dictNames,
String langName );
public static native boolean game_makeFromStream( int gamePtr,
byte[] stream,
CurGameInfo gi,
byte[][] dicts,
String[] dictNames,
String langName,
UtilCtxt util,
JNIUtils jniu,
DrawCtx draw,
@ -76,32 +79,37 @@ public class XwJNI {
// played
public static void game_makeNewGame( int gamePtr, CurGameInfo gi,
JNIUtils jniu, CommonPrefs cp,
byte[][] dicts, String[] dictNames ) {
byte[][] dicts, String[] dictNames,
String langName ) {
game_makeNewGame( gamePtr, gi, (UtilCtxt)null, jniu,
(DrawCtx)null, cp, (TransportProcs)null,
dicts, dictNames );
dicts, dictNames, langName );
}
public static boolean game_makeFromStream( int gamePtr,
byte[] stream,
JNIUtils jniu,
CurGameInfo gi,
byte[][] dicts, String[] dictNames,
byte[][] dicts,
String[] dictNames,
String langName,
CommonPrefs cp ) {
return game_makeFromStream( gamePtr, stream, gi, dicts, dictNames,
(UtilCtxt)null, jniu, (DrawCtx)null, cp,
(TransportProcs)null );
langName, (UtilCtxt)null, jniu,
(DrawCtx)null, cp, (TransportProcs)null );
}
public static boolean game_makeFromStream( int gamePtr,
byte[] stream,
JNIUtils jniu,
CurGameInfo gi,
byte[][] dicts, String[] dictNames,
byte[][] dicts,
String[] dictNames,
String langName,
UtilCtxt util,
CommonPrefs cp ) {
return game_makeFromStream( gamePtr, stream, gi, dicts, dictNames,
util, jniu, (DrawCtx)null, cp,
langName, util, jniu, (DrawCtx)null, cp,
(TransportProcs)null );
}

View file

@ -489,6 +489,7 @@ destroy_stubbed_dict( DictionaryCtxt* dict )
XP_FREE( dict->mpool, dict->faces );
XP_FREE( dict->mpool, dict->chars );
XP_FREE( dict->mpool, dict->name );
XP_FREE( dict->mpool, dict->langName );
XP_FREE( dict->mpool, dict->bitmaps );
XP_FREE( dict->mpool, dict );
} /* destroy_stubbed_dict */
@ -580,6 +581,12 @@ dict_super_init( DictionaryCtxt* dict )
dict->func_dict_getShortName = dict_getName;
} /* dict_super_init */
const XP_UCHAR*
dict_getLangName( const DictionaryCtxt* ctxt )
{
return ctxt->langName;
}
#ifdef CPLUS
}
#endif

View file

@ -74,6 +74,7 @@ struct DictionaryCtxt {
array_edge* base; /* the physical beginning of the dictionary; not
necessarily the entry point for search!! */
XP_UCHAR* name;
XP_UCHAR* langName;
XP_UCHAR* faces;
const XP_UCHAR** facePtrs;
XP_U8* countsAndValues;
@ -143,6 +144,8 @@ XP_U16 dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles,
XP_U16 nTiles, XP_UCHAR* buf, XP_U16 bufSize );
const XP_UCHAR* dict_getTileString( const DictionaryCtxt* ctxt, Tile tile );
const XP_UCHAR* dict_getName( const DictionaryCtxt* ctxt );
const XP_UCHAR* dict_getLangName(const DictionaryCtxt* ctxt );
XP_Bool dict_isUTF8( const DictionaryCtxt* ctxt );
Tile dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key );

View file

@ -2495,13 +2495,13 @@ server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
XP_UCHAR buf[48];
const XP_UCHAR* fmt = util_getUserString( server->vol.util,
STRS_VALUES_HEADER );
const XP_UCHAR* dname;
const XP_UCHAR* langName;
XP_ASSERT( !!server->vol.model );
dict = model_getDictionary( server->vol.model );
dname = dict_getShortName( dict );
XP_SNPRINTF( buf, sizeof(buf), fmt, dname );
langName = dict_getLangName( dict );
XP_SNPRINTF( buf, sizeof(buf), fmt, langName );
stream_catString( stream, buf );
nChars = dict_numTileFaces( dict );