Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Operation Progress Listener #1787

Merged
merged 4 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/java/JavaHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

using namespace mailcore;

static jfieldID getField(JNIEnv * env, jobject obj, const char * fieldName)
static jfieldID getField(JNIEnv * env, jobject obj, const char * fieldName, const char * fieldClass)
{
jclass c = env->GetObjectClass(obj);
return env->GetFieldID(c, fieldName, "J");
return env->GetFieldID(c, fieldName, fieldClass);
}

static jfieldID getHandleField(JNIEnv * env, jobject obj)
{
return getField(env, obj, "nativeHandle");
return getField(env, obj, "nativeHandle", "J");
}

void * mailcore::getHandle(JNIEnv * env, jobject obj)
Expand All @@ -27,17 +27,17 @@ void mailcore::setHandle(JNIEnv *env, jobject obj, void *t)

void * mailcore::getCustomHandle(JNIEnv * env, jobject obj, const char * fieldName)
{
jlong handle = env->GetLongField(obj, getField(env, obj, fieldName));
jlong handle = env->GetLongField(obj, getField(env, obj, fieldName, "J"));
return (void *) handle;
}

void mailcore::setCustomHandle(JNIEnv *env, jobject obj, const char * fieldName, void *t)
{
jlong handle = reinterpret_cast<jlong>(t);
env->SetLongField(obj, getField(env, obj, fieldName), handle);
env->SetLongField(obj, getField(env, obj, fieldName, "J"), handle);
}

jobject mailcore::getObjectField(JNIEnv *env, jobject obj, const char * fieldName)
jobject mailcore::getObjectField(JNIEnv *env, jobject obj, const char * fieldName, const char * fieldClass)
{
return env->GetObjectField(obj, getField(env, obj, fieldName));
return env->GetObjectField(obj, getField(env, obj, fieldName, fieldClass));
}
2 changes: 1 addition & 1 deletion src/java/JavaHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace mailcore {
void setHandle(JNIEnv * env, jobject obj, void * t);
void * getCustomHandle(JNIEnv * env, jobject obj, const char * fieldName);
void setCustomHandle(JNIEnv *env, jobject obj, const char * fieldName, void *t);
jobject getObjectField(JNIEnv *env, jobject obj, const char * fieldName);
jobject getObjectField(JNIEnv *env, jobject obj, const char * fieldName, const char * fieldClass);
}

#endif
4 changes: 2 additions & 2 deletions src/java/JavaIMAPOperationCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void JavaIMAPOperationCallback::bodyProgress(IMAPOperation * session, unsigned i
JNIEnv * env = mEnv;
jclass cls = mEnv->GetObjectClass(mListener);
jmethodID mid = mEnv->GetMethodID(cls, "bodyProgress", "(JJ)V");
mEnv->CallVoidMethod(mListener, mid);
mEnv->CallVoidMethod(mListener, mid, (jlong) current, (jlong) maximum);
}

