From b8c588e02ccf9a755d66bed2c03cd666458006de Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 21 Sep 2020 15:36:33 -0700 Subject: [PATCH] add new jni methods (untested) --- .../org/eehouse/android/xw4/jni/XwJNI.java | 14 +++++++ xwords4/android/jni/Android.mk | 1 + xwords4/android/jni/xwjni.c | 37 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 3e5212d5a..83e1aa356 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -165,6 +165,16 @@ public class XwJNI { dvc_parseMQTTPacket( getJNI().m_ptrGlobals, buf ); } + public static String[] kplr_getPlayers() + { + return kplr_getPlayers( getJNI().m_ptrGlobals ); + } + + public static CommsAddrRec kplr_getAddr( String name ) + { + return kplr_getAddr( getJNI().m_ptrGlobals, name ); + } + private static void cleanGlobals() { synchronized( XwJNI.class ) { // let's be safe here @@ -679,6 +689,10 @@ public class XwJNI { String[] addrToTopic ); private static native void dvc_parseMQTTPacket( long jniState, byte[] buf ); + + private static native String[] kplr_getPlayers( long jniState ); + private static native CommsAddrRec kplr_getAddr( long jniState, String name ); + private static native void cleanGlobals( long jniState ); private static native byte[] gi_to_stream( long jniState, CurGameInfo gi ); private static native void gi_from_stream( long jniState, CurGameInfo gi, diff --git a/xwords4/android/jni/Android.mk b/xwords4/android/jni/Android.mk index f157102d1..a5ed47bc4 100644 --- a/xwords4/android/jni/Android.mk +++ b/xwords4/android/jni/Android.mk @@ -87,6 +87,7 @@ COMMON_SRC_FILES += \ $(COMMON_PATH)/nli.c \ $(COMMON_PATH)/smsproto.c \ $(COMMON_PATH)/device.c \ + $(COMMON_PATH)/knownplyr.c \ LOCAL_CFLAGS+=$(LOCAL_C_INCLUDES) $(LOCAL_DEFINES) -Wall -std=c99 LOCAL_SRC_FILES := $(linux_SRC_FILES) $(LOCAL_SRC_FILES) $(COMMON_SRC_FILES) diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index f8b213efa..284f580ea 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -36,6 +36,7 @@ #include "nli.h" #include "smsproto.h" #include "device.h" +#include "knownplyr.h" #include "utilwrapper.h" #include "drawwrapper.h" @@ -770,6 +771,42 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dvc_1parseMQTTPacket DVC_HEADER_END(); } +JNIEXPORT jobjectArray JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1getPlayers +( JNIEnv* env, jclass C, jlong jniGlobalPtr ) +{ + jobjectArray jnames = NULL; + DVC_HEADER(jniGlobalPtr); + + XP_U16 nFound = 0; + kplr_getPlayers( globalState->dutil, env, NULL, &nFound ); + if ( 0 < nFound ) { + const XP_UCHAR* names[nFound]; + kplr_getPlayers( globalState->dutil, env, names, &nFound ); + jnames = makeStringArray( env, nFound, names ); + } + DVC_HEADER_END(); + return jnames; +} + +JNIEXPORT jobject JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1getAddr +( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jName ) +{ + jobject jaddr = NULL; + DVC_HEADER(jniGlobalPtr); + + CommsAddrRec addr; + const char* name = (*env)->GetStringUTFChars( env, jName, NULL ); + kplr_getAddr( globalState->dutil, env, name, &addr ); + (*env)->ReleaseStringUTFChars( env, jName, name ); + jaddr = makeObjectEmptyConst( env, PKG_PATH("jni/CommsAddrRec") ); + setJAddrRec( env, jaddr, &addr ); + + DVC_HEADER_END(); + return jaddr; +} + JNIEXPORT jbyteArray JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_gi_1to_1stream ( JNIEnv* env, jclass C, jlong jniGlobalPtr, jobject jgi )