mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-29 10:26:36 +01:00
Clean up API (new objects in jni no longer scare me)
This commit is contained in:
parent
4caf660c1c
commit
e2a13a0ec1
3 changed files with 61 additions and 64 deletions
|
@ -46,6 +46,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
|||
import org.eehouse.android.xw4.jni.CommsAddrRec.ConnExpl;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
import org.eehouse.android.xw4.jni.XwJNI.GamePtr;
|
||||
import org.eehouse.android.xw4.jni.XwJNI.TopicsAndPackets;
|
||||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
|
@ -546,10 +547,8 @@ public class MQTTUtils extends Thread
|
|||
NetLaunchInfo nli )
|
||||
{
|
||||
Log.d( TAG, "sendInvite(invitee: %s, nli: %s)", invitee, nli );
|
||||
byte[][][] packets = {null};
|
||||
String[][] topics = {null};
|
||||
XwJNI.dvc_makeMQTTInvites( invitee, nli, topics, packets );
|
||||
addToSendQueue( context, topics[0], packets[0] );
|
||||
TopicsAndPackets tap = XwJNI.dvc_makeMQTTInvites( invitee, nli );
|
||||
addToSendQueue( context, tap );
|
||||
}
|
||||
|
||||
// This goes away? comms_invite() is already getting called. PENDING
|
||||
|
@ -563,10 +562,8 @@ public class MQTTUtils extends Thread
|
|||
private static void notifyNotHere( Context context, String addressee,
|
||||
int gameID )
|
||||
{
|
||||
String[][] topics = {null};
|
||||
byte[][][] packets = {null};
|
||||
XwJNI.dvc_makeMQTTNoSuchGames( addressee, gameID, topics, packets );
|
||||
addToSendQueue( context, topics[0], packets[0] );
|
||||
TopicsAndPackets tap = XwJNI.dvc_makeMQTTNoSuchGames( addressee, gameID );
|
||||
addToSendQueue( context, tap );
|
||||
}
|
||||
|
||||
public static int send( Context context, String addressee, int gameID,
|
||||
|
@ -574,27 +571,23 @@ public class MQTTUtils extends Thread
|
|||
{
|
||||
Log.d( TAG, "send(to:%s, len: %d)", addressee, buf.length );
|
||||
Assert.assertTrueNR( 16 == addressee.length() );
|
||||
String[][] topics = {null};
|
||||
byte[][][] packets = {null};
|
||||
XwJNI.dvc_makeMQTTMessages( addressee, gameID, buf, topics, packets );
|
||||
addToSendQueue( context, topics[0], packets[0] );
|
||||
TopicsAndPackets tap = XwJNI.dvc_makeMQTTMessages( addressee, gameID, buf );
|
||||
addToSendQueue( context, tap );
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
private static void addToSendQueue( Context context, String[] topics, byte[][] packets )
|
||||
private static void addToSendQueue( Context context, TopicsAndPackets tap )
|
||||
{
|
||||
MQTTUtils instance = getOrStart( context );
|
||||
if ( null != instance ) {
|
||||
instance.enqueue( topics, packets );
|
||||
instance.enqueue( tap.topics, tap.packets );
|
||||
}
|
||||
}
|
||||
|
||||
public static void gameDied( Context context, String devID, int gameID )
|
||||
{
|
||||
String[][] topics = {null};
|
||||
byte[][][] packets = {null};
|
||||
XwJNI.dvc_makeMQTTNoSuchGames( devID, gameID, topics, packets );
|
||||
addToSendQueue( context, topics[0], packets[0] );
|
||||
TopicsAndPackets tap = XwJNI.dvc_makeMQTTNoSuchGames( devID, gameID );
|
||||
addToSendQueue( context, tap );
|
||||
}
|
||||
|
||||
public static void ackMessage( Context context, int gameID,
|
||||
|
|
|
@ -154,27 +154,31 @@ public class XwJNI {
|
|||
return dvc_getMQTTSubTopics( getJNI().m_ptrGlobals );
|
||||
}
|
||||
|
||||
public static void dvc_makeMQTTInvites( String invitee, NetLaunchInfo nli,
|
||||
String[][] topics, byte[][][] packets )
|
||||
{
|
||||
dvc_makeMQTTInvites( getJNI().m_ptrGlobals, invitee,
|
||||
nli, topics, packets );
|
||||
public static class TopicsAndPackets {
|
||||
public String[] topics;
|
||||
public byte[][] packets;
|
||||
TopicsAndPackets( String[] topics, byte[][] packets )
|
||||
{
|
||||
this.topics = topics;
|
||||
this.packets = packets;
|
||||
}
|
||||
}
|
||||
|
||||
public static void dvc_makeMQTTMessages( String addressee, int gameID, byte[] buf,
|
||||
String[][] topics, byte[][][] packets )
|
||||
public static TopicsAndPackets dvc_makeMQTTInvites( String invitee, NetLaunchInfo nli )
|
||||
{
|
||||
dvc_makeMQTTMessages( getJNI().m_ptrGlobals, addressee, gameID,
|
||||
buf, topics, packets );
|
||||
return dvc_makeMQTTInvites( getJNI().m_ptrGlobals, invitee, nli );
|
||||
}
|
||||
|
||||
public static void dvc_makeMQTTNoSuchGames( String addressee, int gameID,
|
||||
String[][] topics, byte[][][] packets )
|
||||
public static TopicsAndPackets dvc_makeMQTTMessages( String addressee, int gameID, byte[] buf )
|
||||
{
|
||||
return dvc_makeMQTTMessages( getJNI().m_ptrGlobals, addressee, gameID, buf );
|
||||
}
|
||||
|
||||
public static TopicsAndPackets dvc_makeMQTTNoSuchGames( String addressee, int gameID )
|
||||
{
|
||||
Log.d( TAG, "dvc_makeMQTTNoSuchGames(to: %s, gameID: %X)", addressee, gameID );
|
||||
DbgUtils.printStack( TAG );
|
||||
dvc_makeMQTTNoSuchGames( getJNI().m_ptrGlobals, addressee, gameID,
|
||||
topics, packets );
|
||||
return dvc_makeMQTTNoSuchGames( getJNI().m_ptrGlobals, addressee, gameID );
|
||||
}
|
||||
|
||||
public static void dvc_parseMQTTPacket( String topic, byte[] buf )
|
||||
|
@ -770,20 +774,16 @@ public class XwJNI {
|
|||
private static native String dvc_getMQTTDevID( long jniState );
|
||||
private static native void dvc_resetMQTTDevID( long jniState );
|
||||
private static native String[] dvc_getMQTTSubTopics( long jniState );
|
||||
private static native void dvc_makeMQTTInvites( long jniState,
|
||||
String invitee,
|
||||
NetLaunchInfo nli,
|
||||
String[][] topics,
|
||||
byte[][][] packets );
|
||||
private static native void dvc_makeMQTTMessages( long jniState,
|
||||
String addressee,
|
||||
int gameID, byte[] buf,
|
||||
String[][] topics,
|
||||
byte[][][] packets );
|
||||
|
||||
private static native void dvc_makeMQTTNoSuchGames( long jniState, String addressee,
|
||||
int gameID, String[][] topics,
|
||||
byte[][][] packets );
|
||||
private static native TopicsAndPackets
|
||||
dvc_makeMQTTInvites( long jniState,
|
||||
String invitee,
|
||||
NetLaunchInfo nli );
|
||||
private static native TopicsAndPackets
|
||||
dvc_makeMQTTMessages( long jniState,
|
||||
String addressee,
|
||||
int gameID, byte[] buf );
|
||||
private static native TopicsAndPackets
|
||||
dvc_makeMQTTNoSuchGames( long jniState, String addressee, int gameID );
|
||||
private static native void dvc_parseMQTTPacket( long jniState, String topic,
|
||||
byte[] buf );
|
||||
private static native String[] kplr_getPlayers( long jniState );
|
||||
|
|
|
@ -713,29 +713,32 @@ msgAndTopicProc( void* closure, const XP_UCHAR* topic,
|
|||
XP_ASSERT( mtp->count < VSIZE(mtp->topics) );
|
||||
}
|
||||
|
||||
static void
|
||||
wrapResults( jobjectArray jTopicsOut, jobjectArray jPacketsOut, MTPData* mtp )
|
||||
static jobject
|
||||
wrapResults( MTPData* mtp )
|
||||
{
|
||||
JNIEnv* env = mtp->env;
|
||||
jobject result =
|
||||
makeObjectEmptyConst( env, PKG_PATH("jni/XwJNI$TopicsAndPackets"));
|
||||
|
||||
jobjectArray jTopics = makeStringArray( env, mtp->count, mtp->topics );
|
||||
(*env)->SetObjectArrayElement( env, jTopicsOut, 0, jTopics );
|
||||
setObjectField( env, result, "topics", "[Ljava/lang/String;", jTopics );
|
||||
|
||||
jobjectArray jPackets = makeByteArrayArray( env, mtp->count );
|
||||
for ( int ii = 0; ii < mtp->count; ++ii ) {
|
||||
(*env)->SetObjectArrayElement( env, jPackets, ii, mtp->jPackets[ii] );
|
||||
deleteLocalRef( env, mtp->jPackets[ii] );
|
||||
}
|
||||
(*env)->SetObjectArrayElement( env, jPacketsOut, 0, jPackets );
|
||||
setObjectField( env, result, "packets", "[[B", jPackets );
|
||||
|
||||
deleteLocalRefs( env, jTopics, jPackets, DELETE_NO_REF );
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTInvites
|
||||
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jAddressee,
|
||||
jobject jnli, jobjectArray jTopicsOut,
|
||||
jobjectArray jPacketsOut )
|
||||
jobject jnli )
|
||||
{
|
||||
jobject result;
|
||||
DVC_HEADER(jniGlobalPtr);
|
||||
|
||||
NetLaunchInfo nli;
|
||||
|
@ -749,23 +752,21 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTInvites
|
|||
|
||||
dvc_makeMQTTInvites( globalState->dutil, env, msgAndTopicProc, &mtp,
|
||||
&addressee, &nli );
|
||||
wrapResults( jTopicsOut, jPacketsOut, &mtp );
|
||||
result = wrapResults( &mtp );
|
||||
|
||||
DVC_HEADER_END();
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTMessages
|
||||
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jAddressee,
|
||||
jint jGameID, jbyteArray jmsg,
|
||||
jobjectArray jTopicsOut, jobjectArray jPacketsOut )
|
||||
jint jGameID, jbyteArray jmsg )
|
||||
{
|
||||
jobject result;
|
||||
LOG_FUNC();
|
||||
DVC_HEADER(jniGlobalPtr);
|
||||
|
||||
XP_ASSERT( 1 == (*env)->GetArrayLength( env, jTopicsOut ) );
|
||||
XP_ASSERT( 1 == (*env)->GetArrayLength( env, jPacketsOut ) );
|
||||
|
||||
MTPData mtp = { .env = env, };
|
||||
|
||||
MQTTDevID addressee;
|
||||
|
@ -777,17 +778,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTMessages
|
|||
&addressee, jGameID, (const XP_U8*)buf, len );
|
||||
(*env)->ReleaseByteArrayElements( env, jmsg, buf, 0 );
|
||||
|
||||
wrapResults( jTopicsOut, jPacketsOut, &mtp );
|
||||
result = wrapResults( &mtp );
|
||||
|
||||
DVC_HEADER_END();
|
||||
LOG_RETURN_VOID();
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTNoSuchGames
|
||||
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jAddressee,
|
||||
jint jgameid, jobjectArray jTopicsOut, jobjectArray jPacketsOut )
|
||||
jint jgameid )
|
||||
{
|
||||
jobject result;
|
||||
DVC_HEADER(jniGlobalPtr);
|
||||
|
||||
MTPData mtp = { .env = env, };
|
||||
|
@ -797,9 +800,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1makeMQTTNoSuchGames
|
|||
dvc_makeMQTTNoSuchGames( globalState->dutil, env, msgAndTopicProc, &mtp,
|
||||
&addressee, jgameid );
|
||||
|
||||
wrapResults( jTopicsOut, jPacketsOut, &mtp );
|
||||
result = wrapResults( &mtp );
|
||||
|
||||
DVC_HEADER_END();
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
Loading…
Reference in a new issue