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.DBUtils;
import org.eehouse.android.xw4.DevID;
import org.eehouse.android.xw4.DictUtils;
import org.eehouse.android.xw4.DupeModeTimer;
import org.eehouse.android.xw4.FBMService;
import org.eehouse.android.xw4.GameUtils;
@ -259,16 +260,16 @@ public class DUtilCtxt {
if ( null != data ) {
DBUtils.setBytesFor( m_context, key, data );
if ( BuildConfig.DEBUG ) {
byte[] tmp = load( key, null );
byte[] tmp = load( key );
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 );
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,
// null == result ? 0 : result.length );
@ -336,6 +337,17 @@ public class DUtilCtxt {
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 )
{
DupeModeTimer.timerChanged( m_context, gameID, newVal );

View file

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

View file

@ -26,6 +26,7 @@
#include "game.h"
#include "util.h"
#include "dutil.h"
#include "dictmgr.h"
#include "andglobals.h"
#include "jniutlswrapper.h"
@ -34,7 +35,8 @@ XW_DUtilCtxt* makeDUtil( MPFORMAL JNIEnv* env,
EnvThreadInfo* ti,
#endif
jobject j_dutil, VTableMgr* vtMgr,
JNIUtilCtxt* jniutil, void* closure );
DictMgrCtxt* dmgr, JNIUtilCtxt* jniutil,
void* closure );
void destroyDUtil( XW_DUtilCtxt** dutilp, 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 );
globalState->jniutil = makeJNIUtil( MPPARM(mpool) env, TI_IF(&globalState->ti) jniu );
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->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 );
MPASSIGN( globalState->mpool, mpool );
setGlobalState( globalState );
@ -891,7 +891,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_gi_1from_1stream
CurGameInfo gi = {0};
// XP_MEMSET( &gi, 0, sizeof(gi) );
if ( game_makeFromStream( MPPARM(mpool) env, stream, NULL,
&gi, NULL, NULL, NULL, NULL, NULL, NULL ) ) {
&gi, NULL, NULL, NULL, NULL ) ) {
setJGI( env, jgi, &gi );
} else {
XP_LOGFF( "game_makeFromStream failed" );
@ -1470,9 +1470,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
CommonPrefs cp;
loadCommonPrefs( env, &cp, jcp );
result = game_makeFromStream( MPPARM(mpool) env, stream, &state->game,
globals->gi, dict, &dicts,
globals->util, globals->dctx, &cp,
globals->xportProcs );
globals->gi, globals->util, globals->dctx,
&cp, globals->xportProcs );
stream_destroy( stream, env );
dict_unref( dict, env ); /* game owns it now */
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.DrawCtx
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\$CommsConnTypeSet
javap -s org.eehouse.android.${NODE}.jni.TransportProcs

View file

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

View file

@ -130,7 +130,7 @@ getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
if ( !!result ) {
for ( int ii = 0; ii < gi->nPlayers; ++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,
lp->dictName );
}