|
@ -1,5 +1,4 @@ |
|
|
#include "foundation_pEp_jniadapter_AbstractEngine.h" |
|
|
#include "foundation_pEp_jniadapter_AbstractEngine.h" |
|
|
#include <unistd.h> |
|
|
|
|
|
#include <pEp/keymanagement.h> |
|
|
#include <pEp/keymanagement.h> |
|
|
#include <pEp/message_api.h> |
|
|
#include <pEp/message_api.h> |
|
|
#include <pEp/sync_api.h> |
|
|
#include <pEp/sync_api.h> |
|
@ -326,119 +325,6 @@ int examine_identity(pEp_identity *ident, |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pEp_identity *retrieve_next_identity(void *arg) |
|
|
|
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
|
|
|
locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg); |
|
|
|
|
|
|
|
|
|
|
|
while (!queue->size()) { |
|
|
|
|
|
usleep(100000); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pEp_identity *ident = queue->front(); |
|
|
|
|
|
queue->pop_front(); |
|
|
|
|
|
return ident; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void *keyserver_thread_routine(void *arg) |
|
|
|
|
|
{ |
|
|
|
|
|
PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg); |
|
|
|
|
|
locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg); |
|
|
|
|
|
|
|
|
|
|
|
while (queue->size()) { |
|
|
|
|
|
pEp_identity *ident = queue->front(); |
|
|
|
|
|
queue->pop_front(); |
|
|
|
|
|
free_identity(ident); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete queue; |
|
|
|
|
|
return reinterpret_cast<void *>(status); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup(JNIEnv *env, |
|
|
|
|
|
jobject obj) |
|
|
|
|
|
{ |
|
|
|
|
|
std::mutex *mutex_local = nullptr; |
|
|
|
|
|
{ |
|
|
|
|
|
std::lock_guard<std::mutex> l(global_mutex); |
|
|
|
|
|
pEpLog("called with lock_guard"); |
|
|
|
|
|
mutex_local = get_engine_java_object_mutex(env, obj); |
|
|
|
|
|
} |
|
|
|
|
|
std::lock_guard<std::mutex> l(*mutex_local); |
|
|
|
|
|
|
|
|
|
|
|
pthread_t *thread = nullptr; |
|
|
|
|
|
locked_queue< pEp_identity * > *queue = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
jfieldID thread_handle; |
|
|
|
|
|
jfieldID queue_handle; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J"); |
|
|
|
|
|
queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J"); |
|
|
|
|
|
} |
|
|
|
|
|
catch (std::exception& ex) { |
|
|
|
|
|
assert(0); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle)); |
|
|
|
|
|
if (thread) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
thread = static_cast<pthread_t*>(calloc(1, sizeof(pthread_t))); |
|
|
|
|
|
assert(thread); |
|
|
|
|
|
env->SetLongField(obj, thread_handle, reinterpret_cast<jlong>(thread)); |
|
|
|
|
|
|
|
|
|
|
|
queue = new locked_queue< pEp_identity * >(); |
|
|
|
|
|
env->SetLongField(obj, queue_handle, reinterpret_cast<jlong>(queue)); |
|
|
|
|
|
|
|
|
|
|
|
register_examine_function(Adapter::session(), examine_identity,static_cast<void*>(queue)); |
|
|
|
|
|
|
|
|
|
|
|
pthread_create(thread, nullptr, keyserver_thread_routine, static_cast<void*>(queue)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup(JNIEnv *env, |
|
|
|
|
|
jobject obj) |
|
|
|
|
|
{ |
|
|
|
|
|
std::mutex *mutex_local = nullptr; |
|
|
|
|
|
{ |
|
|
|
|
|
std::lock_guard<std::mutex> l(global_mutex); |
|
|
|
|
|
pEpLog("called with lock_guard"); |
|
|
|
|
|
mutex_local = get_engine_java_object_mutex(env, obj); |
|
|
|
|
|
} |
|
|
|
|
|
std::lock_guard<std::mutex> l(*mutex_local); |
|
|
|
|
|
|
|
|
|
|
|
pthread_t *thread = nullptr; |
|
|
|
|
|
locked_queue< pEp_identity * > *queue = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
jfieldID thread_handle; |
|
|
|
|
|
jfieldID queue_handle; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J"); |
|
|
|
|
|
queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J"); |
|
|
|
|
|
} |
|
|
|
|
|
catch (std::exception& ex) { |
|
|
|
|
|
assert(0); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle)); |
|
|
|
|
|
if (!thread) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
queue = reinterpret_cast<locked_queue<pEp_identity*>*>(env->GetLongField(obj, queue_handle)); |
|
|
|
|
|
|
|
|
|
|
|
env->SetLongField(obj, queue_handle, 0); |
|
|
|
|
|
env->SetLongField(obj, thread_handle, 0); |
|
|
|
|
|
|
|
|
|
|
|
register_examine_function(Adapter::session(), nullptr, nullptr); |
|
|
|
|
|
|
|
|
|
|
|
queue->push_front(nullptr); |
|
|
|
|
|
pthread_join(*thread, nullptr); |
|
|
|
|
|
free(thread); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync(JNIEnv *env, |
|
|
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync(JNIEnv *env, |
|
|
jobject obj) |
|
|
jobject obj) |
|
|
{ |
|
|
{ |
|
|