[sword-svn] r3557 - in trunk: bindings bindings/cordova/org.crosswire.sword.cordova.SWORD/src/ios bindings/objc include
scribe at crosswire.org
scribe at crosswire.org
Mon Jan 1 14:56:29 MST 2018
Author: scribe
Date: 2018-01-01 14:56:29 -0700 (Mon, 01 Jan 2018)
New Revision: 3557
Modified:
trunk/bindings/cordova/org.crosswire.sword.cordova.SWORD/src/ios/SWORD.swift
trunk/bindings/flatapi.cpp
trunk/bindings/objc/Makefile
trunk/include/flatapi.h
Log:
Updated flatapi and ios swift bindings to include SWConfig methods
Modified: trunk/bindings/cordova/org.crosswire.sword.cordova.SWORD/src/ios/SWORD.swift
===================================================================
--- trunk/bindings/cordova/org.crosswire.sword.cordova.SWORD/src/ios/SWORD.swift 2017-12-23 23:43:05 UTC (rev 3556)
+++ trunk/bindings/cordova/org.crosswire.sword.cordova.SWORD/src/ios/SWORD.swift 2018-01-01 21:56:29 UTC (rev 3557)
@@ -4,32 +4,34 @@
@objc(SWORD) class SWORD : CDVPlugin, MFMessageComposeViewControllerDelegate {
var mgr = 0;
- var installMgr = 0
- var disclaimerConfirmed = false;
+ var installMgr = 0
+ var disclaimerConfirmed = false;
@objc(initSWORD:)
func initSWORD(command: CDVInvokedUrlCommand) {
- mgr = 0
- installMgr = 0
- disclaimerConfirmed = false
- mySWORDPlugin = nil
- VERSEKEY_BOOKABBREV = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOKABBREV);
- VERSEKEY_BOOK = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOK);
- VERSEKEY_CHAPTER = Int(org_crosswire_sword_SWModule_VERSEKEY_CHAPTER);
- VERSEKEY_VERSE = Int(org_crosswire_sword_SWModule_VERSEKEY_VERSE);
- VERSEKEY_TESTAMENT = Int(org_crosswire_sword_SWModule_VERSEKEY_TESTAMENT);
- VERSEKEY_OSISREF = Int(org_crosswire_sword_SWModule_VERSEKEY_OSISREF);
- VERSEKEY_CHAPMAX = Int(org_crosswire_sword_SWModule_VERSEKEY_CHAPMAX);
- VERSEKEY_VERSEMAX = Int(org_crosswire_sword_SWModule_VERSEKEY_VERSEMAX);
- VERSEKEY_BOOKNAME = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOKNAME);
- VERSEKEY_SHORTTEXT = Int(org_crosswire_sword_SWModule_VERSEKEY_SHORTTEXT);
+ mgr = 0
+ installMgr = 0
+ disclaimerConfirmed = false
+ mySWORDPlugin = nil
+ VERSEKEY_BOOKABBREV = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOKABBREV);
+ VERSEKEY_BOOK = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOK);
+ VERSEKEY_CHAPTER = Int(org_crosswire_sword_SWModule_VERSEKEY_CHAPTER);
+ VERSEKEY_VERSE = Int(org_crosswire_sword_SWModule_VERSEKEY_VERSE);
+ VERSEKEY_TESTAMENT = Int(org_crosswire_sword_SWModule_VERSEKEY_TESTAMENT);
+ VERSEKEY_OSISREF = Int(org_crosswire_sword_SWModule_VERSEKEY_OSISREF);
+ VERSEKEY_CHAPMAX = Int(org_crosswire_sword_SWModule_VERSEKEY_CHAPMAX);
+ VERSEKEY_VERSEMAX = Int(org_crosswire_sword_SWModule_VERSEKEY_VERSEMAX);
+ VERSEKEY_BOOKNAME = Int(org_crosswire_sword_SWModule_VERSEKEY_BOOKNAME);
+ VERSEKEY_SHORTTEXT = Int(org_crosswire_sword_SWModule_VERSEKEY_SHORTTEXT);
initMgr()
- let libswordVersion = String(cString: org_crosswire_sword_SWMgr_version(mgr))
-debugPrint("libswordVersion: " + libswordVersion)
- self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "initSWORD; Version: " + libswordVersion), callbackId: command.callbackId)
+
+ let libswordVersion = String(cString: org_crosswire_sword_SWMgr_version(mgr))
+ debugPrint("libswordVersion: " + libswordVersion)
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "initSWORD; Version: " + libswordVersion), callbackId: command.callbackId)
}
+
func myToast(message: String) {
let toastController: UIAlertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
self.viewController?.present(toastController, animated: true, completion: nil)
@@ -38,21 +40,24 @@
}
}
+
func initMgr() {
if (mgr == 0) {
- let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
-
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
mgr = org_crosswire_sword_SWMgr_newWithPath(baseDir)
- debugPrint("initMgr, mgr: " + String(describing: mgr))
+debugPrint("initMgr, mgr: " + String(describing: mgr))
}
}
- func reinitMgr() {
- if (mgr != 0) {
- org_crosswire_sword_SWMgr_delete(mgr)
- }
- mgr = 0
- initMgr()
- }
+
+
+ func reinitMgr() {
+ if (mgr != 0) {
+ org_crosswire_sword_SWMgr_delete(mgr)
+ }
+ mgr = 0
+ initMgr()
+ }
+
func reinitInstall() {
if (installMgr != 0) {
@@ -156,86 +161,56 @@
- @objc(SWMgr_addExtraConfig:)
- func SWMgr_addExtraConfig(command: CDVInvokedUrlCommand) {
- var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
+ @objc(SWMgr_addExtraConfig:)
+ func SWMgr_addExtraConfig(command: CDVInvokedUrlCommand) {
+ let blob = command.arguments[0] as? String ?? ""
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
+ let confPath = baseDir + "/extraConfig.conf";
+ let retVal = getStringArray(buffer: org_crosswire_sword_SWConfig_augmentConfig(confPath, blob))
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: retVal), callbackId: command.callbackId)
+ }
+
+
+ @objc(SWMgr_setExtraConfigValue:)
+ func SWMgr_setExtraConfigValue(command: CDVInvokedUrlCommand) {
+ let section = command.arguments[0] as? String ?? ""
+ let key = command.arguments[1] as? String ?? ""
+ let val = command.arguments[2] as? String ?? ""
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
+ let confPath = baseDir + "/extraConfig.conf";
+ org_crosswire_sword_SWConfig_setKeyValue(confPath, section, key, val)
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_setExtraConfigValue"), callbackId: command.callbackId)
+ }
- let toastController: UIAlertController = UIAlertController(title: "", message: "SWMgr_addExtraConfig", preferredStyle: .alert)
-
- self.viewController?.present(toastController, animated: true, completion: nil)
+
+ @objc(SWMgr_getExtraConfigValue:)
+ func SWMgr_getExtraConfigValue(command: CDVInvokedUrlCommand) {
+ let section = command.arguments[0] as? String ?? ""
+ let key = command.arguments[1] as? String ?? ""
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
+ let confPath = baseDir + "/extraConfig.conf";
+ let retVal = String(cString:org_crosswire_sword_SWConfig_getKeyValue(confPath, section, key))
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: retVal), callbackId: command.callbackId)
+ }
+
+
+ @objc(SWMgr_getExtraConfigKeys:)
+ func SWMgr_getExtraConfigKeys(command: CDVInvokedUrlCommand) {
+ let section = command.arguments[0] as? String ?? ""
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
+ let confPath = baseDir + "/extraConfig.conf";
+ let retVal = getStringArray(buffer: org_crosswire_sword_SWConfig_getSectionKeys(confPath, section))
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: retVal), callbackId: command.callbackId)
+ }
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- toastController.dismiss(animated: true, completion: nil)
- }
-
- pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_addExtraConfig")
-
- self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
+
+ @objc(SWMgr_getExtraConfigSections:)
+ func SWMgr_getExtraConfigSections(command: CDVInvokedUrlCommand) {
+ let baseDir = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path)! + "/sword";
+ let confPath = baseDir + "/extraConfig.conf";
+ let retVal = getStringArray(buffer: org_crosswire_sword_SWConfig_getSections(confPath))
+ self.commandDelegate!.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: retVal), callbackId: command.callbackId)
}
- @objc(SWMgr_setExtraConfigValue:)
- func SWMgr_setExtraConfigValue(command: CDVInvokedUrlCommand) {
- var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
-
- let toastController: UIAlertController = UIAlertController(title: "", message: "SWMgr_setExtraConfigValue", preferredStyle: .alert)
-
- self.viewController?.present(toastController, animated: true, completion: nil)
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- toastController.dismiss(animated: true, completion: nil)
- }
-
- pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_setExtraConfigValue")
-
- self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
- }
- @objc(SWMgr_getExtraConfigValue:)
- func SWMgr_getExtraConfigValue(command: CDVInvokedUrlCommand) {
- var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
-
- let toastController: UIAlertController = UIAlertController(title: "", message: "SWMgr_getExtraConfigValue", preferredStyle: .alert)
-
- self.viewController?.present(toastController, animated: true, completion: nil)
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- toastController.dismiss(animated: true, completion: nil)
- }
-
- pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_getExtraConfigValue")
-
- self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
- }
- @objc(SWMgr_getExtraConfigKeys:)
- func SWMgr_getExtraConfigKeys(command: CDVInvokedUrlCommand) {
- var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
-
- let toastController: UIAlertController = UIAlertController(title: "", message: "SWMgr_getExtraConfigKeys", preferredStyle: .alert)
-
- self.viewController?.present(toastController, animated: true, completion: nil)
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- toastController.dismiss(animated: true, completion: nil)
- }
-
- pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_getExtraConfigKeys")
-
- self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
- }
- @objc(SWMgr_getExtraConfigSections:)
- func SWMgr_getExtraConfigSections(command: CDVInvokedUrlCommand) {
- var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
-
- let toastController: UIAlertController = UIAlertController(title: "", message: "SWMgr_getExtraConfigSections", preferredStyle: .alert)
-
- self.viewController?.present(toastController, animated: true, completion: nil)
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- toastController.dismiss(animated: true, completion: nil)
- }
-
- pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "SWMgr_getExtraConfigSections")
-
- self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
- }
@objc(echo:)
Modified: trunk/bindings/flatapi.cpp
===================================================================
--- trunk/bindings/flatapi.cpp 2017-12-23 23:43:05 UTC (rev 3556)
+++ trunk/bindings/flatapi.cpp 2018-01-01 21:56:29 UTC (rev 3557)
@@ -140,6 +140,7 @@
last = 0;
*/
}
+
};
class HandleSWModule {
@@ -296,6 +297,9 @@
const char **HandleInstMgr::remoteSources = 0;
+const char **tmpStringArrayRetVal = 0;
+char *tmpStringRetVal = 0;
+
class InitStatics {
public:
InitStatics() {
@@ -312,6 +316,10 @@
HandleSWMgr::clearGlobalOptionValues();
HandleInstMgr::clearRemoteSources();
+
+ clearStringArray(&tmpStringArrayRetVal);
+ sword::stdstr(&tmpStringRetVal, (const char *)0);
+
}
} _initStatics;
@@ -984,7 +992,12 @@
config["Globals"]["HiAndroid"] = "weeee";
config.save();
}
- return (SWHANDLE) new HandleSWMgr(new WebMgr(confPath.c_str()));
+ SWBuf extraPath = confPath + "extraConfig.conf";
+ bool exists = FileMgr::existsFile(extraPath.c_str());
+SWLog::getSystemLog()->logDebug("libsword: extraConfig %s at path: %s", exists?"Exists":"Absent", extraPath.c_str());
+
+SWLog::getSystemLog()->logDebug("libsword: init() creating WebMgr using path: %s", path);
+ return (SWHANDLE) new HandleSWMgr(new WebMgr(confPath.c_str(), exists?extraPath.c_str():0));
}
@@ -1177,7 +1190,165 @@
return retVal;
}
+
/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getSections
+ * Signature: ()[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_getSections
+ (const char *confPath) {
+
+ clearStringArray(&tmpStringArrayRetVal);
+ int count = 0;
+ const char **retVal = 0;
+ bool exists = FileMgr::existsFile(confPath);
+SWLog::getSystemLog()->logDebug("libsword: getConfigSections %s at path: %s", exists?"Exists":"Absent", confPath);
+ if (exists) {
+ SWConfig config(confPath);
+ SectionMap::const_iterator sit;
+ for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) {
+ count++;
+ }
+ SWLog::getSystemLog()->logDebug("libsword: %d sections found in config", count);
+ retVal = (const char **)calloc(count+1, sizeof(const char *));
+ count = 0;
+ for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) {
+ stdstr((char **)&(retVal[count++]), assureValidUTF8(sit->first.c_str()));
+ }
+ }
+ else {
+ retVal = (const char **)calloc(1, sizeof(const char *));
+ }
+
+ tmpStringArrayRetVal = retVal;
+ return retVal;
+}
+
+
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getSectionKeys
+ * Signature: (Ljava/lang/String;)[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_getSectionKeys
+ (const char *confPath, const char *section) {
+
+ clearStringArray(&tmpStringArrayRetVal);
+ int count = 0;
+ const char **retVal = 0;
+ bool exists = FileMgr::existsFile(confPath);
+ if (exists) {
+ SWConfig config(confPath);
+ SectionMap::const_iterator sit = config.getSections().find(section);
+ if (sit != config.getSections().end()) {
+ ConfigEntMap::const_iterator it;
+ for (it = sit->second.begin(); it != sit->second.end(); ++it) {
+ count++;
+ }
+ retVal = (const char **)calloc(count+1, sizeof(const char *));
+ count = 0;
+ for (it = sit->second.begin(); it != sit->second.end(); ++it) {
+ stdstr((char **)&(retVal[count++]), assureValidUTF8(it->first.c_str()));
+ }
+ }
+ else {
+ retVal = (const char **)calloc(1, sizeof(const char *));
+ }
+ }
+ else {
+ retVal = (const char **)calloc(1, sizeof(const char *));
+ }
+
+ tmpStringArrayRetVal = retVal;
+ return retVal;
+}
+
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getKeyValue
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ */
+const char * SWDLLEXPORT org_crosswire_sword_SWConfig_getKeyValue
+ (const char *confPath, const char *section, const char *key) {
+
+ stdstr(&tmpStringRetVal, 0);
+ bool exists = FileMgr::existsFile(confPath);
+ if (exists) {
+ SWConfig config(confPath);
+ SectionMap::const_iterator sit = config.getSections().find(section);
+ if (sit != config.getSections().end()) {
+ ConfigEntMap::const_iterator it = sit->second.find(key);
+ if (it != sit->second.end()) {
+ stdstr(&tmpStringRetVal, assureValidUTF8(it->second.c_str()));
+ }
+ }
+ }
+
+ return tmpStringRetVal;
+}
+
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: setKeyValue
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+void SWDLLEXPORT org_crosswire_sword_SWConfig_setKeyValue
+ (const char *confPath, const char *section, const char *key, const char *value) {
+
+ SWConfig config(confPath);
+ config[section][key] = value;
+ config.save();
+}
+
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: augmentConfig
+ * Signature: (Ljava/lang/String;)[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_augmentConfig
+ (const char *confPath, const char *configBlob) {
+
+
+ clearStringArray(&tmpStringArrayRetVal);
+ const char **retVal = 0;
+ int count = 0;
+
+ SWBuf myBlob = configBlob;
+
+ SWConfig config(confPath);
+
+ FileMgr::removeFile(confPath);
+ FileDesc *fd = FileMgr::getSystemFileMgr()->open(confPath, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE);
+ fd->getFd();
+ fd->write(myBlob.c_str(), myBlob.size());
+ FileMgr::getSystemFileMgr()->close(fd);
+
+ SWConfig newConfig(confPath);
+
+ config.augment(newConfig);
+ config.save();
+
+ SectionMap::const_iterator sit;
+ for (sit = newConfig.getSections().begin(); sit != newConfig.getSections().end(); ++sit) {
+ count++;
+ }
+ retVal = (const char **)calloc(count+1, sizeof(const char *));
+ count = 0;
+ for (sit = newConfig.getSections().begin(); sit != newConfig.getSections().end(); ++sit) {
+ stdstr((char **)&(retVal[count++]), assureValidUTF8(sit->first.c_str()));
+ }
+
+ tmpStringArrayRetVal = retVal;
+ return retVal;
+}
+
+
+/*
* Class: org_crosswire_sword_SWMgr
* Method: getGlobalOptionValues
* Signature: (Ljava/lang/String;)[Ljava/lang/String;
Modified: trunk/bindings/objc/Makefile
===================================================================
--- trunk/bindings/objc/Makefile 2017-12-23 23:43:05 UTC (rev 3556)
+++ trunk/bindings/objc/Makefile 2018-01-01 21:56:29 UTC (rev 3557)
@@ -12,7 +12,9 @@
deploycordova:
mkdir -p ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
cp ./dependencies/curl/lib/libcurl.a ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
- cp ./Build/Debug-iphonesimulator/libSWORD.a ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
+# cp ./Build/Debug-iphonesimulator/libSWORD.a ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
+# cp ./Build/Debug-iphoneos/libSWORD.a ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
+ cp SWORD/Release-universal/libSWORD.a ../cordova/org.crosswire.sword.cordova.SWORD/libs/ios/
cp ../../include/defs.h ../../include/flatapi.h ../cordova/org.crosswire.sword.cordova.SWORD/src/ios/
Modified: trunk/include/flatapi.h
===================================================================
--- trunk/include/flatapi.h 2017-12-23 23:43:05 UTC (rev 3556)
+++ trunk/include/flatapi.h 2018-01-01 21:56:29 UTC (rev 3557)
@@ -393,7 +393,48 @@
const char ** SWDLLEXPORT org_crosswire_sword_SWMgr_getGlobalOptions
(SWHANDLE hSWMgr);
+
/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getSections
+ * Signature: ()[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_getSections
+ (const char *confPath);
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getSectionKeys
+ * Signature: (Ljava/lang/String;)[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_getSectionKeys
+ (const char *confPath, const char *section);
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: getKeyValue
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ */
+const char * SWDLLEXPORT org_crosswire_sword_SWConfig_getKeyValue
+ (const char *confPath, const char *section, const char *key);
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: setKeyValue
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+void SWDLLEXPORT org_crosswire_sword_SWConfig_setKeyValue
+ (const char *confPath, const char *section, const char *key, const char *value);
+
+/*
+ * Class: org_crosswire_sword_SWConfig
+ * Method: augmentConfig
+ * Signature: (Ljava/lang/String;)[Ljava/lang/String;
+ */
+const char ** SWDLLEXPORT org_crosswire_sword_SWConfig_augmentConfig
+ (const char *confPath, const char *configBlob);
+
+/*
* Class: org_crosswire_sword_SWMgr
* Method: getGlobalOptionValues
* Signature: (Ljava/lang/String;)[Ljava/lang/String;
More information about the sword-cvs
mailing list