From 5bb2bfa7797f78923a3cc918711f6701dcea4c47 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Mon, 28 Nov 2022 19:14:08 +1100 Subject: [PATCH] feat: add some basic stuff to test jni interactions --- libsession-util/src/main/cpp/session_util.cpp | 16 ++++++++++++++++ .../loki/messenger/libsession_util/Config.kt | 1 + 2 files changed, 17 insertions(+) diff --git a/libsession-util/src/main/cpp/session_util.cpp b/libsession-util/src/main/cpp/session_util.cpp index d057826204..0b622337ab 100644 --- a/libsession-util/src/main/cpp/session_util.cpp +++ b/libsession-util/src/main/cpp/session_util.cpp @@ -2,6 +2,13 @@ #include #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(env->GetLongField(obj, pointerField)); +} + extern "C" JNIEXPORT jobject JNICALL Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance( JNIEnv* env, @@ -16,4 +23,13 @@ Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance( env->SetLongField(newConfig, pointerField, reinterpret_cast(profile)); 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)); } \ No newline at end of file diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index a697b44261..9fb75f50ab 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -8,6 +8,7 @@ data class Config(private val /* yucky */ pointer: Long) { var lastError: String? = null + external fun setName(newName: String) } \ No newline at end of file