diff options
Diffstat (limited to 'src')
65 files changed, 2031 insertions, 936 deletions
diff --git a/src/uscxml/Common.h b/src/uscxml/Common.h index 5b29427..017a177 100644 --- a/src/uscxml/Common.h +++ b/src/uscxml/Common.h @@ -54,9 +54,11 @@ typedef unsigned __int32 uint32_t; #include <sys/socket.h> #endif +/** + The usual operators as required for the PIMPL pattern. + */ #define PIMPL_OPERATORS(type) \ -\ -type() : _impl() { }\ +type() : _impl() { } \ type(const std::shared_ptr<type##Impl> impl) : _impl(impl) { }\ type(const type& other) : _impl(other._impl) { }\ virtual ~type() { };\ @@ -73,19 +75,18 @@ bool operator==(const type& other) const {\ bool operator!=(const type& other) const {\ return _impl != other._impl;\ }\ -type& operator= (const type& other) {\ +type& operator= (const type& other) {\ _impl = other._impl;\ return *this;\ } -#define PIMPL_OPERATORS2(type, base) \ -\ +#define PIMPL_OPERATORS_INHERIT(type, base) \ type() : _impl() {}\ -type(std::shared_ptr<type##Impl> const impl) : base(impl), _impl(impl) { }\ -type(const type& other) : base(other._impl), _impl(other._impl) { }\ +type(std::shared_ptr<type##Impl> const impl);\ +type(const type& other);\ virtual ~type() {};\ \ -operator bool() const {\ +operator bool() const {\ return !!_impl;\ }\ bool operator< (const type& other) const {\ @@ -97,14 +98,19 @@ bool operator==(const type& other) const {\ bool operator!=(const type& other) const {\ return _impl != other._impl;\ }\ -type& operator= (const type& other) {\ +type& operator= (const type& other); + + +#define PIMPL_OPERATORS_INHERIT_IMPL(type, base) \ +type::type(std::shared_ptr<type##Impl> const impl) : base(impl), _impl(impl) { }\ +type::type(const type& other) : base(other._impl), _impl(other._impl) { }\ +type& type::operator= (const type& other) {\ _impl = other._impl;\ base::_impl = _impl;\ return *this;\ } - #if defined(_WIN32) inline int setenv(const char *name, const char *value, int overwrite) { int errcode = 0; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index d6f61a2..9f2bfbf 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -20,6 +20,7 @@ #include "uscxml/config.h" #include "uscxml/Common.h" #include "uscxml/Interpreter.h" +#include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/util/DOM.h" #include "uscxml/util/URL.h" @@ -49,7 +50,7 @@ INITIALIZE_EASYLOGGINGPP namespace uscxml { // msxml.h defines all the DOM types as well -//using namespace xercesc; +//using namespace XERCESC_NS; static URL normalizeURL(const std::string url) { URL absUrl(url); @@ -70,48 +71,48 @@ Interpreter Interpreter::fromXML(const std::string& xml, const std::string& base std::shared_ptr<InterpreterImpl> interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); - std::unique_ptr<xercesc::XercesDOMParser> parser(new xercesc::XercesDOMParser()); - std::unique_ptr<xercesc::ErrorHandler> errHandler(new xercesc::HandlerBase()); + std::unique_ptr<XERCESC_NS::XercesDOMParser> parser(new XERCESC_NS::XercesDOMParser()); + std::unique_ptr<XERCESC_NS::ErrorHandler> errHandler(new XERCESC_NS::HandlerBase()); try { - parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); + parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); parser->setDoNamespaces(true); - parser->useScanner(xercesc::XMLUni::fgWFXMLScanner); + parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); parser->setErrorHandler(errHandler.get()); - xercesc::MemBufInputSource is((XMLByte*)xml.c_str(), xml.size(), X("fake")); + XERCESC_NS::MemBufInputSource is((XMLByte*)xml.c_str(), xml.size(), X("fake")); parser->parse(is); interpreterImpl->_document = parser->adoptDocument(); interpreterImpl->_baseURL = absUrl; InterpreterImpl::addInstance(interpreterImpl); - } catch (const xercesc::SAXParseException& toCatch) { + } catch (const XERCESC_NS::SAXParseException& toCatch) { ERROR_PLATFORM_THROW(X(toCatch.getMessage()).str()); - } catch (const xercesc::RuntimeException& toCatch) { + } catch (const XERCESC_NS::RuntimeException& toCatch) { ERROR_PLATFORM_THROW(X(toCatch.getMessage()).str()); - } catch (const xercesc::XMLException& toCatch) { + } catch (const XERCESC_NS::XMLException& toCatch) { ERROR_PLATFORM_THROW(X(toCatch.getMessage()).str()); - } catch (const xercesc::DOMException& toCatch) { + } catch (const XERCESC_NS::DOMException& toCatch) { ERROR_PLATFORM_THROW(X(toCatch.getMessage()).str()); } return interpreter; } -Interpreter Interpreter::fromElement(xercesc::DOMElement* scxml, const std::string& baseURL) { +Interpreter Interpreter::fromElement(XERCESC_NS::DOMElement* scxml, const std::string& baseURL) { URL absUrl = normalizeURL(baseURL); std::shared_ptr<InterpreterImpl> interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); - // *copy* the given xercesc::DOM to get rid of event listeners - xercesc::DOMImplementation* implementation = xercesc::DOMImplementationRegistry::getDOMImplementation(X("core")); + // *copy* the given XERCESC_NS::DOM to get rid of event listeners + XERCESC_NS::DOMImplementation* implementation = XERCESC_NS::DOMImplementationRegistry::getDOMImplementation(X("core")); interpreterImpl->_document = implementation->createDocument(); // we need to import the parent - to support xpath test150 - xercesc::DOMNode* newNode = interpreterImpl->_document->importNode(scxml, true); + XERCESC_NS::DOMNode* newNode = interpreterImpl->_document->importNode(scxml, true); // interpreterImpl->_document->adoptNode(newNode); interpreterImpl->_document->appendChild(newNode); @@ -123,19 +124,19 @@ Interpreter Interpreter::fromElement(xercesc::DOMElement* scxml, const std::stri return interpreter; } -Interpreter Interpreter::fromDocument(xercesc::DOMDocument* dom, const std::string& baseURL, bool copy) { +Interpreter Interpreter::fromDocument(XERCESC_NS::DOMDocument* dom, const std::string& baseURL, bool copy) { URL absUrl = normalizeURL(baseURL); std::shared_ptr<InterpreterImpl> interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); if (copy) { - // *copy* the given xercesc::DOM to get rid of event listeners - xercesc::DOMImplementation* implementation = xercesc::DOMImplementationRegistry::getDOMImplementation(X("core")); + // *copy* the given XERCESC_NS::DOM to get rid of event listeners + XERCESC_NS::DOMImplementation* implementation = XERCESC_NS::DOMImplementationRegistry::getDOMImplementation(X("core")); interpreterImpl->_document = implementation->createDocument(); // we need to import the parent - to support xpath test150 - xercesc::DOMNode* newNode = interpreterImpl->_document->importNode(dom->getDocumentElement(), true); + XERCESC_NS::DOMNode* newNode = interpreterImpl->_document->importNode(dom->getDocumentElement(), true); interpreterImpl->_document->appendChild(newNode); } else { @@ -154,14 +155,14 @@ Interpreter Interpreter::fromURL(const std::string& url) { std::shared_ptr<InterpreterImpl> interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); - std::unique_ptr<xercesc::XercesDOMParser> parser(new xercesc::XercesDOMParser()); - parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); + std::unique_ptr<XERCESC_NS::XercesDOMParser> parser(new XERCESC_NS::XercesDOMParser()); + parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); parser->setDoNamespaces(true); // we do not have a real schema anyway - parser->useScanner(xercesc::XMLUni::fgWFXMLScanner); + parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); - std::unique_ptr<xercesc::ErrorHandler> errHandler(new xercesc::HandlerBase()); + std::unique_ptr<XERCESC_NS::ErrorHandler> errHandler(new XERCESC_NS::HandlerBase()); parser->setErrorHandler(errHandler.get()); @@ -173,13 +174,13 @@ Interpreter Interpreter::fromURL(const std::string& url) { InterpreterImpl::addInstance(interpreterImpl); } - catch (const xercesc::SAXParseException& toCatch) { + catch (const XERCESC_NS::SAXParseException& toCatch) { LOG(ERROR) << X(toCatch.getMessage()); - } catch (const xercesc::RuntimeException& toCatch) { + } catch (const XERCESC_NS::RuntimeException& toCatch) { LOG(ERROR) << X(toCatch.getMessage()); - } catch (const xercesc::XMLException& toCatch) { + } catch (const XERCESC_NS::XMLException& toCatch) { LOG(ERROR) << X(toCatch.getMessage()); - } catch (const xercesc::DOMException& toCatch) { + } catch (const XERCESC_NS::DOMException& toCatch) { LOG(ERROR) << X(toCatch.getMessage()); } @@ -187,9 +188,49 @@ Interpreter Interpreter::fromURL(const std::string& url) { } +void Interpreter::reset() { + return _impl->reset(); +} + +InterpreterState Interpreter::step(bool blocking) { + return _impl->step(blocking); +}; + +void Interpreter::cancel() { + return _impl->cancel(); +} + +bool Interpreter::isInState(const std::string& stateId) { + return _impl->isInState(stateId); +} + +InterpreterState Interpreter::getState() { + return _impl->getState(); +} + +std::list<XERCESC_NS::DOMElement*> Interpreter::getConfiguration() { + return _impl->getConfiguration(); +} + +void Interpreter::receive(const Event& event) { + _impl->enqueueExternal(event); +} + +void Interpreter::setActionLanguage(ActionLanguage actionLanguage) { + return _impl->setActionLanguage(actionLanguage); +} + +void Interpreter::setMonitor(InterpreterMonitor* monitor) { + return _impl->setMonitor(monitor); +} + +std::list<InterpreterIssue> Interpreter::validate() { + return InterpreterIssue::forInterpreter(_impl.get()); +} + std::recursive_mutex StateTransitionMonitor::_mutex; -static void printNodeSet(const std::list<xercesc::DOMElement*> nodes) { +static void printNodeSet(const std::list<XERCESC_NS::DOMElement*> nodes) { std::string seperator; for (auto nIter = nodes.begin(); nIter != nodes.end(); nIter++) { std::cerr << seperator << (HAS_ATTR(*nIter, "id") ? ATTR(*nIter, "id") : DOMUtils::xPathForNode(*nIter)); @@ -197,7 +238,7 @@ static void printNodeSet(const std::list<xercesc::DOMElement*> nodes) { } } -void StateTransitionMonitor::beforeTakingTransition(const xercesc::DOMElement* transition) { +void StateTransitionMonitor::beforeTakingTransition(const XERCESC_NS::DOMElement* transition) { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl; } @@ -205,7 +246,7 @@ void StateTransitionMonitor::beforeTakingTransition(const xercesc::DOMElement* t void StateTransitionMonitor::onStableConfiguration() { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Stable Config: { "; - printNodeSet(_interpreter.getConfiguration()); +// printNodeSet(_interpreter.getConfiguration()); std::cerr << " }" << std::endl; } @@ -224,17 +265,17 @@ void StateTransitionMonitor::beforeProcessingEvent(const uscxml::Event& event) } } -void StateTransitionMonitor::beforeExecutingContent(const xercesc::DOMElement* element) { +void StateTransitionMonitor::beforeExecutingContent(const XERCESC_NS::DOMElement* element) { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Executable Content: " << DOMUtils::xPathForNode(element) << std::endl; } -void StateTransitionMonitor::beforeExitingState(const xercesc::DOMElement* state) { +void StateTransitionMonitor::beforeExitingState(const XERCESC_NS::DOMElement* state) { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Exiting: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; } -void StateTransitionMonitor::beforeEnteringState(const xercesc::DOMElement* state) { +void StateTransitionMonitor::beforeEnteringState(const XERCESC_NS::DOMElement* state) { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Entering: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; @@ -243,7 +284,7 @@ void StateTransitionMonitor::beforeEnteringState(const xercesc::DOMElement* stat void StateTransitionMonitor::beforeMicroStep() { std::lock_guard<std::recursive_mutex> lock(_mutex); std::cerr << "Config: {"; - printNodeSet(_interpreter.getConfiguration()); +// printNodeSet(_interpreter.getConfiguration()); std::cerr << "}" << std::endl; } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index fa5ab05..ae1268f 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -20,20 +20,28 @@ #ifndef INTERPRETER_H_6CD5A168 #define INTERPRETER_H_6CD5A168 + +#include "Common.h" + #include <map> -#include <mutex> #include <string> +#include <vector> -#include "Common.h" -#include "uscxml/interpreter/InterpreterImpl.h" -#include "uscxml/interpreter/InterpreterMonitor.h" // beware cyclic reference! -#include "uscxml/debug/InterpreterIssue.h" // beware cyclic reference! -#include <xercesc/dom/DOM.hpp> +#include "uscxml/interpreter/MicroStep.h" +#include "uscxml/plugins/DataModel.h" +#include "uscxml/interpreter/ContentExecutor.h" +#include "uscxml/interpreter/InterpreterState.h" namespace uscxml { -class InterpreterMonitor; // forward declare +class InterpreterMonitor; +class InterpreterImpl; +class InterpreterIssue; +/** + * @ingroup interpreter + * Options to pass into an interpreter. + */ class USCXML_API InterpreterOptions { public: InterpreterOptions() : @@ -75,60 +83,139 @@ public: }; +/** + * @ingroup interpreter + * Collection of instances for interpreter that constitute its action language. + */ +class USCXML_API ActionLanguage { +public: + MicroStep microStepper; ///< The microstepper instance to use + DataModel dataModel; ///< The datamodel to uses + ContentExecutor execContent; ///< To process executable content elements +}; + +/** + * @ingroup interpreter + * @ingroup facade + * Central class to interpret and process SCXML documents. + + Instances of this class are available from the static constructors. In order + to use an interpreter instance to actually *do* things, you will want to + provide an ActionLanguage and an InterpreterMonitor. + + We did avoid threading primitives within the core interpreter (there is + threading for nested interpeters in the USCXMLInvoker, though). As such, you + will have to call the <step> function continuously. + + */ + class USCXML_API Interpreter { public: - static Interpreter fromDocument(xercesc::DOMDocument* dom, + + /** + * Instantiate an Interpeter with a given XML document. + * @param dom A pointer to the XML document. + * @param baseURL An absolute URL to resolve relative URLs in the document. + * @param copy Whether to make a copy of the document, we deallocate it either way. + */ + static Interpreter fromDocument(XERCESC_NS::DOMDocument* dom, const std::string& baseURL, bool copy = true); - static Interpreter fromElement(xercesc::DOMElement* element, + /** + * Instantiate an Interpeter with a given XML element. + * This constructor will create a new document and copy/import the given element. + * @param element The element to be copies/imported as the new document element. + * @param baseURL An absolute URL to resolve relative URLs in the document. + */ + static Interpreter fromElement(XERCESC_NS::DOMElement* element, const std::string& baseURL); + /** + * Instantiate an Interpeter from a string containined proper XML markup. + * @param xml Textual representation of an SCXML document. + * @param baseURL An absolute URL to resolve relative URLs in the document. + */ static Interpreter fromXML(const std::string& xml, const std::string& baseURL); - static Interpreter fromURL(const std::string& URL); + /** + * Instantiate an Interpeter with a document located at an URL. + * @param url An absolute URL to locate the SCXML document. + */ + static Interpreter fromURL(const std::string& url); + + /** + * Instantiate an Interpeter as a copy of another. + * @param other The other interpreter. + */ static Interpreter fromClone(const Interpreter& other); + /** + * See PIMPL_OPERATORS macro in Common.h + */ PIMPL_OPERATORS(Interpreter); - void reset() { - return _impl->reset(); - } - - InterpreterState step(bool blocking = false) { - return _impl->step(blocking); - }; - - void cancel() { - return _impl->cancel(); - } - - virtual bool isInState(const std::string& stateId) { - return _impl->isInState(stateId); - } - - InterpreterState getState() { - return _impl->getState(); - } - - std::list<xercesc::DOMElement*> getConfiguration() { - return _impl->getConfiguration(); - } - - virtual void receive(const Event& event) { - _impl->enqueueExternal(event); - } - - void setActionLanguage(ActionLanguage actionLanguage) { - return _impl->setActionLanguage(actionLanguage); - } - - void setMonitor(InterpreterMonitor* monitor) { - return _impl->setMonitor(monitor); - } - - std::list<InterpreterIssue> validate() { - return InterpreterIssue::forInterpreter(_impl.get()); - } - + /** + * Perform a single microstep and return. + * @param blocking Whether or not to block the thread when waiting for events + * @return The new state of the interpreter object. + * + * @todo Have Interpreter::step() take a duration to block + */ + InterpreterState step(bool blocking = false); + + /** + * Unblock and mark for finalize. + */ + void cancel(); + + /** + * Finalize and reset interpeter. + */ + void reset(); + + /** + * Get all state elements that constitute the active configuration. + * @return A list of XML elements of the active states. + */ + std::list<XERCESC_NS::DOMElement*> getConfiguration(); + + /** + * Determine whether the state with the given `id` is in the active configuration. + * @param id An identifier for a state from the SCXML document. + * @return Whether the interpreter is in state `id`. + */ + bool isInState(const std::string& stateId); + + /** + * The current state of the interpreter, not to be confused with its configuration. + * @return The current state of the interpreter object. + */ + InterpreterState getState(); + + /** + * Return a list of possible syntactic and semantic issues with the interpreter's state-chart. + * @return A list of InterpreterIssue%s + */ + std::list<InterpreterIssue> validate(); + + /** + * Enqueue an event to the interpreter's external queue. + * @event An event to be enqueued + */ + void receive(const Event& event); + + /** + * Adapt the constituting components for a SCXML interpreter. + */ + void setActionLanguage(ActionLanguage actionLanguage); + + /** + * Attach a monitor to make more details of the interpreter observable. + */ + void setMonitor(InterpreterMonitor* monitor); + + /** + * Return the actual implementation of the Interperter. + */ std::shared_ptr<InterpreterImpl> getImpl() const { return _impl; } @@ -138,24 +225,6 @@ protected: }; -class USCXML_API StateTransitionMonitor : public uscxml::InterpreterMonitor { -public: - StateTransitionMonitor(Interpreter interpreter) : _interpreter(interpreter) {} - virtual ~StateTransitionMonitor() {} - - virtual void beforeTakingTransition(const xercesc::DOMElement* transition); - virtual void beforeExecutingContent(const xercesc::DOMElement* element); - virtual void onStableConfiguration(); - virtual void beforeProcessingEvent(const uscxml::Event& event); - virtual void beforeExitingState(const xercesc::DOMElement* state); - virtual void beforeEnteringState(const xercesc::DOMElement* state); - virtual void beforeMicroStep(); - -protected: - Interpreter _interpreter; - static std::recursive_mutex _mutex; -}; - } #endif /* end of include guard: INTERPRETER_H_6CD5A168 */ diff --git a/src/uscxml/debug/InterpreterIssue.cpp b/src/uscxml/debug/InterpreterIssue.cpp index ce61af6..86947c1 100644 --- a/src/uscxml/debug/InterpreterIssue.cpp +++ b/src/uscxml/debug/InterpreterIssue.cpp @@ -23,15 +23,14 @@ #include "uscxml/util/DOM.h" #include "uscxml/util/String.h" #include "uscxml/util/Predicates.h" -//#include "uscxml/debug/Complexity.h" -#include "uscxml/Interpreter.h" +#include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/plugins/Factory.h" #include <xercesc/dom/DOMDocument.hpp> -namespace uscxml { +using namespace XERCESC_NS; -using namespace xercesc; +namespace uscxml { InterpreterIssue::InterpreterIssue(const std::string& msg, DOMNode* node, IssueSeverity severity, const std::string& specRef) : message(msg), node(node), severity(severity), specRef(specRef) { if (node) @@ -181,7 +180,7 @@ std::list<InterpreterIssue> InterpreterIssue::forInterpreter(InterpreterImpl* in std::list<DOMElement*> scxmls = nodeSets["scxml"]; scxmls.push_back(_scxml); - std::list<xercesc::DOMElement*> reachable = getReachableStates(_scxml); + std::list<XERCESC_NS::DOMElement*> reachable = getReachableStates(_scxml); std::list<DOMElement*>& states = nodeSets["state"]; std::list<DOMElement*>& parallels = nodeSets["parallel"]; diff --git a/src/uscxml/debug/InterpreterIssue.h b/src/uscxml/debug/InterpreterIssue.h index f72a7a4..c807acc 100644 --- a/src/uscxml/debug/InterpreterIssue.h +++ b/src/uscxml/debug/InterpreterIssue.h @@ -2,6 +2,7 @@ * @file * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) * @copyright Simplified BSD + * @brief Identifies some common problems with SCXML documents * * @cond * This program is free software: you can redistribute it and/or modify @@ -20,32 +21,46 @@ #ifndef INTERPRETERISSUE_H_962CB305 #define INTERPRETERISSUE_H_962CB305 +#include "uscxml/config.h" #include "uscxml/Common.h" + #include <list> #include <iostream> -#include <xercesc/dom/DOMNode.hpp> + +// forward declare +namespace XERCESC_NS { + class DOMNode; +} namespace uscxml { class InterpreterImpl; +/** + * Identify and report syntactic and semantic problems with a SCXML state-charts. + * @see uscxml::Interpreter::validate() + */ class USCXML_API InterpreterIssue { public: enum IssueSeverity { - USCXML_ISSUE_FATAL, - USCXML_ISSUE_WARNING, - USCXML_ISSUE_INFO + USCXML_ISSUE_FATAL, ///< Interpreter can not process such a document + USCXML_ISSUE_WARNING, ///< Document is questionable, but formally ok + USCXML_ISSUE_INFO ///< Indicates a possible problem, but maybe perfectly ok }; - InterpreterIssue(const std::string& msg, xercesc::DOMNode* node, IssueSeverity severity, const std::string& specRef = ""); + std::string xPath; ///< Where did the issue arise + std::string message; ///< What is the issue + XERCESC_NS::DOMNode* node; ///< The DOM node pertaining to the issue + IssueSeverity severity; ///< Severity of the issue + std::string specRef; ///< If applicable, the violated section from the standard - std::string xPath; - std::string message; - xercesc::DOMNode* node; - IssueSeverity severity; - std::string specRef; + /** + * Constructor is solely used to report issues at runtime. + */ + InterpreterIssue(const std::string& msg, XERCESC_NS::DOMNode* node, IssueSeverity severity, const std::string& specRef = ""); private: + static std::list<InterpreterIssue> forInterpreter(InterpreterImpl* interpreter); friend class Interpreter; }; diff --git a/src/uscxml/interpreter/ContentExecutorImpl.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 6a06bec..2010ae2 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -17,13 +17,13 @@ * @endcond */ -#include "ContentExecutorImpl.h" +#include "BasicContentExecutor.h" #include "uscxml/util/String.h" #include "uscxml/util/Predicates.h" #include "uscxml/util/UUID.h" #include "uscxml/util/URL.h" -#include "uscxml/messages/Data.h" +#include <xercesc/dom/DOM.hpp> #include <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/sax/HandlerBase.hpp> #include <xercesc/framework/MemBufInputSource.hpp> @@ -32,14 +32,14 @@ namespace uscxml { -using namespace xercesc; +using namespace XERCESC_NS; -void BasicContentExecutorImpl::processRaise(xercesc::DOMElement* content) { +void BasicContentExecutor::processRaise(XERCESC_NS::DOMElement* content) { Event raised(ATTR(content, "event")); _callbacks->enqueueInternal(raised); } -void BasicContentExecutorImpl::processSend(xercesc::DOMElement* element) { +void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { Event sendEvent; std::string target; std::string type = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor"; // default @@ -193,7 +193,7 @@ void BasicContentExecutorImpl::processSend(xercesc::DOMElement* element) { } -void BasicContentExecutorImpl::processCancel(xercesc::DOMElement* content) { +void BasicContentExecutor::processCancel(XERCESC_NS::DOMElement* content) { std::string sendid; if (HAS_ATTR(content, "sendid")) { sendid = ATTR(content, "sendid"); @@ -206,7 +206,7 @@ void BasicContentExecutorImpl::processCancel(xercesc::DOMElement* content) { _callbacks->cancelDelayed(sendid); } -void BasicContentExecutorImpl::processIf(xercesc::DOMElement* content) { +void BasicContentExecutor::processIf(XERCESC_NS::DOMElement* content) { bool blockIsTrue = _callbacks->isTrue(ATTR(content, "cond")); DOMNodeList* children = content->getChildNodes(); @@ -241,12 +241,12 @@ void BasicContentExecutorImpl::processIf(xercesc::DOMElement* content) { } } -void BasicContentExecutorImpl::processAssign(xercesc::DOMElement* content) { +void BasicContentExecutor::processAssign(XERCESC_NS::DOMElement* content) { std::string location = ATTR(content, "location"); _callbacks->assign(location, elementAsData(content)); } -void BasicContentExecutorImpl::processForeach(xercesc::DOMElement* content) { +void BasicContentExecutor::processForeach(XERCESC_NS::DOMElement* content) { std::string array = ATTR(content, "array"); std::string item = ATTR(content, "item"); std::string index = (HAS_ATTR(content, "index") ? ATTR(content, "index") : ""); @@ -266,7 +266,7 @@ void BasicContentExecutorImpl::processForeach(xercesc::DOMElement* content) { } } -void BasicContentExecutorImpl::processLog(xercesc::DOMElement* content) { +void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { std::string label = ATTR(content, "label"); std::string expr = ATTR(content, "expr"); @@ -277,14 +277,14 @@ void BasicContentExecutorImpl::processLog(xercesc::DOMElement* content) { std::cout << d << std::endl; } -void BasicContentExecutorImpl::processScript(xercesc::DOMElement* content) { +void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { // download as necessary std::string scriptContent(X(content->getTextContent())); _callbacks->evalAsData(scriptContent); } -void BasicContentExecutorImpl::process(xercesc::DOMElement* block, const X& xmlPrefix) { +void BasicContentExecutor::process(XERCESC_NS::DOMElement* block, const X& xmlPrefix) { std::string tagName = TAGNAME(block); @@ -379,7 +379,7 @@ void BasicContentExecutorImpl::process(xercesc::DOMElement* block, const X& xmlP } -void BasicContentExecutorImpl::invoke(xercesc::DOMElement* element) { +void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { std::string type; std::string source; bool autoForward = false; @@ -475,7 +475,7 @@ void BasicContentExecutorImpl::invoke(xercesc::DOMElement* element) { USCXML_MONITOR_CALLBACK2(_callbacks->getMonitor(), afterUninvoking, element, invokeEvent.invokeid); } -void BasicContentExecutorImpl::uninvoke(xercesc::DOMElement* invoke) { +void BasicContentExecutor::uninvoke(XERCESC_NS::DOMElement* invoke) { // TODO: DANGER This is the real danger here char* invokeId = (char*)invoke->getUserData(X("invokeid")); assert(invokeId != NULL); @@ -487,7 +487,7 @@ void BasicContentExecutorImpl::uninvoke(xercesc::DOMElement* invoke) { free(invokeId); } -void BasicContentExecutorImpl::raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) { +void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) { Event doneEvent; doneEvent.name = "done.state."; @@ -535,7 +535,7 @@ void BasicContentExecutorImpl::raiseDoneEvent(xercesc::DOMElement* state, xerces } -void BasicContentExecutorImpl::processNameLists(std::map<std::string, Data>& nameMap, DOMElement* element) { +void BasicContentExecutor::processNameLists(std::map<std::string, Data>& nameMap, DOMElement* element) { if (HAS_ATTR(element, "namelist")) { std::list<std::string> names = tokenize(ATTR(element, "namelist")); for (std::list<std::string>::const_iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { @@ -544,7 +544,7 @@ void BasicContentExecutorImpl::processNameLists(std::map<std::string, Data>& nam } } -void BasicContentExecutorImpl::processParams(std::multimap<std::string, Data>& paramMap, DOMElement* element) { +void BasicContentExecutor::processParams(std::multimap<std::string, Data>& paramMap, DOMElement* element) { std::list<DOMElement*> params = DOMUtils::filterChildElements(XML_PREFIX(element).str() + "param", element); for (auto paramIter = params.begin(); paramIter != params.end(); paramIter++) { std::string name = ATTR(*paramIter, "name"); @@ -560,7 +560,7 @@ void BasicContentExecutorImpl::processParams(std::multimap<std::string, Data>& p } } -Data BasicContentExecutorImpl::elementAsData(xercesc::DOMElement* element) { +Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element) { if (HAS_ATTR(element, "expr")) { // return _callbacks->evalAsData(ATTR(element, "expr")); if (LOCALNAME(element) == "content") { @@ -586,22 +586,22 @@ Data BasicContentExecutorImpl::elementAsData(xercesc::DOMElement* element) { // make an attempt to parse as XML try { - xercesc::XercesDOMParser* parser = new xercesc::XercesDOMParser(); - parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); + XERCESC_NS::XercesDOMParser* parser = new XERCESC_NS::XercesDOMParser(); + parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); parser->setDoNamespaces(true); - parser->useScanner(xercesc::XMLUni::fgWFXMLScanner); + parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); - xercesc::ErrorHandler* errHandler = new xercesc::HandlerBase(); + XERCESC_NS::ErrorHandler* errHandler = new XERCESC_NS::HandlerBase(); parser->setErrorHandler(errHandler); std::string tmp = url; - xercesc::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); + XERCESC_NS::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); parser->parse(is); Data d; - xercesc::DOMDocument* doc = parser->adoptDocument(); - d.adoptedDoc = std::make_shared<xercesc::DOMDocument*>(doc); + XERCESC_NS::DOMDocument* doc = parser->adoptDocument(); + d.adoptedDoc = std::make_shared<XERCESC_NS::DOMDocument*>(doc); d.node = doc->getDocumentElement(); return d; diff --git a/src/uscxml/interpreter/BasicContentExecutor.h b/src/uscxml/interpreter/BasicContentExecutor.h new file mode 100644 index 0000000..c3549f6 --- /dev/null +++ b/src/uscxml/interpreter/BasicContentExecutor.h @@ -0,0 +1,63 @@ +/** + * @file + * @author 2016 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 + */ + +#ifndef BASICCONTENTEXECUTOR_H_B873199D +#define BASICCONTENTEXECUTOR_H_B873199D + +#include "ContentExecutorImpl.h" + +namespace uscxml { + +using namespace XERCESC_NS; + +/** + * @ingroup execcontent + * @ingroup impl + */ +class USCXML_API BasicContentExecutor : public ContentExecutorImpl { +public: + BasicContentExecutor(ContentExecutorCallbacks* callbacks) : ContentExecutorImpl(callbacks) {} + virtual ~BasicContentExecutor() {} + + void processRaise(XERCESC_NS::DOMElement* content); + void processSend(XERCESC_NS::DOMElement* element); + void processCancel(XERCESC_NS::DOMElement* content); + void processIf(XERCESC_NS::DOMElement* content); + void processAssign(XERCESC_NS::DOMElement* content); + void processForeach(XERCESC_NS::DOMElement* content); + void processLog(XERCESC_NS::DOMElement* content); + void processScript(XERCESC_NS::DOMElement* content); + + virtual void process(XERCESC_NS::DOMElement* block, const X& xmlPrefix); + + virtual void invoke(XERCESC_NS::DOMElement* invoke); + virtual void uninvoke(XERCESC_NS::DOMElement* invoke); + virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData); + + virtual Data elementAsData(XERCESC_NS::DOMElement* element); + +protected: + void processNameLists(std::map<std::string, Data>& nameMap, XERCESC_NS::DOMElement* element); + void processParams(std::multimap<std::string, Data>& paramMap, XERCESC_NS::DOMElement* element); + +}; + +} + +#endif /* end of include guard: BASICCONTENTEXECUTOR_H_B873199D */ diff --git a/src/uscxml/interpreter/EventQueueImpl.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp index 345da69..5d3fa2d 100644 --- a/src/uscxml/interpreter/EventQueueImpl.cpp +++ b/src/uscxml/interpreter/BasicEventQueue.cpp @@ -17,7 +17,7 @@ * @endcond */ -#include "EventQueueImpl.h" +#include "BasicEventQueue.h" #include <event2/util.h> // for evutil_socket_t #include <event2/thread.h> #include <assert.h> @@ -26,12 +26,12 @@ namespace uscxml { -EventQueueImpl::EventQueueImpl() { +BasicEventQueue::BasicEventQueue() { } -EventQueueImpl::~EventQueueImpl() { +BasicEventQueue::~BasicEventQueue() { } -Event EventQueueImpl::dequeue(bool blocking) { +Event BasicEventQueue::dequeue(bool blocking) { std::lock_guard<std::recursive_mutex> lock(_mutex); if (blocking) { while (_queue.empty()) { @@ -48,7 +48,7 @@ Event EventQueueImpl::dequeue(bool blocking) { } -void EventQueueImpl::enqueue(const Event& event) { +void BasicEventQueue::enqueue(const Event& event) { std::lock_guard<std::recursive_mutex> lock(_mutex); _queue.push_back(event); _cond.notify_all(); @@ -62,7 +62,7 @@ static void dummyCallback(evutil_socket_t fd, short what, void *arg) { evtimer_add(ev, &tv); } -DelayedEventQueueImpl::DelayedEventQueueImpl(DelayedEventQueueCallbacks* callbacks) { +BasicDelayedEventQueue::BasicDelayedEventQueue(DelayedEventQueueCallbacks* callbacks) { _callbacks = callbacks; #ifndef _WIN32 evthread_use_pthreads(); @@ -84,14 +84,14 @@ DelayedEventQueueImpl::DelayedEventQueueImpl(DelayedEventQueueCallbacks* callbac start(); } -DelayedEventQueueImpl::~DelayedEventQueueImpl() { +BasicDelayedEventQueue::~BasicDelayedEventQueue() { stop(); evtimer_del(_dummyEvent); event_free(_dummyEvent); event_base_free(_eventLoop); } -void DelayedEventQueueImpl::timerCallback(evutil_socket_t fd, short what, void *arg) { +void BasicDelayedEventQueue::timerCallback(evutil_socket_t fd, short what, void *arg) { struct callbackData *data = (struct callbackData*)arg; std::lock_guard<std::recursive_mutex> lock(data->eventQueue->_mutex); @@ -103,7 +103,7 @@ void DelayedEventQueueImpl::timerCallback(evutil_socket_t fd, short what, void * data->eventQueue->_callbackData.erase(data->eventUUID); } -void DelayedEventQueueImpl::enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID) { +void BasicDelayedEventQueue::enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID) { std::lock_guard<std::recursive_mutex> lock(_mutex); if(_callbackData.find(eventUUID) != _callbackData.end()) { cancelDelayed(eventUUID); @@ -121,7 +121,7 @@ void DelayedEventQueueImpl::enqueueDelayed(const Event& event, size_t delayMs, c event_add(e, &delay); } -void DelayedEventQueueImpl::cancelAllDelayed() { +void BasicDelayedEventQueue::cancelAllDelayed() { std::lock_guard<std::recursive_mutex> lock(_mutex); while(_callbackData.size() > 0) { @@ -134,7 +134,7 @@ void DelayedEventQueueImpl::cancelAllDelayed() { } -void DelayedEventQueueImpl::cancelDelayed(const std::string& eventId) { +void BasicDelayedEventQueue::cancelDelayed(const std::string& eventId) { std::lock_guard<std::recursive_mutex> lock(_mutex); if(_callbackData.find(eventId) != _callbackData.end()) { @@ -144,8 +144,8 @@ void DelayedEventQueueImpl::cancelDelayed(const std::string& eventId) { } } -void DelayedEventQueueImpl::run(void* instance) { - DelayedEventQueueImpl* INSTANCE = (DelayedEventQueueImpl*)instance; +void BasicDelayedEventQueue::run(void* instance) { + BasicDelayedEventQueue* INSTANCE = (BasicDelayedEventQueue*)instance; int result; while(INSTANCE->_isStarted) { /** @@ -165,15 +165,15 @@ void DelayedEventQueueImpl::run(void* instance) { } } -void DelayedEventQueueImpl::start() { +void BasicDelayedEventQueue::start() { if (_isStarted) { return; } _isStarted = true; - _thread = new std::thread(DelayedEventQueueImpl::run, this); + _thread = new std::thread(BasicDelayedEventQueue::run, this); } -void DelayedEventQueueImpl::stop() { +void BasicDelayedEventQueue::stop() { if (_isStarted) { _isStarted = false; event_base_loopbreak(_eventLoop); diff --git a/src/uscxml/interpreter/BasicEventQueue.h b/src/uscxml/interpreter/BasicEventQueue.h new file mode 100644 index 0000000..cfb2b5d --- /dev/null +++ b/src/uscxml/interpreter/BasicEventQueue.h @@ -0,0 +1,98 @@ +/** + * @file + * @author 2016 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 + */ + +#ifndef BASICEVENTQUEUE_H_39DCC18B +#define BASICEVENTQUEUE_H_39DCC18B + + +#include "EventQueueImpl.h" +#include <string> +#include <map> +#include <list> +#include <thread> +#include <mutex> +#include <condition_variable> + +#include <event2/event.h> + + +namespace uscxml { + +/** + * @ingroup eventqueue + * @ingroup impl + */ +class USCXML_API BasicEventQueue : public EventQueueImpl { +public: + BasicEventQueue(); + virtual ~BasicEventQueue(); + virtual Event dequeue(bool blocking); + virtual void enqueue(const Event& event); + +protected: + std::list<Event> _queue; + std::recursive_mutex _mutex; + std::condition_variable_any _cond; +}; + +/** + * @ingroup eventqueue + * @ingroup impl + */ +class USCXML_API BasicDelayedEventQueue : public BasicEventQueue, public DelayedEventQueueImpl { +public: + BasicDelayedEventQueue(DelayedEventQueueCallbacks* callbacks); + virtual ~BasicDelayedEventQueue(); + virtual void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID); + virtual void cancelDelayed(const std::string& eventId); + virtual void cancelAllDelayed(); + virtual Event dequeue(bool blocking) { + return BasicEventQueue::dequeue(blocking); + } + virtual void enqueue(const Event& event) { + return BasicEventQueue::enqueue(event); + } + +protected: + struct callbackData { + Event userData; + std::string eventUUID; + bool persist; + struct event *event; + BasicDelayedEventQueue* eventQueue; + }; + + bool _isStarted; + std::thread* _thread; + + std::map<std::string, callbackData> _callbackData; + struct event_base* _eventLoop; + struct event* _dummyEvent; + + static void run(void* instance); + void start(); + void stop(); + + static void timerCallback(evutil_socket_t fd, short what, void *arg); + DelayedEventQueueCallbacks* _callbacks; +}; + +} + +#endif /* end of include guard: BASICEVENTQUEUE_H_39DCC18B */ diff --git a/src/uscxml/interpreter/ContentExecutor.cpp b/src/uscxml/interpreter/ContentExecutor.cpp new file mode 100644 index 0000000..e26d66a --- /dev/null +++ b/src/uscxml/interpreter/ContentExecutor.cpp @@ -0,0 +1,46 @@ +/** + * @file + * @author 2016 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 "ContentExecutor.h" +#include "ContentExecutorImpl.h" + +namespace uscxml { + +void ContentExecutor::process(XERCESC_NS::DOMElement* block, const X& xmlPrefix) { + _impl->process(block, xmlPrefix); +} + +void ContentExecutor::invoke(XERCESC_NS::DOMElement* invoke) { + _impl->invoke(invoke); +} + +void ContentExecutor::uninvoke(XERCESC_NS::DOMElement* invoke) { + _impl->uninvoke(invoke); +} + +Data ContentExecutor::elementAsData(XERCESC_NS::DOMElement* element) { + return _impl->elementAsData(element); +} + +void ContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) { + return _impl->raiseDoneEvent(state, doneData); +} + +} diff --git a/src/uscxml/interpreter/ContentExecutor.h b/src/uscxml/interpreter/ContentExecutor.h new file mode 100644 index 0000000..64f5a95 --- /dev/null +++ b/src/uscxml/interpreter/ContentExecutor.h @@ -0,0 +1,59 @@ +/** + * @file + * @author 2016 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 + */ + +#ifndef CONTENTEXECUTOR_H_A2D592FA +#define CONTENTEXECUTOR_H_A2D592FA + + +#include "uscxml/config.h" +#include "uscxml/Common.h" +#include "uscxml/messages/Data.h" +#include <string> + +// forward declare +namespace XERCESC_NS { + class DOMElement; +} + +namespace uscxml { + +class ContentExecutorImpl; +class X; + +/** + * @ingroup execcontent + * @ingroup facade + */ +class USCXML_API ContentExecutor { +public: + PIMPL_OPERATORS(ContentExecutor); + + virtual void process(XERCESC_NS::DOMElement* block, const X& xmlPrefix); + virtual void invoke(XERCESC_NS::DOMElement* invoke); + virtual void uninvoke(XERCESC_NS::DOMElement* invoke); + virtual Data elementAsData(XERCESC_NS::DOMElement* element); + virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData); + +protected: + std::shared_ptr<ContentExecutorImpl> _impl; +}; + +} + +#endif /* end of include guard: CONTENTEXECUTOR_H_A2D592FA */ diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index c0d28a2..e1a7e8c 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -17,20 +17,24 @@ * @endcond */ +#ifndef CONTENTEXECUTORIMPL_H_3ABA8969 +#define CONTENTEXECUTORIMPL_H_3ABA8969 -#ifndef CONTENTEXECUTORIMPL_H_13F2884F -#define CONTENTEXECUTORIMPL_H_13F2884F #include "uscxml/Common.h" #include "uscxml/util/DOM.h" -#include "uscxml/messages/Data.h" #include "uscxml/messages/Event.h" #include "uscxml/interpreter/InterpreterMonitor.h" + #include <xercesc/dom/DOM.hpp> #include <string> namespace uscxml { +/** + * @ingroup execcontent + * @ingroup callback + */ class USCXML_API ContentExecutorCallbacks { public: virtual void enqueueInternal(const Event& event) = 0; @@ -55,7 +59,7 @@ public: virtual std::string getBaseURL() = 0; virtual bool checkValidSendType(const std::string& type, const std::string& target) = 0; virtual void enqueue(const std::string& type, const std::string& target, size_t delayMs, const Event& sendEvent) = 0; - virtual void invoke(const std::string& type, const std::string& src, bool autoForward, xercesc::DOMElement* finalize, const Event& invokeEvent) = 0; + virtual void invoke(const std::string& type, const std::string& src, bool autoForward, XERCESC_NS::DOMElement* finalize, const Event& invokeEvent) = 0; virtual void uninvoke(const std::string& invokeId) = 0; virtual const Event& getCurrentEvent() = 0; @@ -65,79 +69,27 @@ public: }; +/** + * @ingroup execcontent + * @ingroup impl + */ class USCXML_API ContentExecutorImpl { public: ContentExecutorImpl(ContentExecutorCallbacks* callbacks) : _callbacks(callbacks) {} - virtual void process(xercesc::DOMElement* block, const X& xmlPrefix) = 0; + virtual void process(XERCESC_NS::DOMElement* block, const X& xmlPrefix) = 0; - virtual void invoke(xercesc::DOMElement* invoke) = 0; - virtual void uninvoke(xercesc::DOMElement* invoke) = 0; + virtual void invoke(XERCESC_NS::DOMElement* invoke) = 0; + virtual void uninvoke(XERCESC_NS::DOMElement* invoke) = 0; - virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) = 0; - virtual Data elementAsData(xercesc::DOMElement* element) = 0; + virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) = 0; + virtual Data elementAsData(XERCESC_NS::DOMElement* element) = 0; protected: ContentExecutorCallbacks* _callbacks; }; -class USCXML_API BasicContentExecutorImpl : public ContentExecutorImpl { -public: - BasicContentExecutorImpl(ContentExecutorCallbacks* callbacks) : ContentExecutorImpl(callbacks) {} - virtual ~BasicContentExecutorImpl() {} - - void processRaise(xercesc::DOMElement* content); - void processSend(xercesc::DOMElement* element); - void processCancel(xercesc::DOMElement* content); - void processIf(xercesc::DOMElement* content); - void processAssign(xercesc::DOMElement* content); - void processForeach(xercesc::DOMElement* content); - void processLog(xercesc::DOMElement* content); - void processScript(xercesc::DOMElement* content); - - virtual void process(xercesc::DOMElement* block, const X& xmlPrefix); - - virtual void invoke(xercesc::DOMElement* invoke); - virtual void uninvoke(xercesc::DOMElement* invoke); - virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData); - - virtual Data elementAsData(xercesc::DOMElement* element); - -protected: - void processNameLists(std::map<std::string, Data>& nameMap, xercesc::DOMElement* element); - void processParams(std::multimap<std::string, Data>& paramMap, xercesc::DOMElement* element); - -}; - -class USCXML_API ContentExecutor { -public: - PIMPL_OPERATORS(ContentExecutor) - - virtual void process(xercesc::DOMElement* block, const X& xmlPrefix) { - _impl->process(block, xmlPrefix); - } - - virtual void invoke(xercesc::DOMElement* invoke) { - _impl->invoke(invoke); - } - - virtual void uninvoke(xercesc::DOMElement* invoke) { - _impl->uninvoke(invoke); - } - - virtual Data elementAsData(xercesc::DOMElement* element) { - return _impl->elementAsData(element); - } - - virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) { - return _impl->raiseDoneEvent(state, doneData); - } - -protected: - std::shared_ptr<ContentExecutorImpl> _impl; -}; - } -#endif /* end of include guard: CONTENTEXECUTORIMPL_H_13F2884F */ +#endif /* end of include guard: CONTENTEXECUTORIMPL_H_3ABA8969 */ diff --git a/src/uscxml/interpreter/EventQueue.cpp b/src/uscxml/interpreter/EventQueue.cpp new file mode 100644 index 0000000..9b9fa88 --- /dev/null +++ b/src/uscxml/interpreter/EventQueue.cpp @@ -0,0 +1,56 @@ +/** + * @file + * @author 2016 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 "uscxml/Common.h" +#include "EventQueue.h" +#include "EventQueueImpl.h" +#include <string> +#include <map> +#include <list> +#include <thread> +#include <mutex> +#include <condition_variable> + +#include <event2/event.h> + + +namespace uscxml { + +Event EventQueue::dequeue(bool blocking) { + return _impl->dequeue(blocking); +} +void EventQueue::enqueue(const Event& event) { + return _impl->enqueue(event); +} + +PIMPL_OPERATORS_INHERIT_IMPL(DelayedEventQueue, EventQueue) + +void DelayedEventQueue::enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID) { + _impl->enqueueDelayed(event, delayMs, eventUUID); +} +void DelayedEventQueue::cancelDelayed(const std::string& eventUUID) { + return _impl->cancelDelayed(eventUUID); +} + +void DelayedEventQueue::cancelAllDelayed() { + return _impl->cancelAllDelayed(); +} + +} + diff --git a/src/uscxml/interpreter/EventQueue.h b/src/uscxml/interpreter/EventQueue.h new file mode 100644 index 0000000..4409b72 --- /dev/null +++ b/src/uscxml/interpreter/EventQueue.h @@ -0,0 +1,65 @@ +/** + * @file + * @author 2016 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 + */ + +#ifndef EVENTQUEUE_H_C5C41BEE +#define EVENTQUEUE_H_C5C41BEE + +#include "uscxml/Common.h" +#include "uscxml/messages/Event.h" + +namespace uscxml { + +class EventQueueImpl; +class DelayedEventQueueImpl; + +/** + * @ingroup eventqueue + * @ingroup facade + */ +class USCXML_API EventQueue { +public: + PIMPL_OPERATORS(EventQueue); + + virtual Event dequeue(bool blocking); + virtual void enqueue(const Event& event); + +protected: + std::shared_ptr<EventQueueImpl> _impl; + +}; + +/** + * @ingroup eventqueue + * @ingroup facade + */ +class USCXML_API DelayedEventQueue : public EventQueue { +public: + PIMPL_OPERATORS_INHERIT(DelayedEventQueue, EventQueue); + + void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID); + void cancelDelayed(const std::string& eventUUID); + void cancelAllDelayed(); + +protected: + std::shared_ptr<DelayedEventQueueImpl> _impl; +}; + +} + +#endif /* end of include guard: EVENTQUEUE_H_C5C41BEE */ diff --git a/src/uscxml/interpreter/EventQueueImpl.h b/src/uscxml/interpreter/EventQueueImpl.h index 10543c9..1cafd4d 100644 --- a/src/uscxml/interpreter/EventQueueImpl.h +++ b/src/uscxml/interpreter/EventQueueImpl.h @@ -17,8 +17,8 @@ * @endcond */ -#ifndef EVENTSOURCE_H_775AB206 -#define EVENTSOURCE_H_775AB206 +#ifndef EVENTQUEUEIMPL_H_48027643 +#define EVENTQUEUEIMPL_H_48027643 #include "uscxml/Common.h" #include "uscxml/messages/Event.h" @@ -34,92 +34,36 @@ namespace uscxml { +/** + * @ingroup eventqueue + * @ingroup impl + */ class USCXML_API EventQueueImpl { public: - EventQueueImpl(); - virtual ~EventQueueImpl(); - virtual Event dequeue(bool blocking); - virtual void enqueue(const Event& event); - -protected: - std::list<Event> _queue; - std::recursive_mutex _mutex; - std::condition_variable_any _cond; - + virtual Event dequeue(bool blocking) = 0; + virtual void enqueue(const Event& event) = 0; }; +/** + * @ingroup eventqueue + * @ingroup callback + */ class USCXML_API DelayedEventQueueCallbacks { public: virtual void eventReady(Event& event, const std::string& eventId) = 0; }; +/** + * @ingroup eventqueue + * @ingroup impl + */ class USCXML_API DelayedEventQueueImpl : public EventQueueImpl { public: - DelayedEventQueueImpl(DelayedEventQueueCallbacks* callbacks); - virtual ~DelayedEventQueueImpl(); - virtual void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID); - virtual void cancelDelayed(const std::string& eventId); - virtual void cancelAllDelayed(); - -protected: - struct callbackData { - Event userData; - std::string eventUUID; - bool persist; - struct event *event; - DelayedEventQueueImpl* eventQueue; - }; - - bool _isStarted; - std::thread* _thread; - - std::map<std::string, callbackData> _callbackData; - struct event_base* _eventLoop; - struct event* _dummyEvent; - - static void run(void* instance); - void start(); - void stop(); - - static void timerCallback(evutil_socket_t fd, short what, void *arg); - DelayedEventQueueCallbacks* _callbacks; -}; - -class USCXML_API EventQueue { -public: - PIMPL_OPERATORS(EventQueue) - - virtual Event dequeue(bool blocking) { - return _impl->dequeue(blocking); - } - virtual void enqueue(const Event& event) { - return _impl->enqueue(event); - } - -protected: - std::shared_ptr<EventQueueImpl> _impl; - -}; - -class USCXML_API DelayedEventQueue : public EventQueue { -public: - PIMPL_OPERATORS2(DelayedEventQueue, EventQueue) - - void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID) { - _impl->enqueueDelayed(event, delayMs, eventUUID); - } - void cancelDelayed(const std::string& eventUUID) { - return _impl->cancelDelayed(eventUUID); - } - - void cancelAllDelayed() { - return _impl->cancelAllDelayed(); - } - -protected: - std::shared_ptr<DelayedEventQueueImpl> _impl; + virtual void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID) = 0; + virtual void cancelDelayed(const std::string& eventId) = 0; + virtual void cancelAllDelayed() = 0; }; } -#endif /* end of include guard: EVENTSOURCE_H_775AB206 */ +#endif /* end of include guard: EVENTQUEUEIMPL_H_48027643 */ diff --git a/src/uscxml/interpreter/MicroStepFast.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index 158c3ee..99c2d74 100644 --- a/src/uscxml/interpreter/MicroStepFast.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -19,7 +19,7 @@ #undef USCXML_VERBOSE -#include "MicroStepFast.h" +#include "FastMicroStep.h" #include "uscxml/util/DOM.h" #include "uscxml/util/String.h" #include "uscxml/util/Predicates.h" @@ -74,13 +74,13 @@ namespace uscxml { -using namespace xercesc; +using namespace XERCESC_NS; -MicroStepFast::MicroStepFast(MicroStepCallbacks* callbacks) +FastMicroStep::FastMicroStep(MicroStepCallbacks* callbacks) : MicroStepImpl(callbacks), _flags(USCXML_CTX_PRISTINE), _isInitialized(false), _isCancelled(false) { } -MicroStepFast::~MicroStepFast() { +FastMicroStep::~FastMicroStep() { for (size_t i = 0; i < _states.size(); i++) { delete(_states[i]); } @@ -89,7 +89,7 @@ MicroStepFast::~MicroStepFast() { } } -void MicroStepFast::resortStates(DOMNode* node, const X& xmlPrefix) { +void FastMicroStep::resortStates(DOMNode* node, const X& xmlPrefix) { if (node->getNodeType() != DOMNode::ELEMENT_NODE) return; @@ -155,7 +155,7 @@ void MicroStepFast::resortStates(DOMNode* node, const X& xmlPrefix) { } } -void MicroStepFast::init(xercesc::DOMElement* scxml) { +void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { _scxml = scxml; _binding = (HAS_ATTR(_scxml, "binding") && iequals(ATTR(_scxml, "binding"), "late") ? LATE : EARLY); @@ -172,17 +172,18 @@ void MicroStepFast::init(xercesc::DOMElement* scxml) { /** -- All things states -- */ - std::list<xercesc::DOMElement*> tmp; + std::list<XERCESC_NS::DOMElement*> tmp; size_t i, j; - tmp = DOMUtils::inDocumentOrder({ - _xmlPrefix.str() + "state", - _xmlPrefix.str() + "parallel", - _xmlPrefix.str() + "scxml", - _xmlPrefix.str() + "initial", - _xmlPrefix.str() + "final", - _xmlPrefix.str() + "history"}, _scxml); - + tmp = DOMUtils::inDocumentOrder({ + _xmlPrefix.str() + "state", + _xmlPrefix.str() + "parallel", + _xmlPrefix.str() + "scxml", + _xmlPrefix.str() + "initial", + _xmlPrefix.str() + "final", + _xmlPrefix.str() + "history" + }, _scxml); + _states.resize(tmp.size()); _configuration.resize(tmp.size()); _history.resize(tmp.size()); @@ -307,7 +308,7 @@ void MicroStepFast::init(xercesc::DOMElement* scxml) { /** -- All things transitions -- */ - tmp = DOMUtils::inPostFixOrder({_xmlPrefix.str() + "transition"}, _scxml); + tmp = DOMUtils::inPostFixOrder({_xmlPrefix.str() + "transition"}, _scxml); _transitions.resize(tmp.size()); for (i = 0; i < _transitions.size(); i++) { @@ -318,13 +319,13 @@ void MicroStepFast::init(xercesc::DOMElement* scxml) { _transitions[i]->target.resize(_states.size()); tmp.pop_front(); } - assert(tmp.size() == 0); - + assert(tmp.size() == 0); + for (i = 0; i < _transitions.size(); i++) { // establish the transitions' exit set - assert(_transitions[i]->element != NULL); - std::cout << "i: " << i << std::endl << std::flush; + assert(_transitions[i]->element != NULL); + std::cout << "i: " << i << std::endl << std::flush; std::list<DOMElement*> exitList = getExitSet(_transitions[i]->element, _scxml); for (j = 0; j < _states.size(); j++) { if (!exitList.empty() && _states[j]->element == exitList.front()) { @@ -393,11 +394,11 @@ void MicroStepFast::init(xercesc::DOMElement* scxml) { _isInitialized = true; } -void MicroStepFast::markAsCancelled() { +void FastMicroStep::markAsCancelled() { _isCancelled = true; } -InterpreterState MicroStepFast::step(bool blocking) { +InterpreterState FastMicroStep::step(bool blocking) { if (!_isInitialized) { init(_scxml); return USCXML_INITIALIZED; @@ -911,7 +912,7 @@ ESTABLISH_ENTRYSET: return USCXML_MICROSTEPPED; } -void MicroStepFast::reset() { +void FastMicroStep::reset() { _isCancelled = false; _flags = USCXML_CTX_PRISTINE; _configuration.reset(); @@ -921,7 +922,7 @@ void MicroStepFast::reset() { } -bool MicroStepFast::isInState(const std::string& stateId) { +bool FastMicroStep::isInState(const std::string& stateId) { #ifdef USCXML_VERBOSE printStateNames(_configuration); #endif @@ -930,8 +931,8 @@ bool MicroStepFast::isInState(const std::string& stateId) { return _configuration[_stateIds[stateId]]; } -std::list<xercesc::DOMElement*> MicroStepFast::getConfiguration() { - std::list<xercesc::DOMElement*> config; +std::list<XERCESC_NS::DOMElement*> FastMicroStep::getConfiguration() { + std::list<XERCESC_NS::DOMElement*> config; size_t i = _configuration.find_first(); while(i != boost::dynamic_bitset<>::npos) { config.push_back(_states[i]->element); @@ -941,7 +942,7 @@ std::list<xercesc::DOMElement*> MicroStepFast::getConfiguration() { } -std::list<DOMElement*> MicroStepFast::getHistoryCompletion(const DOMElement* history) { +std::list<DOMElement*> FastMicroStep::getHistoryCompletion(const DOMElement* history) { std::set<std::string> elements; elements.insert(_xmlPrefix.str() + "history"); std::list<DOMElement*> histories = DOMUtils::inPostFixOrder(elements, _scxml); @@ -990,7 +991,7 @@ std::list<DOMElement*> MicroStepFast::getHistoryCompletion(const DOMElement* his /** * Print name of states contained in a (debugging). */ -void MicroStepFast::printStateNames(const boost::dynamic_bitset<>& a) { +void FastMicroStep::printStateNames(const boost::dynamic_bitset<>& a) { size_t i; const char* seperator = ""; for (i = 0; i < a.size(); i++) { @@ -1003,7 +1004,7 @@ void MicroStepFast::printStateNames(const boost::dynamic_bitset<>& a) { } #endif -std::list<DOMElement*> MicroStepFast::getCompletion(const DOMElement* state) { +std::list<DOMElement*> FastMicroStep::getCompletion(const DOMElement* state) { if (isHistory(state)) { // we already did in setHistoryCompletion @@ -1044,7 +1045,7 @@ std::list<DOMElement*> MicroStepFast::getCompletion(const DOMElement* state) { /** * See: http://www.w3.org/TR/scxml/#LegalStateConfigurations */ -bool MicroStepFast::hasLegalConfiguration() { +bool FastMicroStep::hasLegalConfiguration() { // The configuration contains exactly one child of the <scxml> element. std::list<DOMElement*> scxmlChilds = getChildStates(_scxml, true); diff --git a/src/uscxml/interpreter/MicroStepFast.h b/src/uscxml/interpreter/FastMicroStep.h index c41be80..3789af9 100644 --- a/src/uscxml/interpreter/MicroStepFast.h +++ b/src/uscxml/interpreter/FastMicroStep.h @@ -17,11 +17,14 @@ * @endcond */ -#ifndef INTERPRETERFAST_H_DA55E52B -#define INTERPRETERFAST_H_DA55E52B +#ifndef FASTMICROSTEP_H_065FE1F7 +#define FASTMICROSTEP_H_065FE1F7 //#define USCXML_VERBOSE 1 +#include "uscxml/config.h" +#include "uscxml/util/DOM.h" // X + #include <vector> #include <set> #include "MicroStepImpl.h" @@ -30,15 +33,19 @@ namespace uscxml { -class MicroStepFast : public MicroStepImpl { +/** + * @ingroup microstep + * @ingroup impl + */ +class FastMicroStep : public MicroStepImpl { public: - MicroStepFast(MicroStepCallbacks* callbacks); - virtual ~MicroStepFast(); + FastMicroStep(MicroStepCallbacks* callbacks); + virtual ~FastMicroStep(); virtual InterpreterState step(bool blocking); virtual void reset(); virtual bool isInState(const std::string& stateId); - virtual std::list<xercesc::DOMElement*> getConfiguration(); + virtual std::list<XERCESC_NS::DOMElement*> getConfiguration(); void markAsCancelled(); protected: @@ -46,14 +53,14 @@ protected: public: Transition() : element(NULL), source(0), onTrans(NULL), type(0) {} - xercesc::DOMElement* element; + XERCESC_NS::DOMElement* element; boost::dynamic_bitset<> conflicts; boost::dynamic_bitset<> exitSet; uint32_t source; boost::dynamic_bitset<> target; - xercesc::DOMElement* onTrans; + XERCESC_NS::DOMElement* onTrans; std::string event; std::string cond; @@ -66,32 +73,32 @@ protected: public: State() : element(NULL), parent(0), documentOrder(0), doneData(NULL), type(0) {} - xercesc::DOMElement* element; + XERCESC_NS::DOMElement* element; boost::dynamic_bitset<> completion; boost::dynamic_bitset<> children; boost::dynamic_bitset<> ancestors; uint32_t parent; uint32_t documentOrder; - std::list<xercesc::DOMElement*> data; - std::list<xercesc::DOMElement*> invoke; - std::list<xercesc::DOMElement*> onEntry; - std::list<xercesc::DOMElement*> onExit; - xercesc::DOMElement* doneData; + std::list<XERCESC_NS::DOMElement*> data; + std::list<XERCESC_NS::DOMElement*> invoke; + std::list<XERCESC_NS::DOMElement*> onEntry; + std::list<XERCESC_NS::DOMElement*> onExit; + XERCESC_NS::DOMElement* doneData; unsigned char type; }; - virtual void init(xercesc::DOMElement* scxml); + virtual void init(XERCESC_NS::DOMElement* scxml); - std::list<xercesc::DOMElement*> getCompletion(const xercesc::DOMElement* state); + std::list<XERCESC_NS::DOMElement*> getCompletion(const XERCESC_NS::DOMElement* state); unsigned char _flags; std::map<std::string, int> _stateIds; std::vector<State*> _states; std::vector<Transition*> _transitions; - std::list<xercesc::DOMElement*> _globalScripts; + std::list<XERCESC_NS::DOMElement*> _globalScripts; boost::dynamic_bitset<> _configuration; boost::dynamic_bitset<> _invocations; @@ -101,7 +108,7 @@ protected: std::set<boost::dynamic_bitset<> > _microstepConfigurations; Binding _binding; - xercesc::DOMElement* _scxml; + XERCESC_NS::DOMElement* _scxml; X _xmlPrefix; X _xmlNS; @@ -110,8 +117,8 @@ protected: Event _event; // we do not care about the event's representation private: - std::list<xercesc::DOMElement*> getHistoryCompletion(const xercesc::DOMElement* state); - void resortStates(xercesc::DOMNode* node, const X& xmlPrefix); + std::list<XERCESC_NS::DOMElement*> getHistoryCompletion(const XERCESC_NS::DOMElement* state); + void resortStates(XERCESC_NS::DOMNode* node, const X& xmlPrefix); // bool hasLegalConfiguration(); @@ -123,5 +130,5 @@ private: } -#endif /* end of include guard: INTERPRETERFAST_H_DA55E52B */ +#endif /* end of include guard: FASTMICROSTEP_H_065FE1F7 */ diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index e61c4ab..880afbc 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -17,12 +17,16 @@ * @endcond */ +#include "uscxml/config.h" #include "uscxml/Common.h" #include "uscxml/util/UUID.h" #include "uscxml/Interpreter.h" +#include "uscxml/interpreter/InterpreterImpl.h" // beware cyclic reference! +#include "uscxml/interpreter/BasicEventQueue.h" #include "uscxml/messages/Event.h" #include "uscxml/util/String.h" #include "uscxml/util/Predicates.h" +#include "uscxml/plugins/InvokerImpl.h" #include "easylogging++.h" @@ -33,14 +37,16 @@ #include <memory> #include <mutex> -#include "uscxml/interpreter/MicroStepFast.h" +#include "uscxml/interpreter/FastMicroStep.h" +#include "uscxml/interpreter/BasicContentExecutor.h" + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/PlatformUtils.hpp> #define VERBOSE 0 namespace uscxml { -using namespace xercesc; - std::map<std::string, std::weak_ptr<InterpreterImpl> > InterpreterImpl::_instances; std::recursive_mutex InterpreterImpl::_instanceMutex; @@ -65,8 +71,8 @@ void InterpreterImpl::addInstance(std::shared_ptr<InterpreterImpl> interpreterIm InterpreterImpl::InterpreterImpl() : _isInitialized(false), _document(NULL), _scxml(NULL), _state(USCXML_INSTANTIATED), _monitor(NULL) { try { - xercesc::XMLPlatformUtils::Initialize(); - } catch (const xercesc::XMLException& toCatch) { + ::xercesc_3_1::XMLPlatformUtils::Initialize(); + } catch (const XERCESC_NS::XMLException& toCatch) { ERROR_PLATFORM_THROW("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); } @@ -80,7 +86,7 @@ InterpreterImpl::~InterpreterImpl() { _delayQueue.cancelAllDelayed(); if (_document) delete _document; - + { std::lock_guard<std::recursive_mutex> lock(_instanceMutex); _instances.erase(getSessionId()); @@ -102,7 +108,7 @@ void InterpreterImpl::setupDOM() { if (!_scxml) { // find scxml element - DOMNodeList* scxmls = NULL; + XERCESC_NS::DOMNodeList* scxmls = NULL; // proper namespace scxmls = _document->getElementsByTagNameNS(X("http://www.w3.org/2005/07/scxml"), X("scxml")); @@ -120,7 +126,7 @@ SCXML_STOP_SEARCH: return; } - _scxml = dynamic_cast<DOMElement*>(scxmls->item(0)); + _scxml = dynamic_cast<XERCESC_NS::DOMElement*>(scxmls->item(0)); _xmlPrefix = _scxml->getPrefix(); _xmlNS = _scxml->getNamespaceURI(); @@ -171,7 +177,7 @@ void InterpreterImpl::init() { } if (!_microStepper) { - _microStepper = MicroStep(std::shared_ptr<MicroStepImpl>(new MicroStepFast(this))); + _microStepper = MicroStep(std::shared_ptr<MicroStepImpl>(new FastMicroStep(this))); } _microStepper.init(_scxml); @@ -179,23 +185,23 @@ void InterpreterImpl::init() { _dataModel = _factory->createDataModel(HAS_ATTR(_scxml, "datamodel") ? ATTR(_scxml, "datamodel") : "null", this); } if (!_execContent) { - _execContent = ContentExecutor(std::shared_ptr<ContentExecutorImpl>(new BasicContentExecutorImpl(this))); + _execContent = ContentExecutor(std::shared_ptr<ContentExecutorImpl>(new BasicContentExecutor(this))); } if (!_externalQueue) { - _externalQueue = EventQueue(std::shared_ptr<EventQueueImpl>(new EventQueueImpl())); + _externalQueue = EventQueue(std::shared_ptr<EventQueueImpl>(new BasicEventQueue())); } if (!_internalQueue) { - _internalQueue = EventQueue(std::shared_ptr<EventQueueImpl>(new EventQueueImpl())); + _internalQueue = EventQueue(std::shared_ptr<EventQueueImpl>(new BasicEventQueue())); } if (!_delayQueue) { - _delayQueue = DelayedEventQueue(std::shared_ptr<DelayedEventQueueImpl>(new DelayedEventQueueImpl(this))); + _delayQueue = DelayedEventQueue(std::shared_ptr<DelayedEventQueueImpl>(new BasicDelayedEventQueue(this))); } _isInitialized = true; } -void InterpreterImpl::initData(xercesc::DOMElement* root) { +void InterpreterImpl::initData(XERCESC_NS::DOMElement* root) { std::string id = ATTR(root, "id"); Data d; try { @@ -330,7 +336,7 @@ void InterpreterImpl::eventReady(Event& sendEvent, const std::string& eventUUID) } } -void InterpreterImpl::invoke(const std::string& type, const std::string& src, bool autoForward, xercesc::DOMElement* finalize, const Event& invokeEvent) { +void InterpreterImpl::invoke(const std::string& type, const std::string& src, bool autoForward, XERCESC_NS::DOMElement* finalize, const Event& invokeEvent) { std::string tmp; if (src.size() > 0) { diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index 7c64779..e1abf9b 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -17,8 +17,8 @@ * @endcond */ -#ifndef INTERPRETERIMPL_H_29D5BEBA -#define INTERPRETERIMPL_H_29D5BEBA +#ifndef INTERPRETERIMPL_H_2A79C83D +#define INTERPRETERIMPL_H_2A79C83D #include <memory> #include <mutex> @@ -29,9 +29,10 @@ #include "uscxml/Common.h" #include "uscxml/util/URL.h" #include "uscxml/plugins/Factory.h" -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" #include "uscxml/interpreter/MicroStepImpl.h" #include "uscxml/interpreter/ContentExecutorImpl.h" +#include "uscxml/interpreter/EventQueue.h" #include "uscxml/interpreter/EventQueueImpl.h" #include "uscxml/util/DOM.h" #include <xercesc/dom/DOM.hpp> @@ -41,13 +42,10 @@ namespace uscxml { class InterpreterMonitor; class InterpreterIssue; -class USCXML_API ActionLanguage { -public: - MicroStep microStepper; - DataModel dataModel; - ContentExecutor execContent; -}; - +/** + * @ingroup interpreter + * @ingroup impl + */ class USCXML_API InterpreterImpl : public MicroStepCallbacks, public DataModelCallbacks, @@ -92,7 +90,7 @@ public: return _state; } - std::list<xercesc::DOMElement*> getConfiguration() { + std::list<XERCESC_NS::DOMElement*> getConfiguration() { return _microStepper.getConfiguration(); } @@ -112,22 +110,22 @@ public: virtual Event dequeueExternal(bool blocking); virtual bool isTrue(const std::string& expr); - virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) { + virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) { _execContent.raiseDoneEvent(state, doneData); } - virtual void process(xercesc::DOMElement* block) { + virtual void process(XERCESC_NS::DOMElement* block) { _execContent.process(block, _xmlPrefix); } virtual bool isMatched(const Event& event, const std::string& eventDesc); - virtual void initData(xercesc::DOMElement* element); + virtual void initData(XERCESC_NS::DOMElement* element); - virtual void invoke(xercesc::DOMElement* invoke) { + virtual void invoke(XERCESC_NS::DOMElement* invoke) { _execContent.invoke(invoke); } - virtual void uninvoke(xercesc::DOMElement* invoke) { + virtual void uninvoke(XERCESC_NS::DOMElement* invoke) { _execContent.uninvoke(invoke); } @@ -154,7 +152,7 @@ public: virtual bool isInState(const std::string& stateId) { return _microStepper.isInState(stateId); } - virtual xercesc::DOMDocument* getDocument() const { + virtual XERCESC_NS::DOMDocument* getDocument() const { return _document; } @@ -201,7 +199,7 @@ public: } virtual bool checkValidSendType(const std::string& type, const std::string& target); - virtual void invoke(const std::string& type, const std::string& src, bool autoForward, xercesc::DOMElement* finalize, const Event& invokeEvent); + virtual void invoke(const std::string& type, const std::string& src, bool autoForward, XERCESC_NS::DOMElement* finalize, const Event& invokeEvent); virtual void uninvoke(const std::string& invokeId); virtual void enqueue(const std::string& type, const std::string& target, size_t delayMs, const Event& sendEvent); @@ -225,7 +223,7 @@ public: static std::map<std::string, std::weak_ptr<InterpreterImpl> > getInstances(); - virtual xercesc::DOMDocument* getDocument() { + virtual XERCESC_NS::DOMDocument* getDocument() { return _document; } @@ -239,8 +237,8 @@ protected: std::string _invokeId; // TODO: Never set! bool _isInitialized; - xercesc::DOMDocument* _document; - xercesc::DOMElement* _scxml; + XERCESC_NS::DOMDocument* _document; + XERCESC_NS::DOMElement* _scxml; std::map<std::string, std::tuple<std::string, std::string, std::string> > _delayedEventTargets; @@ -287,4 +285,4 @@ private: } -#endif /* end of include guard: INTERPRETERIMPL_H_29D5BEBA */ +#endif /* end of include guard: INTERPRETERIMPL_H_2A79C83D */ diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index 6ebdb35..901e1eb 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -17,8 +17,8 @@ * @endcond */ -#ifndef INTERPRETERMONITOR_H_4BA77097 -#define INTERPRETERMONITOR_H_4BA77097 +#ifndef INTERPRETERMONITOR_H_D3F21429 +#define INTERPRETERMONITOR_H_D3F21429 #include "uscxml/Common.h" #include "uscxml/messages/Event.h" @@ -51,23 +51,23 @@ public: virtual void beforeProcessingEvent(const Event& event) {} virtual void beforeMicroStep() {} - virtual void beforeExitingState(const xercesc::DOMElement* state) {} - virtual void afterExitingState(const xercesc::DOMElement* state) {} + virtual void beforeExitingState(const XERCESC_NS::DOMElement* state) {} + virtual void afterExitingState(const XERCESC_NS::DOMElement* state) {} - virtual void beforeExecutingContent(const xercesc::DOMElement* execContent) {} - virtual void afterExecutingContent(const xercesc::DOMElement* execContent) {} + virtual void beforeExecutingContent(const XERCESC_NS::DOMElement* execContent) {} + virtual void afterExecutingContent(const XERCESC_NS::DOMElement* execContent) {} - virtual void beforeUninvoking(const xercesc::DOMElement* invokeElem, const std::string& invokeid) {} - virtual void afterUninvoking(const xercesc::DOMElement* invokeElem, const std::string& invokeid) {} + virtual void beforeUninvoking(const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {} + virtual void afterUninvoking(const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {} - virtual void beforeTakingTransition(const xercesc::DOMElement* transition) {} - virtual void afterTakingTransition(const xercesc::DOMElement* transition) {} + virtual void beforeTakingTransition(const XERCESC_NS::DOMElement* transition) {} + virtual void afterTakingTransition(const XERCESC_NS::DOMElement* transition) {} - virtual void beforeEnteringState(const xercesc::DOMElement* state) {} - virtual void afterEnteringState(const xercesc::DOMElement* state) {} + virtual void beforeEnteringState(const XERCESC_NS::DOMElement* state) {} + virtual void afterEnteringState(const XERCESC_NS::DOMElement* state) {} - virtual void beforeInvoking(const xercesc::DOMElement* invokeElem, const std::string& invokeid) {} - virtual void afterInvoking(const xercesc::DOMElement* invokeElem, const std::string& invokeid) {} + virtual void beforeInvoking(const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {} + virtual void afterInvoking(const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {} virtual void afterMicroStep() {} virtual void onStableConfiguration() {} @@ -90,6 +90,23 @@ protected: }; +class USCXML_API StateTransitionMonitor : public uscxml::InterpreterMonitor { +public: + StateTransitionMonitor() {} + virtual ~StateTransitionMonitor() {} + + virtual void beforeTakingTransition(const XERCESC_NS::DOMElement* transition); + virtual void beforeExecutingContent(const XERCESC_NS::DOMElement* element); + virtual void onStableConfiguration(); + virtual void beforeProcessingEvent(const uscxml::Event& event); + virtual void beforeExitingState(const XERCESC_NS::DOMElement* state); + virtual void beforeEnteringState(const XERCESC_NS::DOMElement* state); + virtual void beforeMicroStep(); + +protected: + static std::recursive_mutex _mutex; +}; + } -#endif /* end of include guard: INTERPRETERMONITOR_H_4BA77097 */ +#endif /* end of include guard: INTERPRETERMONITOR_H_D3F21429 */ diff --git a/src/uscxml/interpreter/InterpreterState.h b/src/uscxml/interpreter/InterpreterState.h new file mode 100644 index 0000000..a4741ed --- /dev/null +++ b/src/uscxml/interpreter/InterpreterState.h @@ -0,0 +1,44 @@ +/** + * @file + * @author 2016 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 + */ + + +#ifndef INTERPRETERSTATE_H_E6CCAEA5 +#define INTERPRETERSTATE_H_E6CCAEA5 + + +#include "uscxml/Common.h" + +namespace uscxml { + +enum InterpreterState { + USCXML_FINISHED = -2, ///< machine reached a final configuration and is done + USCXML_INTERRUPTED = -1, ///< machine received the empty event on the external queue + USCXML_UNDEF = 0, ///< not an actual state + USCXML_IDLE = 1, ///< stable configuration and queues empty + USCXML_INITIALIZED = 2, ///< DOM is setup and all external components instantiated + USCXML_INSTANTIATED = 3, ///< nothing really, just instantiated + USCXML_MICROSTEPPED = 4, ///< processed one transition set + USCXML_MACROSTEPPED = 5, ///< processed all transition sets and reached a stable configuration + USCXML_CANCELLED = 6, ///< machine was cancelled, step once more to finalize +}; + + +} + +#endif /* end of include guard: INTERPRETERSTATE_H_E6CCAEA5 */ diff --git a/src/uscxml/interpreter/MicroStep.cpp b/src/uscxml/interpreter/MicroStep.cpp new file mode 100644 index 0000000..aa75c91 --- /dev/null +++ b/src/uscxml/interpreter/MicroStep.cpp @@ -0,0 +1,47 @@ +/** + * @file + * @author 2012-2016 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 "MicroStep.h" +#include "MicroStepImpl.h" + +namespace uscxml { + +InterpreterState MicroStep::step(bool blocking) { + return _impl->step(blocking); +} +void MicroStep::reset() { + return _impl->reset(); +} +bool MicroStep::isInState(const std::string& stateId) { + return _impl->isInState(stateId); +} + +std::list<XERCESC_NS::DOMElement*> MicroStep::getConfiguration() { + return _impl->getConfiguration(); +} + +void MicroStep::init(XERCESC_NS::DOMElement* scxml) { + _impl->init(scxml); +} + +void MicroStep::markAsCancelled() { + _impl->markAsCancelled(); +} + +}
\ No newline at end of file diff --git a/src/uscxml/interpreter/MicroStep.h b/src/uscxml/interpreter/MicroStep.h new file mode 100644 index 0000000..c20e994 --- /dev/null +++ b/src/uscxml/interpreter/MicroStep.h @@ -0,0 +1,66 @@ +/** + * @file + * @author 2016 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 + */ + +#ifndef MICROSTEP_H_07DA8BFA +#define MICROSTEP_H_07DA8BFA + + +#include <memory> +#include <list> +#include <string> + +#include "uscxml/config.h" +#include "uscxml/Common.h" +#include "uscxml/interpreter/InterpreterState.h" + +// #include <xercesc/dom/DOM.hpp> + +// forward declare +namespace XERCESC_NS { + class DOMElement; +} + +namespace uscxml { + +class MicroStepImpl; + +/** + * @ingroup microstep + * @ingroup facade + */ +class USCXML_API MicroStep { +public: + PIMPL_OPERATORS(MicroStep); + + virtual InterpreterState step(bool blocking); + virtual void reset(); + virtual bool isInState(const std::string& stateId); + + std::list<XERCESC_NS::DOMElement*> getConfiguration(); + + virtual void init(XERCESC_NS::DOMElement* scxml); + virtual void markAsCancelled(); + +protected: + std::shared_ptr<MicroStepImpl> _impl; +}; + +} + +#endif /* end of include guard: MICROSTEP_H_07DA8BFA */ diff --git a/src/uscxml/interpreter/MicroStepImpl.h b/src/uscxml/interpreter/MicroStepImpl.h index 71c03b5..e4cde5d 100644 --- a/src/uscxml/interpreter/MicroStepImpl.h +++ b/src/uscxml/interpreter/MicroStepImpl.h @@ -20,57 +20,50 @@ #ifndef MICROSTEPIMPL_H_98233709 #define MICROSTEPIMPL_H_98233709 -#include <memory> -#include <mutex> +#include "uscxml/config.h" + #include <list> -#include <map> #include <string> +#include <xercesc/dom/DOM.hpp> #include "uscxml/Common.h" +#include "uscxml/Interpreter.h" #include "uscxml/messages/Event.h" -#include "uscxml/interpreter/InterpreterMonitor.h" -#include "uscxml/util/DOM.h" -#include <xercesc/dom/DOM.hpp> - -namespace uscxml { - -enum InterpreterState { - USCXML_FINISHED = -2, ///< machine reached a final configuration and is done - USCXML_INTERRUPTED = -1, ///< machine received the empty event on the external queue - USCXML_UNDEF = 0, ///< not an actual state - USCXML_IDLE = 1, ///< stable configuration and queues empty - USCXML_INITIALIZED = 2, ///< DOM is setup and all external components instantiated - USCXML_INSTANTIATED = 3, ///< nothing really, just instantiated - USCXML_MICROSTEPPED = 4, ///< processed one transition set - USCXML_MACROSTEPPED = 5, ///< processed all transition sets and reached a stable configuration - USCXML_CANCELLED = 6, ///< machine was cancelled, step once more to finalize -}; +namespace uscxml { +/** + * @ingroup microstep + * @ingroup callback + */ class USCXML_API MicroStepCallbacks { public: /** Event Queues / Matching */ virtual Event dequeueInternal() = 0; virtual Event dequeueExternal(bool blocking) = 0; virtual bool isMatched(const Event& event, const std::string& eventDesc) = 0; - virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) = 0; + virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) = 0; /** Datamodel */ virtual bool isTrue(const std::string& expr) = 0; - virtual void initData(xercesc::DOMElement* element) = 0; + virtual void initData(XERCESC_NS::DOMElement* element) = 0; /** Executable Content */ - virtual void process(xercesc::DOMElement* block) = 0; + virtual void process(XERCESC_NS::DOMElement* block) = 0; /** Invocations */ - virtual void invoke(xercesc::DOMElement* invoke) = 0; - virtual void uninvoke(xercesc::DOMElement* invoke) = 0; + virtual void invoke(XERCESC_NS::DOMElement* invoke) = 0; + virtual void uninvoke(XERCESC_NS::DOMElement* invoke) = 0; /** Monitoring */ virtual InterpreterMonitor* getMonitor() = 0; }; +/** + * @ingroup microstep + * @ingroup impl + */ class USCXML_API MicroStepImpl { public: enum Binding { @@ -83,9 +76,9 @@ public: virtual InterpreterState step(bool blocking) = 0; virtual void reset() = 0; ///< Reset state machine virtual bool isInState(const std::string& stateId) = 0; - virtual std::list<xercesc::DOMElement*> getConfiguration() = 0; + virtual std::list<XERCESC_NS::DOMElement*> getConfiguration() = 0; - virtual void init(xercesc::DOMElement* scxml) = 0; + virtual void init(XERCESC_NS::DOMElement* scxml) = 0; virtual void markAsCancelled() = 0; protected: @@ -93,35 +86,6 @@ protected: }; -class USCXML_API MicroStep { -public: - PIMPL_OPERATORS(MicroStep) - - virtual InterpreterState step(bool blocking) { - return _impl->step(blocking); - } - virtual void reset() { - return _impl->reset(); - } - virtual bool isInState(const std::string& stateId) { - return _impl->isInState(stateId); - } - - std::list<xercesc::DOMElement*> getConfiguration() { - return _impl->getConfiguration(); - } - - virtual void init(xercesc::DOMElement* scxml) { - _impl->init(scxml); - } - - virtual void markAsCancelled() { - _impl->markAsCancelled(); - } -protected: - std::shared_ptr<MicroStepImpl> _impl; -}; - } #endif /* end of include guard: MICROSTEPIMPL_H_98233709 */ diff --git a/src/uscxml/messages/Blob.h b/src/uscxml/messages/Blob.h index 9bbf0f7..403485c 100644 --- a/src/uscxml/messages/Blob.h +++ b/src/uscxml/messages/Blob.h @@ -65,7 +65,7 @@ protected: class USCXML_API Blob { public: - PIMPL_OPERATORS(Blob) + PIMPL_OPERATORS(Blob); Blob(size_t size) : _impl(std::shared_ptr<BlobImpl>(new BlobImpl(size))) {} Blob(const char* data, diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h index 55b9f64..6ab3bec 100644 --- a/src/uscxml/messages/Data.h +++ b/src/uscxml/messages/Data.h @@ -24,11 +24,18 @@ #include <map> #include <memory> +#include "uscxml/config.h" #include "uscxml/Common.h" #include "uscxml/util/Convenience.h" #include "uscxml/messages/Blob.h" -#include <xercesc/dom/DOMDocument.hpp> +//#include <xercesc/dom/DOMDocument.hpp> + +// forward declare +namespace XERCESC_NS { + class DOMDocument; + class DOMNode; +} namespace uscxml { @@ -54,8 +61,6 @@ public: } } - Data(xercesc::DOMNode* node) : node(node), type(VERBATIM) {} - // template <typename T> Data(T value, Type type = INTERPRETED) : atom(toStr(value)), type(type) {} // we will have to drop this constructor as it interferes with operator Data() and requires C++11 @@ -214,8 +219,8 @@ public: protected: #endif - xercesc::DOMNode* node; - std::shared_ptr<xercesc::DOMDocument*> adoptedDoc; + XERCESC_NS::DOMNode* node; + std::shared_ptr<XERCESC_NS::DOMDocument*> adoptedDoc; std::map<std::string, Data> compound; std::list<Data> array; std::string atom; diff --git a/src/uscxml/plugins/DataModel.cpp b/src/uscxml/plugins/DataModel.cpp new file mode 100644 index 0000000..96afd89 --- /dev/null +++ b/src/uscxml/plugins/DataModel.cpp @@ -0,0 +1,86 @@ +/** + * @file + * @author 2012-2014 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 "DataModel.h" +#include "DataModelImpl.h" + +namespace uscxml { + +std::list<std::string> DataModel::getNames() { + return _impl->getNames(); +} + +bool DataModel::isValidSyntax(const std::string& expr) { + return _impl->isValidSyntax(expr); +} + +void DataModel::setEvent(const Event& event) { + return _impl->setEvent(event); +} + +Data DataModel::getAsData(const std::string& content) { + return _impl->getAsData(content); +} + +Data DataModel::evalAsData(const std::string& content) { + return _impl->evalAsData(content); +} + +bool DataModel::evalAsBool(const std::string& expr) { + return _impl->evalAsBool(expr); +} + +uint32_t DataModel::getLength(const std::string& expr) { + return _impl->getLength(expr); +} + +void DataModel::setForeach(const std::string& item, + const std::string& array, + const std::string& index, + uint32_t iteration) { + return _impl->setForeach(item, array, index, iteration); +} + +void DataModel::assign(const std::string& location, const Data& data) { + return _impl->assign(location, data); +} + +void DataModel::init(const std::string& location, const Data& data) { + return _impl->init(location, data); +} + +bool DataModel::isDeclared(const std::string& expr) { + return _impl->isDeclared(expr); +} + +size_t DataModel::replaceExpressions(std::string& content) { + return _impl->replaceExpressions(content); +} + +std::string DataModel::andExpressions(std::list<std::string> expressions) { + return _impl->andExpressions(expressions); +} + +void DataModel::addExtension(DataModelExtension* ext) { + return _impl->addExtension(ext); +} + + +} + diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index b08f934..03e557c 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -21,208 +21,65 @@ #define DATAMODEL_H_F1F776F9 #include "uscxml/Common.h" -#include "uscxml/plugins/Invoker.h" -#include "uscxml/plugins/IOProcessor.h" - -#ifndef TIME_BLOCK -# ifdef BUILD_PROFILING -# include "uscxml/concurrency/Timer.h" -# define TIME_BLOCK Measurement msm(&timer); -# else -# define TIME_BLOCK -# endif -#endif +#include "uscxml/messages/Event.h" #include <list> #include <string> #include <memory> -#include <sstream> - -#include <xercesc/dom/DOM.hpp> namespace uscxml { -class InterpreterImpl; class DataModelImpl; +class DataModelExtension; -class USCXML_API DataModelCallbacks { +/** + * @ingroup datamodel + * @ingroup facade + * The facade for data-models. + */ +class USCXML_API DataModel { public: - virtual const std::string& getName() = 0; - virtual const std::string& getSessionId() = 0; - virtual const std::map<std::string, IOProcessor>& getIOProcessors() = 0; - virtual bool isInState(const std::string& stateId) = 0; - virtual xercesc::DOMDocument* getDocument() const = 0; - virtual const std::map<std::string, Invoker>& getInvokers() = 0; -}; -class USCXML_API DataModelExtension { -public: - DataModelExtension() : dm(NULL) {} - virtual ~DataModelExtension() {} - virtual std::string provides() = 0; - virtual Data getValueOf(const std::string& member) = 0; - virtual void setValueOf(const std::string& member, const Data& data) = 0; - DataModelImpl* dm; -}; + PIMPL_OPERATORS(DataModel); -class USCXML_API DataModelImpl { -public: - virtual ~DataModelImpl() {} - virtual std::shared_ptr<DataModelImpl> create(DataModelCallbacks* interpreter) = 0; - virtual std::list<std::string> getNames() = 0; + /// @copydoc DataModelImpl::getNames() + virtual std::list<std::string> getNames(); + /// @copydoc DataModelImpl::isValidSyntax() + virtual bool isValidSyntax(const std::string& expr); - virtual bool isValidSyntax(const std::string& expr) { - return true; // overwrite when datamodel supports it - } - virtual void setEvent(const Event& event) = 0; + /// @copydoc DataModelImpl::setEvent() + virtual void setEvent(const Event& event); - size_t replaceExpressions(std::string& content); + /// @copydoc DataModelImpl::getAsData() + virtual Data getAsData(const std::string& content); + /// @copydoc DataModelImpl::evalAsData() + virtual Data evalAsData(const std::string& content); + /// @copydoc DataModelImpl::evalAsBool() + virtual bool evalAsBool(const std::string& expr); - // foreach - virtual uint32_t getLength(const std::string& expr) = 0; + /// @copydoc DataModelImpl::getLength() + virtual uint32_t getLength(const std::string& expr); + /// @copydoc DataModelImpl::setForeach() virtual void setForeach(const std::string& item, const std::string& array, const std::string& index, - uint32_t iteration) = 0; - - virtual Data getAsData(const std::string& content) = 0; - virtual Data evalAsData(const std::string& content) = 0; - virtual bool evalAsBool(const std::string& expr) = 0; - - virtual bool isDeclared(const std::string& expr) = 0; - - /** - * test147: - * <data id="Var1" expr="0"/> - * - * test150: - * <data id="Var3"> - * [1,2,3] - * </data> - * - * test277: - * <data id="Var1" expr="return"/> - * - */ - virtual void assign(const std::string& location, const Data& data) = 0; - virtual void init(const std::string& location, const Data& data) = 0; - - virtual void setCallbacks(DataModelCallbacks* callbacks) { - _callbacks = callbacks; - } + uint32_t iteration); - virtual void addExtension(DataModelExtension* ext); - virtual std::string andExpressions(std::list<std::string>) { - return ""; - } + /// @copydoc DataModelImpl::assign() + virtual void assign(const std::string& location, const Data& data); + /// @copydoc DataModelImpl::init() + virtual void init(const std::string& location, const Data& data); -protected: - DataModelCallbacks* _callbacks; -}; + /// @copydoc DataModelImpl::isDeclared() + virtual bool isDeclared(const std::string& expr); -class USCXML_API DataModel { -public: + /// @copydoc DataModelImpl::replaceExpressions() + size_t replaceExpressions(std::string& content); + /// @copydoc DataModelImpl::andExpressions() + std::string andExpressions(std::list<std::string> expressions); - DataModel() : _impl() {} - DataModel(const std::shared_ptr<DataModelImpl> impl) : _impl(impl) { } - DataModel(const DataModel& other) : _impl(other._impl) { } - virtual ~DataModel() {}; - - operator bool() const { - return !!_impl; - } - bool operator< (const DataModel& other) const { - return _impl < other._impl; - } - bool operator==(const DataModel& other) const { - return _impl == other._impl; - } - bool operator!=(const DataModel& other) const { - return _impl != other._impl; - } - DataModel& operator= (const DataModel& other) { - _impl = other._impl; - return *this; - } - - virtual std::list<std::string> getNames() { - TIME_BLOCK - return _impl->getNames(); - } - - virtual bool isValidSyntax(const std::string& expr) { - TIME_BLOCK - return _impl->isValidSyntax(expr); - } - - virtual void setEvent(const Event& event) { - TIME_BLOCK - return _impl->setEvent(event); - } - virtual Data getAsData(const std::string& content) { - TIME_BLOCK - return _impl->getAsData(content); - } - virtual Data evalAsData(const std::string& content) { - TIME_BLOCK - return _impl->evalAsData(content); - } - - virtual bool evalAsBool(const std::string& expr) { - TIME_BLOCK - return _impl->evalAsBool(expr); - } - - virtual uint32_t getLength(const std::string& expr) { - TIME_BLOCK - return _impl->getLength(expr); - } - virtual void setForeach(const std::string& item, - const std::string& array, - const std::string& index, - uint32_t iteration) { - TIME_BLOCK - return _impl->setForeach(item, array, index, iteration); - } - - virtual void assign(const std::string& location, const Data& data) { - TIME_BLOCK - return _impl->assign(location, data); - } - - virtual void init(const std::string& location, const Data& data) { - TIME_BLOCK - return _impl->init(location, data); - } - - virtual bool isDeclared(const std::string& expr) { - TIME_BLOCK - return _impl->isDeclared(expr); - } - - size_t replaceExpressions(std::string& content) { - TIME_BLOCK - return _impl->replaceExpressions(content); - } - - std::string andExpressions(std::list<std::string> expressions) { - TIME_BLOCK - return _impl->andExpressions(expressions); - } - - virtual void setCallbacks(DataModelCallbacks* callbacks) { - TIME_BLOCK - _impl->setCallbacks(callbacks); - } - - virtual void addExtension(DataModelExtension* ext) { - TIME_BLOCK - _impl->addExtension(ext); - } - -#ifdef BUILD_PROFILING - Timer timer; -#endif + /// @copydoc DataModelImpl::addExtension() + virtual void addExtension(DataModelExtension* ext); protected: std::shared_ptr<DataModelImpl> _impl; diff --git a/src/uscxml/plugins/DataModelImpl.h b/src/uscxml/plugins/DataModelImpl.h new file mode 100644 index 0000000..e2795c0 --- /dev/null +++ b/src/uscxml/plugins/DataModelImpl.h @@ -0,0 +1,196 @@ +/** + * @file + * @author 2012-2014 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 + */ + +#ifndef DATAMODELIMPL_H_5A33C087 +#define DATAMODELIMPL_H_5A33C087 + +#include "uscxml/config.h" +#include "uscxml/Common.h" +#include "uscxml/plugins/Invoker.h" +#include "uscxml/plugins/IOProcessor.h" + +#include <xercesc/dom/DOM.hpp> + +#include <list> +#include <string> +#include <memory> + +namespace uscxml { + +class InterpreterImpl; +class DataModelImpl; + +/** + * @ingroup datamodel + * @ingroup callback + * Callbacks available for every data-model. + */ +class USCXML_API DataModelCallbacks { +public: + virtual const std::string& getName() = 0; + virtual const std::string& getSessionId() = 0; + virtual const std::map<std::string, IOProcessor>& getIOProcessors() = 0; + virtual bool isInState(const std::string& stateId) = 0; + virtual XERCESC_NS::DOMDocument* getDocument() const = 0; + virtual const std::map<std::string, Invoker>& getInvokers() = 0; +}; + +class USCXML_API DataModelExtension { +public: + DataModelExtension() : dm(NULL) {} + virtual ~DataModelExtension() {} + virtual std::string provides() = 0; + virtual Data getValueOf(const std::string& member) = 0; + virtual void setValueOf(const std::string& member, const Data& data) = 0; + DataModelImpl* dm; +}; + +/** + * @ingroup datamodel + * @ingroup abstract + * Abstract base class for all data-model implementations. + */ +class USCXML_API DataModelImpl { +public: + virtual ~DataModelImpl() {} + + /** + * The Factory wants to instantiate a new instance. + * This function will have to initialize the object. The actual constructor + * is called from within here. The only one who calls the constructor directly + * is the Factory for the prototype object. + * + * @param callbacks The callbacks available to the datamodel + * @return A shared pointer with an initialized instance + */ + virtual std::shared_ptr<DataModelImpl> create(DataModelCallbacks* callbacks) = 0; + + /** + * Return a list of names to be matched by the `datamodel` attribute in SCXML. + */ + virtual std::list<std::string> getNames() = 0; + + /** + * Determine whether a given string constitutes valid syntax in the + * data-model's language. + * @param expr A string, supposedly containing an expression of the data-model. + * @return Whether expr is in L(DM). + */ + virtual bool isValidSyntax(const std::string& expr) { + return true; // overwrite when datamodel supports it + } + + /** + * Set the given event as `_event` in the data-model's global scope. + * @param event The event as it was dequeued from either the internal or external queue. + */ + virtual void setEvent(const Event& event) = 0; + + /** + * Experimental extension to have dynamic content in string literals. + * This function was used to replace ${foo} expressions on the data-model, + * e.g. in text nodes. It will eventually make a reappearance I guess. + * @param content The string with tokens to replace. + * @return How many occurences where replaced. + */ + size_t replaceExpressions(std::string& content); + + ///@name Foreach Support + ///@{ + + // foreach + virtual uint32_t getLength(const std::string& expr) = 0; + virtual void setForeach(const std::string& item, + const std::string& array, + const std::string& index, + uint32_t iteration) = 0; + ///@} + + /** + * Return a string as an *unevaluated* Data object. + * @param content A string with a literal, eppression or compound data-structure in the data-model's language. + * @return An unevaluated structure representing the given compound or literal. + */ + virtual Data getAsData(const std::string& content) = 0; + + /** + * Return a string as an *evaluated* Data object. + * @param content A string with a literal, eppression or compound data-structure in the data-model's language. + * @return An evaluated structure representing the given compound or literal. + */ + virtual Data evalAsData(const std::string& content) = 0; + + /** + * Evaluate a given expression as a boolean. + * This function is a subset of evalAsData() but saves on creating and copying a Data object. + * @param expr An expression in the data-model's language. + * @return Whether the expression evaluates as `true` + */ + virtual bool evalAsBool(const std::string& expr) = 0; + + /** + * Determine whether a given variable / location is declared. + * @param expr The variable / location to check. + * @todo Is this still used? + */ + virtual bool isDeclared(const std::string& expr) = 0; + + /** + * Assign a data object to a location in the data-model. + * There are different occurences in the SCXML IRP tests, e.g. +\verbatim +test147: + <data id="Var1" expr="0"/> + +test150: + <data id="Var3"> + [1,2,3] + </data> + +test277: + <data id="Var1" expr="return"/> +\endverbatim + * @param location A variable or locatio to assign to. + * @param data The Data object with the respective data. + */ + virtual void assign(const std::string& location, const Data& data) = 0; + + /** + * Initialize a variable / location in the data-model with a given data object. + * This is, semantically, very close to assign() but does not assume the + * location to be declared first. + * + * @param location A variable or locatio to assign to. + * @param data The Data object with the respective data. + */ + virtual void init(const std::string& location, const Data& data) = 0; + + + virtual void addExtension(DataModelExtension* ext); + virtual std::string andExpressions(std::list<std::string>) { + return ""; + } + +protected: + DataModelCallbacks* _callbacks; +}; + +} + +#endif /* end of include guard: DATAMODELIMPL_H_5A33C087 */ diff --git a/src/uscxml/plugins/EventHandler.h b/src/uscxml/plugins/EventHandler.h index 401afec..e08b1ad 100644 --- a/src/uscxml/plugins/EventHandler.h +++ b/src/uscxml/plugins/EventHandler.h @@ -21,40 +21,58 @@ #define EVENTHANDLER_H_2801243E #include "uscxml/Common.h" -#include "uscxml/messages/Data.h" #include "uscxml/messages/Event.h" #include <list> #include <string> #include <memory> -#include <sstream> - -#include <xercesc/dom/DOM.hpp> namespace uscxml { class InterpreterImpl; +/** + * @ingroup ioproc + * @ingroup invoker + * @ingroup impl + * Common base class for invokers and i/o processors. + */ + class USCXML_API EventHandlerImpl { public: EventHandlerImpl() {} virtual ~EventHandlerImpl() {} + /** + * Return a list of names for types we implement. + */ virtual std::list<std::string> getNames() = 0; + + /** + * Export a Data object for the `_x['name']` data-model namespace + * @return An object to be represented at `_x['name']` + */ virtual Data getDataModelVariables() = 0; protected: InterpreterImpl* _interpreter; }; +/** + * @ingroup ioproc + * @ingroup invoker + * @ingroup facade + */ class USCXML_API EventHandler { public: PIMPL_OPERATORS(EventHandler); + /// @copydoc EventHandlerImpl::getNames virtual std::list<std::string> getNames() { return _impl->getNames(); } + /// @copydoc EventHandlerImpl::getDataModelVariables virtual Data getDataModelVariables() const { return _impl->getDataModelVariables(); }; diff --git a/src/uscxml/plugins/ExecutableContent.cpp b/src/uscxml/plugins/ExecutableContent.cpp new file mode 100644 index 0000000..349f239 --- /dev/null +++ b/src/uscxml/plugins/ExecutableContent.cpp @@ -0,0 +1,50 @@ +/** + * @file + * @author 2012-2014 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 "ExecutableContent.h" +#include "ExecutableContentImpl.h" + +#include <xercesc/dom/DOM.hpp> +#include <string> +#include <memory> +#include <sstream> + +namespace uscxml { + +std::string ExecutableContent::getLocalName() { + return _impl->getLocalName(); +} + +std::string ExecutableContent::getNamespace() { + return _impl->getNamespace(); +} + +void ExecutableContent::enterElement(XERCESC_NS::DOMElement* node) { + return _impl->enterElement(node); +} + +void ExecutableContent::exitElement(XERCESC_NS::DOMElement* node) { + return _impl->exitElement(node); +} + +bool ExecutableContent::processChildren() { + return _impl->processChildren(); +} + +} diff --git a/src/uscxml/plugins/ExecutableContent.h b/src/uscxml/plugins/ExecutableContent.h index 0190820..14c1d5d 100644 --- a/src/uscxml/plugins/ExecutableContent.h +++ b/src/uscxml/plugins/ExecutableContent.h @@ -20,81 +20,37 @@ #ifndef EXECUTABLECONTENT_H_1E028A2D #define EXECUTABLECONTENT_H_1E028A2D +#include "uscxml/config.h" #include "uscxml/Common.h" + #include <string> #include <memory> #include <sstream> -#include "xercesc/dom/DOM.hpp" - -namespace uscxml { - -class InterpreterImpl; -class USCXML_API ExecutableContentImpl { -public: - ExecutableContentImpl() {}; - virtual ~ExecutableContentImpl() {}; - virtual std::shared_ptr<ExecutableContentImpl> create(InterpreterImpl* interpreter) = 0; +// forward declare +namespace XERCESC_NS { + class DOMElement; +} - virtual void setInterpreter(InterpreterImpl* interpreter) { - _interpreter = interpreter; - } +namespace uscxml { - virtual std::string getLocalName() = 0; ///< The name of the element. - virtual std::string getNamespace() { - return "http://www.w3.org/2005/07/scxml"; ///< The namespace of the element. - } - virtual void enterElement(xercesc::DOMElement* node) = 0; ///< Invoked when entering the element as part of evaluating executable content. - virtual void exitElement(xercesc::DOMElement* node) = 0; ///< Invoked when exiting the element as part of evaluating executable content. - virtual bool processChildren() = 0; ///< Whether or not the interpreter should process this elements children. - -protected: - InterpreterImpl* _interpreter; -}; +class ExecutableContentImpl; +/** + * @ingroup element + * @ingroup facade + * Facade for all executable content implementations. + */ class USCXML_API ExecutableContent { public: - ExecutableContent() : _impl() {} - ExecutableContent(std::shared_ptr<ExecutableContentImpl> const impl) : _impl(impl) { } - ExecutableContent(const ExecutableContent& other) : _impl(other._impl) { } - virtual ~ExecutableContent() {}; - - operator bool() const { - return !!_impl; - } - bool operator< (const ExecutableContent& other) const { - return _impl < other._impl; - } - bool operator==(const ExecutableContent& other) const { - return _impl == other._impl; - } - bool operator!=(const ExecutableContent& other) const { - return _impl != other._impl; - } - ExecutableContent& operator= (const ExecutableContent& other) { - _impl = other._impl; - return *this; - } - - void setInterpreter(InterpreterImpl* interpreter) { - _impl->setInterpreter(interpreter); - } - - std::string getLocalName() { - return _impl->getLocalName(); - } - std::string getNamespace() { - return _impl->getNamespace(); - } - void enterElement(xercesc::DOMElement* node) { - return _impl->enterElement(node); - } - void exitElement(xercesc::DOMElement* node) { - return _impl->exitElement(node); - } - bool processChildren() { - return _impl->processChildren(); - } + PIMPL_OPERATORS(ExecutableContent); + + std::string getLocalName(); + std::string getNamespace(); + void enterElement(XERCESC_NS::DOMElement* node); + void exitElement(XERCESC_NS::DOMElement* node); + bool processChildren(); + protected: std::shared_ptr<ExecutableContentImpl> _impl; diff --git a/src/uscxml/plugins/ExecutableContentImpl.h b/src/uscxml/plugins/ExecutableContentImpl.h new file mode 100644 index 0000000..d033d1e --- /dev/null +++ b/src/uscxml/plugins/ExecutableContentImpl.h @@ -0,0 +1,65 @@ +/** + * @file + * @author 2012-2014 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 + */ + +#ifndef EXECUTABLECONTENTIMPL_H_CCE9F02D +#define EXECUTABLECONTENTIMPL_H_CCE9F02D + +#include "uscxml/config.h" +#include "uscxml/Common.h" + +#include <xercesc/dom/DOM.hpp> +#include <string> +#include <memory> +#include <sstream> + +namespace uscxml { + +class InterpreterImpl; + +/** + * @ingroup element + * @ingroup impl + * Abstract base class fo all elements of executable content. + */ +class USCXML_API ExecutableContentImpl { +public: + ExecutableContentImpl() {}; + virtual ~ExecutableContentImpl() {}; + virtual std::shared_ptr<ExecutableContentImpl> create(InterpreterImpl* interpreter) = 0; + + virtual void setInterpreter(InterpreterImpl* interpreter) { + _interpreter = interpreter; + } + + virtual std::string getLocalName() = 0; ///< The name of the element. + virtual std::string getNamespace() { + return "http://www.w3.org/2005/07/scxml"; ///< The namespace of the element. + } + virtual void enterElement(XERCESC_NS::DOMElement* node) = 0; ///< Invoked when entering the element as part of evaluating executable content. + virtual void exitElement(XERCESC_NS::DOMElement* node) = 0; ///< Invoked when exiting the element as part of evaluating executable content. + virtual bool processChildren() = 0; ///< Whether or not the interpreter should process this elements children. + +protected: + InterpreterImpl* _interpreter; +}; + + +} + +#endif /* end of include guard: EXECUTABLECONTENTIMPL_H_CCE9F02D */ diff --git a/src/uscxml/plugins/Factory.cpp b/src/uscxml/plugins/Factory.cpp index 7c68a30..3600dd1 100644 --- a/src/uscxml/plugins/Factory.cpp +++ b/src/uscxml/plugins/Factory.cpp @@ -24,6 +24,8 @@ #include "uscxml/Interpreter.h" #include <easylogging++.h> +#include "uscxml/plugins/ExecutableContentImpl.h" + // see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system // we will always include these in a build @@ -275,7 +277,6 @@ std::shared_ptr<DataModelImpl> Factory::createDataModel(const std::string& type, std::string canonicalName = _dataModelAliases[type]; if (_dataModels.find(canonicalName) != _dataModels.end()) { std::shared_ptr<DataModelImpl> dataModel = _dataModels[canonicalName]->create(callbacks); - dataModel->setCallbacks(callbacks); return dataModel; } } diff --git a/src/uscxml/plugins/Factory.h b/src/uscxml/plugins/Factory.h index 0ce2af9..e0015b5 100644 --- a/src/uscxml/plugins/Factory.h +++ b/src/uscxml/plugins/Factory.h @@ -26,7 +26,7 @@ #include "uscxml/plugins/EventHandler.h" #include "uscxml/plugins/IOProcessor.h" #include "uscxml/plugins/Invoker.h" -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" #include <string.h> diff --git a/src/uscxml/plugins/IOProcessor.cpp b/src/uscxml/plugins/IOProcessor.cpp new file mode 100644 index 0000000..435d3b6 --- /dev/null +++ b/src/uscxml/plugins/IOProcessor.cpp @@ -0,0 +1,37 @@ +/** + * @file + * @author 2012-2014 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 "IOProcessor.h" +#include "IOProcessorImpl.h" + +namespace uscxml { + +PIMPL_OPERATORS_INHERIT_IMPL(IOProcessor, EventHandler) + +void IOProcessor::eventFromSCXML(const std::string& target, const Event& event) { + _impl->eventFromSCXML(target, event); +} + +bool IOProcessor::isValidTarget(const std::string& target) { + return _impl->isValidTarget(target); +} + + +} + diff --git a/src/uscxml/plugins/IOProcessor.h b/src/uscxml/plugins/IOProcessor.h index c7d90e5..558edfa 100644 --- a/src/uscxml/plugins/IOProcessor.h +++ b/src/uscxml/plugins/IOProcessor.h @@ -26,31 +26,25 @@ namespace uscxml { +class IOProcessorImpl; class InterpreterImpl; -class USCXML_API IOProcessorImpl : public EventHandlerImpl { -public: - - virtual std::shared_ptr<IOProcessorImpl> create(InterpreterImpl* interpreter) = 0; - virtual void eventFromSCXML(const std::string& target, const Event& event) = 0; - virtual bool isValidTarget(const std::string& target) = 0; - -protected: - void eventToSCXML(Event& event, const std::string& type, const std::string& origin, bool internal = false); - -}; - +/** + * @ingroup ioproc + * @ingroup facade + * Facade for I/O processors. + */ class USCXML_API IOProcessor : public EventHandler { public: - PIMPL_OPERATORS2(IOProcessor, EventHandler) - virtual void eventFromSCXML(const std::string& target, const Event& event) { - _impl->eventFromSCXML(target, event); - } + PIMPL_OPERATORS_INHERIT(IOProcessor, EventHandler); + + /// @copydoc IOProcessorImpl::eventFromSCXML + virtual void eventFromSCXML(const std::string& target, const Event& event); + + /// @copydoc IOProcessorImpl::isValidTarget + virtual bool isValidTarget(const std::string& target); - virtual bool isValidTarget(const std::string& target) { - return _impl->isValidTarget(target); - } protected: std::shared_ptr<IOProcessorImpl> _impl; diff --git a/src/uscxml/plugins/IOProcessorImpl.h b/src/uscxml/plugins/IOProcessorImpl.h new file mode 100644 index 0000000..0e5b44a --- /dev/null +++ b/src/uscxml/plugins/IOProcessorImpl.h @@ -0,0 +1,74 @@ +/** + * @file + * @author 2012-2014 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 + */ + +#ifndef IOPROCESSORIMPL_H_92E6AA44 +#define IOPROCESSORIMPL_H_92E6AA44 + + +#include "uscxml/Common.h" +#include "uscxml/plugins/EventHandler.h" +#include "uscxml/messages/Event.h" + +namespace uscxml { + +/** + * @ingroup ioproc + * @ingroup abstract + * Abstract base class for IOProcessor%s implementations. + */ +class USCXML_API IOProcessorImpl : public EventHandlerImpl { +public: + + /** + * Factory demands a new instance. + * @param interpreter The imlementation of the associated Interpreter + * @todo We will eventually introduce callbacks and prevent complete access to the interpreter. + */ + virtual std::shared_ptr<IOProcessorImpl> create(InterpreterImpl* interpreter) = 0; + + /** + * We received an event from the SCXML Interpreter we are associated with. + * @param target Where the event is supposed to be delivered to. + * @param event The event to deliver. + */ + virtual void eventFromSCXML(const std::string& target, const Event& event) = 0; + + /** + * Determine whether the given target is a valid destination for events. + * @param target A target where the Interpreter wants to deliver Event%s to. + * @return Whether or not the target is valid. + */ + virtual bool isValidTarget(const std::string& target) = 0; + +protected: + /** + * Return an event to the SCXML Interpreter instance. + * @param event An event to enqueue at the interpreter's external queue. + * @param type The type of this I/O Processor for `event.origintype`. + * @param origin The origin of this I/O Processor for `event.origin`. + * @param internal If the event is to be delivered to the Interpreter's internal queue instead. + */ + void eventToSCXML(Event& event, const std::string& type, const std::string& origin, bool internal = false); + +}; + +} + + +#endif /* end of include guard: IOPROCESSORIMPL_H_92E6AA44 */ diff --git a/src/uscxml/plugins/Invoker.cpp b/src/uscxml/plugins/Invoker.cpp new file mode 100644 index 0000000..a021ff7 --- /dev/null +++ b/src/uscxml/plugins/Invoker.cpp @@ -0,0 +1,43 @@ +/** + * @file + * @author 2012-2014 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 "Invoker.h" +#include "InvokerImpl.h" + +namespace uscxml { + +PIMPL_OPERATORS_INHERIT_IMPL(Invoker, EventHandler) + +void Invoker::invoke(const std::string& source, const Event& invokeEvent) { + _impl->invoke(source, invokeEvent); +} + +void Invoker::uninvoke() { + _impl->uninvoke(); +} + +void Invoker::eventFromSCXML(const Event& event) { + _impl->eventFromSCXML(event); +} + +XERCESC_NS::DOMElement* Invoker::getFinalize() { + return _impl->getFinalize(); +} + +} diff --git a/src/uscxml/plugins/Invoker.h b/src/uscxml/plugins/Invoker.h index c22b7e3..33a89d6 100644 --- a/src/uscxml/plugins/Invoker.h +++ b/src/uscxml/plugins/Invoker.h @@ -21,63 +21,42 @@ #define INVOKER_H_CAC11892 +#include "uscxml/config.h" #include "uscxml/Common.h" #include "uscxml/plugins/EventHandler.h" #include "uscxml/messages/Event.h" +#include <xercesc/dom/DOM.hpp> -namespace uscxml { - -class Interpreter; - -class USCXML_API InvokerImpl : public EventHandlerImpl { -public: - InvokerImpl() : _finalize(NULL) {}; - virtual ~InvokerImpl() {} - virtual std::list<std::string> getNames() = 0; - - virtual void invoke(const std::string& source, const Event& invokeEvent) = 0; - virtual void uninvoke() = 0; - - virtual void eventFromSCXML(const Event& event) = 0; - - virtual std::shared_ptr<InvokerImpl> create(InterpreterImpl* interpreter) = 0; - virtual xercesc::DOMElement* getFinalize() { - return _finalize; - } - virtual void setFinalize(xercesc::DOMElement* finalize) { - _finalize = finalize; - } - virtual void setInvokeId(const std::string& invokeId) { - _invokeId = invokeId; - } - -protected: - void eventToSCXML(Event& event, const std::string& type, const std::string& invokeId, bool internal = false); +namespace XERCESC_NS { + class DOMDocument; + class DOMNode; +} - xercesc::DOMElement* _finalize; - std::string _invokeId; +namespace uscxml { -}; +class InvokerImpl; +/** + * @ingroup invoker + * @ingroup facade + * Facade for invoker implementation. + */ class USCXML_API Invoker : public EventHandler { public: - PIMPL_OPERATORS2(Invoker, EventHandler); + PIMPL_OPERATORS_INHERIT(Invoker, EventHandler); + + /// @copydoc InvokerImpl::invoke + virtual void invoke(const std::string& source, const Event& invokeEvent); - virtual void invoke(const std::string& source, const Event& invokeEvent) { - _impl->invoke(source, invokeEvent); - } + /// @copydoc InvokerImpl::uninvoke + virtual void uninvoke(); - virtual void uninvoke() { - _impl->uninvoke(); - } + /// @copydoc InvokerImpl::eventFromSCXML + virtual void eventFromSCXML(const Event& event); - virtual void eventFromSCXML(const Event& event) { - _impl->eventFromSCXML(event); - } + /// @copydoc InvokerImpl::getFinalize + virtual XERCESC_NS::DOMElement* getFinalize(); - virtual xercesc::DOMElement* getFinalize() { - return _impl->getFinalize(); - } protected: std::shared_ptr<InvokerImpl> _impl; }; diff --git a/src/uscxml/plugins/InvokerImpl.h b/src/uscxml/plugins/InvokerImpl.h new file mode 100644 index 0000000..d8a3410 --- /dev/null +++ b/src/uscxml/plugins/InvokerImpl.h @@ -0,0 +1,110 @@ +/** + * @file + * @author 2012-2014 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 + */ + +#ifndef INVOKERIMPL_H_8A15A102 +#define INVOKERIMPL_H_8A15A102 + + +#include "uscxml/config.h" +#include "uscxml/Common.h" +#include "uscxml/plugins/EventHandler.h" +#include "uscxml/messages/Event.h" + +namespace uscxml { + +class Interpreter; + +/** + * @ingroup invoker + * @ingroup abstract + * Abstract base class for all invokers. + */ +class USCXML_API InvokerImpl : public EventHandlerImpl { +public: + InvokerImpl() : _finalize(NULL) {}; + virtual ~InvokerImpl() {} + + virtual std::list<std::string> getNames() = 0; + + /** + * Factory demands a new instance. + * @param interpreter The imlementation of the associated Interpreter + * @todo We will eventually introduce callbacks and prevent complete access to the interpreter. + */ + virtual std::shared_ptr<InvokerImpl> create(InterpreterImpl* interpreter) = 0; + + /** + * Invoker's parent state became active at the end of a macro-step. + * @param source The content of the invoke's `src` or evaluated `srcexpr` attribute + * @param invokeEvent The invocation with all its data as an event + */ + virtual void invoke(const std::string& source, const Event& invokeEvent) = 0; + + /** + * The invokers's parent state was left at the end of a macro-step. + */ + virtual void uninvoke() = 0; + + /** + * Interpreter received an event from the SCXML Interpreter. + */ + virtual void eventFromSCXML(const Event& event) = 0; + + /** + * Return the finalize XML element associated with this invoker. + */ + virtual XERCESC_NS::DOMElement* getFinalize() { + return _finalize; + } + + /** + * Set the finalize XML element associated with this invoker. + * @param finalize The finalize XMl element. + */ + virtual void setFinalize(XERCESC_NS::DOMElement* finalize) { + _finalize = finalize; + } + + /** + * Set the invocation identifier as required when returning events. + * @param invokeId The invocation identifier. + */ + virtual void setInvokeId(const std::string& invokeId) { + _invokeId = invokeId; + } + +protected: + /** + * Return an event to the SCXML Interpreter instance. + * @param event An event to enqueue at the interpreter's external queue. + * @param type The type of this I/O Processor for `event.origintype`. + * @param invokeId The invocation identifier of this invocation for `event.invokeid`. + * @param internal If the event is to be delivered to the Interpreter's internal queue instead. + */ + void eventToSCXML(Event& event, const std::string& type, const std::string& invokeId, bool internal = false); + + XERCESC_NS::DOMElement* _finalize; + std::string _invokeId; + +}; + +} + + +#endif /* end of include guard: INVOKERIMPL_H_8A15A102 */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index d43efbe..35d9c4b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -43,12 +43,12 @@ if (exception) \ handleException(exception); -using namespace xercesc; +using namespace XERCESC_NS; static JSValueRef XMLString2JS(const XMLCh* input, JSContextRef context) { JSValueRef output; - char* res = xercesc::XMLString::transcode(input); + char* res = XERCESC_NS::XMLString::transcode(input); JSStringRef stringRef = JSStringCreateWithUTF8CString(res); output = JSValueMakeString(context, stringRef); @@ -70,7 +70,7 @@ static XMLCh* JS2XMLString(JSValueRef input, JSContextRef context) { char* output = new char[maxSize + 1]; JSStringGetUTF8CString(stringInput, output, maxSize); - XMLCh* ret = xercesc::XMLString::transcode(output); + XMLCh* ret = XERCESC_NS::XMLString::transcode(output); return(ret); } @@ -509,7 +509,7 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { // dom node void* privData = NULL; SWIG_JSC_ConvertPtr(_ctx, value, &privData, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, 0); - data.node = (xercesc::DOMNode*)privData; + data.node = (XERCESC_NS::DOMNode*)privData; return data; } std::set<std::string> propertySet; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index b65dc37..c5129a4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -21,14 +21,10 @@ #define JSCDATAMODEL_H_KN8TWG0V #include "uscxml/config.h" -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" #include <list> #include <set> -/** - * There are two variants with JavaScriptCore headers - * Still beats the >20 V8 variants =D - */ #if defined(HAS_JSC_JAVASCRIPTCORE_H) #include <JavaScriptCore/JavaScriptCore.h> #elif defined(HAS_JSC_JAVASCRIPT_H) @@ -48,6 +44,11 @@ class Data; namespace uscxml { +/** + * @ingroup datamodel + * + * ECMAScript data-model via JavaScriptCore. + */ class JSCDataModel : public DataModelImpl { public: JSCDataModel(); @@ -103,7 +104,7 @@ protected: static JSValueRef jsInvokerGetProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); static void jsInvokerListProps(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames); - JSValueRef getNodeAsValue(const xercesc::DOMNode* node); + JSValueRef getNodeAsValue(const XERCESC_NS::DOMNode* node); JSValueRef getDataAsValue(const Data& data); Data getValueAsData(const JSValueRef value); JSValueRef evalAsValue(const std::string& expr, bool dontThrow = false); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index bfa29d8..3ccadcd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -33,17 +33,17 @@ #include "uscxml/util/DOM.h" #include <easylogging++.h> -using namespace xercesc; +using namespace XERCESC_NS; static v8::Local<v8::Value> XMLString2JS(const XMLCh* input) { - char* res = xercesc::XMLString::transcode(input); + char* res = XERCESC_NS::XMLString::transcode(input); v8::Local<v8::Value> handle = v8::String::New(res); return handle; } static XMLCh* JS2XMLString(const v8::Local<v8::Value>& value) { v8::String::AsciiValue s(value); - XMLCh* ret = xercesc::XMLString::transcode(*s); + XMLCh* ret = XERCESC_NS::XMLString::transcode(*s); return(ret); } @@ -137,11 +137,11 @@ std::mutex V8DataModel::_initMutex; v8::Isolate* V8DataModel::_isolate = NULL; void V8NodeListIndexedPropertyHandler(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { - xercesc::DOMNodeList* list; + XERCESC_NS::DOMNodeList* list; SWIG_V8_GetInstancePtr(info.Holder(), (void**)&list); if (list->getLength() >= index) { - xercesc::DOMNode* node = list->item(index); + XERCESC_NS::DOMNode* node = list->item(index); v8::Handle<v8::Value> val = SWIG_NewPointerObj(SWIG_as_voidptr(node), SWIG_TypeDynamicCast(SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_as_voidptrptr(&node)), 0 | 0 ); info.GetReturnValue().Set(val); @@ -528,7 +528,7 @@ Data V8DataModel::getValueAsData(const v8::Local<v8::Value>& value, std::set<v8: return data; } -v8::Local<v8::Value> V8DataModel::getNodeAsValue(const xercesc::DOMNode* node) { +v8::Local<v8::Value> V8DataModel::getNodeAsValue(const XERCESC_NS::DOMNode* node) { return SWIG_NewPointerObj(SWIG_as_voidptr(node), SWIG_TypeDynamicCast(SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_as_voidptrptr(&node)), diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 29b2b58..91ac48d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -20,7 +20,8 @@ #ifndef V8DATAMODEL_H_KN8TWG0V #define V8DATAMODEL_H_KN8TWG0V -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" + #include <list> #include <set> #include <v8.h> @@ -36,6 +37,11 @@ class Data; namespace uscxml { +/** + * @ingroup datamodel + * ECMAScript data-model via Google's V8. + */ + class V8DataModel : public DataModelImpl { public: V8DataModel(); @@ -95,7 +101,7 @@ protected: v8::Local<v8::Value> evalAsValue(const std::string& expr, bool dontThrow = false); v8::Local<v8::Value> getDataAsValue(const Data& data); Data getValueAsData(const v8::Local<v8::Value>& value); - v8::Local<v8::Value> getNodeAsValue(const xercesc::DOMNode* node); + v8::Local<v8::Value> getNodeAsValue(const XERCESC_NS::DOMNode* node); void throwExceptionEvent(const v8::TryCatch& tryCatch); std::set<DataModelExtension*> _extensions; diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index 4e2fd43..7b7121f 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -20,7 +20,7 @@ #ifndef LUADATAMODEL_H_113E014C #define LUADATAMODEL_H_113E014C -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" #include <list> extern "C" { @@ -41,6 +41,11 @@ class Data; namespace uscxml { +/** + * @ingroup datamodel + * Lua data-model. + */ + class LuaDataModel : public DataModelImpl { public: LuaDataModel(); diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp index 773a970..53c414f 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp @@ -63,7 +63,7 @@ Data NULLDataModel::getAsData(const std::string& content) { * The predicate must return 'true' if and only if that state is in the current * state configuration. */ -bool NULLDataModel::evalAsBool(const xercesc::DOMElement* scriptNode, const std::string& expr) { +bool NULLDataModel::evalAsBool(const XERCESC_NS::DOMElement* scriptNode, const std::string& expr) { std::string trimmedExpr = expr; boost::trim(trimmedExpr); if (!boost::istarts_with(trimmedExpr, "in")) diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.h b/src/uscxml/plugins/datamodel/null/NULLDataModel.h index c584357..4bea664 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.h @@ -20,7 +20,7 @@ #ifndef NULLDATAMODEL_H_KN8TWG0V #define NULLDATAMODEL_H_KN8TWG0V -#include "uscxml/plugins/DataModel.h" +#include "uscxml/plugins/DataModelImpl.h" #include <list> #ifdef BUILD_AS_PLUGINS @@ -34,6 +34,10 @@ class Data; namespace uscxml { +/** + * @ingroup datamodel + * NULL data-model. + */ class NULLDataModel : public DataModelImpl { public: NULLDataModel(); @@ -76,7 +80,7 @@ public: return expr; } - virtual bool evalAsBool(const xercesc::DOMElement* scriptNode, + virtual bool evalAsBool(const XERCESC_NS::DOMElement* scriptNode, const std::string& expr); virtual bool evalAsBool(const std::string& expr) { return evalAsBool(NULL, expr); @@ -86,13 +90,13 @@ public: return true; } - virtual void assign(const xercesc::DOMElement* assignElem, - const xercesc::DOMNode* node, + virtual void assign(const XERCESC_NS::DOMElement* assignElem, + const XERCESC_NS::DOMNode* node, const std::string& content) {} virtual void assign(const std::string& location, const Data& data) {} - virtual void init(const xercesc::DOMElement* dataElem, - const xercesc::DOMNode* node, + virtual void init(const XERCESC_NS::DOMElement* dataElem, + const XERCESC_NS::DOMNode* node, const std::string& content) {} virtual void init(const std::string& location, const Data& data) {} diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index 4d3c579..f80d427 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -32,7 +32,7 @@ namespace uscxml { // msxml.h should die in a fire for polluting the global namespace -// using namespace xercesc; +// using namespace XERCESC_NS; #ifdef BUILD_AS_PLUGINS PLUMA_CONNECTOR @@ -136,11 +136,11 @@ void USCXMLInvoker::invoke(const std::string& source, const Event& invokeEvent) if (source.length() > 0) { _invokedInterpreter = Interpreter::fromURL(source); } else if (invokeEvent.data.node) { - xercesc::DOMImplementation* implementation = xercesc::DOMImplementationRegistry::getDOMImplementation(X("core")); - xercesc::DOMDocument* document = implementation->createDocument(); + XERCESC_NS::DOMImplementation* implementation = XERCESC_NS::DOMImplementationRegistry::getDOMImplementation(X("core")); + XERCESC_NS::DOMDocument* document = implementation->createDocument(); // we need to import the parent - to support xpath test150 - xercesc::DOMNode* newNode = document->importNode(invokeEvent.data.node, true); + XERCESC_NS::DOMNode* newNode = document->importNode(invokeEvent.data.node, true); document->appendChild(newNode); // std::cout << *document << std::endl; diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index dac8d8b..f896bac 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -20,8 +20,11 @@ #ifndef USCXMLINVOKER_H_OQFA21IO #define USCXMLINVOKER_H_OQFA21IO -#include <uscxml/Interpreter.h> -#include "uscxml/interpreter/EventQueueImpl.h" +#include "uscxml/interpreter/InterpreterImpl.h" +#include "uscxml/interpreter/BasicEventQueue.h" + +#include "uscxml/plugins/Invoker.h" +#include "uscxml/plugins/InvokerImpl.h" #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" @@ -31,11 +34,15 @@ namespace uscxml { +/** +* @ingroup invoker + * An invoker for other SCXML instances. + */ class USCXMLInvoker : public InvokerImpl, public std::enable_shared_from_this<USCXMLInvoker> { public: - class ParentQueueImpl : public EventQueueImpl { + class ParentQueueImpl : public BasicEventQueue { public: ParentQueueImpl(USCXMLInvoker* invoker) : _invoker(invoker) {} virtual void enqueue(const Event& event); diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h index f7e9f10..b70ce8e 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h @@ -36,8 +36,9 @@ extern "C" { #endif #include "uscxml/server/HTTPServer.h" -#include "uscxml/Interpreter.h" -#include "uscxml/plugins/Factory.h" +#include "uscxml/interpreter/InterpreterImpl.h" +#include "uscxml/plugins/IOProcessorImpl.h" + #ifndef _WIN32 #include <sys/time.h> #endif @@ -50,6 +51,10 @@ extern "C" { namespace uscxml { +/** + * @ingroup ioproc + * The basichttp I/O processor as per standard. + */ class USCXML_PLUGIN_API BasicHTTPIOProcessor : public IOProcessorImpl, public HTTPServlet, public URLMonitor { public: BasicHTTPIOProcessor(); diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h index 3b08e30..21fd13a 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h @@ -20,10 +20,14 @@ #ifndef SCXMLIOProcessor_H_2CUY93KU #define SCXMLIOProcessor_H_2CUY93KU -#include "uscxml/plugins/IOProcessor.h" +#include "uscxml/plugins/IOProcessorImpl.h" namespace uscxml { +/** + * @ingroup ioproc + * The scxml I/O processor as per standard. + */ class SCXMLIOProcessor : public IOProcessorImpl { public: SCXMLIOProcessor(); diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 4891bfe..d7537ea 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -33,7 +33,7 @@ namespace uscxml { -using namespace xercesc; +using namespace XERCESC_NS; // many more tricks: https://graphics.stanford.edu/~seander/bithacks.html @@ -41,7 +41,7 @@ using namespace xercesc; Transformer ChartToC::transform(const Interpreter& other) { ChartToC* c2c = new ChartToC(other); - return boost::shared_ptr<TransformerImpl>(c2c); + return std::shared_ptr<TransformerImpl>(c2c); } ChartToC::ChartToC(const Interpreter& other) : TransformerImpl(other), _topMostMachine(NULL), _parentMachine(NULL) { @@ -69,7 +69,7 @@ ChartToC::ChartToC(const Interpreter& other) : TransformerImpl(other), _topMostM void ChartToC::setHistoryCompletion() { - std::list<DOMElement*> histories = DOMUtils::inPostFixOrder({ XML_PREFIX(_scxml).str() + "history" }, _scxml); + std::list<DOMElement*> histories = DOMUtils::inPostFixOrder({ XML_PREFIX(_scxml).str() + "history" }, _scxml); std::list<DOMElement*> covered; std::list<DOMElement*> perParentcovered; @@ -245,14 +245,14 @@ void ChartToC::prepare() { // make sure initial and history elements always precede propoer states resortStates(_scxml); - std::list<xercesc::DOMElement*> tmp = DOMUtils::inDocumentOrder({ - XML_PREFIX(_scxml).str() + "scxml", - XML_PREFIX(_scxml).str() + "state", - XML_PREFIX(_scxml).str() + "final", - XML_PREFIX(_scxml).str() + "history", - XML_PREFIX(_scxml).str() + "initial", - XML_PREFIX(_scxml).str() + "parallel" - }, _scxml); + std::list<XERCESC_NS::DOMElement*> tmp = DOMUtils::inDocumentOrder({ + XML_PREFIX(_scxml).str() + "scxml", + XML_PREFIX(_scxml).str() + "state", + XML_PREFIX(_scxml).str() + "final", + XML_PREFIX(_scxml).str() + "history", + XML_PREFIX(_scxml).str() + "initial", + XML_PREFIX(_scxml).str() + "parallel" + }, _scxml); _states.insert(_states.end(), tmp.begin(), tmp.end()); // set states' document order and parent attribute @@ -297,7 +297,7 @@ void ChartToC::prepare() { // set transitions' document order and source attribute - tmp = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); + tmp = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); size_t index = 0; for (auto transIter = tmp.begin(); transIter != tmp.end(); transIter++, index++) { DOMElement* transition = *transIter; @@ -1027,7 +1027,7 @@ void ChartToC::writeHelpers(std::ostream& stream) { void ChartToC::writeExecContentFinalize(std::ostream& stream) { // needs to be written prior to invocation elem info - std::list<DOMElement*> finalizes = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "finalize" }, _scxml); + std::list<DOMElement*> finalizes = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "finalize" }, _scxml); if (finalizes.size() > 0) { stream << "#ifndef USCXML_NO_EXEC_CONTENT" << std::endl; @@ -1497,7 +1497,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << "#ifndef USCXML_NO_ELEM_INFO" << std::endl; stream << std::endl; - std::list<DOMElement*> foreachs = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "foreach" }, _scxml); + std::list<DOMElement*> foreachs = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "foreach" }, _scxml); if (foreachs.size() > 0) { _hasElement.insert("foreach"); stream << "static const uscxml_elem_foreach " << _prefix << "_elem_foreachs[" << foreachs.size() << "] = {" << std::endl; @@ -1516,7 +1516,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl; } - std::list<DOMElement*> assigns = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "assign" }, _scxml); + std::list<DOMElement*> assigns = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "assign" }, _scxml); if (assigns.size() > 0) { _hasElement.insert("assign"); stream << "static const uscxml_elem_assign " << _prefix << "_elem_assigns[" << assigns.size() << "] = {" << std::endl; @@ -1549,7 +1549,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { } - std::list<DOMElement*> datas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "data" }, _scxml); + std::list<DOMElement*> datas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "data" }, _scxml); if (datas.size() > 0) { _hasElement.insert("data"); size_t dataIndexOffset = 0; @@ -1607,7 +1607,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl; } - std::list<DOMElement*> params = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "param" }, _scxml); + std::list<DOMElement*> params = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "param" }, _scxml); if (params.size() > 0) { _hasElement.insert("param"); DOMNode* parent = NULL; @@ -1644,7 +1644,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl; } - std::list<DOMElement*> sends = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "send" }, _scxml); + std::list<DOMElement*> sends = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "send" }, _scxml); if (sends.size() > 0) { _hasElement.insert("send"); stream << "static const uscxml_elem_send " << _prefix << "_elem_sends[" << sends.size() << "] = {" << std::endl; @@ -1708,7 +1708,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl; } - std::list<DOMElement*> donedatas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "donedata" }, _scxml); + std::list<DOMElement*> donedatas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "donedata" }, _scxml); stream << "static const uscxml_elem_donedata " << _prefix << "_elem_donedatas[" << donedatas.size() + 1 << "] = {" << std::endl; stream << " /* source, content, contentexpr, params */" << std::endl; size_t i = 0; @@ -1970,7 +1970,7 @@ void ChartToC::writeTransitions(std::ostream& stream) { stream << std::endl; // cross reference transition by document order - is this really needed?! - std::list<DOMElement*> transDocOrder = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); + std::list<DOMElement*> transDocOrder = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); if (_transitions.size() > 0) { stream << "static const uscxml_transition " << _prefix << "_transitions[" << toStr(_transitions.size()) << "] = {" << std::endl; diff --git a/src/uscxml/transform/ChartToC.h b/src/uscxml/transform/ChartToC.h index a34a2e0..43ffc45 100644 --- a/src/uscxml/transform/ChartToC.h +++ b/src/uscxml/transform/ChartToC.h @@ -58,9 +58,9 @@ protected: void writeFSM(std::ostream& stream); void writeCharArrayInitList(std::ostream& stream, const std::string& boolString); - void writeExecContent(std::ostream& stream, const xercesc::DOMNode* node, int indent = 0); + void writeExecContent(std::ostream& stream, const XERCESC_NS::DOMNode* node, int indent = 0); - void resortStates(xercesc::DOMNode* node); + void resortStates(XERCESC_NS::DOMNode* node); void setHistoryCompletion(); void setStateCompletion(); void prepare(); @@ -69,8 +69,8 @@ protected: Interpreter interpreter; - std::vector<xercesc::DOMElement*> _states; - std::vector<xercesc::DOMElement*> _transitions; + std::vector<XERCESC_NS::DOMElement*> _states; + std::vector<XERCESC_NS::DOMElement*> _transitions; std::string _md5; std::string _prefix; diff --git a/src/uscxml/transform/ChartToVHDL.h b/src/uscxml/transform/ChartToVHDL.h index 3d8b00d..89af6fd 100644 --- a/src/uscxml/transform/ChartToVHDL.h +++ b/src/uscxml/transform/ChartToVHDL.h @@ -191,15 +191,15 @@ protected: // event generation void writeExContentBlock(std::ostream & stream, std::string index, - std::list<xercesc::DOMElement*> commandSequence); + std::list<XERCESC_NS::DOMElement*> commandSequence); Trie _eventTrie; - std::list<xercesc::DOMElement*> _execContent; + std::list<XERCESC_NS::DOMElement*> _execContent; private: std::string eventNameEscape(const std::string& eventName); - std::string getLineForExecContent(const xercesc::DOMElement* elem); + std::string getLineForExecContent(const XERCESC_NS::DOMElement* elem); }; diff --git a/src/uscxml/transform/Transformer.h b/src/uscxml/transform/Transformer.h index a490533..fcfda01 100644 --- a/src/uscxml/transform/Transformer.h +++ b/src/uscxml/transform/Transformer.h @@ -23,6 +23,7 @@ #include <iostream> #include <map> #include "uscxml/Interpreter.h" +#include "uscxml/interpreter/InterpreterImpl.h" namespace uscxml { @@ -47,8 +48,8 @@ protected: std::multimap<std::string, std::string> _extensions; std::list<std::string> _options; - xercesc::DOMDocument* _document; - xercesc::DOMElement* _scxml; + XERCESC_NS::DOMDocument* _document; + XERCESC_NS::DOMElement* _scxml; Interpreter interpreter; InterpreterImpl::Binding _binding; @@ -63,7 +64,7 @@ public: // Transformer(const Interpreter& source) { _impl = new (source) } Transformer() : _impl() {} // the empty, invalid interpreter - Transformer(boost::shared_ptr<TransformerImpl> const impl) : _impl(impl) { } + Transformer(std::shared_ptr<TransformerImpl> const impl) : _impl(impl) { } Transformer(const Transformer& other) : _impl(other._impl) { } virtual ~Transformer() {}; @@ -91,7 +92,7 @@ public: return _impl->operator Interpreter(); } - boost::shared_ptr<TransformerImpl> getImpl() { + std::shared_ptr<TransformerImpl> getImpl() { return _impl; } @@ -104,7 +105,7 @@ public: } protected: - boost::shared_ptr<TransformerImpl> _impl; + std::shared_ptr<TransformerImpl> _impl; }; diff --git a/src/uscxml/uscxml.h b/src/uscxml/uscxml.h new file mode 100644 index 0000000..fb5b512 --- /dev/null +++ b/src/uscxml/uscxml.h @@ -0,0 +1,24 @@ +/** + * @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 + * + * @mainpage + */ + +#include "uscxml/Common.h" +#include "uscxml/Interpreter.h" + diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index b68901c..0e1e9fa 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -36,7 +36,7 @@ namespace uscxml { -using namespace xercesc; +using namespace XERCESC_NS; std::ostream& operator<< (std::ostream& os, const DOMNode& node) { @@ -233,8 +233,8 @@ void DOMUtils::inPostFixOrder(const std::set<std::string>& elements, const bool includeEmbeddedDoc, std::list<DOMElement*>& nodes) { - if (root == NULL) - return; + if (root == NULL) + return; DOMNodeList* children = root->getChildNodes(); for (size_t i = 0; i < children->getLength(); i++) { @@ -260,8 +260,8 @@ void DOMUtils::inPostFixOrder(const std::set<std::string>& elements, } std::list<DOMElement*> DOMUtils::inDocumentOrder(const std::set<std::string>& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { + const DOMElement* root, + const bool includeEmbeddedDoc) { std::list<DOMElement*> nodes; inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); return nodes; @@ -271,10 +271,10 @@ void DOMUtils::inDocumentOrder(const std::set<std::string>& elements, const DOMElement* root, const bool includeEmbeddedDoc, std::list<DOMElement*>& nodes) { - if (root == NULL) - return; - - if (elements.find(TAGNAME(root)) != elements.end()) { + if (root == NULL) + return; + + if (elements.find(TAGNAME(root)) != elements.end()) { nodes.push_back((DOMElement*)root); } diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 1f2ced2..0e8621c 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -24,6 +24,7 @@ #include <list> #include <iostream> +#include "uscxml/config.h" #include "uscxml/Common.h" #include <xercesc/util/XMLString.hpp> #include <xercesc/dom/DOM.hpp> @@ -58,57 +59,57 @@ namespace uscxml { class USCXML_API DOMUtils { public: - static const xercesc::DOMNode* getNearestAncestor(const xercesc::DOMNode* node, const std::string tagName); - static bool isDescendant(const xercesc::DOMNode* s1, const xercesc::DOMNode* s2); + static const XERCESC_NS::DOMNode* getNearestAncestor(const XERCESC_NS::DOMNode* node, const std::string tagName); + static bool isDescendant(const XERCESC_NS::DOMNode* s1, const XERCESC_NS::DOMNode* s2); - static bool hasIntersection(const std::list<xercesc::DOMElement*>& l1, - const std::list<xercesc::DOMElement*>& l2); - static bool isMember(const xercesc::DOMElement* node, const std::list<xercesc::DOMElement*>& list); - static bool isMember(const xercesc::DOMNode* node, const std::list<xercesc::DOMNode*>& list); - static bool isMember(const xercesc::DOMNode* node, const xercesc::DOMNodeList* list); + static bool hasIntersection(const std::list<XERCESC_NS::DOMElement*>& l1, + const std::list<XERCESC_NS::DOMElement*>& l2); + static bool isMember(const XERCESC_NS::DOMElement* node, const std::list<XERCESC_NS::DOMElement*>& list); + static bool isMember(const XERCESC_NS::DOMNode* node, const std::list<XERCESC_NS::DOMNode*>& list); + static bool isMember(const XERCESC_NS::DOMNode* node, const XERCESC_NS::DOMNodeList* list); - static std::string xPathForNode(const xercesc::DOMNode* node, + static std::string xPathForNode(const XERCESC_NS::DOMNode* node, const std::string& ns = ""); - static std::string idForNode(const xercesc::DOMNode* node); + static std::string idForNode(const XERCESC_NS::DOMNode* node); - static std::list<xercesc::DOMNode*> getElementsByType(const xercesc::DOMNode* root, - xercesc::DOMNode::NodeType type); + static std::list<XERCESC_NS::DOMNode*> getElementsByType(const XERCESC_NS::DOMNode* root, + XERCESC_NS::DOMNode::NodeType type); - static std::list<xercesc::DOMElement*> inPostFixOrder(const std::set<std::string>& elements, - const xercesc::DOMElement* root, + static std::list<XERCESC_NS::DOMElement*> inPostFixOrder(const std::set<std::string>& elements, + const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc = false); - static std::list<xercesc::DOMElement*> inDocumentOrder(const std::set<std::string>& elements, - const xercesc::DOMElement* root, + static std::list<XERCESC_NS::DOMElement*> inDocumentOrder(const std::set<std::string>& elements, + const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc = false); - static std::list<xercesc::DOMElement*> filterChildElements(const std::string& tagName, - const xercesc::DOMElement* node, + static std::list<XERCESC_NS::DOMElement*> filterChildElements(const std::string& tagName, + const XERCESC_NS::DOMElement* node, bool recurse = false); - static std::list<xercesc::DOMElement*> filterChildElements(const std::string& tagName, - const std::list<xercesc::DOMElement*>& nodeSet, + static std::list<XERCESC_NS::DOMElement*> filterChildElements(const std::string& tagName, + const std::list<XERCESC_NS::DOMElement*>& nodeSet, bool recurse = false); - static std::list<xercesc::DOMNode*> filterChildType(const xercesc::DOMNode::NodeType type, - const xercesc::DOMNode* node, + static std::list<XERCESC_NS::DOMNode*> filterChildType(const XERCESC_NS::DOMNode::NodeType type, + const XERCESC_NS::DOMNode* node, bool recurse = false); - static std::list<xercesc::DOMNode*> filterChildType(const xercesc::DOMNode::NodeType type, - const std::list<xercesc::DOMNode*>& nodeSet, + static std::list<XERCESC_NS::DOMNode*> filterChildType(const XERCESC_NS::DOMNode::NodeType type, + const std::list<XERCESC_NS::DOMNode*>& nodeSet, bool recurse = false); protected: static void inPostFixOrder(const std::set<std::string>& elements, - const xercesc::DOMElement* root, + const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc, - std::list<xercesc::DOMElement*>& nodes); + std::list<XERCESC_NS::DOMElement*>& nodes); static void inDocumentOrder(const std::set<std::string>& elements, - const xercesc::DOMElement* root, + const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc, - std::list<xercesc::DOMElement*>& nodes); + std::list<XERCESC_NS::DOMElement*>& nodes); }; @@ -121,21 +122,21 @@ public : X(X const &other) { _localForm = other._localForm; - _otherForm = xercesc::XMLString::replicate(other._otherForm); + _otherForm = XERCESC_NS::XMLString::replicate(other._otherForm); _deallocOther = true; } void operator=(X const &other) { // did we maybe leak before? _localForm = other._localForm; - _otherForm = xercesc::XMLString::replicate(other._otherForm); + _otherForm = XERCESC_NS::XMLString::replicate(other._otherForm); _deallocOther = true; } X(const XMLCh* const toTranscode) { if (toTranscode != NULL) { // Call the private transcoding method - char* tmp = xercesc::XMLString::transcode(toTranscode); + char* tmp = XERCESC_NS::XMLString::transcode(toTranscode); _localForm = std::string(tmp); - xercesc::XMLString::release(&tmp); + XERCESC_NS::XMLString::release(&tmp); } _otherForm = NULL; _deallocOther = false; @@ -144,21 +145,21 @@ public : X(const std::string& fromTranscode) { // Call the private transcoding method _localForm = fromTranscode; - _otherForm = xercesc::XMLString::transcode(fromTranscode.c_str()); + _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str()); _deallocOther = true; } X(const char* const fromTranscode) { // Call the private transcoding method _localForm = fromTranscode; - _otherForm = xercesc::XMLString::transcode(fromTranscode); + _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode); _deallocOther = true; } X(char* fromTranscode) { // Call the private transcoding method _localForm = fromTranscode; - _otherForm = xercesc::XMLString::transcode(fromTranscode); + _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode); _deallocOther = true; } @@ -169,7 +170,7 @@ public : ~X() { if (_deallocOther) - xercesc::XMLString::release(&_otherForm); + XERCESC_NS::XMLString::release(&_otherForm); } const std::string& str() const { @@ -199,7 +200,7 @@ private: }; USCXML_API std::ostream& operator<< (std::ostream& os, const X& xmlString); -USCXML_API std::ostream& operator<< (std::ostream& os, const xercesc::DOMNode& node); +USCXML_API std::ostream& operator<< (std::ostream& os, const XERCESC_NS::DOMNode& node); } diff --git a/src/uscxml/util/Predicates.cpp b/src/uscxml/util/Predicates.cpp index 6ac092f..2f46d75 100644 --- a/src/uscxml/util/Predicates.cpp +++ b/src/uscxml/util/Predicates.cpp @@ -22,7 +22,7 @@ namespace uscxml { -using namespace xercesc; +using namespace XERCESC_NS; std::list<DOMElement*> getChildStates(const DOMElement* state, bool properOnly) { std::list<DOMElement*> children; @@ -39,8 +39,8 @@ std::list<DOMElement*> getChildStates(const DOMElement* state, bool properOnly) return children; } -std::list<xercesc::DOMElement*> getChildStates(const std::list<xercesc::DOMElement*>& states, bool properOnly) { - std::list<xercesc::DOMElement*> children; +std::list<XERCESC_NS::DOMElement*> getChildStates(const std::list<XERCESC_NS::DOMElement*>& states, bool properOnly) { + std::list<XERCESC_NS::DOMElement*> children; for (auto stateIter = states.begin(); stateIter != states.end(); stateIter++) { std::list<DOMElement*> tmp = getChildStates(*stateIter, properOnly); children.merge(tmp); diff --git a/src/uscxml/util/Predicates.h b/src/uscxml/util/Predicates.h index 50c69b6..7bc4a9c 100644 --- a/src/uscxml/util/Predicates.h +++ b/src/uscxml/util/Predicates.h @@ -28,32 +28,32 @@ namespace uscxml { -std::list<xercesc::DOMElement*> getChildStates(const xercesc::DOMElement* state, bool properOnly = true); -std::list<xercesc::DOMElement*> getChildStates(const std::list<xercesc::DOMElement*>& states, bool properOnly = true); -xercesc::DOMElement* getParentState(const xercesc::DOMElement* element); -xercesc::DOMElement* getSourceState(const xercesc::DOMElement* transition); -xercesc::DOMElement* findLCCA(const std::list<xercesc::DOMElement*>& states); -std::list<xercesc::DOMElement*> getProperAncestors(const xercesc::DOMElement* s1, const xercesc::DOMElement* s2); - -std::list<xercesc::DOMElement*> getTargetStates(const xercesc::DOMElement* transition, const xercesc::DOMElement* root); -std::list<xercesc::DOMElement*> getEffectiveTargetStates(const xercesc::DOMElement* transition); -xercesc::DOMElement* getTransitionDomain(const xercesc::DOMElement* transition, const xercesc::DOMElement* root); - -bool isInEmbeddedDocument(const xercesc::DOMNode* node); - -std::list<xercesc::DOMElement*> getStates(const std::list<std::string>& stateIds, const xercesc::DOMElement* root); -xercesc::DOMElement* getState(const std::string& stateId, const xercesc::DOMElement* root); -std::list<xercesc::DOMElement*> getInitialStates(const xercesc::DOMElement* state, const xercesc::DOMElement* root); -std::list<xercesc::DOMElement*> getReachableStates(const xercesc::DOMElement* root); -std::list<xercesc::DOMElement*> getExitSet(const xercesc::DOMElement* transition, const xercesc::DOMElement* root); -bool conflicts(const xercesc::DOMElement* transition1, const xercesc::DOMElement* transition2, const xercesc::DOMElement* root); - -bool isState(const xercesc::DOMElement* state, bool properOnly = true); -bool isCompound(const xercesc::DOMElement* state); -bool isAtomic(const xercesc::DOMElement* state); -bool isParallel(const xercesc::DOMElement* state); -bool isFinal(const xercesc::DOMElement* state); -bool isHistory(const xercesc::DOMElement* state); +std::list<XERCESC_NS::DOMElement*> getChildStates(const XERCESC_NS::DOMElement* state, bool properOnly = true); +std::list<XERCESC_NS::DOMElement*> getChildStates(const std::list<XERCESC_NS::DOMElement*>& states, bool properOnly = true); +XERCESC_NS::DOMElement* getParentState(const XERCESC_NS::DOMElement* element); +XERCESC_NS::DOMElement* getSourceState(const XERCESC_NS::DOMElement* transition); +XERCESC_NS::DOMElement* findLCCA(const std::list<XERCESC_NS::DOMElement*>& states); +std::list<XERCESC_NS::DOMElement*> getProperAncestors(const XERCESC_NS::DOMElement* s1, const XERCESC_NS::DOMElement* s2); + +std::list<XERCESC_NS::DOMElement*> getTargetStates(const XERCESC_NS::DOMElement* transition, const XERCESC_NS::DOMElement* root); +std::list<XERCESC_NS::DOMElement*> getEffectiveTargetStates(const XERCESC_NS::DOMElement* transition); +XERCESC_NS::DOMElement* getTransitionDomain(const XERCESC_NS::DOMElement* transition, const XERCESC_NS::DOMElement* root); + +bool isInEmbeddedDocument(const XERCESC_NS::DOMNode* node); + +std::list<XERCESC_NS::DOMElement*> getStates(const std::list<std::string>& stateIds, const XERCESC_NS::DOMElement* root); +XERCESC_NS::DOMElement* getState(const std::string& stateId, const XERCESC_NS::DOMElement* root); +std::list<XERCESC_NS::DOMElement*> getInitialStates(const XERCESC_NS::DOMElement* state, const XERCESC_NS::DOMElement* root); +std::list<XERCESC_NS::DOMElement*> getReachableStates(const XERCESC_NS::DOMElement* root); +std::list<XERCESC_NS::DOMElement*> getExitSet(const XERCESC_NS::DOMElement* transition, const XERCESC_NS::DOMElement* root); +bool conflicts(const XERCESC_NS::DOMElement* transition1, const XERCESC_NS::DOMElement* transition2, const XERCESC_NS::DOMElement* root); + +bool isState(const XERCESC_NS::DOMElement* state, bool properOnly = true); +bool isCompound(const XERCESC_NS::DOMElement* state); +bool isAtomic(const XERCESC_NS::DOMElement* state); +bool isParallel(const XERCESC_NS::DOMElement* state); +bool isFinal(const XERCESC_NS::DOMElement* state); +bool isHistory(const XERCESC_NS::DOMElement* state); } diff --git a/src/uscxml/util/URL.cpp b/src/uscxml/util/URL.cpp index a576f8b..cb3abe3 100644 --- a/src/uscxml/util/URL.cpp +++ b/src/uscxml/util/URL.cpp @@ -140,7 +140,7 @@ URL URLImpl::resolveWithCWD(URLImpl* relative) { } currPath[sizeof(currPath) - 1] = '\0'; /* not really required? */ - // without the trailing slash, last component is assumed a file + // without the trailing slash, last component is assumed a file std::shared_ptr<URLImpl> cwdURL(new URLImpl(std::string("file://") + currPath + PATH_SEPERATOR)); return resolve(relative, cwdURL.get()); diff --git a/src/uscxml/util/URL.h b/src/uscxml/util/URL.h index f545fe8..dba8e3d 100644 --- a/src/uscxml/util/URL.h +++ b/src/uscxml/util/URL.h @@ -190,7 +190,8 @@ protected: class USCXML_API URL { public: - PIMPL_OPERATORS(URL) + PIMPL_OPERATORS(URL); + URL(const std::string url) : _impl(new URLImpl(url)) {} bool isAbsolute() { diff --git a/src/uscxml/util/UUID.cpp b/src/uscxml/util/UUID.cpp index 34e3e75..6f7cf96 100644 --- a/src/uscxml/util/UUID.cpp +++ b/src/uscxml/util/UUID.cpp @@ -17,12 +17,16 @@ * @endcond */ -#include "UUID.h" #include <sstream> #include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/random_generator.hpp> + +#include "UUID.h" namespace uscxml { -boost::uuids::random_generator UUID::uuidGen; + +// hide from public header +boost::uuids::random_generator uuidGen; std::string UUID::getUUID() { boost::uuids::uuid uuid = uuidGen(); diff --git a/src/uscxml/util/UUID.h b/src/uscxml/util/UUID.h index 873d963..bc362c0 100644 --- a/src/uscxml/util/UUID.h +++ b/src/uscxml/util/UUID.h @@ -21,7 +21,6 @@ #define UUID_H_8X65R2EI #include "uscxml/Common.h" -#include <boost/uuid/uuid_generators.hpp> #include <string> namespace uscxml { @@ -30,7 +29,6 @@ class USCXML_API UUID { public: static std::string getUUID(); static bool isUUID(const std::string& uuid); - static boost::uuids::random_generator uuidGen; }; } |