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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
#include "uscxml/Common.h"
#include "uscxml/config.h"
#include "uscxml/Factory.h"
#include "uscxml/Message.h"
#include "uscxml/Interpreter.h"
#include <glog/logging.h>
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
#ifdef BUILD_AS_PLUGINS
# include "uscxml/plugins/Plugins.h"
#else
# include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h"
# include "uscxml/plugins/ioprocessor/comet/CometIOProcessor.h"
# include "uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h"
# include "uscxml/plugins/invoker/scxml/USCXMLInvoker.h"
# include "uscxml/plugins/invoker/http/HTTPServletInvoker.h"
# include "uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h"
# include "uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h"
# include "uscxml/plugins/invoker/system/SystemInvoker.h"
# include "uscxml/plugins/invoker/xhtml/XHTMLInvoker.h"
#ifdef PROTOBUF_FOUND
# include "uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h"
#endif
# ifdef UMUNDO_FOUND
# include "uscxml/plugins/invoker/umundo/UmundoInvoker.h"
# include "uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h"
# endif
# ifdef OPENSCENEGRAPH_FOUND
# include "uscxml/plugins/invoker/graphics/openscenegraph/OSGInvoker.h"
# include "uscxml/plugins/invoker/graphics/openscenegraph/converter/OSGConverter.h"
# endif
# ifdef MILES_FOUND
# include "uscxml/plugins/invoker/miles/MilesSessionInvoker.h"
# include "uscxml/plugins/invoker/miles/SpatialAudio.h"
# endif
# ifdef FFMPEG_FOUND
# include "uscxml/plugins/invoker/ffmpeg/FFMPEGInvoker.h"
# endif
# ifdef V8_FOUND
# include "uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h"
# endif
# ifdef JSC_FOUND
# include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h"
# endif
# ifdef SWI_FOUND
# include "uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h"
# endif
#include "uscxml/plugins/datamodel/null/NULLDataModel.h"
#include "uscxml/plugins/datamodel/xpath/XPathDataModel.h"
# include "uscxml/plugins/element/fetch/FetchElement.h"
# include "uscxml/plugins/element/respond/RespondElement.h"
# include "uscxml/plugins/element/postpone/PostponeElement.h"
# if 0
# include "uscxml/plugins/element/mmi/MMIEvents.h"
# endif
#endif
#define ELEMENT_MMI_REGISTER(class)\
class##Element* class = new class##Element(); \
registerExecutableContent(class);
namespace uscxml {
Factory::Factory(Factory* parentFactory) : _parentFactory(parentFactory) {
}
Factory::Factory() {
_parentFactory = NULL;
#ifdef BUILD_AS_PLUGINS
if (pluginPath.length() == 0) {
// try to read USCXML_PLUGIN_PATH environment variable
pluginPath = (getenv("USCXML_PLUGIN_PATH") != NULL ? getenv("USCXML_PLUGIN_PATH") : "");
}
if (pluginPath.length() > 0) {
pluma.acceptProviderType<InvokerImplProvider>();
pluma.acceptProviderType<IOProcessorImplProvider>();
pluma.acceptProviderType<DataModelImplProvider>();
pluma.acceptProviderType<ExecutableContentImplProvider>();
pluma.loadFromFolder(pluginPath);
std::vector<InvokerImplProvider*> invokerProviders;
pluma.getProviders(invokerProviders);
for (std::vector<InvokerImplProvider*>::iterator it = invokerProviders.begin() ; it != invokerProviders.end() ; ++it) {
InvokerImpl* invoker = (*it)->create();
registerInvoker(invoker);
}
std::vector<IOProcessorImplProvider*> ioProcessorProviders;
pluma.getProviders(ioProcessorProviders);
for (std::vector<IOProcessorImplProvider*>::iterator it = ioProcessorProviders.begin() ; it != ioProcessorProviders.end() ; ++it) {
IOProcessorImpl* ioProcessor = (*it)->create();
registerIOProcessor(ioProcessor);
}
std::vector<DataModelImplProvider*> dataModelProviders;
pluma.getProviders(dataModelProviders);
for (std::vector<DataModelImplProvider*>::iterator it = dataModelProviders.begin() ; it != dataModelProviders.end() ; ++it) {
DataModelImpl* dataModel = (*it)->create();
registerDataModel(dataModel);
}
}
#else
#ifdef UMUNDO_FOUND
{
UmundoInvoker* invoker = new UmundoInvoker();
registerInvoker(invoker);
}
{
VoiceXMLInvoker* invoker = new VoiceXMLInvoker();
registerInvoker(invoker);
}
#endif
#ifdef MILES_FOUND
{
MilesSessionInvoker* invoker = new MilesSessionInvoker();
registerInvoker(invoker);
}
{
SpatialAudio* invoker = new SpatialAudio();
registerInvoker(invoker);
}
#endif
#ifdef FFMPEG_FOUND
{
FFMPEGInvoker* invoker = new FFMPEGInvoker();
registerInvoker(invoker);
}
#endif
#ifdef OPENSCENEGRAPH_FOUND
{
OSGInvoker* invoker = new OSGInvoker();
registerInvoker(invoker);
}
{
OSGConverter* invoker = new OSGConverter();
registerInvoker(invoker);
}
#endif
#if (defined V8_FOUND && defined BUILD_DM_ECMA)
{
V8DataModel* dataModel = new V8DataModel();
registerDataModel(dataModel);
}
#endif
#if (defined JSC_FOUND && defined BUILD_DM_ECMA)
{
JSCDataModel* dataModel = new JSCDataModel();
registerDataModel(dataModel);
}
#endif
#if (defined SWI_FOUND && defined BUILD_DM_PROLOG)
{
SWIDataModel* dataModel = new SWIDataModel();
registerDataModel(dataModel);
}
#endif
#ifdef BUILD_DM_XPATH
{
XPathDataModel* dataModel = new XPathDataModel();
registerDataModel(dataModel);
}
#endif
#ifdef PROTOBUF_FOUND
{
MMIHTTPIOProcessor* ioProcessor = new MMIHTTPIOProcessor();
registerIOProcessor(ioProcessor);
}
#endif
// these are always available
{
NULLDataModel* dataModel = new NULLDataModel();
registerDataModel(dataModel);
}
{
XHTMLInvoker* invoker = new XHTMLInvoker();
registerInvoker(invoker);
}
{
USCXMLInvoker* invoker = new USCXMLInvoker();
registerInvoker(invoker);
}
{
HTTPServletInvoker* invoker = new HTTPServletInvoker();
registerInvoker(invoker);
}
{
HeartbeatInvoker* invoker = new HeartbeatInvoker();
registerInvoker(invoker);
}
{
DirMonInvoker* invoker = new DirMonInvoker();
registerInvoker(invoker);
}
{
SystemInvoker* invoker = new SystemInvoker();
registerInvoker(invoker);
}
{
BasicHTTPIOProcessor* ioProcessor = new BasicHTTPIOProcessor();
registerIOProcessor(ioProcessor);
}
{
SCXMLIOProcessor* ioProcessor = new SCXMLIOProcessor();
registerIOProcessor(ioProcessor);
}
{
InterpreterServlet* ioProcessor = new InterpreterServlet();
registerIOProcessor(ioProcessor);
}
{
FetchElement* element = new FetchElement();
registerExecutableContent(element);
}
{
RespondElement* element = new RespondElement();
registerExecutableContent(element);
}
{
PostponeElement* element = new PostponeElement();
registerExecutableContent(element);
}
#endif
}
Factory::~Factory() {
#ifdef BUILD_AS_PLUGINS
pluma.unloadAll();
#endif
}
void Factory::registerIOProcessor(IOProcessorImpl* ioProcessor) {
std::set<std::string> names = ioProcessor->getNames();
std::set<std::string>::iterator nameIter = names.begin();
if (nameIter != names.end()) {
std::string canonicalName = *nameIter;
_ioProcessors[canonicalName] = ioProcessor;
while(nameIter != names.end()) {
_ioProcessorAliases[*nameIter] = canonicalName;
nameIter++;
}
}
}
void Factory::registerDataModel(DataModelImpl* dataModel) {
std::set<std::string> names = dataModel->getNames();
std::set<std::string>::iterator nameIter = names.begin();
if (nameIter != names.end()) {
std::string canonicalName = *nameIter;
_dataModels[canonicalName] = dataModel;
while(nameIter != names.end()) {
_dataModelAliases[*nameIter] = canonicalName;
nameIter++;
}
}
}
void Factory::registerInvoker(InvokerImpl* invoker) {
std::set<std::string> names = invoker->getNames();
std::set<std::string>::iterator nameIter = names.begin();
if (nameIter != names.end()) {
std::string canonicalName = *nameIter;
_invokers[canonicalName] = invoker;
while(nameIter != names.end()) {
_invokerAliases[*nameIter] = canonicalName;
nameIter++;
}
}
}
void Factory::registerExecutableContent(ExecutableContentImpl* executableContent) {
std::string localName = executableContent->getLocalName();
std::string nameSpace = executableContent->getNamespace();
_executableContent[std::make_pair(localName, nameSpace)] = executableContent;
}
std::map<std::string, IOProcessorImpl*> Factory::getIOProcessors() {
std::map<std::string, IOProcessorImpl*> ioProcs;
if (_parentFactory) {
ioProcs = _parentFactory->getIOProcessors();
}
std::map<std::string, IOProcessorImpl*>::iterator ioProcIter = _ioProcessors.begin();
while(ioProcIter != _ioProcessors.end()) {
ioProcs.insert(std::make_pair(ioProcIter->first, ioProcIter->second));
ioProcIter++;
}
return ioProcs;
}
boost::shared_ptr<InvokerImpl> Factory::createInvoker(const std::string& type, InterpreterImpl* interpreter) {
// do we have this type ourself?
if (_invokerAliases.find(type) != _invokerAliases.end()) {
std::string canonicalName = _invokerAliases[type];
if (_invokers.find(canonicalName) != _invokers.end()) {
return _invokers[canonicalName]->create(interpreter);
}
}
// lookup in parent factory
if (_parentFactory) {
return _parentFactory->createInvoker(type, interpreter);
} else {
LOG(ERROR) << "No " << type << " Invoker known";
}
return boost::shared_ptr<InvokerImpl>();
}
boost::shared_ptr<DataModelImpl> Factory::createDataModel(const std::string& type, InterpreterImpl* interpreter) {
// do we have this type ourself?
if (_dataModelAliases.find(type) != _dataModelAliases.end()) {
std::string canonicalName = _dataModelAliases[type];
if (_dataModels.find(canonicalName) != _dataModels.end()) {
return _dataModels[canonicalName]->create(interpreter);
}
}
// lookup in parent factory
if (_parentFactory) {
return _parentFactory->createDataModel(type, interpreter);
} else {
LOG(ERROR) << "No " << type << " Datamodel known";
}
return boost::shared_ptr<DataModelImpl>();
}
boost::shared_ptr<IOProcessorImpl> Factory::createIOProcessor(const std::string& type, InterpreterImpl* interpreter) {
// do we have this type ourself?
if (_ioProcessorAliases.find(type) != _ioProcessorAliases.end()) {
std::string canonicalName = _ioProcessorAliases[type];
if (_ioProcessors.find(canonicalName) != _ioProcessors.end()) {
return _ioProcessors[canonicalName]->create(interpreter);
}
}
// lookup in parent factory
if (_parentFactory) {
return _parentFactory->createIOProcessor(type, interpreter);
} else {
LOG(ERROR) << "No " << type << " Datamodel known";
}
return boost::shared_ptr<IOProcessorImpl>();
}
boost::shared_ptr<ExecutableContentImpl> Factory::createExecutableContent(const std::string& localName, const std::string& nameSpace, InterpreterImpl* interpreter) {
// do we have this type in this factory?
std::string actualNameSpace = (nameSpace.length() == 0 ? "http://www.w3.org/2005/07/scxml" : nameSpace);
if (_executableContent.find(std::make_pair(localName, actualNameSpace)) != _executableContent.end()) {
return _executableContent[std::make_pair(localName, actualNameSpace)]->create(interpreter);
}
// lookup in parent factory
if (_parentFactory) {
return _parentFactory->createExecutableContent(localName, nameSpace, interpreter);
} else {
LOG(ERROR) << "Executable content " << localName << " in " << actualNameSpace << " not available in factory";
}
return boost::shared_ptr<ExecutableContentImpl>();
}
Factory* Factory::getInstance() {
if (_instance == NULL) {
_instance = new Factory();
}
return _instance;
}
void EventHandlerImpl::returnEvent(Event& event) {
if (event.invokeid.length() == 0)
event.invokeid = _invokeId;
if (event.type == 0)
event.type = Event::EXTERNAL;
if (event.origin.length() == 0)
event.origin = "#_" + _invokeId;
if (event.origintype.length() == 0)
event.origintype = _type;
_interpreter->receive(event);
}
Factory* Factory::_instance = NULL;
std::string Factory::pluginPath;
}
|