summaryrefslogtreecommitdiff
path: root/bindings/corba/orbitcpp
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/corba/orbitcpp')
-rw-r--r--bindings/corba/orbitcpp/Makefile48
-rw-r--r--bindings/corba/orbitcpp/server.cpp45
-rw-r--r--bindings/corba/orbitcpp/swordorb-impl.cpp231
-rw-r--r--bindings/corba/orbitcpp/swordorb-impl.hpp67
-rw-r--r--bindings/corba/orbitcpp/testclient.cpp61
5 files changed, 452 insertions, 0 deletions
diff --git a/bindings/corba/orbitcpp/Makefile b/bindings/corba/orbitcpp/Makefile
new file mode 100644
index 0000000..0aabb16
--- /dev/null
+++ b/bindings/corba/orbitcpp/Makefile
@@ -0,0 +1,48 @@
+all: server testclient
+
+#comment these out if you didn't compile sword with lucene support
+luceneflags=-DUSELUCENE
+lucenelibs=-lclucene
+#----------------------------------
+
+LIBS += ${lucenelibs}
+CFLAGS += ${luceneflags}
+CXXFLAGS += ${luceneflags}
+
+server: swordorb-common.o server.cpp swordorb-impl.o swordorb-cpp.o swordorb-cpp-common.o swordorb-stubs.o swordorb-cpp-stubs.o swordorb-cpp-skels.o swordorb-skels.o swordorb-cpp.o
+ g++ -g -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -o server server.cpp swordorb-impl.o swordorb-common.o swordorb-cpp-common.o swordorb-stubs.o swordorb-cpp-stubs.o swordorb-cpp-skels.o swordorb-skels.o `orbit2-config --libs` -lORBit-2-cpp -lsword -lz ${LIBS}
+
+testclient: testclient.cpp swordorb-impl.cpp swordorb-common.o swordorb-cpp-common.o swordorb-stubs.o swordorb-cpp-stubs.o swordorb-skels.o swordorb-cpp-skels.o
+ g++ -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -o testclient testclient.cpp swordorb-common.o swordorb-cpp-common.o swordorb-stubs.o swordorb-cpp-stubs.o swordorb-skels.o swordorb-cpp-skels.o `orbit2-config --libs` -lORBit-2-cpp
+
+swordorb-cpp.o: swordorb-cpp.cc
+ g++ -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-cpp.cc
+
+swordorb-impl.o: swordorb-impl.cpp
+ g++ -g -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-impl.cpp
+
+swordorb-common.o: swordorb-common.c
+ gcc -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-common.c
+
+swordorb-common.c: ./../swordorb.idl
+ orbit-idl-2 -l c ./../swordorb.idl
+ orbit-idl-2 -l cpp ./../swordorb.idl
+
+swordorb-cpp-common.o: swordorb-cpp-common.cc
+ g++ -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-cpp-common.cc
+
+swordorb-stubs.o: swordorb-stubs.c
+ gcc -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-stubs.c
+
+swordorb-cpp-stubs.o: swordorb-cpp-stubs.cc
+ g++ -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-cpp-stubs.cc
+
+swordorb-skels.o: swordorb-skels.c
+ gcc -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-skels.c
+
+swordorb-cpp-skels.o: swordorb-cpp-skels.cc
+ g++ -I. -I../../../include -I/usr/include/orbitcpp-2.0/ `orbit2-config --cflags` -g -c swordorb-cpp-skels.cc
+
+clean:
+ rm -f *.h *.cc *.o *.c server testclient
+
diff --git a/bindings/corba/orbitcpp/server.cpp b/bindings/corba/orbitcpp/server.cpp
new file mode 100644
index 0000000..b60e1d9
--- /dev/null
+++ b/bindings/corba/orbitcpp/server.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include "swordorb-impl.hpp"
+#include <iostream>
+#include <swmgr.h>
+#include <markupfiltmgr.h>
+
+sword::SWMgr swordmgr(new sword::MarkupFilterMgr(sword::FMT_WEBIF));
+
+int main (int argc, char* argv[]) {
+ try {
+ // Initialize the CORBA orb
+ CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
+
+ // Get the root POA
+ CORBA::Object_var pfobj = orb->resolve_initial_references("RootPOA");
+
+ PortableServer::POA_var rootPOA =
+ PortableServer::POA::_narrow(pfobj);
+
+ // Activate the root POA's manager
+ PortableServer::POAManager_var mgr = rootPOA->the_POAManager();
+
+ mgr->activate();
+
+ // Create a Servant and explicitly create a CORBA object
+ swordorb::SWMgr_impl servant(&swordmgr);
+ CORBA::Object_var object = servant._this();
+
+ // Here we get the IOR for the Hello server object.
+ // Our "client" will use the IOR to find the object to connect to
+ CORBA::String_var ref = orb->object_to_string( object );
+
+ // print out the IOR
+ std::cout << ref << std::endl;
+
+ // run the server event loop
+ orb->run();
+ }
+ catch(const CORBA::Exception& ex)
+ {
+ std::cout << "Exception caught." << std::endl;
+ }
+
+}
diff --git a/bindings/corba/orbitcpp/swordorb-impl.cpp b/bindings/corba/orbitcpp/swordorb-impl.cpp
new file mode 100644
index 0000000..c775b41
--- /dev/null
+++ b/bindings/corba/orbitcpp/swordorb-impl.cpp
@@ -0,0 +1,231 @@
+#include "swordorb-impl.hpp"
+#include <iostream>
+#include <swmgr.h>
+#include <versekey.h>
+#include <treekeyidx.h>
+#include <swbuf.h>
+
+/*
+char* swordorb::SWModule_impl::helloWorld(const char* greeting) throw(CORBA::SystemException) {
+ std::cout << "Server: Greeting was \"" << greeting << "\"" << std::endl;
+ return CORBA::string_dup("Hello client, from server!");
+}
+*/
+
+using sword::VerseKey;
+using sword::SWBuf;
+using sword::TreeKeyIdx;
+
+namespace swordorb {
+
+sword::RawText NULLMod("/dev/null", SWNULL, SWNULL);
+
+ModInfoList *SWMgr_impl::getModInfoList() throw(CORBA::SystemException) {
+
+ ModInfoList *milist = new ModInfoList;
+ sword::SWModule *module = 0;
+ int size = 0;
+ for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) {
+ if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey"))))
+ size++;
+ }
+ milist->length(size);
+ int i = 0;
+ for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) {
+ module = it->second;
+ if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) {
+ SWBuf type = module->Type();
+ SWBuf cat = module->getConfigEntry("Category");
+ if (cat.length() > 0)
+ type = cat;
+ (*milist)[i].name = CORBA::string_dup(module->Name());
+ (*milist)[i].description = CORBA::string_dup(module->Description());
+ (*milist)[i].category = CORBA::string_dup(type.c_str());
+ (*milist)[i++].language = CORBA::string_dup(module->Lang());
+ }
+ }
+ return milist;
+}
+
+
+
+SWModule_ptr SWMgr_impl::getModuleByName(const char *name) throw(CORBA::SystemException) {
+ SWModuleMap::iterator it;
+ SWModule_ptr retVal;
+ sword::SWModule *mod = delegate->Modules[name];
+ it = moduleImpls.find((mod)?name:SWNULL);
+ if (it == moduleImpls.end()) {
+ moduleImpls[(mod)?name:SWNULL] = new SWModule_impl((mod)?mod:&NULLMod);
+ it = moduleImpls.find((mod)?name:SWNULL);
+ }
+ if (it != moduleImpls.end()) {
+ retVal = it->second->_this();
+ }
+ return ::swordorb::SWModule::_duplicate(retVal);
+}
+
+
+StringList *SWMgr_impl::getGlobalOptions() throw(CORBA::SystemException) {
+ sword::StringList options = delegate->getGlobalOptions();
+ StringList *retVal = new StringList;
+ int count = 0;
+ for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
+ count++;
+ }
+ retVal->length(count);
+ count = 0;
+ for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
+ (*retVal)[count++] = CORBA::string_dup(it->c_str());
+ }
+ return retVal;
+}
+
+
+StringList *SWMgr_impl::getGlobalOptionValues(const char *option) throw(CORBA::SystemException) {
+ sword::StringList options = delegate->getGlobalOptionValues(option);
+ StringList *retVal = new StringList;
+ int count = 0;
+ for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
+ count++;
+ }
+ retVal->length(count);
+ count = 0;
+ for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
+ (*retVal)[count++] = CORBA::string_dup(it->c_str());
+ }
+ return retVal;
+}
+
+void SWMgr_impl::terminate() throw(CORBA::SystemException) {
+ exit(0);
+}
+
+
+CORBA::Boolean SWMgr_impl::testConnection() throw(CORBA::SystemException) {
+ return true;
+}
+
+
+char *SWModule_impl::getCategory() throw(CORBA::SystemException) {
+ SWBuf type = delegate->Type();
+ SWBuf cat = delegate->getConfigEntry("Category");
+ if (cat.length() > 0)
+ type = cat;
+ return CORBA::string_dup((char *)type.c_str());
+}
+
+
+SearchHitList *SWModule_impl::search(const char *istr, SearchType searchType, CORBA::Long flags, const char *scope) throw(CORBA::SystemException) {
+ int stype = 2;
+ sword::ListKey lscope;
+ sword::VerseKey parser;
+ if (searchType == REGEX) stype = 0;
+ if (searchType == PHRASE) stype = -1;
+ if (searchType == MULTIWORD) stype = -2;
+ sword::ListKey result;
+
+ if ((scope) && (strlen(scope)) > 0) {
+ lscope = parser.ParseVerseList(scope, parser, true);
+ result = delegate->Search(istr, stype, flags, &lscope);
+ }
+ else result = delegate->Search(istr, stype, flags);
+
+ SearchHitList *retVal = new SearchHitList;
+ int count = 0;
+ for (result = sword::TOP; !result.Error(); result++) count++;
+ retVal->length(count);
+ int i = 0;
+ for (result = sword::TOP; !result.Error(); result++) {
+ (*retVal)[i].modName = CORBA::string_dup(delegate->Name());
+ (*retVal)[i].key = CORBA::string_dup((const char *)result);
+ (*retVal)[i++].score = (long)result.getElement()->userData;
+ }
+
+ return retVal;
+}
+
+
+
+StringList *SWModule_impl::getEntryAttribute(const char *level1, const char *level2, const char *level3) throw(CORBA::SystemException) {
+ delegate->RenderText(); // force parse
+ sword::AttributeTypeList &entryAttribs = delegate->getEntryAttributes();
+ sword::AttributeTypeList::iterator i1 = entryAttribs.find(level1);
+ sword::AttributeList::iterator i2;
+ sword::AttributeValue::iterator i3, j3;
+ StringList *retVal = new StringList;
+ int count = 0;
+
+ if (i1 != entryAttribs.end()) {
+ i2 = i1->second.find(level2);
+ if (i2 != i1->second.end()) {
+ i3 = i2->second.find(level3);
+ if (i3 != i2->second.end()) {
+ for (j3 = i3; j3 != i2->second.end(); j3++)
+ count++;
+ retVal->length(count);
+ count = 0;
+ for (j3 = i3; j3 != i2->second.end(); j3++) {
+ (*retVal)[count++] = CORBA::string_dup(i3->second.c_str());
+ }
+ }
+ }
+ }
+ if (!count)
+ retVal->length(count);
+
+ return retVal;
+}
+
+
+StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) {
+ sword::SWKey *key = delegate->getKey();
+ StringList *retVal = new StringList;
+ int count = 0;
+
+ sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
+ if (vkey) {
+ retVal->length(6);
+ SWBuf num;
+ num.appendFormatted("%d", vkey->Testament());
+ (*retVal)[0] = CORBA::string_dup(num.c_str());
+ num = "";
+ num.appendFormatted("%d", vkey->Book());
+ (*retVal)[1] = CORBA::string_dup(num.c_str());
+ num = "";
+ num.appendFormatted("%d", vkey->Chapter());
+ (*retVal)[2] = CORBA::string_dup(num.c_str());
+ num = "";
+ num.appendFormatted("%d", vkey->Verse());
+ (*retVal)[3] = CORBA::string_dup(num.c_str());
+ num = "";
+ num.appendFormatted("%d", vkey->books[vkey->Testament()-1][vkey->Book()-1].chapmax);
+ (*retVal)[4] = CORBA::string_dup(num.c_str());
+ num = "";
+ num.appendFormatted("%d", vkey->books[vkey->Testament()-1][vkey->Book()-1].versemax[vkey->Chapter()-1]);
+ (*retVal)[5] = CORBA::string_dup(num.c_str());
+ }
+ else {
+ TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key);
+ if (tkey) {
+ if (tkey->firstChild()) {
+ do {
+ count++;
+ }
+ while (tkey->nextSibling());
+ tkey->parent();
+ }
+ retVal->length(count);
+ count = 0;
+ if (tkey->firstChild()) {
+ do {
+ (*retVal)[count++] = CORBA::string_dup(tkey->getLocalName());
+ }
+ while (tkey->nextSibling());
+ tkey->parent();
+ }
+ }
+ }
+ return retVal;
+}
+
+}
diff --git a/bindings/corba/orbitcpp/swordorb-impl.hpp b/bindings/corba/orbitcpp/swordorb-impl.hpp
new file mode 100644
index 0000000..bd3be38
--- /dev/null
+++ b/bindings/corba/orbitcpp/swordorb-impl.hpp
@@ -0,0 +1,67 @@
+#ifndef _ORBIT_CPP_IDL_sword_IMPL_HH
+#define _ORBIT_CPP_IDL_sword_IMPL_HH
+
+#include "swordorb-cpp-skels.h"
+#include <swmodule.h>
+#include <swmgr.h>
+#include <rawtext.h>
+#include <map>
+
+
+namespace swordorb {
+
+static const char *SWNULL = "<SWNULL>";
+extern sword::RawText NULLMod;
+
+//Inherit from abstract Skeleton:
+class SWModule_impl : public POA_swordorb::SWModule {
+ sword::SWModule *delegate;
+public:
+ SWModule_impl(sword::SWModule *delegate) { this->delegate = delegate; }
+
+ SearchHitList *search(const char *istr, SearchType searchType, CORBA::Long flags, const char *scope) throw(CORBA::SystemException);
+ void terminateSearch() throw(CORBA::SystemException) { delegate->terminateSearch = true; }
+ char error() throw(CORBA::SystemException) { return delegate->Error(); }
+ CORBA::Long getEntrySize() throw(CORBA::SystemException) { return delegate->getEntrySize(); }
+ void setKeyText(const char *key) throw(CORBA::SystemException) { delegate->KeyText(key); }
+ char *getKeyText() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->KeyText()); }
+ StringList *getKeyChildren() throw(CORBA::SystemException);
+ char *getName() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->Name()); }
+ char *getDescription() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->Description()); }
+ char *getCategory() throw(CORBA::SystemException);
+ void previous() throw(CORBA::SystemException) { delegate->decrement(); }
+ void next() throw(CORBA::SystemException) { delegate->increment(); }
+ void begin() throw(CORBA::SystemException) { delegate->setPosition(sword::TOP); }
+ char *getStripText() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->StripText()); }
+ StringList *getEntryAttribute(const char *level1, const char *level2, const char *level3) throw(CORBA::SystemException);
+ char *getRenderText() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->RenderText()); }
+ char *getConfigEntry(const char *key) throw(CORBA::SystemException) { return CORBA::string_dup(((char *)delegate->getConfigEntry(key)) ? (char *)delegate->getConfigEntry(key):SWNULL); }
+
+};
+
+typedef std::map<std::string, SWModule_impl *> SWModuleMap;
+
+class SWMgr_impl : public POA_swordorb::SWMgr {
+ sword::SWMgr *delegate;
+ SWModuleMap moduleImpls;
+public:
+ SWMgr_impl(sword::SWMgr *delegate) { this->delegate = delegate; }
+
+ ModInfoList *getModInfoList() throw(CORBA::SystemException);
+ SWModule_ptr getModuleByName(const char *name) throw(CORBA::SystemException);
+ char *getPrefixPath() throw(CORBA::SystemException) { return CORBA::string_dup(delegate->prefixPath); }
+ char *getConfigPath() throw(CORBA::SystemException) { return CORBA::string_dup(delegate->configPath); }
+ void setGlobalOption(const char *option, const char *value) throw(CORBA::SystemException) { delegate->setGlobalOption(option, value); }
+ char *getGlobalOption(const char *option) throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->getGlobalOption(option)); }
+ char *getGlobalOptionTip(const char *option) throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->getGlobalOptionTip(option)); }
+ StringList *getGlobalOptions() throw(CORBA::SystemException);
+ StringList *getGlobalOptionValues(const char *option) throw(CORBA::SystemException);
+ void setCipherKey(const char *modName, const char *key) throw(CORBA::SystemException) { delegate->setCipherKey(modName, key); }
+ void terminate() throw(CORBA::SystemException);
+ CORBA::Boolean testConnection() throw(CORBA::SystemException);
+
+};
+}; // namespace hellomodule
+
+
+#endif //_ORBIT_CPP_IDL_helloworld_IMPL_HH
diff --git a/bindings/corba/orbitcpp/testclient.cpp b/bindings/corba/orbitcpp/testclient.cpp
new file mode 100644
index 0000000..2bbb60c
--- /dev/null
+++ b/bindings/corba/orbitcpp/testclient.cpp
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: f; c-basic-offset: 4 -*- */
+
+#include "swordorb-cpp-stubs.h"
+#include "swordorb-cpp-common.h"
+#include <iostream>
+
+int main (int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ std::cerr << "Usage:" << std::endl
+ << " " << argv[0] << " IOR" << std::endl
+ << std::endl;
+ return -1;
+ }
+
+ try
+ {
+ // Initialize ORBit
+ CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv, "orbit-local-orb");
+
+ // Get a reference to the server from the IOR passed on the
+ // command line
+ CORBA::Object_var obj = orb->string_to_object(argv[1]);
+ swordorb::SWMgr_var mgr = swordorb::SWMgr::_narrow(obj);
+
+ swordorb::SWModule_ptr module;
+ swordorb::ModInfoList *modInfoList;
+
+ std::cout << "Connected: " << mgr->testConnection() << "\n";
+ std::cout << "PrefixPath: " << mgr->getPrefixPath() << "\n";
+ std::cout << "ConfigPath: " << mgr->getConfigPath() << "\n";
+ modInfoList = mgr->getModInfoList();
+ std::cout << "sequence length: " << modInfoList->length() << "\n";
+/*
+ for (int i = 0; i < modInfoList->length(); i++) {
+ std::cout << (*modInfoList)[i].name << ": " << (*modInfoList)[i].category << ": " << (*modInfoList)[i].language << "\n";
+ module = mgr->getModuleByName((*modInfoList)[i].name);
+ module->setKeyText("jas1:19");
+ std::cout << module->getRenderText() << "\n";
+ }
+*/
+ module = mgr->getModuleByName("NASB");
+ module->setKeyText("jn3:1");
+ std::cout << module->getRenderText();
+ /*
+ swordorb::SearchHitList *searchResults;
+ searchResults = module->search("God love world", swordorb::MULTIWORD, 0, "");
+ for (int i = 0; i < searchResults->length(); i++) {
+ std::cout << (*searchResults)[i].key << "\n";
+ }
+ */;
+
+
+
+ } catch(const CORBA::Exception& ex) {
+ std::cout << "Exception caught. Maybe the server is not running, or the IOR is wrong." << std::endl;
+ }
+
+ return 0;
+}