1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
%module(directors="1", allprotected="1") uscxmlNativeCSharp
// provide a macro for the header files
#define SWIGIMPORTED 1
%include <stl.i>
%include <std_map.i>
%include <std_string.i>
%include <inttypes.i>
%include "../stl_set.i"
%include "../stl_list.i"
%include <boost_shared_ptr.i>
// these are needed at least for the templates to work
typedef uscxml::Data Data;
typedef uscxml::Event Event;
typedef uscxml::InvokeRequest InvokeRequest;
typedef uscxml::SendRequest SendRequest;
typedef uscxml::Invoker Invoker;
typedef uscxml::IOProcessor IOProcessor;
typedef uscxml::DataModel DataModel;
typedef uscxml::ExecutableContent ExecutableContent;
typedef uscxml::InvokerImpl InvokerImpl;
typedef uscxml::IOProcessorImpl IOProcessorImpl;
typedef uscxml::DataModelImpl DataModelImpl;
typedef uscxml::ExecutableContentImpl ExecutableContentImpl;
%feature("director") uscxml::WrappedInvoker;
%feature("director") uscxml::WrappedDataModel;
%feature("director") uscxml::WrappedIOProcessor;
%feature("director") uscxml::WrappedExecutableContent;
%feature("director") uscxml::WrappedInterpreterMonitor;
// disable warning related to unknown base class
#pragma SWIG nowarn=401
// do not warn when we override symbols via extend
#pragma SWIG nowarn=302
// do not warn when ignoring overrided method
#pragma SWIG nowarn=516
%csconst(1);
%rename(equals) operator==;
%rename(isValid) operator bool;
//**************************************************
// This ends up in the generated wrapper code
//**************************************************
%{
#include "../../../uscxml/Message.h"
#include "../../../uscxml/Factory.h"
#include "../../../uscxml/Interpreter.h"
#include "../../../uscxml/concurrency/BlockingQueue.h"
#include "../wrapped/WrappedInvoker.h"
#include "../wrapped/WrappedDataModel.h"
#include "../wrapped/WrappedExecutableContent.h"
#include "../wrapped/WrappedIOProcessor.h"
#include "../wrapped/WrappedInterpreterMonitor.h"
using namespace uscxml;
using namespace Arabica::DOM;
// the wrapped* C++ classes get rid of DOM nodes and provide more easily wrapped base classes
#include "../wrapped/WrappedInvoker.cpp"
#include "../wrapped/WrappedDataModel.cpp"
#include "../wrapped/WrappedExecutableContent.cpp"
#include "../wrapped/WrappedIOProcessor.cpp"
#include "../wrapped/WrappedInterpreterMonitor.cpp"
%}
// 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);
}
%}
%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();
%}
%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
WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML);
WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI);
WRAP_THROW_EXCEPTION(uscxml::Interpreter::step);
WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret);
%define WRAP_TO_STRING( CLASSNAME )
%csmethodmodifiers CLASSNAME::ToString() "public override";
%extend CLASSNAME {
virtual std::string ToString() {
std::stringstream ss;
ss << *self;
return ss.str();
}
};
%enddef
WRAP_TO_STRING(uscxml::Event);
WRAP_TO_STRING(uscxml::Data);
WRAP_TO_STRING(uscxml::SendRequest);
WRAP_TO_STRING(uscxml::InvokeRequest);
%include "../uscxml_ignores.i"
//***********************************************
// Beautify important classes
//***********************************************
%csmethodmodifiers uscxml::Event::getParamMap() "private";
%csmethodmodifiers uscxml::Event::getParamMapKeys() "private";
%csmethodmodifiers uscxml::Event::setParamMap(const std::map<std::string, std::list<uscxml::Data> >&) "private";
%csmethodmodifiers uscxml::Event::getNameListKeys() "private";
%csmethodmodifiers uscxml::Interpreter::getIOProcessorKeys() "private";
%csmethodmodifiers uscxml::Interpreter::getInvokerKeys() "private";
%csmethodmodifiers uscxml::Interpreter::getInvokers() "private";
%csmethodmodifiers uscxml::Interpreter::getIOProcessors() "private";
%csmethodmodifiers uscxml::Data::getCompoundKeys() "private";
%include "../uscxml_beautify.i"
%typemap(csimports) uscxml::Interpreter %{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
%}
%typemap(cscode) uscxml::Interpreter %{
public Dictionary<string, NativeIOProcessor> getIOProcessors() {
Dictionary<string, NativeIOProcessor> ioProcs = new Dictionary<string, NativeIOProcessor>();
StringVector keys = getIOProcessorKeys();
IOProcMap ioProcMap = getIOProcessorsNative();
for (int i = 0; i < keys.Count; i++) {
ioProcs[keys[i]] = ioProcMap[keys[i]];
}
return ioProcs;
}
public Dictionary<string, NativeInvoker> getInvokers() {
Dictionary<string, NativeInvoker> invokers = new Dictionary<string, NativeInvoker>();
StringVector keys = getInvokerKeys();
InvokerMap invokerMap = getInvokersNative();
for (int i = 0; i < keys.Count; i++) {
invokers[keys[i]] = invokerMap[keys[i]];
}
return invokers;
}
%}
%rename(getCompoundNative) uscxml::Data::getCompound();
%rename(getArrayNative) uscxml::Data::getArray();
%rename(setCompoundNative) uscxml::Data::setCompound(const std::map<std::string, Data>&);
%rename(setArrayNative) uscxml::Data::setArray(const std::list<Data>&);
%csmethodmodifiers uscxml::Data::getCompound() "private";
%csmethodmodifiers uscxml::Data::getArray() "private";
%csmethodmodifiers uscxml::Data::setCompound(const std::map<std::string, Data>&) "private";
%csmethodmodifiers uscxml::Data::setArray(const std::list<Data>&) "private";
%csmethodmodifiers uscxml::Data::getCompoundKeys() "private";
%typemap(csimports) uscxml::Data %{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
%}
%typemap(cscode) uscxml::Data %{
public Data(List<Data> arr) : this() {
setArray(arr);
}
public Data(Dictionary<string, Data> compound) : this() {
setCompound(compound);
}
public Dictionary<string, Data> getCompound() {
Dictionary<string, Data> compound = new Dictionary<string, Data>();
DataMap dataMap = getCompoundNative();
StringVector dataMapKeys = getCompoundKeys();
for (int i = 0; i < dataMapKeys.Count; i++) {
compound[dataMapKeys[i]] = dataMap[dataMapKeys[i]];
}
return compound;
}
public void setCompound(Dictionary<string, Data> compound) {
DataMap dataMap = new DataMap();
foreach(KeyValuePair<string, Data> entry in compound) {
dataMap.Add(entry);
}
setCompoundNative(dataMap);
}
public List<Data> getArray() {
List<Data> arr = new List<Data>();
DataList dataList = getArrayNative();
for (int i = 0; i < dataList.size(); i++) {
arr.Add(dataList.get(i));
}
return arr;
}
public void setArray(List<Data> arr) {
DataList dataList = new DataList();
foreach (Data data in arr) {
dataList.add(data);
}
setArrayNative(dataList);
}
%}
%rename(getNameListNative) uscxml::Event::getNameList();
%rename(getParamsNative) uscxml::Event::getParams();
%rename(setNameListNative) uscxml::Event::setNameList(const std::map<std::string, Data>&);
%rename(setParamsNative) uscxml::Event::setParams(const std::multimap<std::string, Data>&);
%csmethodmodifiers uscxml::Event::getNameList() "private";
%csmethodmodifiers uscxml::Event::getNameListKeys() "private";
%csmethodmodifiers uscxml::Event::getParams() "private";
%csmethodmodifiers uscxml::Event::setNameList(const std::map<std::string, Data>&) "private";
%csmethodmodifiers uscxml::Event::setParams(const std::multimap<std::string, Data>&) "private";
%typemap(csimports) uscxml::Event %{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
%}
%typemap(cscode) uscxml::Event %{
public Dictionary<string, List<Data> > getParams() {
Dictionary<string, List<Data>> parameters = new Dictionary<string, List<Data>>();
ParamMap paramMap = getParamMap();
foreach (KeyValuePair<string, DataList> entry in paramMap) {
DataList dataList = entry.Value;
List<Data> paramList = new List<Data>();
for (int i = 0; i < dataList.size(); i++) {
Data data = dataList.get(i);
paramList.Add(data);
}
parameters.Add(entry.Key, paramList);
}
return parameters;
}
public void setParams(Dictionary<string, List<Data>> parameters) {
ParamMap paramMap = new ParamMap();
foreach(KeyValuePair<string, List<Data>> entry in parameters) {
DataList dataList = new DataList();
foreach (Data data in entry.Value) {
dataList.add(data);
}
paramMap.Add(entry.Key, dataList);
}
setParamMap(paramMap);
}
public Dictionary<string, Data> getNameList() {
Dictionary<string, Data> nameList = new Dictionary<string, Data>();
DataMap nameListMap = getNameListNative();
StringVector nameListMapKeys = getNameListKeys();
for (int i = 0; i < nameListMapKeys.Count; i++) {
nameList[nameListMapKeys[i]] = nameListMap[nameListMapKeys[i]];
}
return nameList;
}
public void setNameList(Dictionary<string, Data> nameList) {
DataMap dataMap = new DataMap();
foreach (KeyValuePair<string, Data> entry in nameList) {
dataMap.Add(entry);
}
setNameListNative(dataMap);
}
%}
//***********************************************
// Parse the header file to generate wrappers
//***********************************************
%include "../../../uscxml/Common.h"
%include "../../../uscxml/Factory.h"
%include "../../../uscxml/Message.h"
%include "../../../uscxml/Interpreter.h"
%include "../../../uscxml/concurrency/BlockingQueue.h"
%include "../../../uscxml/messages/Blob.h"
%include "../../../uscxml/messages/Data.h"
%include "../../../uscxml/messages/Event.h"
%include "../../../uscxml/messages/InvokeRequest.h"
%include "../../../uscxml/messages/SendRequest.h"
%include "../../../uscxml/plugins/DataModel.h"
%include "../../../uscxml/plugins/EventHandler.h"
%include "../../../uscxml/plugins/ExecutableContent.h"
%include "../../../uscxml/plugins/Invoker.h"
%include "../../../uscxml/plugins/IOProcessor.h"
%include "../wrapped/WrappedInvoker.h"
%include "../wrapped/WrappedDataModel.h"
%include "../wrapped/WrappedExecutableContent.h"
%include "../wrapped/WrappedIOProcessor.h"
%include "../wrapped/WrappedInterpreterMonitor.h"
%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(ParamMap) std::map<std::string, std::list<uscxml::Data> >;
%template(IOProcMap) std::map<std::string, IOProcessor>;
%template(InvokerMap) std::map<std::string, Invoker>;
%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>;
|