Browse Source

Added NeedsFastPollCallback

JNI-44
Edouard Tisserant 9 years ago
parent
commit
dd1de5b4ca
  1. 9
      src/org/pEp/jniadapter/AbstractEngine.java
  2. 5
      src/org/pEp/jniadapter/Sync.java
  3. 11
      src/org_pEp_jniadapter_AbstractEngine.cc

9
src/org/pEp/jniadapter/AbstractEngine.java

@ -155,6 +155,15 @@ abstract class AbstractEngine implements AutoCloseable {
this.notifyHandshakeCallback = notifyHandshakeCallback;
}
public int needsFastPollCallFromC(Boolean fast_poll_needed) {
if (needsFastPollCallback != null) {
needsFastPollCallback.needsFastPoll(fast_poll_needed);
} else {
throw new RuntimeException("Callback not set");
}
return 0;
}
public int notifyHandshakeCallFromC(_Identity _myself, _Identity _partner, SyncHandshakeSignal _signal) {
Identity myself = new Identity(_myself);
Identity partner = new Identity(_partner);

5
src/org/pEp/jniadapter/Sync.java

@ -10,6 +10,11 @@ import org.pEp.jniadapter.pEpException;
public interface Sync {
interface NeedsFastPollCallback {
void needsFastPollCallFromC(Boolean fast_poll_needed);
}
interface MessageToSendCallback {
void messageToSend(Message message);
}

11
src/org_pEp_jniadapter_AbstractEngine.cc

@ -199,6 +199,7 @@ extern "C" {
static jobject sync_obj = NULL;
static JNIEnv* sync_env = NULL;
static jmethodID needsFastPollMethodID = NULL;
static jmethodID notifyHandShakeMethodID = NULL;
static jmethodID messageToSendMethodID = NULL;
static jclass messageClass = NULL;
@ -276,11 +277,15 @@ extern "C" {
time_t now, end;
void *msg;
jboolean needs_fast_poll = (timeout != NULL);
if(timeout && *timeout != 0){
now = time(NULL);
end = now + *timeout;
}
sync_env->CallVoidMethod(sync_obj, needsFastPollMethodID, needs_fast_poll);
while (!queue->size()){
// TODO: add blocking dequeue
usleep(100000);
@ -312,6 +317,12 @@ extern "C" {
jclass clazz = sync_env->GetObjectClass(sync_obj);
needsFastPollMethodID = sync_env->GetMethodID(
clazz,
"needsFastPollCallFromC",
"(Z)I");
assert(needsFastPollMethodID);
notifyHandShakeMethodID = sync_env->GetMethodID(
clazz,
"notifyHandshakeCallFromC",

Loading…
Cancel
Save