feat: add some basic stuff to test jni interactions

This commit is contained in:
0x330a 2022-11-28 19:14:08 +11:00
parent 4045333dbc
commit 5bb2bfa779
2 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,13 @@
#include <string>
#include "session/config/user_profile.hpp"
session::config::UserProfile* ptrToProfile(JNIEnv* env, jobject obj) {
jclass configClass = env->FindClass("network/loki/messenger/libsession_util/Config");
jfieldID pointerField = env->GetFieldID(configClass, "pointer", "J");
return (session::config::UserProfile*) reinterpret_cast<long>(env->GetLongField(obj, pointerField));
}
extern "C" JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance(
JNIEnv* env,
@ -17,3 +24,12 @@ Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance(
return newConfig;
}
extern "C" JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_Config_setName(
JNIEnv* env,
jobject obj,
jstring newName) {
auto profile = ptrToProfile(env, obj);
profile->set_name(env->GetStringUTFChars(newName, nullptr));
}

View File

@ -8,6 +8,7 @@ data class Config(private val /* yucky */ pointer: Long) {
var lastError: String? = null
external fun setName(newName: String)
}