summaryrefslogtreecommitdiffstats
path: root/src/bindings/swig/csharp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-06-25 21:05:44 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-06-25 21:05:44 (GMT)
commite3767be4f9c5874d9c996200f2e9705ce31a5976 (patch)
treebe3d06f550286e23eeb3252277c1a2b7d12554ef /src/bindings/swig/csharp
parent758bda908ded461c9d34d274a18454ffba4b7450 (diff)
downloaduscxml-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/csharp')
-rw-r--r--src/bindings/swig/csharp/CMakeLists.txt4
-rw-r--r--src/bindings/swig/csharp/org/uscxml/InterpreterException.cs7
-rw-r--r--src/bindings/swig/csharp/stl_list.i49
-rw-r--r--src/bindings/swig/csharp/stl_set.i73
-rw-r--r--src/bindings/swig/csharp/uscxml.i180
5 files changed, 94 insertions, 219 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>;