diff options
Diffstat (limited to 'src/uscxml/interpreter')
-rw-r--r-- | src/uscxml/interpreter/BasicEventQueue.cpp | 15 | ||||
-rw-r--r-- | src/uscxml/interpreter/BasicEventQueue.h | 6 | ||||
-rw-r--r-- | src/uscxml/interpreter/ContentExecutor.h | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/EventQueue.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/interpreter/EventQueue.h | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/EventQueueImpl.h | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/FastMicroStep.cpp | 24 | ||||
-rw-r--r-- | src/uscxml/interpreter/FastMicroStep.h | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterImpl.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterImpl.h | 6 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterMonitor.h | 6 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterState.h | 3 | ||||
-rw-r--r-- | src/uscxml/interpreter/MicroStep.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/interpreter/MicroStep.h | 4 | ||||
-rw-r--r-- | src/uscxml/interpreter/MicroStepImpl.h | 4 |
15 files changed, 50 insertions, 38 deletions
diff --git a/src/uscxml/interpreter/BasicEventQueue.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp index 5d3fa2d..ee2346d 100644 --- a/src/uscxml/interpreter/BasicEventQueue.cpp +++ b/src/uscxml/interpreter/BasicEventQueue.cpp @@ -31,13 +31,20 @@ BasicEventQueue::BasicEventQueue() { BasicEventQueue::~BasicEventQueue() { } -Event BasicEventQueue::dequeue(bool blocking) { +Event BasicEventQueue::dequeue(size_t blockMs) { std::lock_guard<std::recursive_mutex> lock(_mutex); - if (blocking) { - while (_queue.empty()) { - _cond.wait(_mutex); + + if (blockMs > 0) { + // block for given milliseconds or until queue is filled + std::chrono::time_point<std::chrono::system_clock> end, now; + now = std::chrono::system_clock::now(); + end = now + std::chrono::milliseconds(blockMs); + + while (std::chrono::system_clock::now() < end && _queue.empty()) { + _cond.wait_for(_mutex, std::chrono::system_clock::now() - end); } } + if (_queue.size() > 0) { Event event = _queue.front(); _queue.pop_front(); diff --git a/src/uscxml/interpreter/BasicEventQueue.h b/src/uscxml/interpreter/BasicEventQueue.h index cfb2b5d..15a1c3c 100644 --- a/src/uscxml/interpreter/BasicEventQueue.h +++ b/src/uscxml/interpreter/BasicEventQueue.h @@ -42,7 +42,7 @@ class USCXML_API BasicEventQueue : public EventQueueImpl { public: BasicEventQueue(); virtual ~BasicEventQueue(); - virtual Event dequeue(bool blocking); + virtual Event dequeue(size_t blockMs); virtual void enqueue(const Event& event); protected: @@ -62,8 +62,8 @@ public: 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 Event dequeue(size_t blockMs) { + return BasicEventQueue::dequeue(blockMs); } virtual void enqueue(const Event& event) { return BasicEventQueue::enqueue(event); diff --git a/src/uscxml/interpreter/ContentExecutor.h b/src/uscxml/interpreter/ContentExecutor.h index 64f5a95..be0de78 100644 --- a/src/uscxml/interpreter/ContentExecutor.h +++ b/src/uscxml/interpreter/ContentExecutor.h @@ -28,7 +28,7 @@ // forward declare namespace XERCESC_NS { - class DOMElement; +class DOMElement; } namespace uscxml { diff --git a/src/uscxml/interpreter/EventQueue.cpp b/src/uscxml/interpreter/EventQueue.cpp index 9b9fa88..c460e02 100644 --- a/src/uscxml/interpreter/EventQueue.cpp +++ b/src/uscxml/interpreter/EventQueue.cpp @@ -32,8 +32,8 @@ namespace uscxml { -Event EventQueue::dequeue(bool blocking) { - return _impl->dequeue(blocking); +Event EventQueue::dequeue(size_t blockMs) { + return _impl->dequeue(blockMs); } void EventQueue::enqueue(const Event& event) { return _impl->enqueue(event); diff --git a/src/uscxml/interpreter/EventQueue.h b/src/uscxml/interpreter/EventQueue.h index 4409b72..1e8b018 100644 --- a/src/uscxml/interpreter/EventQueue.h +++ b/src/uscxml/interpreter/EventQueue.h @@ -36,7 +36,7 @@ class USCXML_API EventQueue { public: PIMPL_OPERATORS(EventQueue); - virtual Event dequeue(bool blocking); + virtual Event dequeue(size_t blockMs); virtual void enqueue(const Event& event); protected: diff --git a/src/uscxml/interpreter/EventQueueImpl.h b/src/uscxml/interpreter/EventQueueImpl.h index 1cafd4d..1ccd3f1 100644 --- a/src/uscxml/interpreter/EventQueueImpl.h +++ b/src/uscxml/interpreter/EventQueueImpl.h @@ -40,7 +40,7 @@ namespace uscxml { */ class USCXML_API EventQueueImpl { public: - virtual Event dequeue(bool blocking) = 0; + virtual Event dequeue(size_t blockMs) = 0; virtual void enqueue(const Event& event) = 0; }; diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index bf58f7b..3ad5515 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -290,23 +290,23 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { if (parent && parent->getNodeType() == DOMNode::ELEMENT_NODE) { State* uscxmlState = (State*)parent->getUserData(X("uscxmlState")); // parent maybe a content element - if (uscxmlState != NULL) { - _states[i]->parent = uscxmlState->documentOrder; - } + if (uscxmlState != NULL) { + _states[i]->parent = uscxmlState->documentOrder; + } } while(parent && parent->getNodeType() == DOMNode::ELEMENT_NODE) { State* uscxmlState = (State*)parent->getUserData(X("uscxmlState")); - if (uscxmlState == NULL) - break; + if (uscxmlState == NULL) + break; - // ancestors - BIT_SET_AT(uscxmlState->documentOrder, _states[i]->ancestors); + // ancestors + BIT_SET_AT(uscxmlState->documentOrder, _states[i]->ancestors); - // children - BIT_SET_AT(i, uscxmlState->children); - parent = parent->getParentNode(); + // children + BIT_SET_AT(i, uscxmlState->children); + parent = parent->getParentNode(); } } @@ -403,7 +403,7 @@ void FastMicroStep::markAsCancelled() { _isCancelled = true; } -InterpreterState FastMicroStep::step(bool blocking) { +InterpreterState FastMicroStep::step(size_t blockMs) { if (!_isInitialized) { init(_scxml); return USCXML_INITIALIZED; @@ -517,7 +517,7 @@ InterpreterState FastMicroStep::step(bool blocking) { _flags |= USCXML_CTX_STABLE; } - if ((_event = _callbacks->dequeueExternal(blocking))) { + if ((_event = _callbacks->dequeueExternal(blockMs))) { USCXML_MONITOR_CALLBACK1(_callbacks->getMonitor(), beforeProcessingEvent, _event); goto SELECT_TRANSITIONS; } diff --git a/src/uscxml/interpreter/FastMicroStep.h b/src/uscxml/interpreter/FastMicroStep.h index 3789af9..023bb8f 100644 --- a/src/uscxml/interpreter/FastMicroStep.h +++ b/src/uscxml/interpreter/FastMicroStep.h @@ -42,7 +42,7 @@ public: FastMicroStep(MicroStepCallbacks* callbacks); virtual ~FastMicroStep(); - virtual InterpreterState step(bool blocking); + virtual InterpreterState step(size_t blockMs); virtual void reset(); virtual bool isInState(const std::string& stateId); virtual std::list<XERCESC_NS::DOMElement*> getConfiguration(); diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 880afbc..3383411 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -259,8 +259,8 @@ bool InterpreterImpl::checkValidSendType(const std::string& type, const std::str return true; } -Event InterpreterImpl::dequeueExternal(bool blocking) { - _currEvent = _externalQueue.dequeue(blocking); +Event InterpreterImpl::dequeueExternal(size_t blockMs) { + _currEvent = _externalQueue.dequeue(blockMs); if (_currEvent) { _dataModel.setEvent(_currEvent); diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index e1abf9b..e693bbf 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -65,12 +65,12 @@ public: void cloneFrom(InterpreterImpl* other); void cloneFrom(std::shared_ptr<InterpreterImpl> other); - virtual InterpreterState step(bool blocking) { + virtual InterpreterState step(size_t blockMs) { if (!_isInitialized) { init(); _state = USCXML_INITIALIZED; } else { - _state = _microStepper.step(blocking); + _state = _microStepper.step(blockMs); } return _state; } @@ -107,7 +107,7 @@ public: _dataModel.setEvent(_currEvent); return _currEvent; } - virtual Event dequeueExternal(bool blocking); + virtual Event dequeueExternal(size_t blockMs); virtual bool isTrue(const std::string& expr); virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) { diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index 901e1eb..8dac445 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -20,6 +20,7 @@ #ifndef INTERPRETERMONITOR_H_D3F21429 #define INTERPRETERMONITOR_H_D3F21429 +#include "uscxml/config.h" #include "uscxml/Common.h" #include "uscxml/messages/Event.h" #include "uscxml/debug/InterpreterIssue.h" @@ -41,6 +42,11 @@ if (callback) { callback->function(arg1); } #define USCXML_MONITOR_CALLBACK2(callback, function, arg1, arg2) \ if (callback) { callback->function(arg1, arg2); } +// forward declare +namespace XERCESC_NS { + class DOMElement; +} + namespace uscxml { class USCXML_API InterpreterMonitor { diff --git a/src/uscxml/interpreter/InterpreterState.h b/src/uscxml/interpreter/InterpreterState.h index a4741ed..5acbd74 100644 --- a/src/uscxml/interpreter/InterpreterState.h +++ b/src/uscxml/interpreter/InterpreterState.h @@ -27,8 +27,7 @@ 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_FINISHED = -1, ///< machine reached a final configuration and is done 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 diff --git a/src/uscxml/interpreter/MicroStep.cpp b/src/uscxml/interpreter/MicroStep.cpp index aa75c91..2876be5 100644 --- a/src/uscxml/interpreter/MicroStep.cpp +++ b/src/uscxml/interpreter/MicroStep.cpp @@ -22,8 +22,8 @@ namespace uscxml { -InterpreterState MicroStep::step(bool blocking) { - return _impl->step(blocking); +InterpreterState MicroStep::step(size_t blockMs) { + return _impl->step(blockMs); } void MicroStep::reset() { return _impl->reset(); diff --git a/src/uscxml/interpreter/MicroStep.h b/src/uscxml/interpreter/MicroStep.h index c20e994..a8ea4f0 100644 --- a/src/uscxml/interpreter/MicroStep.h +++ b/src/uscxml/interpreter/MicroStep.h @@ -33,7 +33,7 @@ // forward declare namespace XERCESC_NS { - class DOMElement; +class DOMElement; } namespace uscxml { @@ -48,7 +48,7 @@ class USCXML_API MicroStep { public: PIMPL_OPERATORS(MicroStep); - virtual InterpreterState step(bool blocking); + virtual InterpreterState step(size_t blockMs); virtual void reset(); virtual bool isInState(const std::string& stateId); diff --git a/src/uscxml/interpreter/MicroStepImpl.h b/src/uscxml/interpreter/MicroStepImpl.h index e4cde5d..be9d974 100644 --- a/src/uscxml/interpreter/MicroStepImpl.h +++ b/src/uscxml/interpreter/MicroStepImpl.h @@ -41,7 +41,7 @@ class USCXML_API MicroStepCallbacks { public: /** Event Queues / Matching */ virtual Event dequeueInternal() = 0; - virtual Event dequeueExternal(bool blocking) = 0; + virtual Event dequeueExternal(size_t blockMs) = 0; virtual bool isMatched(const Event& event, const std::string& eventDesc) = 0; virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) = 0; @@ -73,7 +73,7 @@ public: MicroStepImpl(MicroStepCallbacks* callbacks) : _callbacks(callbacks) {} - virtual InterpreterState step(bool blocking) = 0; + virtual InterpreterState step(size_t blockMs) = 0; virtual void reset() = 0; ///< Reset state machine virtual bool isInState(const std::string& stateId) = 0; virtual std::list<XERCESC_NS::DOMElement*> getConfiguration() = 0; |