summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Message.h
blob: 006d5153c446aff7245ba615178d9b89acda40cb (plain)
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
#ifndef EVENT_H_XZAQ4HR
#define EVENT_H_XZAQ4HR

#include <map>
#include <list>
#include <set>
#include <vector>
#include <string>

#include <DOM/Document.hpp>
#include <DOM/io/Stream.hpp>

#include <inttypes.h>

#define TAGNAME(elem) ((Arabica::DOM::Element<std::string>)elem).getTagName()
#define LOCALNAME(elem) ((Arabica::DOM::Element<std::string>)elem).getLocalName()
#define ATTR(elem, attr) ((Arabica::DOM::Element<std::string>)elem).getAttribute(attr)
#define HAS_ATTR(elem, attr) ((Arabica::DOM::Element<std::string>)elem).hasAttribute(attr)

namespace uscxml {

class Data {
public:
	enum Type {
	    VERBATIM,
	    INTERPRETED
	};

	Data() {}
	Data(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {}
	Data(const Arabica::DOM::Node<std::string>& dom);
	virtual ~Data() {}

	static Data fromJSON(const std::string& jsonString);
	static Data fromXML(const std::string& xmlString);
	Arabica::DOM::Document<std::string> toDocument();
	std::string toXMLString() {
		std::stringstream ss;
		ss << toDocument();
		return ss.str();
	}

	std::map<std::string, Data> getCompund() { return compound; }
	void setCompound(const std::map<std::string, Data>& compound) { this->compound = compound; }

	std::list<Data> getArray() { return array; }
	void setArray(const std::list<Data>& array) { this->array = array; }

	std::string getAtom() { return atom; }
	void setAtom(const std::string& atom) { this->atom = atom; }

	Type getType() { return type; }
	void setType(const Type type) { this->type = type; }

	
#ifdef SWIGIMPORTED
protected:
#endif

	std::map<std::string, Data> compound;
	std::list<Data> array;
	std::string atom;
	Type type;

protected:
	Arabica::DOM::Document<std::string> toNode(const Arabica::DOM::Document<std::string>& factory, const Data& data);

#ifndef SWIGJAVA
	friend std::ostream& operator<< (std::ostream& os, const Data& data);
#endif
};

class Event {
public:
	enum Type {
	    INTERNAL = 1,
	    EXTERNAL = 2,
	    PLATFORM = 3
	};

	Event() : type(INTERNAL) {}
	Event(const Arabica::DOM::Node<std::string>& xmlString) : type(INTERNAL) {};
	bool operator< (const Event& other) const     {
		return this < &other;
	}

	std::string getName() { return name; }
	void setName(const std::string& name) { this->name = name; }

	Type getType() { return type; }
	void setType(const Type type) { this->type = type; }

	std::string getOrigin() { return origin; }
	void setOrigin(const std::string& origin) { this->origin = origin; }

	std::string getOriginType() { return origintype; }
	void setOriginType(const std::string& originType) { this->origintype = originType; }

	Arabica::DOM::Node<std::string> getDOM() { return dom; }
	void setDOM(const Arabica::DOM::Node<std::string>& dom) { this->dom = dom; }

	std::string getSendId() { return sendid; }
	void setSendId(const std::string& sendId) { this->sendid = sendId; }

	std::string getInvokeId() { return invokeid; }
	void setInvokeId(const std::string& invokeId) { this->invokeid = invokeId; }

	Data getData() { return data; }
	void setData(const Data& invokeId) { this->data = data; }

	static Event fromXML(const std::string& xmlString);
	Arabica::DOM::Document<std::string> toDocument();
	std::string toXMLString() {
		std::stringstream ss;
		ss << toDocument();
		return ss.str();
	}

#ifdef SWIGIMPORTED
protected:
#endif

	std::string name;
	Type type;
	std::string origin;
	std::string origintype;
	Arabica::DOM::Node<std::string> dom;
	std::string sendid;
	std::string invokeid;
	Data data;

#ifndef SWIG
	friend std::ostream& operator<< (std::ostream& os, const Event& event);
#endif
};

class InvokeRequest : public Event {
public:
	InvokeRequest(Event event) : Event(event) {}
	InvokeRequest() {}
	
	std::string getType() { return type; }
	void setType(const std::string& type) { this->type = type; }

	std::string getSource() { return src; }
	void setSource(const std::string& src) { this->src = src; }

	std::string getContent() { return content; }
	void setContent(const std::string& content) { this->content = content; }
	
	bool isAutoForwarded() { return autoForward; }
	void setAutoForwarded(bool autoForward) { this->autoForward = autoForward; }

#ifdef SWIG
	/// TODO: Do we want to set namelist and params as well?
	std::map<std::string, std::string> getNameList() { return namelist; }

