summaryrefslogtreecommitdiffstats
path: root/src/uscxml
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml')
-rw-r--r--src/uscxml/Interpreter.cpp4
-rw-r--r--src/uscxml/Interpreter.h5
-rw-r--r--src/uscxml/interpreter/InterpreterImpl.cpp13
-rw-r--r--src/uscxml/interpreter/InterpreterImpl.h6
-rw-r--r--src/uscxml/interpreter/InterpreterMonitor.h321
-rw-r--r--src/uscxml/util/Predicates.cpp1
6 files changed, 333 insertions, 17 deletions
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index c4025ba..f3aedee 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -271,6 +271,10 @@ std::list<InterpreterIssue> Interpreter::validate() {
return InterpreterIssue::forInterpreter(_impl.get());
}
+LambdaMonitor& Interpreter::on() {
+ return _impl->on();
+}
+
#if 1
static void printNodeSet(Logger& logger, const std::list<XERCESC_NS::DOMElement*> nodes) {
std::string seperator;
diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h
index 3c44400..aff77a2 100644
--- a/src/uscxml/Interpreter.h
+++ b/src/uscxml/Interpreter.h
@@ -34,6 +34,7 @@
#include "uscxml/interpreter/ContentExecutor.h"
#include "uscxml/interpreter/EventQueue.h"
#include "uscxml/interpreter/InterpreterState.h"
+#include "uscxml/interpreter/InterpreterMonitor.h"
#ifdef max
#error define NOMINMAX or undefine the max macro please (https://support.microsoft.com/en-us/kb/143208)
@@ -42,6 +43,7 @@
namespace uscxml {
class InterpreterMonitor;
+class LambdaMonitor;
class InterpreterImpl;
class InterpreterIssue;
@@ -234,6 +236,9 @@ public:
std::shared_ptr<InterpreterImpl> getImpl() const {
return _impl;
}
+
+ LambdaMonitor& on();
+
#if 0
// "Ambiguous user-defined-conversion" with operator bool() on MSVC from Visual Studio 12
explicit operator MicroStepCallbacks*() {
diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp
index 414dba2..1caa3f0 100644
--- a/src/uscxml/interpreter/InterpreterImpl.cpp
+++ b/src/uscxml/interpreter/InterpreterImpl.cpp
@@ -103,6 +103,9 @@ InterpreterImpl::~InterpreterImpl() {
if (_document)
delete _document;
+ if (_lambdaMonitor)
+ delete _lambdaMonitor;
+
{
std::lock_guard<std::recursive_mutex> lock(_instanceMutex);
_instances.erase(getSessionId());
@@ -139,7 +142,7 @@ void InterpreterImpl::reset() {
if (_microStepper)
_microStepper.reset();
- _isInitialized = false;
+// _isInitialized = false;
_state = USCXML_INSTANTIATED;
// _dataModel.reset();
if (_delayQueue)
@@ -622,4 +625,12 @@ void InterpreterImpl::enqueueAtParent(const Event& event) {
}
+LambdaMonitor& InterpreterImpl::on() {
+ if (_lambdaMonitor == NULL) {
+ _lambdaMonitor = new LambdaMonitor();
+ addMonitor(_lambdaMonitor);
+ }
+ return *_lambdaMonitor;
+}
+
}
diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h
index 42d61f2..2f5fb07 100644
--- a/src/uscxml/interpreter/InterpreterImpl.h
+++ b/src/uscxml/interpreter/InterpreterImpl.h
@@ -269,9 +269,13 @@ public:
return _document;
}
+ LambdaMonitor& on();
+
protected:
static void addInstance(std::shared_ptr<InterpreterImpl> instance);
-
+
+ LambdaMonitor* _lambdaMonitor = NULL;
+
Binding _binding;
ActionLanguage _al;
diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h
index 43b7f53..ed62675 100644
--- a/src/uscxml/interpreter/InterpreterMonitor.h
+++ b/src/uscxml/interpreter/InterpreterMonitor.h
@@ -65,26 +65,47 @@ public:
InterpreterMonitor(Logger logger) : _copyToInvokers(false), _logger(logger) {}
virtual ~InterpreterMonitor() {}
- virtual void beforeProcessingEvent(const std::string& sessionId, const Event& event) {}
+ virtual void beforeProcessingEvent(const std::string& sessionId,
+ const Event& event) {}
virtual void beforeMicroStep(const std::string& sessionId) {}
- virtual void beforeExitingState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state) {}
- virtual void afterExitingState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state) {}
+ virtual void beforeExitingState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {}
+ virtual void afterExitingState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {}
- virtual void beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent) {}
- virtual void afterExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent) {}
+ virtual void beforeExecutingContent(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent) {}
+ virtual void afterExecutingContent(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent) {}
- virtual void beforeUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
- virtual void afterUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
+ virtual void beforeUninvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {}
+ virtual void afterUninvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {}
- virtual void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {}
- virtual void afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {}
+ virtual void beforeTakingTransition(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition) {}
+ virtual void afterTakingTransition(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition) {}
- virtual void beforeEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state) {}
- virtual void afterEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state) {}
+ virtual void beforeEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {}
+ virtual void afterEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {}
- virtual void beforeInvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
- virtual void afterInvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid) {}
+ virtual void beforeInvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {}
+ virtual void afterInvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {}
virtual void afterMicroStep(const std::string& sessionId) {}
virtual void onStableConfiguration(const std::string& sessionId) {}
@@ -92,7 +113,8 @@ public:
virtual void beforeCompletion(const std::string& sessionId) {}
virtual void afterCompletion(const std::string& sessionId) {}
- virtual void reportIssue(const std::string& sessionId, const InterpreterIssue& issue) {}
+ virtual void reportIssue(const std::string& sessionId,
+ const InterpreterIssue& issue) {}
void copyToInvokers(bool copy) {
_copyToInvokers = copy;
@@ -125,6 +147,277 @@ protected:
std::string _logPrefix;
};
+class USCXML_API LambdaMonitor : public InterpreterMonitor {
+public:
+ void processEvent(std::function<void (const std::string& sessionId,
+ const Event& event)> callback) {
+ _beforeProcessingEvent = callback;
+ }
+
+
+ void microStep(std::function<void (const std::string& sessionId)> callback,
+ bool after = false) {
+ if (after) {
+ _afterMicroStep = callback;
+ } else {
+ _beforeMicroStep = callback;
+ }
+
+ }
+
+ void exitState(std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> callback,
+ bool after = false) {
+ if (after) {
+ _afterExitingState = callback;
+ } else {
+ _beforeExitingState = callback;
+ }
+ }
+
+ void executeContent(std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent)> callback,
+ bool after = false) {
+ if (after) {
+ _afterExecutingContent = callback;
+ } else {
+ _beforeExecutingContent = callback;
+ }
+ }
+
+ void uninvoke(std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> callback,
+ bool after = false) {
+ if (after) {
+ _afterUninvoking = callback;
+ } else {
+ _beforeUninvoking = callback;
+ }
+ }
+
+ void transition(std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition)> callback,
+ bool after = false) {
+ if (after) {
+ _afterTakingTransition = callback;
+ } else {
+ _beforeTakingTransition = callback;
+ }
+ }
+
+ void enterState(std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> callback,
+ bool after = false) {
+ _beforeEnteringState = callback;
+ if (after) {
+ _afterEnteringState = callback;
+ } else {
+ _beforeEnteringState = callback;
+ }
+
+ }
+
+ void invoke(std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> callback,
+ bool after = false) {
+ if (after) {
+ _afterInvoking = callback;
+ } else {
+ _beforeInvoking = callback;
+ }
+ }
+
+ void stableConfiguration(std::function<void (const std::string& sessionId)> callback) {
+ _onStableConfiguration = callback;
+ }
+
+ void completion(std::function<void (const std::string& sessionId)> callback,
+ bool after = false) {
+ if (after) {
+ _afterCompletion = callback;
+ } else {
+ _beforeCompletion = callback;
+ }
+
+ }
+
+ void reportIssue(std::function<void (const std::string& sessionId,
+ const InterpreterIssue& issue)> callback) {
+ _reportIssue = callback;
+ }
+
+protected:
+
+ std::function<void (const std::string& sessionId,
+ const Event& event)> _beforeProcessingEvent;
+
+ std::function<void (const std::string& sessionId)> _beforeMicroStep;
+
+ std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> _beforeExitingState;
+
+ std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> _afterExitingState;
+
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent)> _beforeExecutingContent;
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent)> _afterExecutingContent;
+
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> _beforeUninvoking;
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> _afterUninvoking;
+
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition)> _beforeTakingTransition;
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition)> _afterTakingTransition;
+
+ std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> _beforeEnteringState;
+ std::function<void (const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state)> _afterEnteringState;
+
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> _beforeInvoking;
+ std::function<void (const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid)> _afterInvoking;
+
+ std::function<void (const std::string& sessionId)> _afterMicroStep;
+ std::function<void (const std::string& sessionId)> _onStableConfiguration;
+
+ std::function<void (const std::string& sessionId)> _beforeCompletion;
+ std::function<void (const std::string& sessionId)> _afterCompletion;
+
+ std::function<void (const std::string& sessionId,
+ const InterpreterIssue& issue)> _reportIssue;
+
+
+
+ void beforeProcessingEvent(const std::string& sessionId,
+ const Event& event) {
+ if (_beforeProcessingEvent)
+ _beforeProcessingEvent(sessionId, event);
+ }
+ void beforeMicroStep(const std::string& sessionId) {
+ if (_beforeMicroStep)
+ _beforeMicroStep(sessionId);
+ }
+
+ void beforeExitingState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
+ if (_beforeExitingState)
+ _beforeExitingState(sessionId, stateName, state);
+ }
+
+ void afterExitingState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
+ if (_afterExitingState)
+ _afterExitingState(sessionId, stateName, state);
+ }
+
+ void beforeExecutingContent(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent) {
+ if (_beforeExecutingContent)
+ _beforeExecutingContent(sessionId, execContent);
+ }
+ void afterExecutingContent(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* execContent) {
+ if (_afterExecutingContent)
+ _afterExecutingContent(sessionId, execContent);
+
+ }
+
+ void beforeUninvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {
+ if (_beforeUninvoking)
+ _beforeUninvoking(sessionId, invokeElem, invokeid);
+ }
+ void afterUninvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {
+ if (_afterUninvoking)
+ _afterUninvoking(sessionId, invokeElem, invokeid);
+ }
+
+ void beforeTakingTransition(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition) {
+ if (_beforeTakingTransition)
+ _beforeTakingTransition(sessionId, transition);
+ }
+ void afterTakingTransition(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* transition) {
+ if (_afterTakingTransition)
+ _afterTakingTransition(sessionId, transition);
+ }
+
+ void beforeEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
+ if (_beforeEnteringState)
+ _beforeEnteringState(sessionId, stateName, state);
+ }
+ void afterEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
+ if (_afterEnteringState)
+ _afterEnteringState(sessionId, stateName, state);
+ }
+
+ void beforeInvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {
+ if (_beforeInvoking)
+ _beforeInvoking(sessionId, invokeElem, invokeid);
+ }
+ void afterInvoking(const std::string& sessionId,
+ const XERCESC_NS::DOMElement* invokeElem,
+ const std::string& invokeid) {
+ if (_afterInvoking)
+ _afterInvoking(sessionId, invokeElem, invokeid);
+ }
+
+ void afterMicroStep(const std::string& sessionId) {
+ if (_afterMicroStep)
+ _afterMicroStep(sessionId);
+ }
+ void onStableConfiguration(const std::string& sessionId) {
+ if (_onStableConfiguration)
+ _onStableConfiguration(sessionId);
+ }
+
+ void beforeCompletion(const std::string& sessionId) {
+ if (_beforeCompletion)
+ _beforeCompletion(sessionId);
+ }
+ void afterCompletion(const std::string& sessionId) {
+ if (_afterCompletion)
+ _afterCompletion(sessionId);
+ }
+
+ void reportIssue(const std::string& sessionId,
+ const InterpreterIssue& issue) {
+ if (_reportIssue)
+ _reportIssue(sessionId, issue);
+ }
+};
+
}
#endif /* end of include guard: INTERPRETERMONITOR_H_D3F21429 */
diff --git a/src/uscxml/util/Predicates.cpp b/src/uscxml/util/Predicates.cpp
index 6649907..1f95a52 100644
--- a/src/uscxml/util/Predicates.cpp
+++ b/src/uscxml/util/Predicates.cpp
@@ -328,7 +328,6 @@ DOMElement* getState(const std::string& stateId, const DOMElement* root) {
}
// no state with such an id in document!
- assert(false);
return NULL;
}