blob: 37ec6699540046a8a007264528d1a2eea1cabded (
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
|
/**
* @file
* @author 2012-2013 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 "USCXMLInvoker.h"
#include <glog/logging.h>
#ifdef BUILD_AS_PLUGINS
#include <Pluma/Connector.hpp>
#endif
namespace uscxml {
#ifdef BUILD_AS_PLUGINS
PLUMA_CONNECTOR
bool pluginConnect(pluma::Host& host) {
host.add( new USCXMLInvokerProvider() );
return true;
}
#endif
USCXMLInvoker::USCXMLInvoker() : _cancelled(false) {
_parentQueue._invoker = this;
}
USCXMLInvoker::~USCXMLInvoker() {
_cancelled = true;
};
boost::shared_ptr<InvokerImpl> USCXMLInvoker::create(InterpreterImpl* interpreter) {
boost::shared_ptr<USCXMLInvoker> invoker = boost::shared_ptr<USCXMLInvoker>(new USCXMLInvoker());
invoker->_parentInterpreter = interpreter;
return invoker;
}
Data USCXMLInvoker::getDataModelVariables() {
Data data;
return data;
}
void USCXMLInvoker::send(const SendRequest& req) {
_invokedInterpreter.receive(req);
}
void USCXMLInvoker::cancel(const std::string sendId) {
assert(false);
}
void USCXMLInvoker::invoke(const InvokeRequest& req) {
if (req.src.length() > 0) {
_invokedInterpreter = Interpreter::fromURI(req.src);
} else if (req.dom) {
Arabica::DOM::DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation();
Arabica::DOM::Document<std::string> dom = domFactory.createDocument(req.dom.getNamespaceURI(), "", 0);
// we need to import the parent - to support xpath test150
Arabica::DOM::Node<std::string> newNode = dom.importNode(req.dom, true);
dom.appendChild(newNode);
// TODO: where do we get the namespace from?
_invokedInterpreter = Interpreter::fromDOM(dom, std::map<std::string, std::string>());
} else if (req.content.size() > 0) {
_invokedInterpreter = Interpreter::fromXML(req.content);
} else {
LOG(ERROR) << "Cannot invoke nested SCXML interpreter, neither src attribute nor content nor DOM is given";
}
if (_invokedInterpreter) {
DataModel dataModel(_invokedInterpreter.getImpl()->getDataModel());
_invokedInterpreter.getImpl()->setParentQueue(&_parentQueue);
// transfer namespace prefixes
_invokedInterpreter.setNameSpaceInfo(_parentInterpreter->getNameSpaceInfo());
_invokedInterpreter.getImpl()->_sessionId = req.invokeid;
/// test240 assumes that invoke request params will carry over to the datamodel
_invokedInterpreter.getImpl()->setInvokeRequest(req);
_invokedInterpreter.start();
// tthread::this_thread::sleep_for(tthread::chrono::seconds(1));
} else {
/// test 530
_parentInterpreter->receive(Event("done.invoke." + _invokeId, Event::PLATFORM));
}
}
void USCXMLInvoker::ParentQueue::push(const SendRequest& event) {
// test 252
if (_invoker->_cancelled)
return;
SendRequest copyEvent(event);
copyEvent.invokeid = _invoker->_invokeId;
_invoker->_parentInterpreter->receive(copyEvent);
}
}
|