make android compile/run with wasm changes

This commit is contained in:
Eric House 2021-03-07 08:28:17 -08:00
parent 34aee3d7d0
commit 970c2f6f9a
7 changed files with 100 additions and 32 deletions

View file

@ -31,6 +31,7 @@ import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.Channels; import org.eehouse.android.xw4.Channels;
import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.DBUtils;
import org.eehouse.android.xw4.DevID; import org.eehouse.android.xw4.DevID;
import org.eehouse.android.xw4.DictUtils;
import org.eehouse.android.xw4.DupeModeTimer; import org.eehouse.android.xw4.DupeModeTimer;
import org.eehouse.android.xw4.FBMService; import org.eehouse.android.xw4.FBMService;
import org.eehouse.android.xw4.GameUtils; import org.eehouse.android.xw4.GameUtils;
@ -259,16 +260,16 @@ public class DUtilCtxt {
if ( null != data ) { if ( null != data ) {
DBUtils.setBytesFor( m_context, key, data ); DBUtils.setBytesFor( m_context, key, data );
if ( BuildConfig.DEBUG ) { if ( BuildConfig.DEBUG ) {
byte[] tmp = load( key, null ); byte[] tmp = load( key );
Assert.assertTrue( Arrays.equals( tmp, data ) ); Assert.assertTrue( Arrays.equals( tmp, data ) );
} }
} }
} }
public byte[] load( String key, String keySuffix ) public byte[] load( String key )
{ {
// Log.d( TAG, "load(%s, %s)", key, keySuffix ); // Log.d( TAG, "load(%s, %s)", key, keySuffix );
byte[] result = DBUtils.getBytesFor( m_context, key, keySuffix ); byte[] result = DBUtils.getBytesFor( m_context, key );
// Log.d( TAG, "load(%s, %s) returning %d bytes", key, keySuffix, // Log.d( TAG, "load(%s, %s) returning %d bytes", key, keySuffix,
// null == result ? 0 : result.length ); // null == result ? 0 : result.length );
@ -336,6 +337,17 @@ public class DUtilCtxt {
return msg; return msg;
} }
public String getDictPath( int lang, String name )
{
Log.d( TAG, "getDictPath(%d, %s)", lang, name );
String[] names = { name };
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
String path = pairs.m_paths[0];
Assert.assertNotNull( path );
Log.d( TAG, "getDictPath(%s) => %s", name, path );
return path;
}
public void onDupTimerChanged( int gameID, int oldVal, int newVal ) public void onDupTimerChanged( int gameID, int oldVal, int newVal )
{ {
DupeModeTimer.timerChanged( m_context, gameID, newVal ); DupeModeTimer.timerChanged( m_context, gameID, newVal );

View file

@ -36,6 +36,7 @@ typedef struct _AndDUtil {
XW_DUtilCtxt dutil; XW_DUtilCtxt dutil;
JNIUtilCtxt* jniutil; JNIUtilCtxt* jniutil;
jobject jdutil; /* global ref to object implementing XW_DUtilCtxt */ jobject jdutil; /* global ref to object implementing XW_DUtilCtxt */
DictMgrCtxt* dictMgr;
XP_UCHAR* userStrings[N_AND_USER_STRINGS]; XP_UCHAR* userStrings[N_AND_USER_STRINGS];
XP_U32 userStringsBits; XP_U32 userStringsBits;
#ifdef MAP_THREAD_TO_ENV #ifdef MAP_THREAD_TO_ENV
@ -479,13 +480,14 @@ and_dutil_getUserQuantityString( XW_DUtilCtxt* duc, XWEnv xwe,
} }
static void static void
and_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key, and_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* keys[],
const void* data, XP_U16 len ) const void* data, XP_U32 len )
{ {
DUTIL_CBK_HEADER( "store", "(Ljava/lang/String;[B)V" ); DUTIL_CBK_HEADER( "store", "(Ljava/lang/String;[B)V" );
XP_ASSERT( NULL == keys[1] );
jbyteArray jdata = makeByteArray( env, len, data ); jbyteArray jdata = makeByteArray( env, len, data );
jstring jkey = (*env)->NewStringUTF( env, key ); jstring jkey = (*env)->NewStringUTF( env, keys[0] );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jkey, jdata ); (*env)->CallVoidMethod( env, dutil->jdutil, mid, jkey, jdata );
@ -495,26 +497,25 @@ and_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key,
} }
static jbyteArray static jbyteArray
loadToByteArray( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key, loadToByteArray( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key )
const XP_UCHAR* keySuffix )
{ {
jbyteArray result = NULL; jbyteArray result = NULL;
DUTIL_CBK_HEADER( "load", "(Ljava/lang/String;Ljava/lang/String;)[B"); DUTIL_CBK_HEADER( "load", "(Ljava/lang/String;)[B");
jstring jkey = (*env)->NewStringUTF( env, key ); jstring jkey = (*env)->NewStringUTF( env, key );
jstring jkeySuffix = (*env)->NewStringUTF( env, keySuffix ); result = (*env)->CallObjectMethod( env, dutil->jdutil, mid, jkey );
result = (*env)->CallObjectMethod( env, dutil->jdutil, mid, jkey, jkeySuffix ); deleteLocalRef( env, jkey );
deleteLocalRefs( env, jkey, jkeySuffix, DELETE_NO_REF );
DUTIL_CBK_TAIL(); DUTIL_CBK_TAIL();
return result; return result;
} }
static void static void
and_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key, and_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* keys[],
const XP_UCHAR* keySuffix, void* data, XP_U16* lenp ) void* data, XP_U32* lenp )
{ {
XP_ASSERT( NULL == keys[1] );
JNIEnv* env = xwe; JNIEnv* env = xwe;
jbyteArray jvalue = loadToByteArray( duc, env, key, keySuffix ); jbyteArray jvalue = loadToByteArray( duc, env, keys[0] );
jsize len = 0; jsize len = 0;
if ( jvalue != NULL ) { if ( jvalue != NULL ) {
len = (*env)->GetArrayLength( env, jvalue ); len = (*env)->GetArrayLength( env, jvalue );
@ -528,6 +529,21 @@ and_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key,
*lenp = len; *lenp = len;
} }
#ifdef XWFEATURE_DEVICE
static void
and_dutil_forEach( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* keys[],
OnOneProc proc, void* closure )
{
XP_ASSERT(0);
}
static void
and_dutil_remove( XW_DUtilCtxt* duc, const XP_UCHAR* keys[] )
{
XP_ASSERT(0);
}
#endif
static void static void
and_util_notifyIllegalWords( XW_UtilCtxt* uc, XWEnv xwe, BadWordInfo* bwi, and_util_notifyIllegalWords( XW_UtilCtxt* uc, XWEnv xwe, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost ) XP_U16 turn, XP_Bool turnLost )
@ -780,7 +796,7 @@ and_util_getDevUtilCtxt( XW_UtilCtxt* uc, XWEnv xwe )
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
static XP_UCHAR* static XP_UCHAR*
and_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr, XP_U16 len ) and_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr, XP_U32 len )
{ {
AndDUtil* dutil = (AndDUtil*)duc; AndDUtil* dutil = (AndDUtil*)duc;
JNIEnv* env = xwe; JNIEnv* env = xwe;
@ -792,6 +808,35 @@ and_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr, XP_U16 len )
} }
#endif #endif
const DictionaryCtxt*
and_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
XP_LangCode lang, const XP_UCHAR* dictName )
{
XP_LOGFF( "(lang: %d, name: %s)", lang, dictName );
JNIEnv* env = xwe;
AndDUtil* dutil = (AndDUtil*)duc;
JNIUtilCtxt* jniutil = dutil->jniutil;
DictMgrCtxt* dictMgr = dutil->dictMgr;
DictionaryCtxt* dict = (DictionaryCtxt*)
dmgr_get( dictMgr, xwe, dictName );
if ( !dict ) {
jstring jname = (*env)->NewStringUTF( env, dictName );
jstring jpath = NULL;
DUTIL_CBK_HEADER( "getDictPath", "(ILjava/lang/String;)Ljava/lang/String;" );
jpath = (*env)->CallObjectMethod( env, dutil->jdutil, mid, lang, jname );
DUTIL_CBK_TAIL();
dict = makeDict( MPPARM(duc->mpool) xwe,
TI_IF(&globalState->ti)
dictMgr, jniutil,
jname, NULL, jpath, NULL, false );
deleteLocalRefs( env, jname, jpath, DELETE_NO_REF );
}
LOG_RETURNF( "%p", dict );
return dict;
}
static void static void
and_dutil_notifyPause( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID, DupPauseType pauseTyp, and_dutil_notifyPause( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID, DupPauseType pauseTyp,
XP_U16 pauser, const XP_UCHAR* name, XP_U16 pauser, const XP_UCHAR* name,
@ -977,7 +1022,8 @@ makeDUtil( MPFORMAL JNIEnv* env,
EnvThreadInfo* ti, EnvThreadInfo* ti,
#endif #endif
jobject jdutil, VTableMgr* vtMgr, jobject jdutil, VTableMgr* vtMgr,
JNIUtilCtxt* jniutil, void* closure ) DictMgrCtxt* dmgr, JNIUtilCtxt* jniutil,
void* closure )
{ {
AndDUtil* dutil = (AndDUtil*)XP_CALLOC( mpool, sizeof(*dutil) ); AndDUtil* dutil = (AndDUtil*)XP_CALLOC( mpool, sizeof(*dutil) );
dutil_super_init( MPPARM(mpool) &dutil->dutil ); dutil_super_init( MPPARM(mpool) &dutil->dutil );
@ -987,6 +1033,7 @@ makeDUtil( MPFORMAL JNIEnv* env,
dutil->jniutil = jniutil; dutil->jniutil = jniutil;
dutil->dutil.closure = closure; dutil->dutil.closure = closure;
dutil->dutil.vtMgr = vtMgr; dutil->dutil.vtMgr = vtMgr;
dutil->dictMgr = dmgr;
if ( NULL != jdutil ) { if ( NULL != jdutil ) {
dutil->jdutil = (*env)->NewGlobalRef( env, jdutil ); dutil->jdutil = (*env)->NewGlobalRef( env, jdutil );
@ -999,6 +1046,11 @@ makeDUtil( MPFORMAL JNIEnv* env,
SET_DPROC(getUserQuantityString); SET_DPROC(getUserQuantityString);
SET_DPROC(storePtr); SET_DPROC(storePtr);
SET_DPROC(loadPtr); SET_DPROC(loadPtr);
# ifdef XWFEATURE_DEVICE
SET_DPROC(forEach);
SET_DPROC(remove);
# endif
# ifdef XWFEATURE_DEVID # ifdef XWFEATURE_DEVID
SET_DPROC(getDevID); SET_DPROC(getDevID);
SET_DPROC(deviceRegistered); SET_DPROC(deviceRegistered);
@ -1009,6 +1061,7 @@ makeDUtil( MPFORMAL JNIEnv* env,
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
SET_DPROC(md5sum); SET_DPROC(md5sum);
#endif #endif
SET_DPROC(getDict);
SET_DPROC(notifyPause); SET_DPROC(notifyPause);
SET_DPROC(onDupTimerChanged); SET_DPROC(onDupTimerChanged);

View file

@ -26,6 +26,7 @@
#include "game.h" #include "game.h"
#include "util.h" #include "util.h"
#include "dutil.h" #include "dutil.h"
#include "dictmgr.h"
#include "andglobals.h" #include "andglobals.h"
#include "jniutlswrapper.h" #include "jniutlswrapper.h"
@ -34,7 +35,8 @@ XW_DUtilCtxt* makeDUtil( MPFORMAL JNIEnv* env,
EnvThreadInfo* ti, EnvThreadInfo* ti,
#endif #endif
jobject j_dutil, VTableMgr* vtMgr, jobject j_dutil, VTableMgr* vtMgr,
JNIUtilCtxt* jniutil, void* closure ); DictMgrCtxt* dmgr, JNIUtilCtxt* jniutil,
void* closure );
void destroyDUtil( XW_DUtilCtxt** dutilp, JNIEnv* env ); void destroyDUtil( XW_DUtilCtxt** dutilp, JNIEnv* env );
XW_UtilCtxt* makeUtil( MPFORMAL JNIEnv* env, XW_UtilCtxt* makeUtil( MPFORMAL JNIEnv* env,

View file

@ -383,10 +383,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_globalsInit
map_init( MPPARM(mpool) &globalState->ti, env ); map_init( MPPARM(mpool) &globalState->ti, env );
globalState->jniutil = makeJNIUtil( MPPARM(mpool) env, TI_IF(&globalState->ti) jniu ); globalState->jniutil = makeJNIUtil( MPPARM(mpool) env, TI_IF(&globalState->ti) jniu );
globalState->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) ); globalState->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
globalState->dutil = makeDUtil( MPPARM(mpool) env, TI_IF(&globalState->ti)
jdutil, globalState->vtMgr,
globalState->jniutil, NULL );
globalState->dictMgr = dmgr_make( MPPARM_NOCOMMA( mpool ) ); globalState->dictMgr = dmgr_make( MPPARM_NOCOMMA( mpool ) );
globalState->dutil = makeDUtil( MPPARM(mpool) env, TI_IF(&globalState->ti)
jdutil, globalState->vtMgr, globalState->dictMgr,
globalState->jniutil, NULL );
globalState->smsProto = smsproto_init( MPPARM( mpool ) env, globalState->dutil ); globalState->smsProto = smsproto_init( MPPARM( mpool ) env, globalState->dutil );
MPASSIGN( globalState->mpool, mpool ); MPASSIGN( globalState->mpool, mpool );
setGlobalState( globalState ); setGlobalState( globalState );
@ -891,7 +891,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_gi_1from_1stream
CurGameInfo gi = {0}; CurGameInfo gi = {0};
// XP_MEMSET( &gi, 0, sizeof(gi) ); // XP_MEMSET( &gi, 0, sizeof(gi) );
if ( game_makeFromStream( MPPARM(mpool) env, stream, NULL, if ( game_makeFromStream( MPPARM(mpool) env, stream, NULL,
&gi, NULL, NULL, NULL, NULL, NULL, NULL ) ) { &gi, NULL, NULL, NULL, NULL ) ) {
setJGI( env, jgi, &gi ); setJGI( env, jgi, &gi );
} else { } else {
XP_LOGFF( "game_makeFromStream failed" ); XP_LOGFF( "game_makeFromStream failed" );
@ -1470,9 +1470,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
CommonPrefs cp; CommonPrefs cp;
loadCommonPrefs( env, &cp, jcp ); loadCommonPrefs( env, &cp, jcp );
result = game_makeFromStream( MPPARM(mpool) env, stream, &state->game, result = game_makeFromStream( MPPARM(mpool) env, stream, &state->game,
globals->gi, dict, &dicts, globals->gi, globals->util, globals->dctx,
globals->util, globals->dctx, &cp, &cp, globals->xportProcs );
globals->xportProcs );
stream_destroy( stream, env ); stream_destroy( stream, env );
dict_unref( dict, env ); /* game owns it now */ dict_unref( dict, env ); /* game owns it now */
dict_unref_all( &dicts, env ); dict_unref_all( &dicts, env );

View file

@ -43,6 +43,7 @@ javah -o /tmp/javah$$.txt org.eehouse.android.${NODE}.jni.XwJNI
javap -s org.eehouse.android.${NODE}.jni.XwJNI javap -s org.eehouse.android.${NODE}.jni.XwJNI
javap -s org.eehouse.android.${NODE}.jni.DrawCtx javap -s org.eehouse.android.${NODE}.jni.DrawCtx
javap -s org.eehouse.android.${NODE}.jni.UtilCtxt javap -s org.eehouse.android.${NODE}.jni.UtilCtxt
javap -s org.eehouse.android.${NODE}.jni.DUtilCtxt
javap -s org.eehouse.android.${NODE}.jni.CommsAddrRec javap -s org.eehouse.android.${NODE}.jni.CommsAddrRec
javap -s org.eehouse.android.${NODE}.jni.CommsAddrRec\$CommsConnTypeSet javap -s org.eehouse.android.${NODE}.jni.CommsAddrRec\$CommsConnTypeSet
javap -s org.eehouse.android.${NODE}.jni.TransportProcs javap -s org.eehouse.android.${NODE}.jni.TransportProcs

View file

@ -57,15 +57,16 @@ typedef struct _DUtilVtable {
XWStreamCtxt* inOut ); XWStreamCtxt* inOut );
void (*m_dutil_storePtr)( XW_DUtilCtxt* duc, XWEnv xwe, void (*m_dutil_storePtr)( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* keys[], const XP_UCHAR* keys[],
void* data, XP_U32 len); const void* data, XP_U32 len);
void (*m_dutil_loadPtr)( XW_DUtilCtxt* duc, XWEnv xwe, void (*m_dutil_loadPtr)( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* keys[], const XP_UCHAR* keys[],
void* data, XP_U32* lenp ); void* data, XP_U32* lenp );
# ifdef XWFEATURE_DEVICE
void (*m_dutil_forEach)( XW_DUtilCtxt* duc, XWEnv xwe, void (*m_dutil_forEach)( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* keys[], const XP_UCHAR* keys[],
OnOneProc proc, void* closure ); OnOneProc proc, void* closure );
void (*m_dutil_remove)( XW_DUtilCtxt* duc, const XP_UCHAR* keys[] ); void (*m_dutil_remove)( XW_DUtilCtxt* duc, const XP_UCHAR* keys[] );
#endif
#ifdef XWFEATURE_SMS #ifdef XWFEATURE_SMS
XP_Bool (*m_dutil_phoneNumbersSame)( XW_DUtilCtxt* uc, XWEnv xwe, const XP_UCHAR* p1, XP_Bool (*m_dutil_phoneNumbersSame)( XW_DUtilCtxt* uc, XWEnv xwe, const XP_UCHAR* p1,
const XP_UCHAR* p2 ); const XP_UCHAR* p2 );
@ -125,11 +126,11 @@ void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
#define dutil_storeStream(duc, e, k, s) \ #define dutil_storeStream(duc, e, k, s) \
(duc)->vtable.m_dutil_storeStream((duc), (e), (k), (s)); (duc)->vtable.m_dutil_storeStream((duc), (e), (k), (s));
#define dutil_storePtr(duc, e, k, p, l) \ #define dutil_storePtr(duc, e, k, p, l) \
(duc)->vtable.m_dutil_storePtr((duc), (e), (k), (p), (l)); (duc)->vtable.m_dutil_storePtr((duc), (e), (k), (p), (l))
#define dutil_loadStream(duc, e, k, s) \ #define dutil_loadStream(duc, e, k, s) \
(duc)->vtable.m_dutil_loadStream((duc), (e), (k), (s)); (duc)->vtable.m_dutil_loadStream((duc), (e), (k), (s))
#define dutil_loadPtr(duc, e, k, p, l) \ #define dutil_loadPtr(duc, e, k, p, l) \
(duc)->vtable.m_dutil_loadPtr((duc), (e), (k), (p), (l)); (duc)->vtable.m_dutil_loadPtr((duc), (e), (k), (p), (l))
# define dutil_forEach( duc, xwe, keys, proc, closure ) \ # define dutil_forEach( duc, xwe, keys, proc, closure ) \
(duc)->vtable.m_dutil_forEach((duc), (xwe), (keys), (proc), (closure) ) (duc)->vtable.m_dutil_forEach((duc), (xwe), (keys), (proc), (closure) )
#define dutil_remove(duc, keys) \ #define dutil_remove(duc, keys) \

View file

@ -130,7 +130,7 @@ getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
if ( !!result ) { if ( !!result ) {
for ( int ii = 0; ii < gi->nPlayers; ++ii ) { for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
const LocalPlayer* lp = &gi->players[ii]; const LocalPlayer* lp = &gi->players[ii];
if ( lp->isLocal && !!lp->dictName ) { if ( lp->isLocal && !!lp->dictName && lp->dictName[0] ) {
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, langCode, playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, langCode,
lp->dictName ); lp->dictName );
} }