diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
commit | e3767be4f9c5874d9c996200f2e9705ce31a5976 (patch) | |
tree | be3d06f550286e23eeb3252277c1a2b7d12554ef /src/uscxml | |
parent | 758bda908ded461c9d34d274a18454ffba4b7450 (diff) | |
download | uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.zip uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.gz uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.bz2 |
Work on bindings
- Introduced exceptions into C# and Java
- Moved binding examples to /embedding
- Interpreter will now throw exceptions, beware!
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/Interpreter.cpp | 25 | ||||
-rw-r--r-- | src/uscxml/Interpreter.h | 12 | ||||
-rw-r--r-- | src/uscxml/URL.h | 4 | ||||
-rw-r--r-- | src/uscxml/concurrency/tinythread.cpp | 21 | ||||
-rw-r--r-- | src/uscxml/concurrency/tinythread.h | 4 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.cpp | 2 |
6 files changed, 48 insertions, 20 deletions
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 4ffa92c..9770387 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -82,7 +82,8 @@ #define VALID_FROM_IDLE(newState) ( \ newState == InterpreterState::USCXML_DESTROYED || \ - newState == InterpreterState::USCXML_MICROSTEPPED \ + newState == InterpreterState::USCXML_MICROSTEPPED || \ + newState == InterpreterState::USCXML_MACROSTEPPED \ ) #define VALID_FROM_FINISHED(newState) ( \ @@ -90,6 +91,12 @@ newState == InterpreterState::USCXML_INSTANTIATED \ ) +#define THROW_ERROR_PLATFORM(msg) \ + Event e; \ + e.name = "error.platform"; \ + e.data.compound["cause"] = Data(msg, Data::VERBATIM); \ + throw e; \ + /// macro to catch exceptions in executeContent #define CATCH_AND_DISTRIBUTE(msg) \ @@ -378,8 +385,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { URL absUrl(uri); if (!absUrl.isAbsolute()) { if (!absUrl.toAbsoluteCwd()) { - LOG(ERROR) << "Given URL is not absolute or does not have file schema"; - return Interpreter(); + THROW_ERROR_PLATFORM("Given URL is not absolute or does not have file schema"); } } @@ -401,8 +407,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { std::stringstream ss; ss << absUrl; if (absUrl.downloadFailed()) { - LOG(ERROR) << "Downloading SCXML document from " << absUrl << " failed"; - return interpreter; + THROW_ERROR_PLATFORM("Downloading SCXML document from " + absUrl.asString() + " failed"); } interpreter = fromXML(ss.str()); } @@ -412,7 +417,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { interpreter._impl->_baseURI = URL::asBaseURL(absUrl); interpreter._impl->_sourceURI = absUrl; } else { - LOG(ERROR) << "Cannot create interpreter from URI '" << absUrl.asString() << "'"; + THROW_ERROR_PLATFORM("Cannot create interpreter from URI " + absUrl.asString() + "'"); } return interpreter; } @@ -439,8 +444,12 @@ Interpreter Interpreter::fromInputSource(Arabica::SAX::InputSource<std::string>& interpreterImpl->setNameSpaceInfo(parser.nameSpace); interpreterImpl->_document = parser.getDocument(); } else { -// assert(parser.errorsReported()); - interpreterImpl->setInterpreterState(InterpreterState::USCXML_FAULTED, parser.errors()); + if (parser.errorsReported()) { + THROW_ERROR_PLATFORM(parser.errors()) + } else { + THROW_ERROR_PLATFORM("Failed to create interpreter"); +// interpreterImpl->setInterpreterState(InterpreterState::USCXML_FAULTED, parser.errors()); + } } return interpreter; } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index d9aeac3..9a3e553 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -315,11 +315,11 @@ public: URL::toBaseURL(baseURI); _baseURI = baseURI; } - URL getBaseURI() { - return _baseURI; + std::string getBaseURI() { + return _baseURI.asString(); } - URL getSourceURI() { - return _sourceURI; + std::string getSourceURI() { + return _sourceURI.asString(); } void setCmdLineOptions(std::map<std::string, std::string> params); @@ -652,10 +652,10 @@ public: void setSourceURI(std::string sourceURI) { return _impl->setSourceURI(sourceURI); } - URL getSourceURI() { + std::string getSourceURI() { return _impl->getSourceURI(); } - URL getBaseURI() { + std::string getBaseURI() { return _impl->getBaseURI(); } diff --git a/src/uscxml/URL.h b/src/uscxml/URL.h index 5f55454..fd89503 100644 --- a/src/uscxml/URL.h +++ b/src/uscxml/URL.h @@ -261,7 +261,9 @@ public: return _impl->pathComponents(); } const std::string asString() const { - return _impl->asString(); + if (_impl) + return _impl->asString(); + return ""; } static std::string tmpDir(); diff --git a/src/uscxml/concurrency/tinythread.cpp b/src/uscxml/concurrency/tinythread.cpp index 6167545..d46cda3 100644 --- a/src/uscxml/concurrency/tinythread.cpp +++ b/src/uscxml/concurrency/tinythread.cpp @@ -85,10 +85,27 @@ condition_variable::~condition_variable() { #endif #if defined(_TTHREAD_WIN32_) -void condition_variable::_wait() { +void condition_variable::_wait(unsigned int ms) { + if (ms <= 0) + ms = INFINITE; // Wait for either event to become signaled due to notify_one() or // notify_all() being called - int result = WaitForMultipleObjects(2, mEvents, FALSE, INFINITE); + int result = WaitForMultipleObjects(2, mEvents, FALSE, ms); + if (result == WAIT_FAILED) { + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL); +// UM_LOG_ERR("%s", lpMsgBuf); + LocalFree(lpMsgBuf); + + } // Check if we are the last waiter EnterCriticalSection(&mWaitersCountLock); diff --git a/src/uscxml/concurrency/tinythread.h b/src/uscxml/concurrency/tinythread.h index 9d211f4..867f036 100644 --- a/src/uscxml/concurrency/tinythread.h +++ b/src/uscxml/concurrency/tinythread.h @@ -421,7 +421,7 @@ public: // Release the mutex while waiting for the condition (will decrease // the number of waiters when done)... aMutex.unlock(); - _wait(); + _wait(0); aMutex.lock(); #else pthread_cond_wait(&mHandle, &aMutex.mHandle); @@ -483,7 +483,7 @@ public: private: #if defined(_TTHREAD_WIN32_) - void _wait(); + void _wait(unsigned int ms); HANDLE mEvents[2]; ///< Signal and broadcast event HANDLEs. unsigned int mWaitersCount; ///< Count of the number of waiters. CRITICAL_SECTION mWaitersCountLock; ///< Serialize access to mWaitersCount. diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 17c11d6..d7528f0 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -228,7 +228,7 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { Data sessionData; sessionData.compound["name"] = Data(instance->getName(), Data::VERBATIM); sessionData.compound["id"] = Data(instance->getSessionId(), Data::VERBATIM); - sessionData.compound["source"] = Data(instance->getSourceURI().asString(), Data::VERBATIM); + sessionData.compound["source"] = Data(instance->getSourceURI(), Data::VERBATIM); sessionData.compound["xml"].node = instance->getDocument(); replyData.compound["sessions"].array.push_back(sessionData); |