Browse Source

ENGINE-133 showHandshake => notifyHandshake

JNI-44
Edouard Tisserant 6 years ago
parent
commit
89509c8287
4 changed files with 51 additions and 16 deletions
  1. +6
    -6
      src/org/pEp/jniadapter/AbstractEngine.java
  2. +2
    -2
      src/org/pEp/jniadapter/Sync.java
  3. +33
    -7
      src/org_pEp_jniadapter_AbstractEngine.cc
  4. +10
    -1
      src/pEp.yml2

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

@ -12,7 +12,7 @@ abstract class AbstractEngine implements AutoCloseable {
private Sync.MessageToSendCallback messageToSendCallback;
private Sync.showHandshakeCallback showHandshakeCallback;
private Sync.notifyHandshakeCallback notifyHandshakeCallback;
private native void init() throws pEpException;
private native void release();
@ -151,16 +151,16 @@ abstract class AbstractEngine implements AutoCloseable {
this.messageToSendCallback = messageToSendCallback;
}
public void setShowHandshakeCallback(Sync.showHandshakeCallback showHandshakeCallback) {
this.showHandshakeCallback = showHandshakeCallback;
public void setnotifyHandshakeCallback(Sync.notifyHandshakeCallback notifyHandshakeCallback) {
this.notifyHandshakeCallback = notifyHandshakeCallback;
}
public int showHandshakeCallFromC(_Identity _myself, _Identity _partner) {
public int notifyHandshakeCallFromC(_Identity _myself, _Identity _partner, SyncHandshakeSignal _signal) {
Identity myself = new Identity(_myself);
Identity partner = new Identity(_partner);
if (showHandshakeCallback != null) {
showHandshakeCallback.showHandshake(myself, partner);
if (notifyHandshakeCallback != null) {
notifyHandshakeCallback.notifyHandshake(myself, partner, _signal);
} else {
throw new RuntimeException("Callback not set");
}


+ 2
- 2
src/org/pEp/jniadapter/Sync.java View File

@ -14,8 +14,8 @@ public interface Sync {
void messageToSend(Message message);
}
interface showHandshakeCallback {
void showHandshake(Identity myself, Identity partner);
interface notifyHandshakeCallback {
void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal);
}
}

+ 33
- 7
src/org_pEp_jniadapter_AbstractEngine.cc View File

@ -199,14 +199,14 @@ extern "C" {
static jobject sync_obj = NULL;
static JNIEnv* sync_env = NULL;
static jmethodID showHandShakeMethodID = NULL;
static jmethodID notifyHandShakeMethodID = NULL;
static jmethodID messageToSendMethodID = NULL;
static jclass messageClass = NULL;
static jclass identityClass = NULL;
static jmethodID messageConstructorMethodID = NULL;
// Called by sync thread only
PEP_STATUS show_handshake(void *obj, pEp_identity *me, pEp_identity *partner)
PEP_STATUS notify_handshake(void *obj, pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
{
jobject me_ = NULL;
jobject partner_ = NULL;
@ -214,7 +214,33 @@ extern "C" {
me_ = from_identity(sync_env, me, identityClass);
partner_ = from_identity(sync_env, partner, identityClass);
jint result = sync_env->CallIntMethod(sync_obj, showHandShakeMethodID, me_, partner_);
jobject signal_ = NULL;
{
jclass clazz_signal = findClass(sync_env, "org/pEp/jniadapter/SyncHandshakeSignal");
assert(clazz_signal);
jmethodID method_values = sync_env->GetStaticMethodID(clazz_signal, "values",
"()[Lorg/pEp/jniadapter/SyncHandshakeSignal;");
assert(method_values);
jfieldID field_value = sync_env->GetFieldID(clazz_signal, "value", "I");
assert(field_value);
jobjectArray values = (jobjectArray) sync_env->CallStaticObjectMethod(clazz_signal,
method_values);
assert(values);
jsize values_size = sync_env->GetArrayLength(values);
for (jsize i = 0; i < values_size; i++) {
jobject element = sync_env->GetObjectArrayElement(values, i);
assert(element);
jint value = sync_env->GetIntField(element, field_value);
if (value == (jint) signal) {
signal_ = element;
break;
}
}
}
jint result = sync_env->CallIntMethod(sync_obj, notifyHandShakeMethodID, me_, partner_, signal_);
return (PEP_STATUS) result;
}
@ -286,11 +312,11 @@ extern "C" {
jclass clazz = sync_env->GetObjectClass(sync_obj);
showHandShakeMethodID = sync_env->GetMethodID(
notifyHandShakeMethodID = sync_env->GetMethodID(
clazz,
"showHandshakeCallFromC",
"notifyHandshakeCallFromC",
"(Lorg/pEp/jniadapter/_Identity;Lorg/pEp/jniadapter/_Identity;)I");
assert(showHandShakeMethodID);
assert(notifyHandShakeMethodID);
messageToSendMethodID = sync_env->GetMethodID(
clazz,
@ -372,7 +398,7 @@ extern "C" {
register_sync_callbacks(session,
(void *) queue,
message_to_send,
show_handshake,
notify_handshake,
inject_sync_msg,
retrieve_next_sync_msg);


+ 10
- 1
src/pEp.yml2 View File

@ -53,7 +53,7 @@ namespace pEp {
pEp_contraints_violated                         > 0x0802
pEp_cannot_encode                               > 0x0803
pEp_sync_no_trustwords_callback                 > 0x0901
pEp_sync_no_notify_callback                  > 0x0901
pEp_sync_illegal_message                        > 0x0902
pEp_sync_no_inject_callback                     > 0x0903
@ -124,6 +124,15 @@ namespace pEp {
sync_handshake_rejected > 1
};
enum SyncHandshakeSignal {
sync_handshake_dismiss_dialog > 0
sync_handshake_show_dialog > 1
sync_handshake_success > 2
sync_handshake_failure > 3
sync_device_added > 4
sync_group_created > 5
};
interface Engine {
method encrypt_message(
in message src,


Loading…
Cancel
Save