[sword-svn] r3229 - in trunk: bindings/java-jni/jni bindings/java-jni/src/org/crosswire/android/sword src/mgr
scribe at crosswire.org
scribe at crosswire.org
Fri May 9 02:32:36 MST 2014
Author: scribe
Date: 2014-05-09 02:32:36 -0700 (Fri, 09 May 2014)
New Revision: 3229
Modified:
trunk/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h
trunk/bindings/java-jni/jni/swordstub.cpp
trunk/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java
trunk/src/mgr/ftplibftpt.cpp
Log:
Added progress reporting during installation. Fixed ftplib progress
reporting.
Modified: trunk/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h
===================================================================
--- trunk/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h 2014-05-07 02:04:32 UTC (rev 3228)
+++ trunk/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h 2014-05-09 09:32:36 UTC (rev 3229)
@@ -69,7 +69,7 @@
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule
- (JNIEnv *, jobject, jstring, jstring);
+ (JNIEnv *, jobject, jstring, jstring, jobject);
/*
* Class: org_crosswire_android_sword_InstallMgr
Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp 2014-05-07 02:04:32 UTC (rev 3228)
+++ trunk/bindings/java-jni/jni/swordstub.cpp 2014-05-09 09:32:36 UTC (rev 3229)
@@ -37,6 +37,7 @@
#include <localemgr.h>
#include <treekeyidx.h>
#include <installmgr.h>
+#include <remotetrans.h>
#include "webmgr.hpp"
#include "org_crosswire_android_sword_SWMgr.h"
@@ -53,6 +54,65 @@
namespace {
WebMgr *mgr = 0;
InstallMgr *installMgr = 0;
+
+class InstallStatusReporter : public StatusReporter {
+public:
+ JNIEnv *env;
+ jobject callback;
+ unsigned long last;
+ void init(JNIEnv *env, jobject callback) {
+ this->env = env;
+ this->callback = callback;
+ last = 0xffffffff;
+ }
+ virtual void update(unsigned long totalBytes, unsigned long completedBytes) {
+ if (completedBytes != last) {
+ last = completedBytes;
+ jclass cls = env->GetObjectClass(callback);
+ jmethodID mid = env->GetMethodID(cls, "update", "(JJ)V");
+ if (mid != 0) {
+ env->CallVoidMethod(callback, mid, (jlong)totalBytes, (jlong)completedBytes);
+ }
+ env->DeleteLocalRef(cls);
+ }
+
+/*
+ int p = (totalBytes > 0) ? (int)(74.0 * ((double)completedBytes / (double)totalBytes)) : 0;
+ for (;last < p; ++last) {
+ if (!last) {
+ SWBuf output;
+ output.setFormatted("[ File Bytes: %ld", totalBytes);
+ while (output.size() < 75) output += " ";
+ output += "]";
+ cout << output.c_str() << "\n ";
+ }
+ cout << "-";
+ }
+ cout.flush();
+*/
+ }
+ virtual void preStatus(long totalBytes, long completedBytes, const char *message) {
+ jclass cls = env->GetObjectClass(callback);
+ jmethodID mid = env->GetMethodID(cls, "preStatus", "(JJLjava/lang/String;)V");
+ if (mid != 0) {
+ jstring msg = env->NewStringUTF(assureValidUTF8((const char *)message));
+ env->CallVoidMethod(callback, mid, (jlong)totalBytes, (jlong)completedBytes, msg);
+ env->DeleteLocalRef(msg);
+ }
+ env->DeleteLocalRef(cls);
+/*
+ SWBuf output;
+ output.setFormatted("[ Total Bytes: %ld; Completed Bytes: %ld", totalBytes, completedBytes);
+ while (output.size() < 75) output += " ";
+ output += "]";
+ cout << "\n" << output.c_str() << "\n ";
+ int p = (int)(74.0 * (double)completedBytes/totalBytes);
+ for (int i = 0; i < p; ++i) { cout << "="; }
+ cout << "\n\n" << message << "\n";
+ last = 0;
+*/
+ }
+} *installStatusReporter = 0;
bool disclaimerConfirmed = false;
class AndroidLogger : public SWLog {
@@ -96,6 +156,9 @@
static void initInstall() {
+ if (!installStatusReporter) {
+ installStatusReporter = new InstallStatusReporter();
+ }
if (!installMgr) {
SWLog::getSystemLog()->logDebug("initInstall: installMgr is null");
SWBuf baseDir = "/sdcard/sword/InstallMgr";
@@ -109,7 +172,7 @@
config["General"]["PassiveFTP"] = "true";
config.Save();
}
- installMgr = new InstallMgr(baseDir);
+ installMgr = new InstallMgr(baseDir, installStatusReporter);
if (disclaimerConfirmed) installMgr->setUserDisclaimerConfirmed(true);
SWLog::getSystemLog()->logDebug("initInstall: instantiated InstallMgr with baseDir: %s", baseDir.c_str());
}
@@ -1138,6 +1201,7 @@
if (mid != 0) {
p->env->CallVoidMethod(p->progressReporter, mid, (jint)percent);
}
+ p->env->DeleteLocalRef(cls);
}
}
@@ -1409,17 +1473,18 @@
return ret;
}
-
/*
* Class: org_crosswire_android_sword_InstallMgr
* Method: remoteInstallModule
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule
- (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) {
+ (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS, jobject progressReporter) {
initInstall();
+ installStatusReporter->init(env, progressReporter);
+
const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL);
SWLog::getSystemLog()->logDebug("remoteInstallModule: sourceName: %s\n", sourceName);
InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
@@ -1446,6 +1511,15 @@
int error = installMgr->installModule(mgr, 0, module->getName(), is);
+ jclass cls = env->GetObjectClass(progressReporter);
+ jmethodID mid = env->GetMethodID(cls, "preStatus", "(JJLjava/lang/String;)V");
+ if (mid != 0) {
+ jstring msg = env->NewStringUTF("Complete");
+ env->CallVoidMethod(progressReporter, mid, (jlong)0, (jlong)0, msg);
+ env->DeleteLocalRef(msg);
+ }
+ env->DeleteLocalRef(cls);
+
return error;
}
Modified: trunk/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java
===================================================================
--- trunk/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java 2014-05-07 02:04:32 UTC (rev 3228)
+++ trunk/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java 2014-05-09 09:32:36 UTC (rev 3229)
@@ -23,6 +23,11 @@
package org.crosswire.android.sword;
public class InstallMgr {
+
+ public static interface InstallProgressReporter {
+ public void update(long totalBytes, long completedBytes);
+ public void preStatus(long totalBytes, long completedBytes, String message);
+ }
public native void reInit();
@@ -32,7 +37,8 @@
public native String [] getRemoteSources();
public native int refreshRemoteSource(String sourceName);
public native SWMgr.ModInfo [] getRemoteModInfoList(String sourceName);
- public native int remoteInstallModule(String sourceName, String modName);
+ public native int remoteInstallModule(String sourceName, String modName, InstallProgressReporter progressReporter);
+ public int remoteInstallModule(String sourceName, String modName) { return remoteInstallModule(sourceName, modName, null); }
public native SWModule getRemoteModuleByName(String source, String name);
}
Modified: trunk/src/mgr/ftplibftpt.cpp
===================================================================
--- trunk/src/mgr/ftplibftpt.cpp 2014-05-07 02:04:32 UTC (rev 3228)
+++ trunk/src/mgr/ftplibftpt.cpp 2014-05-09 09:32:36 UTC (rev 3229)
@@ -56,9 +56,9 @@
static int my_fprogress(netbuf *nControl, int xfered, void *arg) {
if (arg) {
MyProgressData *pd = (MyProgressData *)arg;
- SWLog::getSystemLog()->logDebug("FTPLibFTPTransport report progress: totalSize: %ld; xfered: %d\n", pd->totalSize, xfered);
+//SWLog::getSystemLog()->logDebug("FTPLibFTPTransport report progress: totalSize: %ld; xfered: %d\n", pd->totalSize, xfered);
if (pd->sr) {
- pd->sr->statusUpdate(pd->totalSize, xfered);
+ pd->sr->update(pd->totalSize, xfered);
}
if (*(pd->term)) return 0;
}
More information about the sword-cvs
mailing list