[sword-svn] r3241 - trunk/bindings/java-jni/jni
scribe at crosswire.org
scribe at crosswire.org
Sat Jul 12 09:27:44 MST 2014
Author: scribe
Date: 2014-07-12 09:27:44 -0700 (Sat, 12 Jul 2014)
New Revision: 3241
Modified:
trunk/bindings/java-jni/jni/Android.mk
trunk/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h
trunk/bindings/java-jni/jni/swordstub.cpp
Log:
Biblesync additions to jni bindings to support inclusion of biblesync
functionality in cordova
Modified: trunk/bindings/java-jni/jni/Android.mk
===================================================================
--- trunk/bindings/java-jni/jni/Android.mk 2014-07-12 16:27:35 UTC (rev 3240)
+++ trunk/bindings/java-jni/jni/Android.mk 2014-07-12 16:27:44 UTC (rev 3241)
@@ -186,6 +186,13 @@
../../../src/frontend/swlog.cpp \
../../../src/utilfuns/zlib/untgz.c
+# add BibleSync
+LOCAL_C_INCLUDES += ../biblesync/include
+LOCAL_SRC_FILES += \
+ ../../../../biblesync/src/biblesync.cc \
+ ../../../../biblesync/src/ifaddrs.c
+
+
#../../../src/modules/common/bz2comprs.cpp \
#../../../src/modules/common/xzcomprs.cpp \
#../../../../../sword/src/mgr/curlftpt.cpp \
@@ -204,6 +211,10 @@
LOCAL_MODULE := libsword
LOCAL_C_INCLUDES := ../sword/include ../sword/include/internal/regex
+
+# add BibleSync stuff
+LOCAL_C_INCLUDES += ../biblesync/include
+
LOCAL_CFLAGS += -D__unix__ \
-Dunix \
-D_FTPLIB_NO_COMPAT \
Modified: trunk/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h
===================================================================
--- trunk/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h 2014-07-12 16:27:35 UTC (rev 3240)
+++ trunk/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h 2014-07-12 16:27:44 UTC (rev 3241)
@@ -135,6 +135,23 @@
JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setDefaultLocale
(JNIEnv *, jobject, jstring);
+/*
+ * Class: org_crosswire_android_sword_SWMgr
+ * Method: sendBibleSyncMessage
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_sendBibleSyncMessage
+ (JNIEnv *, jobject, jstring);
+
+
+/*
+ * Class: org_crosswire_android_sword_SWMgr
+ * Method: registerBibleSyncListener
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_registerBibleSyncListener
+ (JNIEnv *, jobject, jobject);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp 2014-07-12 16:27:35 UTC (rev 3240)
+++ trunk/bindings/java-jni/jni/swordstub.cpp 2014-07-12 16:27:44 UTC (rev 3241)
@@ -39,6 +39,12 @@
#include <installmgr.h>
#include <remotetrans.h>
+#define BIBLESYNC
+
+#ifdef BIBLESYNC
+#include <biblesync.hh>
+#endif
+
#include "webmgr.hpp"
#include "org_crosswire_android_sword_SWMgr.h"
#include "org_crosswire_android_sword_SWModule.h"
@@ -55,6 +61,12 @@
WebMgr *mgr = 0;
InstallMgr *installMgr = 0;
+#ifdef BIBLESYNC
+BibleSync *bibleSync = 0;
+#endif
+jobject bibleSyncListener = 0;
+JNIEnv *bibleSyncListenerEnv = 0;
+
class InstallStatusReporter : public StatusReporter {
public:
JNIEnv *env;
@@ -189,9 +201,57 @@
}
}
+#ifdef BIBLESYNC
+void bibleSyncCallback(char cmd, string bible, string ref, string alt, string group, string domain, string info, string dump) {
+SWLog::getSystemLog()->logDebug("bibleSync callback msg: %c; bible: %s; ref: %s; alt: %s; group: %s; domain: %s; info: %s; dump: %s", cmd, bible.c_str(), ref.c_str(), alt.c_str(), group.c_str(), domain.c_str(), info.c_str(), dump.c_str());
+ if (::bibleSyncListener) {
+SWLog::getSystemLog()->logDebug("bibleSync listener is true");
+ jclass cls = bibleSyncListenerEnv->GetObjectClass(::bibleSyncListener);
+ jmethodID mid = bibleSyncListenerEnv->GetMethodID(cls, "messageReceived", "(Ljava/lang/String;)V");
+SWLog::getSystemLog()->logDebug("bibleSync listener mid: %ld", mid);
+ if (mid) {
+SWLog::getSystemLog()->logDebug("bibleSync listener mid is available");
+ switch(cmd) {
+ // error
+ case 'E':
+ // mismatch
+ case 'M':
+ // new speaker
+ case 'S':
+ // dead speaker
+ case 'D':
+ // announce
+ case 'A':
+ break;
+ // navigation
+ case 'N':
+SWLog::getSystemLog()->logDebug("bibleSync Nav Received: %s", ref.c_str());
+ jstring msg = bibleSyncListenerEnv->NewStringUTF(ref.c_str());
+ bibleSyncListenerEnv->CallVoidMethod(::bibleSyncListener, mid, msg);
+ bibleSyncListenerEnv->DeleteLocalRef(msg);
+ break;
+ }
+ }
+SWLog::getSystemLog()->logDebug("bibleSync listener deleting local ref to cls");
+ bibleSyncListenerEnv->DeleteLocalRef(cls);
+ }
}
+#endif
+static void initBibleSync() {
+#ifdef BIBLESYNC
+ if (!bibleSync) {
+SWLog::getSystemLog()->logDebug("bibleSync initializing c-tor");
+ bibleSync = new BibleSync("SWORD", (const char *)SWVersion().currentVersion, "SwordUser");
+SWLog::getSystemLog()->logDebug("bibleSync initializing setMode");
+ bibleSync->setMode(BSP_MODE_PERSONAL, bibleSyncCallback, "passphrase");
+ }
+#endif
+}
+}
+
+
JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_version
(JNIEnv *env, jobject me) {
@@ -697,7 +757,8 @@
SWModule *module = getModule(env, me);
- return (module) ? module->popError() : -99;
+ int error = (module) ? module->popError() : -99;
+ return error;
}
@@ -1510,6 +1571,7 @@
JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule
(JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS, jobject progressReporter) {
+ init();
initInstall();
installStatusReporter->init(env, progressReporter);
@@ -1615,3 +1677,46 @@
installMgr->setUserDisclaimerConfirmed(true);
}
+
+/*
+ * Class: org_crosswire_android_sword_SWMgr
+ * Method: sendBibleSyncMessage
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_sendBibleSyncMessage
+ (JNIEnv *env, jobject me, jstring osisRefJS) {
+ initBibleSync();
+ const char *osisRef = env->GetStringUTFChars(osisRefJS, NULL);
+
+#ifdef BIBLESYNC
+ BibleSync_xmit_status retval = bibleSync->Transmit(BSP_SYNC, "Bible", osisRef);
+#endif
+
+ env->ReleaseStringUTFChars(osisRefJS, osisRef);
+}
+
+
+/*
+ * NOTE: this method blocks and should be called in a new thread
+ * Class: org_crosswire_android_sword_SWMgr
+ * Method: registerBibleSyncListener
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_registerBibleSyncListener
+ (JNIEnv *env, jobject me, jobject bibleSyncListener) {
+SWLog::getSystemLog()->logDebug("registerBibleSyncListener");
+ ::bibleSyncListener = bibleSyncListener;
+ ::bibleSyncListenerEnv = env;
+SWLog::getSystemLog()->logDebug("registerBibleSyncListener - calling init");
+ initBibleSync();
+#ifdef BIBLESYNC
+SWLog::getSystemLog()->logDebug("registerBibleSyncListener - starting while listener");
+ while(::bibleSyncListener) {
+SWLog::getSystemLog()->logDebug("bibleSyncListener - while loop iteration");
+ BibleSync::Receive(bibleSync);
+SWLog::getSystemLog()->logDebug("bibleSyncListener - sleeping for 2 seconds");
+ sleep(2);
+ }
+#endif
+}
+
More information about the sword-cvs
mailing list