Browse Source

introduce engine.startSync() and engine.stopSync()

JNI-88
Volker Birk 3 years ago
parent
commit
14ebadc786
4 changed files with 53 additions and 28 deletions
  1. +3
    -0
      src/org/pEp/jniadapter/AbstractEngine.java
  2. +26
    -18
      src/org_pEp_jniadapter_AbstractEngine.cc
  3. +3
    -1
      test/Makefile
  4. +21
    -9
      test/Testing.java

+ 3
- 0
src/org/pEp/jniadapter/AbstractEngine.java View File

@ -39,6 +39,9 @@ abstract class AbstractEngine implements AutoCloseable {
public native void startKeyserverLookup();
public native void stopKeyserverLookup();
public native void startSync();
public native void stopSync();
public static byte[] toUTF8(String str) {
if (str == null)
return null;


+ 26
- 18
src/org_pEp_jniadapter_AbstractEngine.cc View File

@ -24,12 +24,6 @@ static struct _debug_log {
#include "throw_pEp_exception.hh"
#include "jniutils.hh"
#ifdef ANDROID
#define ATTACH_CURRENT_THREAD(env, args) jvm->AttachCurrentThread(&env, args);
#else
#define ATTACH_CURRENT_THREAD(env, args) jvm->AttachCurrentThread((void **) &env, args);
#endif
namespace pEp {
using namespace pEp::JNIAdapter;
using namespace pEp::Adapter;
@ -61,8 +55,13 @@ namespace pEp {
{
JNIEnv *thread_env = nullptr;
int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6);
if (status < 0)
status = ATTACH_CURRENT_THREAD(thread_env, nullptr);
if (status < 0) {
#ifdef ANDROID
status = jvm->AttachCurrentThread(&thread_env, nullptr);
#else
status = jvm->AttachCurrentThread((void **) &thread_env, nullptr);
#endif
}
assert(status >= 0);
return thread_env;
}
@ -188,18 +187,10 @@ extern "C" {
env->GetJavaVM(&jvm);
jni_init();
obj = env->NewGlobalRef(me);
_messageToSend = messageToSend;
}
#ifdef DISABLE_SYNC
_messageToSend = messageToSend;
session();
#else
if (first) {
debug_log << "######## starting sync\n";
startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::startup_sync, &JNISync::shutdown_sync);
}
#endif
first = false;
session();
}
JNIEXPORT void JNICALL Java_org_pEp_jniadapter_AbstractEngine_release(
@ -316,5 +307,22 @@ extern "C" {
free(thread);
}
JNIEXPORT void JNICALL Java_org_pEp_jniadapter_AbstractEngine_startSync(
JNIEnv *env,
jobject obj
)
{
debug_log << "######## starting sync\n";
startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::startup_sync, &JNISync::shutdown_sync);
}
JNIEXPORT void JNICALL Java_org_pEp_jniadapter_AbstractEngine_stopSync(
JNIEnv *env,
jobject obj
)
{
shutdown();
}
} // extern "C"

+ 3
- 1
test/Makefile View File

@ -13,4 +13,6 @@ test: Testing.class SyncCallbacks.class
clean:
rm -f *.class
rm -f *.log
rm -f *.pEp_*
rm -f .pEp_*
rm -Rf .gnupg
rm -Rf .lldb

+ 21
- 9
test/Testing.java View File

@ -114,17 +114,29 @@ class Testing {
ex.printStackTrace();
}
// try {
// Thread.sleep(1000);
// }
// catch (InterruptedException ex) {
//
// }
e.startSync();
// Keygen
System.out.println("Generating keys: ");
Identity user2 = new Identity();
user2.user_id = "pEp_own_userId";
user2.me = true;
user2.username = "Test User 2";
user2.address = "jniTestUser2@peptest.ch";
user2 = e.myself(user2);
System.out.print("Keys generated: ");
System.out.println(user2.fpr);
// it's not necessary - you can just shutdown Sync and that's it
// but for this test give sync a chance to process all messages
try {
Thread.sleep(200);
}
catch (InterruptedException ex) { }
e.stopSync();
System.exit(0);
}
}

Loading…
Cancel
Save