From 25a07dcfde765b9c445e41011fce651b9e38ec7a Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 16 Apr 2020 20:33:49 +0200 Subject: [PATCH] Added Logging of every c/c++ function call (in DEBUG build only) resolved possible var name ambiguity corrected some formatting inconsistencies --- src/basic_api.cc | 15 + ...oundation_pEp_jniadapter_AbstractEngine.cc | 556 +++++++++--------- src/foundation_pEp_jniadapter__Blob.cc | 5 +- src/gen_cpp_Engine.ysl2 | 2 + src/gen_cpp_Message.ysl2 | 31 +- src/identity_api.cc | 9 +- 6 files changed, 329 insertions(+), 289 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index e5ebc38..86be576 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -20,6 +20,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine_trustwords( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); char *words; size_t wsize; @@ -57,6 +58,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_myself( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); PEP_STATUS status = ::myself(session(), _ident); @@ -75,6 +77,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_updateIdentity( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); ::update_identity(session(), _ident); @@ -89,6 +92,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_setOwnKey( jbyteArray fpr ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); char *_fpr = to_string(env, fpr); @@ -109,6 +113,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_keyMistrusted( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); if (_ident->fpr == NULL || _ident->fpr[0] == 0) { @@ -132,6 +137,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_keyResetTrust( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); if (_ident->fpr == NULL || _ident->fpr[0] == 0) { @@ -155,6 +161,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_trustPersonalKey( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); if (_ident->fpr == NULL || _ident->fpr[0] == 0) { @@ -178,6 +185,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_trustOwnKey( jobject ident ) { + pEpLog("called"); pEp_identity *_ident = to_identity(env, ident); if (_ident->fpr == NULL || _ident->fpr[0] == 0) { @@ -194,6 +202,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_importKey( jbyteArray key ) { + pEpLog("called"); size_t _size = (size_t) env->GetArrayLength(key); char *_key = (char *) env->GetByteArrayElements(key, NULL); @@ -217,6 +226,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_config_1passive_1mo jboolean enable ) { + pEpLog("called"); ::config_passive_mode(session(), (bool)enable); } @@ -227,6 +237,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_config_1unencrypted jboolean enable ) { + pEpLog("called"); ::config_unencrypted_subject(session(), (bool)enable); } @@ -236,6 +247,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1add( jbyteArray fpr ) { + pEpLog("called"); char *_fpr = to_string(env, fpr); if(_fpr == NULL){ @@ -257,6 +269,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1delete( jbyteArray fpr ) { + pEpLog("called"); char *_fpr = to_string(env, fpr); if(_fpr == NULL){ @@ -278,6 +291,7 @@ JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1is_1 jbyteArray fpr ) { + pEpLog("called"); char *_fpr = to_string(env, fpr); bool _listed = 0; @@ -302,6 +316,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine_getCrashdumpL jint maxlines ) { + pEpLog("called"); int _maxlines = (int) maxlines; char *_logdata; diff --git a/src/foundation_pEp_jniadapter_AbstractEngine.cc b/src/foundation_pEp_jniadapter_AbstractEngine.cc index 68d932c..51754d3 100644 --- a/src/foundation_pEp_jniadapter_AbstractEngine.cc +++ b/src/foundation_pEp_jniadapter_AbstractEngine.cc @@ -1,17 +1,4 @@ #include "foundation_pEp_jniadapter_AbstractEngine.h" - -#ifndef NDEBUG -#include -auto& debug_log = std::cerr; -#else -// the compiler should optimize this away -static struct _debug_log { - _debug_log& operator<<(const char*) { return *this; } - _debug_log& operator<<(int) { return *this; } - _debug_log& operator<<(double) { return *this; } -} debug_log; -#endif - #include #include #include @@ -20,333 +7,360 @@ static struct _debug_log { #include #include #include - +#include #include "throw_pEp_exception.hh" #include "jniutils.hh" namespace pEp { - using namespace pEp::JNIAdapter; - using namespace utility; +using namespace pEp::JNIAdapter; +using namespace utility; // for libpEpAdapter locked queue impl. TODO:rename - bool first = true; +bool first = true; - JavaVM *jvm= nullptr; +JavaVM *jvm= nullptr; - std::mutex mutex_obj; +std::mutex mutex_obj; - jfieldID field_value = nullptr; - jmethodID messageConstructorMethodID = nullptr; - jmethodID messageToSendMethodID = nullptr; - jmethodID notifyHandShakeMethodID = nullptr; - jmethodID needsFastPollMethodID = nullptr; - jmethodID method_values = nullptr; +jfieldID field_value = nullptr; +jmethodID messageConstructorMethodID = nullptr; +jmethodID messageToSendMethodID = nullptr; +jmethodID notifyHandShakeMethodID = nullptr; +jmethodID needsFastPollMethodID = nullptr; +jmethodID method_values = nullptr; - jobject obj = nullptr; +jobject obj = nullptr; - jclass messageClass = nullptr; - jclass identityClass = nullptr;; - jclass signalClass = nullptr; - jclass engineClass = nullptr; +jclass messageClass = nullptr; +jclass identityClass = nullptr;; +jclass signalClass = nullptr; +jclass engineClass = nullptr; - class JNISync { - public: - JNIEnv * env() - { - JNIEnv *thread_env = nullptr; - int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6); - if (status < 0) { +class JNISync { +public: + JNIEnv * env() + { + pEpLog("called"); + JNIEnv *thread_env = nullptr; + int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6); + if (status < 0) { #ifdef ANDROID - status = jvm->AttachCurrentThread(&thread_env, nullptr); + status = jvm->AttachCurrentThread(&thread_env, nullptr); #else - status = jvm->AttachCurrentThread((void **) &thread_env, nullptr); + status = jvm->AttachCurrentThread((void **) &thread_env, nullptr); #endif - } - assert(status >= 0); - return thread_env; - } - - void onSyncStartup() - { - env(); - } - - void onSyncShutdown() - { - jvm->DetachCurrentThread(); } - } o; - - void jni_init() { - JNIEnv *_env = o.env(); - - messageClass = reinterpret_cast( - _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message"))); - identityClass = reinterpret_cast( - _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity"))); - signalClass = reinterpret_cast( - _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal"))); - engineClass = reinterpret_cast(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine"))); - - messageConstructorMethodID = _env->GetMethodID(messageClass, "", "(J)V"); - messageToSendMethodID = _env->GetMethodID( - engineClass, - "messageToSendCallFromC", - "(Lfoundation/pEp/jniadapter/Message;)I"); - needsFastPollMethodID = _env->GetMethodID( - engineClass, - "needsFastPollCallFromC", - "(Z)I"); - notifyHandShakeMethodID = _env->GetMethodID( - engineClass, - "notifyHandshakeCallFromC", - "(Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/SyncHandshakeSignal;)I"); - - method_values = o.env()->GetStaticMethodID(signalClass, "values", - "()[Lfoundation/pEp/jniadapter/SyncHandshakeSignal;"); - field_value = o.env()->GetFieldID(signalClass, "value", "I"); + assert(status >= 0); + return thread_env; } - PEP_STATUS messageToSend(message *msg) + void onSyncStartup() { - std::lock_guard l(mutex_obj); + pEpLog("called"); + env(); + } - debug_log << "\n############### messageToSend() called\n"; - jobject msg_ = nullptr; + void onSyncShutdown() + { + pEpLog("called"); + jvm->DetachCurrentThread(); + } +} o; + +void jni_init() { + pEpLog("called"); + JNIEnv *_env = o.env(); + + messageClass = reinterpret_cast( + _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message"))); + identityClass = reinterpret_cast( + _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity"))); + signalClass = reinterpret_cast( + _env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal"))); + engineClass = reinterpret_cast(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine"))); + + messageConstructorMethodID = _env->GetMethodID(messageClass, "", "(J)V"); + messageToSendMethodID = _env->GetMethodID( + engineClass, + "messageToSendCallFromC", + "(Lfoundation/pEp/jniadapter/Message;)I"); + needsFastPollMethodID = _env->GetMethodID( + engineClass, + "needsFastPollCallFromC", + "(Z)I"); + notifyHandShakeMethodID = _env->GetMethodID( + engineClass, + "notifyHandshakeCallFromC", + "(Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/_Identity;Lfoundation/pEp/jniadapter/SyncHandshakeSignal;)I"); + + method_values = o.env()->GetStaticMethodID(signalClass, "values", + "()[Lfoundation/pEp/jniadapter/SyncHandshakeSignal;"); + field_value = o.env()->GetFieldID(signalClass, "value", "I"); +} - assert(messageClass && messageConstructorMethodID && obj && messageToSendMethodID); +PEP_STATUS messageToSend(message *msg) +{ + pEpLog("called"); + std::lock_guard l(mutex_obj); - msg_ = o.env()->NewObject(messageClass, messageConstructorMethodID, (jlong) msg); + pEpLog("############### messageToSend() called"); + jobject msg_ = nullptr; - PEP_STATUS status = (PEP_STATUS) o.env()->CallIntMethod(obj, messageToSendMethodID, msg_); - if (o.env()->ExceptionCheck()) { - o.env()->ExceptionDescribe(); - status = PEP_UNKNOWN_ERROR; - o.env()->ExceptionClear(); - } + assert(messageClass && messageConstructorMethodID && obj && messageToSendMethodID); + msg_ = o.env()->NewObject(messageClass, messageConstructorMethodID, (jlong) msg); - return status; + PEP_STATUS status = (PEP_STATUS) o.env()->CallIntMethod(obj, messageToSendMethodID, msg_); + if (o.env()->ExceptionCheck()) { + o.env()->ExceptionDescribe(); + status = PEP_UNKNOWN_ERROR; + o.env()->ExceptionClear(); } - PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) - { - std::lock_guard l(mutex_obj); - - debug_log << "\n############### notifyHandshake() called\n"; - jobject me_ = nullptr; - jobject partner_ = nullptr; - - me_ = from_identity(o.env(), me, identityClass); - partner_ = from_identity(o.env(), partner, identityClass); - - jobject signal_ = nullptr; - { - assert(signalClass); - assert(method_values); - assert(field_value); - - jobjectArray values = (jobjectArray) o.env()->CallStaticObjectMethod(signalClass, - method_values); - if (o.env()->ExceptionCheck()) { - o.env()->ExceptionClear(); - return PEP_UNKNOWN_ERROR; - } - jsize values_size = o.env()->GetArrayLength(values); - for (jsize i = 0; i < values_size; i++) { - jobject element = o.env()->GetObjectArrayElement(values, i); - assert(element); - jint value = o.env()->GetIntField(element, field_value); - if (value == (jint) signal) { - signal_ = element; - break; - } - o.env() -> DeleteLocalRef(element); - } - } + return status; +} + +PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) +{ + pEpLog("called"); + std::lock_guard l(mutex_obj); - assert(obj && notifyHandShakeMethodID); + pEpLog("############### notifyHandshake() called"); + jobject me_ = nullptr; + jobject partner_ = nullptr; + + me_ = from_identity(o.env(), me, identityClass); + partner_ = from_identity(o.env(), partner, identityClass); + + jobject signal_ = nullptr; + { + assert(signalClass); + assert(method_values); + assert(field_value); - PEP_STATUS status = (PEP_STATUS) o.env()->CallIntMethod(obj, notifyHandShakeMethodID, me_, partner_, signal_); + jobjectArray values = (jobjectArray) o.env()->CallStaticObjectMethod(signalClass, + method_values); if (o.env()->ExceptionCheck()) { o.env()->ExceptionClear(); return PEP_UNKNOWN_ERROR; } - return status; + jsize values_size = o.env()->GetArrayLength(values); + for (jsize i = 0; i < values_size; i++) { + jobject element = o.env()->GetObjectArrayElement(values, i); + assert(element); + jint value = o.env()->GetIntField(element, field_value); + if (value == (jint) signal) { + signal_ = element; + break; + } + o.env() -> DeleteLocalRef(element); + } } -} -extern "C" { - using namespace pEp; + assert(obj && notifyHandShakeMethodID); - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init( - JNIEnv *env, - jobject me - ) - { - if (first) { - first = false; - env->GetJavaVM(&jvm); - jni_init(); - obj = env->NewGlobalRef(me); - Adapter::_messageToSend = messageToSend; - } - Adapter::session(); + PEP_STATUS status = (PEP_STATUS) o.env()->CallIntMethod(obj, notifyHandShakeMethodID, me_, partner_, signal_); + if (o.env()->ExceptionCheck()) { + o.env()->ExceptionClear(); + return PEP_UNKNOWN_ERROR; } - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release( - JNIEnv *env, - jobject me - ) - { - Adapter::session(pEp::Adapter::release); - } + return status; +} +} - JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion(JNIEnv *env, jobject) - { - return env->NewStringUTF(::get_engine_version()); +extern "C" { +using namespace pEp; + +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + if (first) { + pEpLog("first Engine instance"); + first = false; + env->GetJavaVM(&jvm); + jni_init(); + obj = env->NewGlobalRef(me); + Adapter::_messageToSend = messageToSend; } + Adapter::session(); +} - JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getProtocolVersion(JNIEnv *env, jobject) - { - return env->NewStringUTF(::get_protocol_version()); - } +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + Adapter::session(pEp::Adapter::release); +} - int examine_identity(pEp_identity *ident, void *arg) - { - locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; - queue->push_back(identity_dup(ident)); - return 0; - } +JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion( + JNIEnv *env, + jobject + ) +{ + pEpLog("called"); + return env->NewStringUTF(::get_engine_version()); +} - pEp_identity *retrieve_next_identity(void *arg) - { - locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; +JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getProtocolVersion( + JNIEnv *env, + jobject + ) +{ + pEpLog("called"); + return env->NewStringUTF(::get_protocol_version()); +} - while (!queue->size()) - usleep(100000); +int examine_identity(pEp_identity *ident, void *arg) +{ + pEpLog("called"); + locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; + queue->push_back(identity_dup(ident)); + return 0; +} + +pEp_identity *retrieve_next_identity(void *arg) +{ + pEpLog("called"); + locked_queue< pEp_identity * > *queue = (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) +{ + pEpLog("called"); + PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg); + locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; + + while (queue->size()) { pEp_identity *ident = queue->front(); queue->pop_front(); - return ident; + free_identity(ident); } - static void *keyserver_thread_routine(void *arg) - { - PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg); - locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; - - while (queue->size()) { - pEp_identity *ident = queue->front(); - queue->pop_front(); - free_identity(ident); - } + delete queue; + return (void *) status; +} - delete queue; - return (void *) status; +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startKeyserverLookup( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + 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; } - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startKeyserverLookup( - JNIEnv *env, - jobject obj - ) - { - pthread_t *thread = nullptr; - locked_queue< pEp_identity * > *queue = nullptr; - - jfieldID thread_handle; - jfieldID queue_handle; + thread = (pthread_t *) env->GetLongField(me, thread_handle); + if (thread) + return; - 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 = (pthread_t *) calloc(1, sizeof(pthread_t)); + assert(thread); + env->SetLongField(me, thread_handle, (jlong) thread); - thread = (pthread_t *) env->GetLongField(obj, thread_handle); - if (thread) - return; + queue = new locked_queue< pEp_identity * >(); + env->SetLongField(me, queue_handle, (jlong) queue); - thread = (pthread_t *) calloc(1, sizeof(pthread_t)); - assert(thread); - env->SetLongField(obj, thread_handle, (jlong) thread); + register_examine_function(Adapter::session(), examine_identity, (void *) queue); - queue = new locked_queue< pEp_identity * >(); - env->SetLongField(obj, queue_handle, (jlong) queue); - - register_examine_function(Adapter::session(), examine_identity, (void *) queue); + pthread_create(thread, nullptr, keyserver_thread_routine, (void *) queue); +} - pthread_create(thread, nullptr, keyserver_thread_routine, (void *) queue); +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopKeyserverLookup( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + 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; } - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopKeyserverLookup( - JNIEnv *env, - jobject obj - ) - { - 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 = (pthread_t *) env->GetLongField(me, thread_handle); + if (!thread) + return; - thread = (pthread_t *) env->GetLongField(obj, thread_handle); - if (!thread) - return; + queue = (locked_queue< pEp_identity * > *) env->GetLongField(me, queue_handle); - queue = (locked_queue< pEp_identity * > *) env->GetLongField(obj, queue_handle); + env->SetLongField(me, queue_handle, (jlong) 0); + env->SetLongField(me, thread_handle, (jlong) 0); - env->SetLongField(obj, queue_handle, (jlong) 0); - env->SetLongField(obj, thread_handle, (jlong) 0); + register_examine_function(Adapter::session(), nullptr, nullptr); - register_examine_function(Adapter::session(), nullptr, nullptr); + queue->push_front(nullptr); + pthread_join(*thread, nullptr); + free(thread); +} - queue->push_front(nullptr); - pthread_join(*thread, nullptr); - free(thread); +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startSync( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + pEpLog("######## starting sync"); + try { + Adapter::startup(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown); } - - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startSync( - JNIEnv *env, - jobject obj - ) - { - debug_log << "######## starting sync\n"; - try { - Adapter::startup(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown); - } - catch (RuntimeError& ex) { - throw_pEp_Exception(env, ex.status); - return; - } + catch (RuntimeError& ex) { + throw_pEp_Exception(env, ex.status); + return; } +} - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopSync( - JNIEnv *env, - jobject obj - ) - { - Adapter::shutdown(); - } +JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopSync( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + Adapter::shutdown(); +} - JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning - (JNIEnv *, jobject) - { - return (jboolean) Adapter::is_sync_running(); - } +JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning( + JNIEnv *env, + jobject me + ) +{ + pEpLog("called"); + return (jboolean) Adapter::is_sync_running(); +} } // extern "C" diff --git a/src/foundation_pEp_jniadapter__Blob.cc b/src/foundation_pEp_jniadapter__Blob.cc index 60c94a0..9669c0a 100644 --- a/src/foundation_pEp_jniadapter__Blob.cc +++ b/src/foundation_pEp_jniadapter__Blob.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -32,9 +33,9 @@ extern "C" { using namespace std; using namespace pEp::JNIAdapter; -JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER - (JNIEnv *env, jobject obj) +JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(JNIEnv *env, jobject obj) { + pEpLog("called"); bloblist_t *b = to_blob(env, obj); char *out = nullptr; diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index ab67f0d..4881b7b 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/gen_cpp_Engine.ysl2 @@ -15,6 +15,7 @@ tstylesheet { #include #include #include + #include #include "foundation_pEp_jniadapter_«@name».h" #include "throw_pEp_exception.hh" #include "jniutils.hh" @@ -49,6 +50,7 @@ tstylesheet { jobject obj`apply "parm[in|inout]", mode=sig` ) { + pEpLog("called"); || apply "parm[in|inout]", mode=in; diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index 8a7c598..d73497a 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/gen_cpp_Message.ysl2 @@ -1,4 +1,5 @@ include yslt.yml2 +include yslt.yml2 tstylesheet { include ./textutils.ysl2 @@ -18,6 +19,7 @@ tstylesheet { #include #include #include + #include #include "jniutils.hh" #include "throw_pEp_exception.hh" @@ -47,8 +49,9 @@ tstylesheet { using namespace pEp::JNIAdapter; - JNIEXPORT jlong JNICALL - Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj) { + JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj) + { + pEpLog("called"); ::«@name» * _obj = ::new_«@name»(PEP_dir_incoming); if (!_obj) { outOfMemory(env); @@ -57,17 +60,18 @@ tstylesheet { return (jlong) (int64_t) (intptr_t) _obj; } - JNIEXPORT void JNICALL - Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value) { + JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value) + { + pEpLog("called"); if (value) { ::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value; ::free_«@name»(_obj); } } - JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»( - JNIEnv *env, jobject msg, jbyteArray mime_text) { - + JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»(JNIEnv *env, jobject msg, jbyteArray mime_text) + { + pEpLog("called"); char *_mime_text = to_string(env, mime_text); size_t _size = (size_t) env->GetArrayLength(mime_text); @@ -80,6 +84,7 @@ tstylesheet { JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env, jobject msg) { + pEpLog("called"); «@name» *_obj = «@name»_ptr(env, msg); char *mime_text = nullptr; PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text); @@ -132,8 +137,9 @@ tstylesheet { with "name", "concat('set', $jname)"; } || - JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL - «$getname»(JNIEnv *env, jobject obj) { + JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env, jobject obj) + { + pEpLog("called"); «$name» *_obj = «$name»_ptr(env, obj); || choose { @@ -145,9 +151,10 @@ tstylesheet { || } - JNIEXPORT void JNICALL - «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) { - «$name» *_obj = «$name»_ptr(env, obj); + JNIEXPORT void JNICALL «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) + { + pEpLog("called"); + «$name» *_obj = «$name»_ptr(env, obj); || choose { when "../enum[@name=$type]" diff --git a/src/identity_api.cc b/src/identity_api.cc index 3b2533e..e11d4ab 100644 --- a/src/identity_api.cc +++ b/src/identity_api.cc @@ -1,14 +1,15 @@ #include - +#include #include "jniutils.hh" extern "C" { -JNIEXPORT jint JNICALL -Java_foundation_pEp_jniadapter_Identity__1getRating(JNIEnv *env, jobject thiz, jint comm_type) { +JNIEXPORT jint JNICALL Java_foundation_pEp_jniadapter_Identity__1getRating(JNIEnv *env, jobject thiz, jint comm_type) +{ + pEpLog("called"); return ::rating_from_comm_type((PEP_comm_type) comm_type); - } + } // extern "C"