mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
Create and pass enum into relayErrorProc
This commit is contained in:
parent
135d936a7d
commit
cd0afbfae8
4 changed files with 46 additions and 3 deletions
|
@ -405,6 +405,35 @@ intToJenumField( JNIEnv* env, jobject jobj, int val, const char* field,
|
|||
(*env)->DeleteLocalRef( env, clazz );
|
||||
} /* intToJenumField */
|
||||
|
||||
/* Cons up a new enum instance and set its value */
|
||||
jobject
|
||||
intToJEnum( JNIEnv* env, int val, const char* enumSig )
|
||||
{
|
||||
jobject jenum = NULL;
|
||||
jclass clazz = (*env)->FindClass( env, enumSig );
|
||||
XP_ASSERT( !!clazz );
|
||||
/* jmethodID mid = getMethodID( env, clazz, "<init>", "()V" ); */
|
||||
/* XP_ASSERT( !!mid ); */
|
||||
/* jenum = (*env)->NewObject( env, clazz, mid ); */
|
||||
/* XP_ASSERT( !!jenum ); */
|
||||
|
||||
char buf[128];
|
||||
snprintf( buf, sizeof(buf), "()[L%s;", enumSig );
|
||||
jmethodID mid = (*env)->GetStaticMethodID( env, clazz, "values", buf );
|
||||
XP_ASSERT( !!mid );
|
||||
|
||||
jobject jvalues = (*env)->CallStaticObjectMethod( env, clazz, mid );
|
||||
XP_ASSERT( !!jvalues );
|
||||
XP_ASSERT( val < (*env)->GetArrayLength( env, jvalues ) );
|
||||
/* get the value we want */
|
||||
jenum = (*env)->GetObjectArrayElement( env, jvalues, val );
|
||||
XP_ASSERT( !!jenum );
|
||||
|
||||
(*env)->DeleteLocalRef( env, jvalues );
|
||||
(*env)->DeleteLocalRef( env, clazz );
|
||||
return jenum;
|
||||
} /* intToJEnum */
|
||||
|
||||
XWStreamCtxt*
|
||||
and_empty_stream( MPFORMAL AndGlobals* globals )
|
||||
{
|
||||
|
|
|
@ -48,4 +48,5 @@ jint jenumFieldToInt( JNIEnv* env, jobject j_gi, const char* field,
|
|||
const char* fieldSig );
|
||||
void intToJenumField( JNIEnv* env, jobject j_gi, int val, const char* field,
|
||||
const char* fieldSig );
|
||||
jobject intToJEnum( JNIEnv* env, int val, const char* enumSig );
|
||||
#endif
|
||||
|
|
|
@ -109,7 +109,20 @@ and_xport_relayConnd( void* closure, XP_Bool allHere, XP_U16 nMissing )
|
|||
static void
|
||||
and_xport_relayError( void* closure, XWREASON relayErr )
|
||||
{
|
||||
LOG_FUNC();
|
||||
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
||||
if ( NULL != aprocs->jxport ) {
|
||||
JNIEnv* env = *aprocs->envp;
|
||||
jmethodID mid;
|
||||
const char* sig = "(Lorg/eehouse/android/xw4/jni/"
|
||||
"TransportProcs$XWRELAY_ERROR;)V";
|
||||
mid = getMethodID( env, aprocs->jxport, "relayErrorProc", sig );
|
||||
|
||||
jobject jenum = intToJEnum( env, relayErr, "org/eehouse/android/xw4/jni/"
|
||||
"TransportProcs$XWRELAY_ERROR" );
|
||||
(*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum );
|
||||
|
||||
(*env)->DeleteLocalRef( env, jenum );
|
||||
}
|
||||
}
|
||||
|
||||
TransportProcs*
|
||||
|
|
|
@ -293,7 +293,7 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
|
||||
public void relayStatus( int newState )
|
||||
{
|
||||
Utils.logf( "relayStatus called" );
|
||||
Utils.logf( "relayStatus called; state=" + newState );
|
||||
}
|
||||
|
||||
public void relayConnd( boolean allHere, int nMissing )
|
||||
|
@ -312,6 +312,6 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
|
||||
public void relayErrorProc( XWRELAY_ERROR relayErr )
|
||||
{
|
||||
Utils.logf( "relayErrorProc called" );
|
||||
Utils.logf( "relayErrorProc called; got " + relayErr.toString() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue