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. 200
      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
)
{
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;

200
src/foundation_pEp_jniadapter_AbstractEngine.cc

@ -1,17 +1,4 @@
#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 <unistd.h>
#include <assert.h>
@ -20,38 +7,39 @@ static struct _debug_log {
#include <pEp/message_api.h>
#include <pEp/sync_api.h>
#include <pEp/Adapter.hh>
#include <pEp/utils.hh>
#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:
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) {
@ -67,16 +55,19 @@ namespace pEp {
void onSyncStartup()
{
pEpLog("called");
env();
}
void onSyncShutdown()
{
pEpLog("called");
jvm->DetachCurrentThread();
}
} o;
} o;
void jni_init() {
void jni_init() {
pEpLog("called");
JNIEnv *_env = o.env();
messageClass = reinterpret_cast<jclass>(
@ -104,13 +95,14 @@ namespace pEp {
method_values = o.env()->GetStaticMethodID(signalClass, "values",
"()[Lfoundation/pEp/jniadapter/SyncHandshakeSignal;");
field_value = o.env()->GetFieldID(signalClass, "value", "I");
}
}
PEP_STATUS messageToSend(message *msg)
{
PEP_STATUS messageToSend(message *msg)
{
pEpLog("called");
std::lock_guard<std::mutex> l(mutex_obj);
debug_log << "\n############### messageToSend() called\n";
pEpLog("############### messageToSend() called");
jobject msg_ = nullptr;
assert(messageClass && messageConstructorMethodID && obj && messageToSendMethodID);
@ -126,13 +118,14 @@ namespace pEp {
return status;
}
}
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
{
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
{
pEpLog("called");
std::lock_guard<std::mutex> l(mutex_obj);
debug_log << "\n############### notifyHandshake() called\n";
pEpLog("############### notifyHandshake() called");
jobject me_ = nullptr;
jobject partner_ = nullptr;
@ -174,18 +167,20 @@ namespace pEp {
}
return status;
}
}
}
extern "C" {
using namespace pEp;
using namespace pEp;
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init(
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();
@ -193,35 +188,46 @@ extern "C" {
Adapter::_messageToSend = messageToSend;
}
Adapter::session();
}
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(
JNIEnv *env,
jobject me
)
{
{
pEpLog("called");
Adapter::session(pEp::Adapter::release);
}
}
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion(JNIEnv *env, jobject)
{
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getVersion(
JNIEnv *env,
jobject
)
{
pEpLog("called");
return env->NewStringUTF(::get_engine_version());
}
}
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getProtocolVersion(JNIEnv *env, jobject)
{
JNIEXPORT jstring JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_getProtocolVersion(
JNIEnv *env,
jobject
)
{
pEpLog("called");
return env->NewStringUTF(::get_protocol_version());
}
}
int examine_identity(pEp_identity *ident, void *arg)
{
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)
{
pEp_identity *retrieve_next_identity(void *arg)
{
pEpLog("called");
locked_queue< pEp_identity * > *queue = (locked_queue< pEp_identity * > *) arg;
while (!queue->size())
@ -230,10 +236,11 @@ extern "C" {
pEp_identity *ident = queue->front();
queue->pop_front();
return ident;
}
}
static void *keyserver_thread_routine(void *arg)
{
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;
@ -245,13 +252,14 @@ extern "C" {
delete queue;
return (void *) status;
}
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startKeyserverLookup(
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startKeyserverLookup(
JNIEnv *env,
jobject obj
jobject me
)
{
{
pEpLog("called");
pthread_t *thread = nullptr;
locked_queue< pEp_identity * > *queue = nullptr;
@ -267,27 +275,28 @@ extern "C" {
return;
}
thread = (pthread_t *) env->GetLongField(obj, thread_handle);
thread = (pthread_t *) env->GetLongField(me, thread_handle);
if (thread)
return;
thread = (pthread_t *) calloc(1, sizeof(pthread_t));
assert(thread);
env->SetLongField(obj, thread_handle, (jlong) thread);
env->SetLongField(me, thread_handle, (jlong) thread);
queue = new locked_queue< pEp_identity * >();
env->SetLongField(obj, queue_handle, (jlong) queue);
env->SetLongField(me, 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(
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_stopKeyserverLookup(
JNIEnv *env,
jobject obj
jobject me
)
{
{
pEpLog("called");
pthread_t *thread = nullptr;
locked_queue< pEp_identity * > *queue = nullptr;
@ -303,28 +312,29 @@ extern "C" {
return;
}
thread = (pthread_t *) env->GetLongField(obj, thread_handle);
thread = (pthread_t *) env->GetLongField(me, thread_handle);
if (!thread)
return;
queue = (locked_queue< pEp_identity * > *) env->GetLongField(obj, queue_handle);
queue = (locked_queue< pEp_identity * > *) env->GetLongField(me, queue_handle);
env->SetLongField(obj, queue_handle, (jlong) 0);
env->SetLongField(obj, thread_handle, (jlong) 0);
env->SetLongField(me, queue_handle, (jlong) 0);
env->SetLongField(me, thread_handle, (jlong) 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_startSync(
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_startSync(
JNIEnv *env,
jobject obj
jobject me
)
{
debug_log << "######## starting sync\n";
{
pEpLog("called");
pEpLog("######## starting sync");
try {
Adapter::startup<JNISync>(messageToSend, notifyHandshake, &o, &JNISync::onSyncStartup, &JNISync::onSyncShutdown);
}
@ -332,21 +342,25 @@ extern "C" {
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,
jobject obj
jobject me
)
{
{
pEpLog("called");
Adapter::shutdown();
}
}
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning
(JNIEnv *, jobject)
{
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_isSyncRunning(
JNIEnv *env,
jobject me
)
{
pEpLog("called");
return (jboolean) Adapter::is_sync_running();
}
}
} // extern "C"

5
src/foundation_pEp_jniadapter__Blob.cc

@ -1,6 +1,7 @@
#include <pEp/bloblist.h>
#include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h>
#include <pEp/utils.hh>
#include <iostream>
#include <cstring>
#include <cassert>
@ -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;

2
src/gen_cpp_Engine.ysl2

@ -15,6 +15,7 @@ tstylesheet {
#include <pEp/openpgp_compat.h>
#include <pEp/key_reset.h>
#include <pEp/Adapter.hh>
#include <pEp/utils.hh>
#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;

29
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 <assert.h>
#include <pEp/«@name».h>
#include <pEp/mime.h>
#include <pEp/utils.hh>
#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,8 +151,9 @@ tstylesheet {
||
}
JNIEXPORT void JNICALL
«$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) {
JNIEXPORT void JNICALL «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value)
{
pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj);
||
choose {

9
src/identity_api.cc

@ -1,14 +1,15 @@
#include <pEp/message_api.h>
#include <pEp/utils.hh>
#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"

Loading…
Cancel
Save