void JavaIMAPOperationCallback::itemProgress(IMAPOperation * session, unsigned int current, unsigned int maximum)
Expand All @@ -41,5 +41,5 @@ void JavaIMAPOperationCallback::itemProgress(IMAPOperation * session, unsigned i
JNIEnv * env = mEnv;
jclass cls = mEnv->GetObjectClass(mListener);
jmethodID mid = mEnv->GetMethodID(cls, "itemProgress", "(JJ)V");
mEnv->CallVoidMethod(mListener, mid);
mEnv->CallVoidMethod(mListener, mid, (jlong) current, (jlong) maximum);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPAppendMessageOperation_setupNati
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(NULL);

jobject javaListener = getObjectField(env, obj, "listener");
jobject javaListener = getObjectField(env, obj, "listener", "J");
if (javaListener != NULL) {
callback = new JavaIMAPOperationCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(callback);
Expand Down
5 changes: 3 additions & 2 deletions src/java/native/com_libmailcore_IMAPFetchContentOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPFetchContentOperation_setupNativ
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(NULL);

jobject javaListener = getObjectField(env, obj, "listener");
jobject javaListener = getObjectField(env, obj, "listener", "Lcom/libmailcore/IMAPOperationProgressListener;");
if (javaListener != NULL) {
callback = new JavaIMAPOperationCallback(env, javaListener);
jobject c = reinterpret_cast<jobject>(env->NewGlobalRef(javaListener));
callback = new JavaIMAPOperationCallback(env, c);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(callback);
}
MC_POOL_END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPFetchMessagesOperation_setupNati
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(NULL);

jobject javaListener = getObjectField(env, obj, "listener");
jobject javaListener = getObjectField(env, obj, "listener", "J");
if (javaListener != NULL) {
callback = new JavaIMAPOperationCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPFetchParsedContentOperation_setu
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(NULL);

jobject javaListener = getObjectField(env, obj, "listener");
jobject javaListener = getObjectField(env, obj, "listener", "J");
if (javaListener != NULL) {
callback = new JavaIMAPOperationCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setImapCallback(callback);
Expand Down
4 changes: 2 additions & 2 deletions src/java/native/com_libmailcore_IMAPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPSession_setupNativeOperationQueu
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(NULL);

jobject javaListener = getObjectField(env, obj, "operationQueueListener");
jobject javaListener = getObjectField(env, obj, "operationQueueListener", "J");
if (javaListener != NULL) {
callback = new JavaOperationQueueCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(callback);
Expand All @@ -495,7 +495,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_IMAPSession_setupNativeConnectionLog
MC_SAFE_RELEASE(logger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(NULL);

jobject javaLogger = getObjectField(env, obj, "connectionLogger");
jobject javaLogger = getObjectField(env, obj, "connectionLogger", "J");
if (javaLogger != NULL) {
logger = new JavaConnectionLogger(env, javaLogger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(logger);
Expand Down
4 changes: 2 additions & 2 deletions src/java/native/com_libmailcore_NNTPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_NNTPSession_setupNativeOperationQueu
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(NULL);

jobject javaListener = getObjectField(env, obj, "operationQueueListener");
jobject javaListener = getObjectField(env, obj, "operationQueueListener", "J");
if (javaListener != NULL) {
callback = new JavaOperationQueueCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(callback);
Expand All @@ -165,7 +165,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_NNTPSession_setupNativeConnectionLog
MC_SAFE_RELEASE(logger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(NULL);

jobject javaLogger = getObjectField(env, obj, "connectionLogger");
jobject javaLogger = getObjectField(env, obj, "connectionLogger", "J");
if (javaLogger != NULL) {
logger = new JavaConnectionLogger(env, javaLogger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(logger);
Expand Down
4 changes: 2 additions & 2 deletions src/java/native/com_libmailcore_POPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_POPSession_setupNativeOperationQueue
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(NULL);

jobject javaListener = getObjectField(env, obj, "operationQueueListener");
jobject javaListener = getObjectField(env, obj, "operationQueueListener", "J");
if (javaListener != NULL) {
callback = new JavaOperationQueueCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(callback);
Expand All @@ -139,7 +139,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_POPSession_setupNativeConnectionLogg
MC_SAFE_RELEASE(logger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(NULL);

jobject javaLogger = getObjectField(env, obj, "connectionLogger");
jobject javaLogger = getObjectField(env, obj, "connectionLogger", "J");
if (javaLogger != NULL) {
logger = new JavaConnectionLogger(env, javaLogger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(logger);
Expand Down
4 changes: 2 additions & 2 deletions src/java/native/com_libmailcore_SMTPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_SMTPSession_setupNativeOperationQueu
MC_SAFE_RELEASE(callback);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(NULL);

jobject javaListener = getObjectField(env, obj, "operationQueueListener");
jobject javaListener = getObjectField(env, obj, "operationQueueListener", "J");
if (javaListener != NULL) {
callback = new JavaOperationQueueCallback(env, javaListener);
MC_JAVA_NATIVE_INSTANCE->setOperationQueueCallback(callback);
Expand All @@ -123,7 +123,7 @@ JNIEXPORT void JNICALL Java_com_libmailcore_SMTPSession_setupNativeConnectionLog
MC_SAFE_RELEASE(logger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(NULL);

jobject javaLogger = getObjectField(env, obj, "connectionLogger");
jobject javaLogger = getObjectField(env, obj, "connectionLogger", "J");
if (javaLogger != NULL) {
logger = new JavaConnectionLogger(env, javaLogger);
MC_JAVA_NATIVE_INSTANCE->setConnectionLogger(logger);
Expand Down