move methods from util to dutil

This commit is contained in:
Eric House 2024-10-31 10:16:03 -07:00
parent a9e26e9fc8
commit fc30abd126
7 changed files with 84 additions and 85 deletions

View file

@ -269,41 +269,6 @@ and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* isoCodeStr,
UTIL_CBK_TAIL();
}
const DictionaryCtxt*
and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
const XP_UCHAR* XP_UNUSED_DBG(isoCode),
const XP_UCHAR* dictName )
{
XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName );
JNIEnv* env = xwe;
XW_DUtilCtxt* duc = util_getDevUtilCtxt( uc, xwe );
DictMgrCtxt* dictMgr = ((AndDUtil*)duc)->dictMgr;
DictionaryCtxt* dict = (DictionaryCtxt*)
dmgr_get( dictMgr, xwe, dictName );
if ( !dict ) {
jstring jname = (*env)->NewStringUTF( env, dictName );
jobjectArray jstrs = makeStringArray( env, 1, NULL );
jobjectArray jbytes = makeByteArrayArray( env, 1 );
DUTIL_CBK_HEADER( "getDictPath",
"(Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jname, jstrs, jbytes );
DUTIL_CBK_TAIL();
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
jbyteArray jdata = (*env)->GetObjectArrayElement( env, jbytes, 0 );
dict = makeDict( MPPARM(duc->mpool) xwe,
TI_IF( ((AndDUtil*)duc)->ti )
dictMgr, ((AndDUtil*)duc)->jniutil,
jname, jdata, jpath, NULL, false );
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF );
}
return dict;
}
static void
and_util_notifyGameOver( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 XP_UNUSED(quitter) )
{
@ -398,20 +363,6 @@ and_dutil_getCurSeconds( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv xwe )
return curSeconds;
}
static DictionaryCtxt*
and_util_makeEmptyDict( XW_UtilCtxt* uc, XWEnv xwe )
{
#ifdef STUBBED_DICT
XP_ASSERT(0);
#else
AndGameGlobals* globals = (AndGameGlobals*)uc->closure;
DictionaryCtxt* result =
and_dictionary_make_empty( MPPARM( ((AndUtil*)uc)->util.mpool )
globals->jniutil );
return (DictionaryCtxt*)dict_ref( result, xwe );
#endif
}
static const XP_UCHAR*
and_dutil_getUserString( XW_DUtilCtxt* duc, XWEnv xwe, XP_U16 stringCode )
{
@ -986,6 +937,54 @@ and_dutil_sendViaWeb( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 resultKey,
DUTIL_CBK_TAIL();
}
const DictionaryCtxt*
and_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* XP_UNUSED_DBG(isoCode),
const XP_UCHAR* dictName )
{
XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName );
JNIEnv* env = xwe;
DictMgrCtxt* dictMgr = ((AndDUtil*)duc)->dictMgr;
DictionaryCtxt* dict = (DictionaryCtxt*)
dmgr_get( dictMgr, xwe, dictName );
if ( !dict ) {
jstring jname = (*env)->NewStringUTF( env, dictName );
jobjectArray jstrs = makeStringArray( env, 1, NULL );
jobjectArray jbytes = makeByteArrayArray( env, 1 );
DUTIL_CBK_HEADER( "getDictPath",
"(Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jname, jstrs, jbytes );
DUTIL_CBK_TAIL();
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
jbyteArray jdata = (*env)->GetObjectArrayElement( env, jbytes, 0 );
dict = makeDict( MPPARM(duc->mpool) xwe,
TI_IF( ((AndDUtil*)duc)->ti )
dictMgr, ((AndDUtil*)duc)->jniutil,
jname, jdata, jpath, NULL, false );
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF );
}
return dict;
}
static DictionaryCtxt*
and_dutil_makeEmptyDict( XW_DUtilCtxt* duc, XWEnv xwe )
{
#ifdef STUBBED_DICT
XP_ASSERT(0);
#else
AndDUtil* dutil = (AndDUtil*)duc;
JNIUtilCtxt* jniutil = dutil->jniutil;
DictionaryCtxt* result =
and_dictionary_make_empty( MPPARM(duc->mpool) jniutil );
return (DictionaryCtxt*)dict_ref( result, xwe );
#endif
}
static cJSON*
and_dutil_getRegValues( XW_DUtilCtxt* duc, XWEnv xwe )
{
@ -1041,7 +1040,6 @@ makeUtil( MPFORMAL JNIEnv* env,
SET_PROC(notifyDupStatus);
SET_PROC(informUndo);
SET_PROC(informNetDict);
SET_PROC(getDict);
SET_PROC(notifyGameOver);
#ifdef XWFEATURE_HILITECELL
SET_PROC(hiliteCell);
@ -1051,7 +1049,6 @@ makeUtil( MPFORMAL JNIEnv* env,
SET_PROC(clearTimer);
SET_PROC(requestTime);
SET_PROC(altKeyDown);
SET_PROC(makeEmptyDict);
SET_PROC(notifyIllegalWords);
#ifdef XWFEATURE_CHAT
SET_PROC(showChat);
@ -1160,6 +1157,8 @@ makeDUtil( MPFORMAL JNIEnv* env,
SET_DPROC(onGameGoneReceived);
SET_DPROC(sendViaWeb);
SET_DPROC(getDict);
SET_DPROC(makeEmptyDict);
SET_DPROC(getRegValues);
#undef SET_DPROC

View file

@ -110,6 +110,11 @@ typedef struct _DUtilVtable {
cJSON* (*m_dutil_getRegValues)( XW_DUtilCtxt* duc, XWEnv xwe );
void (*m_dutil_sendViaWeb)( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 resultKey,
const XP_UCHAR* api, const cJSON* params );
DictionaryCtxt* (*m_dutil_makeEmptyDict)( XW_DUtilCtxt* duc, XWEnv xwe );
const DictionaryCtxt* (*m_dutil_getDict)( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* isoCode,
const XP_UCHAR* dictName );
} DUtilVtable;
struct XW_DUtilCtxt {
@ -200,6 +205,10 @@ void dutil_super_cleanup( XW_DUtilCtxt* dutil, XWEnv xwe );
(duc)->vtable.m_dutil_onGameGoneReceived((duc),(xwe),(gameID),(from))
#define dutil_sendViaWeb( duc, xwe, resultKey, api, params ) \
(duc)->vtable.m_dutil_sendViaWeb((duc), (xwe), (resultKey), (api), (params))
#define dutil_makeEmptyDict(duc, xwe) \
(duc)->vtable.m_dutil_makeEmptyDict((duc), (xwe))
#define dutil_getDict(duc, xwe, isoCode, dictName) \
(duc)->vtable.m_dutil_getDict((duc), (xwe), (isoCode), (dictName))
#define dutil_getRegValues( duc, xwe ) \
(duc)->vtable.m_dutil_getRegValues( (duc), (xwe) )

View file

@ -134,14 +134,15 @@ getDicts( const CurGameInfo* gi, XW_UtilCtxt* util, XWEnv xwe,
PlayerDicts* playerDicts )
{
const XP_UCHAR* isoCode = gi->isoCodeStr;
const DictionaryCtxt* result = util_getDict( util, xwe, isoCode, gi->dictName );
XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe );
const DictionaryCtxt* result = dutil_getDict( dutil, xwe, isoCode, gi->dictName );
XP_MEMSET( playerDicts, 0, sizeof(*playerDicts) );
if ( !!result ) {
for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
const LocalPlayer* lp = &gi->players[ii];
if ( lp->isLocal && !!lp->dictName && lp->dictName[0] ) {
playerDicts->dicts[ii] = util_getDict( util, xwe, isoCode,
lp->dictName );
playerDicts->dicts[ii] = dutil_getDict( dutil, xwe, isoCode,
lp->dictName );
}
}
}

View file

@ -2284,7 +2284,7 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
if ( streamVersion < STREAM_VERS_NOEMPTYDICT ) {
SRVR_LOGFF( "loading and dropping empty dict" );
DictionaryCtxt* empty = util_makeEmptyDict( server->vol.util, xwe );
DictionaryCtxt* empty = dutil_makeEmptyDict( server->vol.dutil, xwe );
dict_loadFromStream( empty, xwe, stream );
dict_unref( empty, xwe );
}

View file

@ -119,9 +119,6 @@ typedef struct UtilVtable {
const XP_UCHAR* oldName, const XP_UCHAR* newName,
const XP_UCHAR* newSum,
XWPhoniesChoice phoniesAction );
const DictionaryCtxt* (*m_util_getDict)( XW_UtilCtxt* uc, XWEnv xwe,
const XP_UCHAR* isoCode,
const XP_UCHAR* dictName );
void (*m_util_notifyGameOver)( XW_UtilCtxt* uc, XWEnv xwe, XP_S16 quitter );
#ifdef XWFEATURE_HILITECELL
XP_Bool (*m_util_hiliteCell)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 col, XP_U16 row );
@ -136,7 +133,6 @@ typedef struct UtilVtable {
void (*m_util_requestTime)( XW_UtilCtxt* uc, XWEnv xwe );
XP_Bool (*m_util_altKeyDown)( XW_UtilCtxt* uc, XWEnv xwe );
DictionaryCtxt* (*m_util_makeEmptyDict)( XW_UtilCtxt* uc, XWEnv xwe );
void (*m_util_notifyIllegalWords)( XW_UtilCtxt* uc, XWEnv xwe,
const BadWordInfo* bwi,
@ -246,9 +242,6 @@ struct XW_UtilCtxt {
#define util_informNetDict(uc,e, cd, on, nn, ns, pa ) \
(uc)->vtable->m_util_informNetDict( (uc), (e), (cd), (on), (nn), (ns), \
(pa) )
#define util_getDict( uc, xwe, isoCode, dictName ) \
(uc)->vtable->m_util_getDict((uc), (xwe), (isoCode), (dictName))
#define util_notifyGameOver( uc,e, q ) \
(uc)->vtable->m_util_notifyGameOver((uc), (e), (q))
@ -271,9 +264,6 @@ struct XW_UtilCtxt {
#define util_altKeyDown( uc,e ) \
(uc)->vtable->m_util_altKeyDown((uc),(e))
#define util_makeEmptyDict( uc, e ) \
(uc)->vtable->m_util_makeEmptyDict((uc), (e))
#define util_notifyIllegalWords( uc,e, w, d, p, b, k ) \
(uc)->vtable->m_util_notifyIllegalWords((uc), (e), (w), (d), (p), (b), (k))

View file

@ -303,6 +303,24 @@ linux_dutil_sendViaWeb( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
pthread_detach( thrd );
}
static DictionaryCtxt*
linux_dutil_makeEmptyDict( XW_DUtilCtxt* duc, XWEnv xwe )
{
XP_DEBUGF( "linux_util_makeEmptyDict called" );
LaunchParams* params = (LaunchParams*)duc->closure;
return linux_dictionary_make( MPPARM(params->mpool) xwe, NULL, NULL, XP_FALSE );
}
static const DictionaryCtxt*
linux_dutil_getDict( XW_DUtilCtxt* duc, XWEnv xwe,
const XP_UCHAR* XP_UNUSED(isoCode), const XP_UCHAR* dictName )
{
LaunchParams* params = (LaunchParams*)duc->closure;
DictionaryCtxt* result = linux_dictionary_make( MPPARM(params->mpool) xwe,
params, dictName, XP_TRUE );
return result;
}
static cJSON*
linux_dutil_getRegValues( XW_DUtilCtxt* duc, XWEnv xwe )
{
@ -432,6 +450,8 @@ linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
SET_PROC(onCtrlReceived);
SET_PROC(onGameGoneReceived);
SET_PROC(sendViaWeb);
SET_PROC(makeEmptyDict);
SET_PROC(getDict);
SET_PROC(getRegValues);
#ifdef DUTIL_TIMERS
SET_PROC(setTimer);

View file

@ -118,24 +118,6 @@ linux_freep( void** ptrp )
}
#endif
static DictionaryCtxt*
linux_util_makeEmptyDict( XW_UtilCtxt* XP_UNUSED_DBG(uctx), XWEnv xwe )
{
XP_DEBUGF( "linux_util_makeEmptyDict called" );
return linux_dictionary_make( MPPARM(uctx->mpool) xwe, NULL, NULL, XP_FALSE );
} /* linux_util_makeEmptyDict */
static const DictionaryCtxt*
linux_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
const XP_UCHAR* XP_UNUSED(isoCode), const XP_UCHAR* dictName )
{
CommonGlobals* cGlobals = (CommonGlobals*)uc->closure;
LaunchParams* params = cGlobals->params;
DictionaryCtxt* result = linux_dictionary_make( MPPARM(uc->mpool) xwe,
params, dictName, XP_TRUE );
return result;
}
static void
linux_util_getInviteeName( XW_UtilCtxt* XP_UNUSED(uc), XWEnv XP_UNUSED(xwe),
XP_U16 index, XP_UCHAR* buf, XP_U16* bufLen )
@ -163,8 +145,6 @@ linux_util_vt_init( MPFORMAL XW_UtilCtxt* util )
#endif
util->vtable = XP_MALLOC( mpool, sizeof(UtilVtable) );
util->vtable->m_util_makeEmptyDict = linux_util_makeEmptyDict;
util->vtable->m_util_getDict = linux_util_getDict;
util->vtable->m_util_getInviteeName = linux_util_getInviteeName;
util->vtable->m_util_getDevUtilCtxt = linux_util_getDevUtilCtxt;