Browse Source

Added Logging of every c/c++ function call (in DEBUG build only)

resolved possible var name ambiguity
corrected some formatting inconsistencies
JNI-92
heck 5 years ago
parent
commit
25a07dcfde
  1. 15
      src/basic_api.cc
  2. 556
      src/foundation_pEp_jniadapter_AbstractEngine.cc
  3. 5
      src/foundation_pEp_jniadapter__Blob.cc
  4. 2
      src/gen_cpp_Engine.ysl2
  5. 29
      src/gen_cpp_Message.ysl2
  6. 9
      src/identity_api.cc

15
src/basic_api.cc

@ -20,6 +20,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine_trustwords(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
char *words; char *words;
size_t wsize; size_t wsize;
@ -57,6 +58,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_myself(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
PEP_STATUS status = ::myself(session(), _ident); PEP_STATUS status = ::myself(session(), _ident);
@ -75,6 +77,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_updateIdentity(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
::update_identity(session(), _ident); ::update_identity(session(), _ident);
@ -89,6 +92,7 @@ JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_setOwnKey(
jbyteArray fpr jbyteArray fpr
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
char *_fpr = to_string(env, fpr); char *_fpr = to_string(env, fpr);
@ -109,6 +113,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_keyMistrusted(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
@ -132,6 +137,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_keyResetTrust(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
@ -155,6 +161,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_trustPersonalKey(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
@ -178,6 +185,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_trustOwnKey(
jobject ident jobject ident
) )
{ {
pEpLog("called");
pEp_identity *_ident = to_identity(env, ident); pEp_identity *_ident = to_identity(env, ident);
if (_ident->fpr == NULL || _ident->fpr[0] == 0) { if (_ident->fpr == NULL || _ident->fpr[0] == 0) {
@ -194,6 +202,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_importKey(
jbyteArray key jbyteArray key
) )
{ {
pEpLog("called");
size_t _size = (size_t) env->GetArrayLength(key); size_t _size = (size_t) env->GetArrayLength(key);
char *_key = (char *) env->GetByteArrayElements(key, NULL); char *_key = (char *) env->GetByteArrayElements(key, NULL);
@ -217,6 +226,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_config_1passive_1mo
jboolean enable jboolean enable
) )
{ {
pEpLog("called");
::config_passive_mode(session(), (bool)enable); ::config_passive_mode(session(), (bool)enable);
} }
@ -227,6 +237,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_config_1unencrypted
jboolean enable jboolean enable
) )
{ {
pEpLog("called");
::config_unencrypted_subject(session(), (bool)enable); ::config_unencrypted_subject(session(), (bool)enable);
} }
@ -236,6 +247,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1add(
jbyteArray fpr jbyteArray fpr
) )
{ {
pEpLog("called");
char *_fpr = to_string(env, fpr); char *_fpr = to_string(env, fpr);
if(_fpr == NULL){ if(_fpr == NULL){
@ -257,6 +269,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1delete(
jbyteArray fpr jbyteArray fpr
) )
{ {
pEpLog("called");
char *_fpr = to_string(env, fpr); char *_fpr = to_string(env, fpr);
if(_fpr == NULL){ if(_fpr == NULL){
@ -278,6 +291,7 @@ JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine_blacklist_1is_1
jbyteArray fpr jbyteArray fpr
) )
{ {
pEpLog("called");
char *_fpr = to_string(env, fpr); char *_fpr = to_string(env, fpr);
bool _listed = 0; bool _listed = 0;
@ -302,6 +316,7 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine_getCrashdumpL
jint maxlines jint maxlines
) )
{ {
pEpLog("called");
int _maxlines = (int) maxlines; int _maxlines = (int) maxlines;
char *_logdata; char *_logdata;

556
src/foundation_pEp_jniadapter_AbstractEngine.cc

@ -1,17 +1,4 @@
#include "foundation_pEp_jniadapter_AbstractEngine.h" #include "foundation_pEp_jniadapter_AbstractEngine.h"
#ifndef NDEBUG
#include <iostream>
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 <stdexcept> #include <stdexcept>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
@ -20,333 +7,360 @@ static struct _debug_log {
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/Adapter.hh> #include <pEp/Adapter.hh>
#include <pEp/utils.hh>
#include "throw_pEp_exception.hh" #include "throw_pEp_exception.hh"
#include "jniutils.hh" #include "jniutils.hh"
namespace pEp { namespace pEp {
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
using namespace utility; 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; jfieldID field_value = nullptr;
jmethodID messageConstructorMethodID = nullptr; jmethodID messageConstructorMethodID = nullptr;
jmethodID messageToSendMethodID = nullptr; jmethodID messageToSendMethodID = nullptr;
jmethodID notifyHandShakeMethodID = nullptr; jmethodID notifyHandShakeMethodID = nullptr;
jmethodID needsFastPollMethodID = nullptr; jmethodID needsFastPollMethodID = nullptr;
jmethodID method_values = nullptr; jmethodID method_values = nullptr;
jobject obj = nullptr; jobject obj = nullptr;
jclass messageClass = nullptr; jclass messageClass = nullptr;
jclass identityClass = nullptr;; jclass identityClass = nullptr;;
jclass signalClass = nullptr; jclass signalClass = nullptr;
jclass engineClass = nullptr; jclass engineClass = nullptr;
class JNISync { class JNISync {
public: public:
JNIEnv * env() JNIEnv * env()
{ {
JNIEnv *thread_env = nullptr; pEpLog("called");
int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6); JNIEnv *thread_env = nullptr;
if (status < 0) { int status = jvm->GetEnv((void**)&thread_env, JNI_VERSION_1_6);
if (status < 0) {
#ifdef ANDROID #ifdef ANDROID
status = jvm->AttachCurrentThread(&thread_env, nullptr); status = jvm->AttachCurrentThread(&thread_env, nullptr);
#else #else
status = jvm->AttachCurrentThread((void **) &thread_env, nullptr); status = jvm->AttachCurrentThread((void **) &thread_env, nullptr);
#endif #endif
}
assert(status >= 0);
return thread_env;
}
void onSyncStartup()
{
env();
}
void onSyncShutdown()
{
jvm->DetachCurrentThread();
} }
} o; assert(status >= 0);
return thread_env;
void jni_init() {
JNIEnv *_env = o.env();
messageClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message")));
identityClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity")));
signalClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal")));
engineClass = reinterpret_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine")));
messageConstructorMethodID = _env->GetMethodID(messageClass, "<init>", "(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");
} }
PEP_STATUS messageToSend(message *msg) void onSyncStartup()
{ {
std::lock_guard<std::mutex> l(mutex_obj); pEpLog("called");
env();
}
debug_log << "\n############### messageToSend() called\n"; void onSyncShutdown()
jobject msg_ = nullptr; {
pEpLog("called");
jvm->DetachCurrentThread();
}
} o;
void jni_init() {
pEpLog("called");
JNIEnv *_env = o.env();
messageClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Message")));
identityClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/_Identity")));
signalClass = reinterpret_cast<jclass>(
_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/SyncHandshakeSignal")));
engineClass = reinterpret_cast<jclass>(_env->NewGlobalRef(findClass(_env, "foundation/pEp/jniadapter/Engine")));
messageConstructorMethodID = _env->GetMethodID(messageClass, "<init>", "(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<std::mutex> 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_); assert(messageClass && messageConstructorMethodID && obj && messageToSendMethodID);
if (o.env()->ExceptionCheck()) {
o.env()->ExceptionDescribe();
status = PEP_UNKNOWN_ERROR;
o.env()->ExceptionClear();
}
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<std::mutex> 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); return status;
for (jsize i = 0; i < values_size; i++) { }
jobject element = o.env()->GetObjectArrayElement(values, i);
assert(element); PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
jint value = o.env()->GetIntField(element, field_value); {
if (value == (jint) signal) { pEpLog("called");
signal_ = element; std::lock_guard<std::mutex> l(mutex_obj);
break;
}
o.env() -> DeleteLocalRef(element);
}
}
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()) { if (o.env()->ExceptionCheck()) {
o.env()->ExceptionClear(); o.env()->ExceptionClear();
return PEP_UNKNOWN_ERROR; 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" { assert(obj && notifyHandShakeMethodID);
using namespace pEp;
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init( PEP_STATUS status = (PEP_STATUS) o.env()->CallIntMethod(obj, notifyHandShakeMethodID, me_, partner_, signal_);
JNIEnv *env, if (o.env()->ExceptionCheck()) {
jobject me o.env()->ExceptionClear();
) return PEP_UNKNOWN_ERROR;
{
if (first) {
first = false;
env->GetJavaVM(&jvm);
jni_init();
obj = env->NewGlobalRef(me);
Adapter::_messageToSend = messageToSend;
}
Adapter::session();
} }
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release( return status;
JNIEnv *env, }
jobject me }
)
{
Adapter::session(pEp::Adapter::release);
}
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion(JNIEnv *env, jobject) extern "C" {
{ using namespace pEp;
return env->NewStringUTF(::get_engine_version());
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) JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(
{ JNIEnv *env,
return env->NewStringUTF(::get_protocol_version()); jobject me
} )
{
pEpLog("called");
Adapter::session(pEp::Adapter::release);
}
int examine_identity(pEp_identity *ident, void *arg) JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion(
{ JNIEnv *env,
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; jobject
queue->push_back(identity_dup(ident)); )
return 0; {
} pEpLog("called");
return env->NewStringUTF(::get_engine_version());
}
pEp_identity *retrieve_next_identity(void *arg) JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getProtocolVersion(
{ JNIEnv *env,
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg; jobject
)
{
pEpLog("called");
return env->NewStringUTF(::get_protocol_version());
}
while (!queue->size()) int examine_identity(pEp_identity *ident, void *arg)
usleep(100000); {
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(); pEp_identity *ident = queue->front();
queue->pop_front(); queue->pop_front();
return ident; free_identity(ident);
} }
static void *keyserver_thread_routine(void *arg) delete queue;
{ return (void *) status;
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; JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startKeyserverLookup(
return (void *) status; 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( thread = (pthread_t *) env->GetLongField(me, thread_handle);
JNIEnv *env, if (thread)
jobject obj return;
)
{
pthread_t *thread = nullptr;
locked_queue< pEp_identity * > *queue = nullptr;
jfieldID thread_handle;
jfieldID queue_handle;
try { thread = (pthread_t *) calloc(1, sizeof(pthread_t));
thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J"); assert(thread);
queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J"); env->SetLongField(me, thread_handle, (jlong) thread);
}
catch (std::exception& ex) {
assert(0);
return;
}
thread = (pthread_t *) env->GetLongField(obj, thread_handle); queue = new locked_queue< pEp_identity * >();
if (thread) env->SetLongField(me, queue_handle, (jlong) queue);
return;
thread = (pthread_t *) calloc(1, sizeof(pthread_t)); register_examine_function(Adapter::session(), examine_identity, (void *) queue);
assert(thread);
env->SetLongField(obj, thread_handle, (jlong) thread);
queue = new locked_queue< pEp_identity * >(); pthread_create(thread, nullptr, keyserver_thread_routine, (void *) queue);
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); 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( thread = (pthread_t *) env->GetLongField(me, thread_handle);
JNIEnv *env, if (!thread)
jobject obj return;
)
{
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(obj, thread_handle); queue = (locked_queue< pEp_identity * > *) env->GetLongField(me, queue_handle);
if (!thread)
return;
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); register_examine_function(Adapter::session(), nullptr, nullptr);
env->SetLongField(obj, thread_handle, (jlong) 0);
register_examine_function(Adapter::session(), nullptr, nullptr); queue->push_front(nullptr);
pthread_join(*thread, nullptr);
free(thread);
}
queue->push_front(nullptr); JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startSync(
pthread_join(*thread, nullptr); JNIEnv *env,
free(thread); jobject me
)
{
pEpLog("called");
pEpLog("######## starting sync");
try {
Adapter::startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown);
} }
catch (RuntimeError& ex) {
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startSync( throw_pEp_Exception(env, ex.status);
JNIEnv *env, return;
jobject obj
)
{
debug_log << "######## starting sync\n";
try {
Adapter::startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown);
}
catch (RuntimeError& ex) {
throw_pEp_Exception(env, ex.status);
return;
}
} }
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopSync( JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopSync(
JNIEnv *env, JNIEnv *env,
jobject obj jobject me
) )
{ {
Adapter::shutdown(); pEpLog("called");
} Adapter::shutdown();
}
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning(
(JNIEnv *, jobject) JNIEnv *env,
{ jobject me
return (jboolean) Adapter::is_sync_running(); )
} {
pEpLog("called");
return (jboolean) Adapter::is_sync_running();
}
} // extern "C" } // extern "C"

5
src/foundation_pEp_jniadapter__Blob.cc

@ -1,6 +1,7 @@
#include <pEp/bloblist.h> #include <pEp/bloblist.h>
#include <pEp/sync_codec.h> #include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h> #include <pEp/distribution_codec.h>
#include <pEp/utils.hh>
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
@ -32,9 +33,9 @@ extern "C" {
using namespace std; using namespace std;
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter__1Blob__1dataToXER(JNIEnv *env, jobject obj)
(JNIEnv *env, jobject obj)
{ {
pEpLog("called");
bloblist_t *b = to_blob(env, obj); bloblist_t *b = to_blob(env, obj);
char *out = nullptr; char *out = nullptr;

2
src/gen_cpp_Engine.ysl2

@ -15,6 +15,7 @@ tstylesheet {
#include <pEp/openpgp_compat.h> #include <pEp/openpgp_compat.h>
#include <pEp/key_reset.h> #include <pEp/key_reset.h>
#include <pEp/Adapter.hh> #include <pEp/Adapter.hh>
#include <pEp/utils.hh>
#include "foundation_pEp_jniadapter_«@name».h" #include "foundation_pEp_jniadapter_«@name».h"
#include "throw_pEp_exception.hh" #include "throw_pEp_exception.hh"
#include "jniutils.hh" #include "jniutils.hh"
@ -49,6 +50,7 @@ tstylesheet {
jobject obj`apply "parm[in|inout]", mode=sig` jobject obj`apply "parm[in|inout]", mode=sig`
) )
{ {
pEpLog("called");
|| ||
apply "parm[in|inout]", mode=in; apply "parm[in|inout]", mode=in;

29
src/gen_cpp_Message.ysl2

@ -1,4 +1,5 @@
include yslt.yml2 include yslt.yml2
include yslt.yml2
tstylesheet { tstylesheet {
include ./textutils.ysl2 include ./textutils.ysl2
@ -18,6 +19,7 @@ tstylesheet {
#include <assert.h> #include <assert.h>
#include <pEp/«@name».h> #include <pEp/«@name».h>
#include <pEp/mime.h> #include <pEp/mime.h>
#include <pEp/utils.hh>
#include "jniutils.hh" #include "jniutils.hh"
#include "throw_pEp_exception.hh" #include "throw_pEp_exception.hh"
@ -47,8 +49,9 @@ tstylesheet {
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj)
Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj) { {
pEpLog("called");
::«@name» * _obj = ::new_«@name»(PEP_dir_incoming); ::«@name» * _obj = ::new_«@name»(PEP_dir_incoming);
if (!_obj) { if (!_obj) {
outOfMemory(env); outOfMemory(env);
@ -57,17 +60,18 @@ tstylesheet {
return (jlong) (int64_t) (intptr_t) _obj; return (jlong) (int64_t) (intptr_t) _obj;
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value)
Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value) { {
pEpLog("called");
if (value) { if (value) {
::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value; ::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value;
::free_«@name»(_obj); ::free_«@name»(_obj);
} }
} }
JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»( JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»(JNIEnv *env, jobject msg, jbyteArray mime_text)
JNIEnv *env, jobject msg, jbyteArray mime_text) { {
pEpLog("called");
char *_mime_text = to_string(env, mime_text); char *_mime_text = to_string(env, mime_text);
size_t _size = (size_t) env->GetArrayLength(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) JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env, jobject msg)
{ {
pEpLog("called");
«@name» *_obj = «@name»_ptr(env, msg); «@name» *_obj = «@name»_ptr(env, msg);
char *mime_text = nullptr; char *mime_text = nullptr;
PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text); PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text);
@ -132,8 +137,9 @@ tstylesheet {
with "name", "concat('set', $jname)"; with "name", "concat('set', $jname)";
} }
|| ||
JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env, jobject obj)
«$getname»(JNIEnv *env, jobject obj) { {
pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj); «$name» *_obj = «$name»_ptr(env, obj);
|| ||
choose { choose {
@ -145,8 +151,9 @@ tstylesheet {
|| ||
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value)
«$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) { {
pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj); «$name» *_obj = «$name»_ptr(env, obj);
|| ||
choose { choose {

9
src/identity_api.cc

@ -1,14 +1,15 @@
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/utils.hh>
#include "jniutils.hh" #include "jniutils.hh"
extern "C" { extern "C" {
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL Java_foundation_pEp_jniadapter_Identity__1getRating(JNIEnv *env, jobject thiz, jint comm_type)
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); return ::rating_from_comm_type((PEP_comm_type) comm_type);
} }
} // extern "C" } // extern "C"

Loading…
Cancel
Save