	virtual const std::vector<std::string> getNameListKeys() {
		std::set<std::string> keys;
		namelist_t::const_iterator nameListIter = namelist.begin();
		while (nameListIter != namelist.end()) {
			keys.insert(nameListIter->first);
			nameListIter++;
		}
		return std::vector<std::string>(keys.begin(), keys.end());
	}

	// substitute multimap by map with vectors for language bindings
	std::map<std::string, std::vector<std::string> > getParams() {
		std::map<std::string, std::vector<std::string> > paramsMap;
		params_t::iterator paramIter = params.begin();
		while(paramIter != params.end()) {
			paramsMap[paramIter->first].push_back(paramIter->second);
			paramIter++;
		}
		return paramsMap;
	}
	
	const std::vector<std::string> getParamKeys() {
		std::set<std::string> keys;
		params_t::iterator paramIter = params.begin();
		while(paramIter != params.end()) {
			keys.insert(paramIter->first);
			paramIter++;
		}
		return std::vector<std::string>(keys.begin(), keys.end());
	}
	
#else
	std::map<std::string, std::string>& getNameList() { return namelist; }
	std::multimap<std::string, std::string>& getParams() { return params; }
#endif

	static InvokeRequest fromXML(const std::string& xmlString);
	Arabica::DOM::Document<std::string> toDocument();
	std::string toXMLString() {
		std::stringstream ss;
		ss << toDocument();
		return ss.str();
	}

#ifdef SWIGIMPORTED
protected:
#endif
	std::string type;
	std::string src;
	std::string content;
	bool autoForward;
	std::map<std::string, std::string> namelist;
	std::multimap<std::string, std::string> params;

	typedef std::multimap<std::string, std::string> params_t;
	typedef std::map<std::string, std::string> namelist_t;

#ifndef SWIG
	friend std::ostream& operator<< (std::ostream& os, const InvokeRequest& sendReq);
#endif

};

class SendRequest : public Event {
public:
	SendRequest() {}
	SendRequest(Event event) : Event(event) {}

	std::string getTarget() { return target; }
	void setTarget(const std::string& target) { this->target = target; }

	std::string getType() { return type; }
	void setType(const std::string& type) { this->type = type; }

	uint32_t getDelayMs() { return delayMs; }
	void setDelayMs(uint32_t delayMs) { this->delayMs = delayMs; }
	
	std::string getContent() { return content; }
	void setContent(const std::string& content) { this->content = content; }

#ifdef SWIG
	/// TODO: Do we want to set namelist and params as well?
	std::map<std::string, std::string> getNameList() { return namelist; }

	virtual const std::vector<std::string> getNameListKeys() {
		std::set<std::string> keys;
		namelist_t::const_iterator nameListIter = namelist.begin();
		while (nameListIter != namelist.end()) {
			keys.insert(nameListIter->first);
			nameListIter++;
		}
		return std::vector<std::string>(keys.begin(), keys.end());
	}

	// substitute multimap by map with vectors for language bindings
	std::map<std::string, std::vector<std::string> > getParams() {
		std::map<std::string, std::vector<std::string> > paramsMap;
		params_t::iterator paramIter = params.begin();
		while(paramIter != params.end()) {
			paramsMap[paramIter->first].push_back(paramIter->second);
			paramIter++;
		}
		return paramsMap;
	}
	
	const std::vector<std::string> getParamKeys() {
		std::set<std::string> keys;
		params_t::iterator paramIter = params.begin();
		while(paramIter != params.end()) {
			keys.insert(paramIter->first);
			paramIter++;
		}
		return std::vector<std::string>(keys.begin(), keys.end());
	}
	
#else
	std::map<std::string, std::string>& getNameList() { return namelist; }
	std::multimap<std::string, std::string>& getParams() { return params; }
#endif

	static SendRequest fromXML(const std::string& xmlString);
	Arabica::DOM::Document<std::string> toDocument();
	std::string toXMLString() {
		std::stringstream ss;
		ss << toDocument();
		//    std::cout << ss.str() << std::endl;
		return ss.str();
	}

#ifdef SWIGIMPORTED
protected:
#endif
	std::string target;
	std::string type;
	uint32_t delayMs;
	std::string content;

	std::map<std::string, std::string> namelist;
	std::multimap<std::string, std::string> params;
	
	typedef std::map<std::string, std::string> namelist_t;
	typedef std::multimap<std::string, std::string> params_t;

#ifndef SWIG
	friend std::ostream& operator<< (std::ostream& os, const SendRequest& sendReq);
#endif

};

}


#endif /* end of include guard: EVENT_H_XZAQ4HR */