mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
call back into java for util_getCurSeconds implementation so java and
C world are sure to be using the same clock.
This commit is contained in:
parent
ebaa22594d
commit
8281bd7f10
6 changed files with 32 additions and 5 deletions
|
@ -484,6 +484,19 @@ and_empty_stream( MPFORMAL AndGlobals* globals )
|
|||
return stream;
|
||||
}
|
||||
|
||||
XP_U32
|
||||
getCurSeconds( JNIEnv* env )
|
||||
{
|
||||
jclass clazz = (*env)->FindClass( env, PKG_PATH("Utils") );
|
||||
XP_ASSERT( !!clazz );
|
||||
jmethodID mid = (*env)->GetStaticMethodID( env, clazz,
|
||||
"getCurSeconds", "()J" );
|
||||
jlong result = (*env)->CallStaticLongMethod( env, clazz, mid );
|
||||
|
||||
deleteLocalRef( env, clazz );
|
||||
return result;
|
||||
}
|
||||
|
||||
void deleteLocalRef( JNIEnv* env, jobject jobj )
|
||||
{
|
||||
if ( NULL != jobj ) {
|
||||
|
|
|
@ -72,6 +72,8 @@ void intToJenumField( JNIEnv* env, jobject jobj, int val, const char* field,
|
|||
jobject intToJEnum( JNIEnv* env, int val, const char* enumSig );
|
||||
jint jEnumToInt( JNIEnv* env, jobject jenum );
|
||||
|
||||
XP_U32 getCurSeconds( JNIEnv* env );
|
||||
|
||||
void deleteLocalRef( JNIEnv* env, jobject jobj );
|
||||
void deleteLocalRefs( JNIEnv* env, jobject jobj, ... );
|
||||
# define DELETE_NO_REF ((jobject)-1) /* terminates above varargs list */
|
||||
|
|
|
@ -369,9 +369,12 @@ and_util_altKeyDown( XW_UtilCtxt* uc )
|
|||
XP_U32
|
||||
and_util_getCurSeconds( XW_UtilCtxt* uc )
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday( &tv, NULL );
|
||||
return tv.tv_sec;
|
||||
AndUtil* andutil = (AndUtil*)uc;
|
||||
XP_U32 curSeconds = getCurSeconds( *andutil->env );
|
||||
/* struct timeval tv; */
|
||||
/* gettimeofday( &tv, NULL ); */
|
||||
/* XP_LOGF( "%s: %d vs %d", __func__, (int)tv.tv_sec, (int)curSeconds ); */
|
||||
return curSeconds;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
|
|||
gi->gameID = getInt( env, j_gi, "gameID" );
|
||||
if ( 0 == gi->gameID ) {
|
||||
while ( 0 == gi->gameID ) {
|
||||
gi->gameID = and_util_getCurSeconds( NULL );
|
||||
gi->gameID = getCurSeconds( env );
|
||||
}
|
||||
setInt( env, j_gi, "gameID", gi->gameID );
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
|
|||
MPASSIGN( state->mpool, mpool );
|
||||
globals->vtMgr = make_vtablemgr(MPPARM_NOCOMMA(mpool));
|
||||
|
||||
XP_U32 secs = and_util_getCurSeconds( NULL );
|
||||
XP_U32 secs = getCurSeconds( env );
|
||||
XP_LOGF( "initing srand with %ld", secs );
|
||||
srandom( secs );
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import junit.framework.Assert;
|
||||
|
@ -362,6 +363,13 @@ public class Utils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static long getCurSeconds()
|
||||
{
|
||||
long millis = new Date().getTime();
|
||||
int result = (int)(millis / 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void setFirstBootStatics( Context context )
|
||||
{
|
||||
int thisVersion = 0;
|
||||
|
|
|
@ -53,5 +53,6 @@ javap -s org.eehouse.android.${NODE}.jni.UtilCtxt
|
|||
javap -s org.eehouse.android.${NODE}.jni.CommsAddrRec
|
||||
javap -s org.eehouse.android.${NODE}.jni.TransportProcs
|
||||
javap -s org.eehouse.android.${NODE}.jni.JNIUtils
|
||||
javap -s org.eehouse.android.${NODE}.Utils
|
||||
cat /tmp/javah$$.txt
|
||||
rm /tmp/javah$$.txt
|
||||
|
|
Loading…
Reference in a new issue