diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
commit | e3767be4f9c5874d9c996200f2e9705ce31a5976 (patch) | |
tree | be3d06f550286e23eeb3252277c1a2b7d12554ef /src/bindings/swig | |
parent | 758bda908ded461c9d34d274a18454ffba4b7450 (diff) | |
download | uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.zip uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.gz uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.bz2 |
Work on bindings
- Introduced exceptions into C# and Java
- Moved binding examples to /embedding
- Interpreter will now throw exceptions, beware!
Diffstat (limited to 'src/bindings/swig')
18 files changed, 591 insertions, 335 deletions
diff --git a/src/bindings/swig/csharp/CMakeLists.txt b/src/bindings/swig/csharp/CMakeLists.txt index 6310778..80d093e 100644 --- a/src/bindings/swig/csharp/CMakeLists.txt +++ b/src/bindings/swig/csharp/CMakeLists.txt @@ -59,6 +59,8 @@ if (DMCS_EXECUTABLE OR CSC_EXECUTABLE) # build managed code part if (CSC_EXECUTABLE) ADD_CUSTOM_TARGET(csharp + COMMAND ${CMAKE_COMMAND} -E + copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${CSC_EXECUTABLE} /target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll @@ -67,6 +69,8 @@ if (DMCS_EXECUTABLE OR CSC_EXECUTABLE) COMMENT "Creating umundoCSharp.dll for C# ...") else() ADD_CUSTOM_TARGET(csharp + COMMAND ${CMAKE_COMMAND} -E + copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${DMCS_EXECUTABLE} -target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll diff --git a/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs b/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs new file mode 100644 index 0000000..f86dc0e --- /dev/null +++ b/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs @@ -0,0 +1,7 @@ +namespace org.uscxml { + class InterpreterException : System.ApplicationException { + public InterpreterException(string message) + : base(message) { + } + } +}
\ No newline at end of file diff --git a/src/bindings/swig/csharp/stl_list.i b/src/bindings/swig/csharp/stl_list.i deleted file mode 100644 index aabd448..0000000 --- a/src/bindings/swig/csharp/stl_list.i +++ /dev/null @@ -1,49 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * std_list.i - * ----------------------------------------------------------------------------- */ - -%include <std_common.i> - -%{ -#include <list> -#include <stdexcept> -%} - -namespace std { - - template<class T> class list { - public: - typedef size_t size_type; - typedef T value_type; - typedef const value_type& const_reference; - list(); - size_type size() const; - %rename(isEmpty) empty; - bool empty() const; - void clear(); - %rename(add) push_back; - void push_back(const value_type& x); - %extend { - const_reference get(int i) throw (std::out_of_range) { - int size = int(self->size()); - int j; - if (i>=0 && i<size) { - std::list<T>::const_iterator p; - p=self->begin(); - for (j=0; j<i; j++) {p++;} - return (*p); - } - else - throw std::out_of_range("list index out of range"); - } - } - }; -} - -%define specialize_std_list(T) -#warning "specialize_std_list - specialization for type T no longer needed" -%enddef - diff --git a/src/bindings/swig/csharp/stl_set.i b/src/bindings/swig/csharp/stl_set.i deleted file mode 100644 index d009a7b..0000000 --- a/src/bindings/swig/csharp/stl_set.i +++ /dev/null @@ -1,73 +0,0 @@ -/*========================================================================= - - Program: GDCM (Grassroots DICOM). A DICOM library - - Copyright (c) 2006-2011 Mathieu Malaterre - All rights reserved. - See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notice for more information. - -=========================================================================*/ -/* ----------------------------------------------------------------------------- - * std_set.i - * - * SWIG typemaps for std::set - * ----------------------------------------------------------------------------- */ - -%include <std_common.i> - -// ------------------------------------------------------------------------ -// std::set -// ------------------------------------------------------------------------ - -%{ -#include <set> -#include <algorithm> -#include <stdexcept> -%} - -// exported class - -namespace std { - - template<class V> class set { - // add typemaps here - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef V value_type; - set(); - set(const set<V> &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - const V& get(const V& key) throw (std::out_of_range) { - std::set<V>::iterator i = self->find(key); - if (i != self->end()) - return *i; - else - throw std::out_of_range("key not found"); - } - void insert(const V& key) { // Do NOT call this function 'set' ! - self->insert(key); - } - void del(const V& key) throw (std::out_of_range) { - std::set<V>::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const V& key) { - std::set<V>::iterator i = self->find(key); - return i != self->end(); - } - } - }; - -}
\ No newline at end of file diff --git a/src/bindings/swig/csharp/uscxml.i b/src/bindings/swig/csharp/uscxml.i index 07604c4..e7b7d62 100644 --- a/src/bindings/swig/csharp/uscxml.i +++ b/src/bindings/swig/csharp/uscxml.i @@ -20,9 +20,15 @@ typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; typedef uscxml::SendRequest SendRequest; +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 %csconst(1); @@ -31,14 +37,6 @@ typedef uscxml::SendRequest SendRequest; %rename(equals) operator==; %rename(isValid) operator bool; -%ignore operator!=; -%ignore operator<; -%ignore operator=; -%ignore operator[]; -%ignore operator std::list<Data>; -%ignore operator std::string; -%ignore operator std::map<std::string,Data>; -%ignore operator<<; //************************************************** @@ -49,6 +47,7 @@ typedef uscxml::SendRequest SendRequest; #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" +#include "../../../uscxml/concurrency/BlockingQueue.h" #include "../../../uscxml/Interpreter.h" //#include <DOM/Document.hpp> @@ -59,104 +58,89 @@ typedef uscxml::SendRequest SendRequest; #include "../wrapped/WrappedInvoker.h" #include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" using namespace uscxml; using namespace Arabica::DOM; #include "../wrapped/WrappedInvoker.cpp" #include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" %} -%ignore uscxml::NumAttr; -%ignore uscxml::SCXMLParser; -%ignore uscxml::InterpreterImpl; +// see http://binf.gmu.edu/software/SWIG/CSharp.html#csharp_exceptions +%insert(runtime) %{ + // Code to handle throwing of C# CustomApplicationException from C/C++ code. + // The equivalent delegate to the callback, CSharpExceptionCallback_t, is CustomExceptionDelegate + // and the equivalent customExceptionCallback instance is customDelegate + typedef void (SWIGSTDCALL* CSharpExceptionCallback_t)(const char *); + CSharpExceptionCallback_t customExceptionCallback = NULL; + + extern "C" SWIGEXPORT + void SWIGSTDCALL CustomExceptionRegisterCallback(CSharpExceptionCallback_t customCallback) { + customExceptionCallback = customCallback; + } + + // Note that SWIG detects any method calls named starting with + // SWIG_CSharpSetPendingException for warning 845 + static void SWIG_CSharpSetPendingExceptionCustom(const char *msg) { + customExceptionCallback(msg); + } +%} -%ignore create(); +%pragma(csharp) imclasscode=%{ + class CustomExceptionHelper { + // C# delegate for the C/C++ customExceptionCallback + public delegate void CustomExceptionDelegate(string message); + static CustomExceptionDelegate customDelegate = + new CustomExceptionDelegate(SetPendingCustomException); + + [System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] + public static extern + void CustomExceptionRegisterCallback(CustomExceptionDelegate customCallback); + + static void SetPendingCustomException(string message) { + SWIGPendingException.Set(new org.uscxml.InterpreterException(message)); + } + + static CustomExceptionHelper() { + CustomExceptionRegisterCallback(customDelegate); + } + } + static CustomExceptionHelper exceptionHelper = new CustomExceptionHelper(); +%} -%ignore uscxml::Interpreter::getDelayQueue(); -%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); +%define WRAP_THROW_EXCEPTION( MATCH ) +%exception MATCH %{ +try { + $action +} catch (uscxml::Event& e) { + std::stringstream ss; + ss << std::endl << e; + SWIG_CSharpSetPendingExceptionCustom(ss.str().c_str()); +} +%} +%enddef -%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); -%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element<std::string>&, const std::string&); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::step); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret); -%ignore uscxml::Event::Event(const Arabica::DOM::Node<std::string>&); -%ignore uscxml::Event::getStrippedDOM; -%ignore uscxml::Event::getFirstDOMElement; -%ignore uscxml::Event::getDOM(); -%ignore uscxml::Event::setDOM(const Arabica::DOM::Document<std::string>&); -%ignore uscxml::Event::toDocument(); -%template(DataList) std::list<uscxml::Data>; -%template(DataMap) std::map<std::string, uscxml::Data>; -%template(StringSet) std::set<std::string>; -%template(StringVector) std::vector<std::string>; -%template(ParamPair) std::pair<std::string, uscxml::Data>; -%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; -%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; -%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%include "../uscxml_ignores.i" %rename Data DataNative; -%feature("director") uscxml::WrappedInvoker; -%feature("director") uscxml::WrappedDataModel; - // translate param multimap to Map<String, List<Data> > %rename(getParamsNative) uscxml::Event::getParams(); %csmethodmodifiers uscxml::Event::getParams() "private"; -%extend uscxml::Event { - std::vector<std::pair<std::string, Data> > getParamPairs() { - std::vector<std::pair<std::string, Data> > pairs; - std::multimap<std::string, Data>::iterator paramPairIter = self->getParams().begin(); - while(paramPairIter != self->getParams().end()) { - pairs.push_back(*paramPairIter); - paramPairIter++; - } - return pairs; - } -}; - -%extend uscxml::Interpreter { - std::vector<std::string> getIOProcessorKeys() { - std::vector<std::string> keys; - std::map<std::string, IOProcessor>::const_iterator iter = self->getIOProcessors().begin(); - while(iter != self->getIOProcessors().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - - std::vector<std::string> getInvokerKeys() { - std::vector<std::string> keys; - std::map<std::string, Invoker>::const_iterator iter = self->getInvokers().begin(); - while(iter != self->getInvokers().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - -}; - -%extend uscxml::Data { - std::vector<std::string> getCompundKeys() { - std::vector<std::string> keys; - std::map<std::string, Data>::const_iterator iter = self->compound.begin(); - while(iter != self->compound.end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } -}; - +%include "../uscxml_beautify.i" //*********************************************** @@ -167,19 +151,21 @@ using namespace Arabica::DOM; %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" - -# %include <DOM/Document.hpp> -# %include <DOM/Node.hpp> -# %include <DOM/Element.hpp> -# %include <DOM/Attr.hpp> -# %include <DOM/Text.hpp> +%include "../../../uscxml/concurrency/BlockingQueue.h" %include "../wrapped/WrappedInvoker.h" %include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" + -# %template(XMLDocument) Arabica::DOM::Document<std::string>; -# %template(XMLNode) Arabica::DOM::Node<std::string>; -# %template(XMLElement) Arabica::DOM::Element<std::string>; -# %template(XMLAttr) Arabica::DOM::Attr<std::string>; -# %template(XMLText) Arabica::DOM::Text<std::string>; +%template(DataList) std::list<uscxml::Data>; +%template(DataMap) std::map<std::string, uscxml::Data>; +%template(StringSet) std::set<std::string>; +%template(StringVector) std::vector<std::string>; +%template(StringList) std::list<std::string>; +%template(ParamPair) std::pair<std::string, uscxml::Data>; +%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; +%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; +%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>; diff --git a/src/bindings/swig/java/CMakeLists.txt b/src/bindings/swig/java/CMakeLists.txt index 51d67bb..3a7e9e0 100644 --- a/src/bindings/swig/java/CMakeLists.txt +++ b/src/bindings/swig/java/CMakeLists.txt @@ -33,3 +33,42 @@ set_target_properties(uscxmlNativeJava PROPERTIES COMPILE_FLAGS "-DSWIG") swig_link_libraries(uscxmlNativeJava uscxml) set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE) + +FIND_PROGRAM(ANT_EXECUTABLE ant PATHS $ENV{ANT_HOME}/bin ENV PATH ) +if (ANT_EXECUTABLE) + set(JAR_EXCLUDE_DEBUG OFF) + set(JAR_EXCLUDE_JNI OFF) + + # include all the JNI libraries prepared from DIST_PREPARE builds on the various desktop platforms + if (DIST_PREPARE) + if (CMAKE_CROSSCOMPILING) + if (ANDROID) + find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc protoc.exe) + set(JAR_EXCLUDE_JNI ON) # JNI inside jar not allowed with Android + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/android) + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/${CMAKE_CROSSCOMPILING_TARGET_LC}) + endif() + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package) + endif() + else() + # when not preparing a distribution, just put the jar into the libs + SET(JAR_JNI_ROOT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + endif() + + ADD_CUSTOM_TARGET(java + COMMAND ${ANT_EXECUTABLE} + -Dlib.dir=${JAR_JNI_ROOT_PATH} + -Dsrc.dir=${PROJECT_SOURCE_DIR} + -Dbuild.dir=${PROJECT_BINARY_DIR} + -Dbuild.type=${CMAKE_BUILD_TYPE} + -Dexclude.debug=${JAR_EXCLUDE_DEBUG} + -Dexclude.jni=${JAR_EXCLUDE_JNI} + -f build-java.xml + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/contrib/java + COMMENT "Creating the jar ...") + +else() + message(STATUS "Could not find ant binary - will not build jars") +endif()
\ No newline at end of file diff --git a/src/bindings/swig/java/org/uscxml/InterpreterException.java b/src/bindings/swig/java/org/uscxml/InterpreterException.java new file mode 100644 index 0000000..b089566 --- /dev/null +++ b/src/bindings/swig/java/org/uscxml/InterpreterException.java @@ -0,0 +1,9 @@ +package org.uscxml; + +public class InterpreterException extends Exception { + private static final long serialVersionUID = -3534919496547591015L; + + public InterpreterException(String msg) { + super(msg); + } +} diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index f72084e..b780f74 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -3,10 +3,6 @@ // provide a macro for the header files #define SWIGIMPORTED 1 -// import swig typemaps -//%include <arrays_java.i> -//%include <inttypes.i> - %include <stl.i> %include <std_map.i> %include <std_string.i> @@ -22,25 +18,20 @@ typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; typedef uscxml::SendRequest SendRequest; +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 %javaconst(1); -# %shared_ptr(uscxml::dom::Element); -# %shared_ptr(uscxml::dom::Executable); - %rename(equals) operator==; %rename(isValid) operator bool; -%ignore operator!=; -%ignore operator<; -%ignore operator=; -%ignore operator[]; -%ignore operator std::list<Data>; -%ignore operator std::string; -%ignore operator std::map<std::string,Data>; -%ignore operator<<; //************************************************** @@ -52,113 +43,54 @@ typedef uscxml::SendRequest SendRequest; #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" #include "../../../uscxml/Interpreter.h" - -//#include <DOM/Document.hpp> -//#include <DOM/Node.hpp> -//#include <DOM/Element.hpp> -//#include <DOM/Attr.hpp> -//#include <DOM/Text.hpp> +#include "../../../uscxml/concurrency/BlockingQueue.h" #include "../wrapped/WrappedInvoker.h" #include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" using namespace uscxml; using namespace Arabica::DOM; #include "../wrapped/WrappedInvoker.cpp" #include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" %} -%ignore uscxml::NumAttr; -%ignore uscxml::SCXMLParser; -%ignore uscxml::InterpreterImpl; - -%ignore create(); - -%ignore uscxml::Interpreter::getDelayQueue(); - -%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); - -%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); -%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element<std::string>&, const std::string&); - -%ignore uscxml::Event::Event(const Arabica::DOM::Node<std::string>&); -%ignore uscxml::Event::getStrippedDOM; -%ignore uscxml::Event::getFirstDOMElement; -%ignore uscxml::Event::getDOM(); -%ignore uscxml::Event::setDOM(const Arabica::DOM::Document<std::string>&); -%ignore uscxml::Event::toDocument(); - -%template(DataList) std::list<uscxml::Data>; -%template(DataMap) std::map<std::string, uscxml::Data>; -%template(StringSet) std::set<std::string>; -%template(StringVector) std::vector<std::string>; -%template(ParamPair) std::pair<std::string, uscxml::Data>; -%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; -%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; -%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%define WRAP_THROW_EXCEPTION( MATCH ) +%javaexception("org.uscxml.InterpreterException") MATCH { + try { + $action + } + catch ( uscxml::Event& e ) { + jclass eclass = jenv->FindClass("org/uscxml/InterpreterException"); + if ( eclass ) { + std::stringstream ss; + ss << std::endl << e; + jenv->ThrowNew( eclass, ss.str().c_str() ); + } + } +} +%enddef + +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::step); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret); + + +%include "../uscxml_ignores.i" %rename Data DataNative; -%feature("director") uscxml::WrappedInvoker; -%feature("director") uscxml::WrappedDataModel; - // translate param multimap to Map<String, List<Data> > %rename(getParamsNative) uscxml::Event::getParams(); %javamethodmodifiers uscxml::Event::getParams() "private"; -%extend uscxml::Event { - std::vector<std::pair<std::string, Data> > getParamPairs() { - std::vector<std::pair<std::string, Data> > pairs; - std::multimap<std::string, Data>::iterator paramPairIter = self->getParams().begin(); - while(paramPairIter != self->getParams().end()) { - pairs.push_back(*paramPairIter); - paramPairIter++; - } - return pairs; - } -}; - -%extend uscxml::Interpreter { - std::vector<std::string> getIOProcessorKeys() { - std::vector<std::string> keys; - std::map<std::string, IOProcessor>::const_iterator iter = self->getIOProcessors().begin(); - while(iter != self->getIOProcessors().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - - std::vector<std::string> getInvokerKeys() { - std::vector<std::string> keys; - std::map<std::string, Invoker>::const_iterator iter = self->getInvokers().begin(); - while(iter != self->getInvokers().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - -}; - -%extend uscxml::Data { - std::vector<std::string> getCompundKeys() { - std::vector<std::string> keys; - std::map<std::string, Data>::const_iterator iter = self->compound.begin(); - while(iter != self->compound.end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } -}; - +%include "../uscxml_beautify.i" //*********************************************** @@ -169,19 +101,21 @@ using namespace Arabica::DOM; %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" - -# %include <DOM/Document.hpp> -# %include <DOM/Node.hpp> -# %include <DOM/Element.hpp> -# %include <DOM/Attr.hpp> -# %include <DOM/Text.hpp> +%include "../../../uscxml/concurrency/BlockingQueue.h" %include "../wrapped/WrappedInvoker.h" %include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" + -# %template(XMLDocument) Arabica::DOM::Document<std::string>; -# %template(XMLNode) Arabica::DOM::Node<std::string>; -# %template(XMLElement) Arabica::DOM::Element<std::string>; -# %template(XMLAttr) Arabica::DOM::Attr<std::string>; -# %template(XMLText) Arabica::DOM::Text<std::string>; +%template(DataList) std::list<uscxml::Data>; +%template(DataMap) std::map<std::string, uscxml::Data>; +%template(StringSet) std::set<std::string>; +%template(StringVector) std::vector<std::string>; +%template(StringList) std::list<std::string>; +%template(ParamPair) std::pair<std::string, uscxml::Data>; +%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; +%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; +%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>; diff --git a/src/bindings/swig/uscxml_beautify.i b/src/bindings/swig/uscxml_beautify.i new file mode 100644 index 0000000..8b57e78 --- /dev/null +++ b/src/bindings/swig/uscxml_beautify.i @@ -0,0 +1,67 @@ +%extend uscxml::Event { + std::vector<std::pair<std::string, Data> > getParamPairs() { + std::vector<std::pair<std::string, Data> > pairs; + std::multimap<std::string, Data>::iterator paramPairIter = self->getParams().begin(); + while(paramPairIter != self->getParams().end()) { + pairs.push_back(*paramPairIter); + paramPairIter++; + } + return pairs; + } +}; + +%extend uscxml::Interpreter { + + std::vector<std::string> getBasicConfiguration() { + Arabica::XPath::NodeSet<std::string> nativeConfig = self->getBasicConfiguration(); + std::vector<std::string> config; + for (int i = 0; i < nativeConfig.size(); i++) { + Arabica::DOM::Element<std::string> elem(nativeConfig[i]); + config.push_back(elem.getAttribute("id")); + } + return config; + } + + std::vector<std::string> getConfiguration() { + Arabica::XPath::NodeSet<std::string> nativeConfig = self->getConfiguration(); + std::vector<std::string> config; + for (int i = 0; i < nativeConfig.size(); i++) { + Arabica::DOM::Element<std::string> elem(nativeConfig[i]); + config.push_back(elem.getAttribute("id")); + } + return config; + } + + std::vector<std::string> getIOProcessorKeys() { + std::vector<std::string> keys; + std::map<std::string, IOProcessor>::const_iterator iter = self->getIOProcessors().begin(); + while(iter != self->getIOProcessors().end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } + + std::vector<std::string> getInvokerKeys() { + std::vector<std::string> keys; + std::map<std::string, Invoker>::const_iterator iter = self->getInvokers().begin(); + while(iter != self->getInvokers().end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } + +}; + +%extend uscxml::Data { + std::vector<std::string> getCompundKeys() { + std::vector<std::string> keys; + std::map<std::string, Data>::const_iterator iter = self->compound.begin(); + while(iter != self->compound.end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } +}; diff --git a/src/bindings/swig/uscxml_ignores.i b/src/bindings/swig/uscxml_ignores.i new file mode 100644 index 0000000..4f8b2a3 --- /dev/null +++ b/src/bindings/swig/uscxml_ignores.i @@ -0,0 +1,54 @@ +%ignore uscxml::NumAttr; +%ignore uscxml::SCXMLParser; +%ignore uscxml::InterpreterImpl; + +%ignore create(); + +%ignore uscxml::Interpreter::getDelayQueue(); +%ignore uscxml::Interpreter::fromDOM; +%ignore uscxml::Interpreter::fromClone; +%ignore uscxml::Interpreter::start(); +%ignore uscxml::Interpreter::stop(); +%ignore uscxml::Interpreter::setCmdLineOptions(std::map<std::string, std::string>); +%ignore uscxml::Interpreter::getDocument; +%ignore uscxml::Interpreter::getImpl; +%ignore uscxml::Interpreter::runOnMainThread; +%ignore uscxml::Interpreter::getHTTPServlet(); +%ignore uscxml::Interpreter::getNodeSetForXPath(const std::string&); +%ignore uscxml::Interpreter::isLegalConfiguration(const Arabica::XPath::NodeSet<std::string>&); +%ignore uscxml::Interpreter::getInstances(); + +%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); + +%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); +%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); +%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Node<std::string>&, const std::string&); +%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); +%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); +%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Node<std::string>&, const std::string&); +%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); +%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element<std::string>&, const std::string&); +%ignore uscxml::WrappedDataModel::evalAsBool(const Arabica::DOM::Node<std::string>&, const std::string&); + +%ignore uscxml::WrappedExecutableContent::create(InterpreterImpl*); +%ignore uscxml::WrappedExecutableContent::enterElement(const Arabica::DOM::Node<std::string>&); +%ignore uscxml::WrappedExecutableContent::exitElement(const Arabica::DOM::Node<std::string>&); + +%ignore uscxml::WrappedIOProcessor::create(InterpreterImpl*); + +%ignore uscxml::Event::Event(const Arabica::DOM::Node<std::string>&); +%ignore uscxml::Event::getStrippedDOM; +%ignore uscxml::Event::getFirstDOMElement; +%ignore uscxml::Event::getDOM(); +%ignore uscxml::Event::setDOM(const Arabica::DOM::Document<std::string>&); +%ignore uscxml::Event::toDocument(); + +%ignore operator!=; +%ignore operator<; +%ignore operator=; +%ignore operator[]; +%ignore operator std::list<Data>; +%ignore operator std::string; +%ignore operator std::map<std::string,Data>; +%ignore operator<<; + diff --git a/src/bindings/swig/wrapped/WrappedDataModel.cpp b/src/bindings/swig/wrapped/WrappedDataModel.cpp index 901d246..8ba57be 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.cpp +++ b/src/bindings/swig/wrapped/WrappedDataModel.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #include "WrappedDataModel.h" namespace uscxml { diff --git a/src/bindings/swig/wrapped/WrappedDataModel.h b/src/bindings/swig/wrapped/WrappedDataModel.h index 2b1ad48..026bed2 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.h +++ b/src/bindings/swig/wrapped/WrappedDataModel.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #ifndef WRAPPEDDATAMODEL_H_DBAAD6AF #define WRAPPEDDATAMODEL_H_DBAAD6AF diff --git a/src/bindings/swig/wrapped/WrappedExecutableContent.cpp b/src/bindings/swig/wrapped/WrappedExecutableContent.cpp new file mode 100644 index 0000000..a876754 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedExecutableContent.cpp @@ -0,0 +1,27 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#include "WrappedExecutableContent.h" + +namespace uscxml { + +WrappedExecutableContent::WrappedExecutableContent() {} +WrappedExecutableContent::~WrappedExecutableContent() {} + +}
\ No newline at end of file diff --git a/src/bindings/swig/wrapped/WrappedExecutableContent.h b/src/bindings/swig/wrapped/WrappedExecutableContent.h new file mode 100644 index 0000000..24c6978 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedExecutableContent.h @@ -0,0 +1,86 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#ifndef WRAPPEDEXECUTABLECONTENT_H_F690F480 +#define WRAPPEDEXECUTABLECONTENT_H_F690F480 + +#include "../../../uscxml/Message.h" +#include "../../../uscxml/Factory.h" +#include "../../../uscxml/Interpreter.h" + +namespace uscxml { + +class WrappedExecutableContent : public ExecutableContentImpl { +public: + WrappedExecutableContent(); + virtual ~WrappedExecutableContent(); + + virtual WrappedExecutableContent* create(const Interpreter& interpreter) { + return new WrappedExecutableContent(); + } + + virtual boost::shared_ptr<ExecutableContentImpl> create(InterpreterImpl* interpreter) { + _interpreter = interpreter->shared_from_this(); + return boost::shared_ptr<ExecutableContentImpl>(create(_interpreter)); + } + + virtual std::string getLocalName() { + return ""; + } + + virtual std::string getNamespace() { + return "http://www.w3.org/2005/07/scxml"; + } + + virtual void enterElement(const Arabica::DOM::Node<std::string>& node) { + std::ostringstream ssElement; + ssElement << node; + enterElement(ssElement.str()); + } + + virtual void exitElement(const Arabica::DOM::Node<std::string>& node) { + std::ostringstream ssElement; + ssElement << node; + exitElement(ssElement.str()); + } + + virtual bool processChildren() { + return false; + } + + virtual void enterElement(const std::string& node) { + + } + + virtual void exitElement(const std::string& node) { + + } + + void croak() throw(Event) { + + } + +private: + Interpreter _interpreter; +}; + +} + + +#endif /* end of include guard: WRAPPEDEXECUTABLECONTENT_H_F690F480 */ diff --git a/src/bindings/swig/wrapped/WrappedIOProcessor.cpp b/src/bindings/swig/wrapped/WrappedIOProcessor.cpp new file mode 100644 index 0000000..2f39d80 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedIOProcessor.cpp @@ -0,0 +1,27 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#include "WrappedIOProcessor.h" + +namespace uscxml { + +WrappedIOProcessor::WrappedIOProcessor() {} +WrappedIOProcessor::~WrappedIOProcessor() {} + +}
\ No newline at end of file diff --git a/src/bindings/swig/wrapped/WrappedIOProcessor.h b/src/bindings/swig/wrapped/WrappedIOProcessor.h new file mode 100644 index 0000000..70c400e --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedIOProcessor.h @@ -0,0 +1,62 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#ifndef WRAPPEDIOPROCESSOR_H_AE98064A +#define WRAPPEDIOPROCESSOR_H_AE98064A + +#include "../../../uscxml/Message.h" +#include "../../../uscxml/Factory.h" +#include "../../../uscxml/Interpreter.h" + +namespace uscxml { + +class WrappedIOProcessor : public IOProcessorImpl { +public: + WrappedIOProcessor(); + virtual ~WrappedIOProcessor(); + + virtual WrappedIOProcessor* create(const Interpreter& interpreter) { + return new WrappedIOProcessor(); + } + + virtual boost::shared_ptr<IOProcessorImpl> create(InterpreterImpl* interpreter) { + _interpreter = interpreter->shared_from_this(); + return boost::shared_ptr<IOProcessorImpl>(create(_interpreter)); + } + virtual std::list<std::string> getNames() { + return std::list<std::string>(); + }; + + virtual Data getDataModelVariables() { + Data data; + return data; + } + + virtual void send(const SendRequest& req) { + + } + +private: + Interpreter _interpreter; +}; + +} + + +#endif /* end of include guard: WRAPPEDIOPROCESSOR_H_AE98064A */ diff --git a/src/bindings/swig/wrapped/WrappedInvoker.cpp b/src/bindings/swig/wrapped/WrappedInvoker.cpp index b775878..8187a9f 100644 --- a/src/bindings/swig/wrapped/WrappedInvoker.cpp +++ b/src/bindings/swig/wrapped/WrappedInvoker.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #include "WrappedInvoker.h" namespace uscxml { diff --git a/src/bindings/swig/wrapped/WrappedInvoker.h b/src/bindings/swig/wrapped/WrappedInvoker.h index 61eedac..ff56b15 100644 --- a/src/bindings/swig/wrapped/WrappedInvoker.h +++ b/src/bindings/swig/wrapped/WrappedInvoker.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + #ifndef WRAPPEDINVOKER_H_F9725D47 #define WRAPPEDINVOKER_H_F9725D47 |