diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/uscxml/debug/Breakpoint.cpp | 24 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.cpp | 40 | ||||
-rw-r--r-- | src/uscxml/interpreter/ContentExecutorImpl.h | 1 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterImpl.h | 4 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterMonitor.h | 6 | ||||
-rw-r--r-- | src/uscxml/interpreter/MicroStepImpl.h | 1 | ||||
-rw-r--r-- | src/uscxml/server/HTTPServer.cpp | 17 |
7 files changed, 63 insertions, 30 deletions
diff --git a/src/uscxml/debug/Breakpoint.cpp b/src/uscxml/debug/Breakpoint.cpp index 1e40ee3..3287075 100644 --- a/src/uscxml/debug/Breakpoint.cpp +++ b/src/uscxml/debug/Breakpoint.cpp @@ -86,20 +86,20 @@ Breakpoint::Breakpoint(const Data& data) { if (data.hasKey("eventName")) eventName = data.at("eventName").atom; - if (data.hasKey("executableName")) - executableName = data.at("executableName").atom; + if (data.hasKey("execName")) + executableName = data.at("execName").atom; - if (data.hasKey("executableXPath")) - executableXPath = data.at("executableXPath").atom; + if (data.hasKey("execXPath")) + executableXPath = data.at("execXPath").atom; if (data.hasKey("stateId")) stateId = data.at("stateId").atom; - if (data.hasKey("transSourceId")) - transSourceId = data.at("transSourceId").atom; + if (data.hasKey("source")) + transSourceId = data.at("source").atom; - if (data.hasKey("transTargetId")) - transTargetId = data.at("transTargetId").atom; + if (data.hasKey("target")) + transTargetId = data.at("target").atom; } @@ -173,10 +173,10 @@ Data Breakpoint::toData() const { data.compound["eventName"] = Data(eventName, Data::VERBATIM); if (executableName.length() > 0) - data.compound["executableName"] = Data(executableName, Data::VERBATIM); + data.compound["execName"] = Data(executableName, Data::VERBATIM); if (executableXPath.length() > 0) { - data.compound["executableXPath"] = Data(executableXPath, Data::VERBATIM); + data.compound["execXPath"] = Data(executableXPath, Data::VERBATIM); } if (element) @@ -186,10 +186,10 @@ Data Breakpoint::toData() const { data.compound["stateId"] = Data(stateId, Data::VERBATIM); if (transSourceId.length() > 0) - data.compound["transSourceId"] = Data(transSourceId, Data::VERBATIM); + data.compound["source"] = Data(transSourceId, Data::VERBATIM); if (transTargetId.length() > 0) - data.compound["transTargetId"] = Data(transTargetId, Data::VERBATIM); + data.compound["target"] = Data(transTargetId, Data::VERBATIM); if (condition.length() > 0) data.compound["condition"] = Data(condition, Data::VERBATIM); diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index 042235e..60dcdfb 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -86,7 +86,9 @@ void DebugSession::breakExecution(Data replyData) { replyData.compound["replyType"] = Data("breakpoint", Data::VERBATIM); _debugger->pushData(shared_from_this(), replyData); - _resumeCond.wait(_mutex); + + // wait for resume from the client + _resumeCond.wait(_mutex); } Data DebugSession::debugPrepare(const Data& data) { @@ -102,14 +104,18 @@ Data DebugSession::debugPrepare(const Data& data) { _isAttached = false; - if (data.hasKey("xml")) { - _interpreter = Interpreter::fromXML(data.at("xml").atom, (data.hasKey("url") ? data.at("url").atom : "")); - } else if (data.hasKey("url")) { - _interpreter = Interpreter::fromURL(data.at("url").atom); - } else { - _interpreter = Interpreter(); - } - + try { + if (data.hasKey("xml")) { + _interpreter = Interpreter::fromXML(data.at("xml").atom, (data.hasKey("url") ? data.at("url").atom : "")); + } else if (data.hasKey("url")) { + _interpreter = Interpreter::fromURL(data.at("url").atom); + } else { + _interpreter = Interpreter(); + } + } catch(ErrorEvent e) { + std::cerr << e; + } catch(...) {} + if (_interpreter) { // register ourself as a monitor _interpreter.addMonitor(_debugger); @@ -201,7 +207,7 @@ void DebugSession::run(void* instance) { InterpreterState state = USCXML_UNDEF; while(state != USCXML_FINISHED && INSTANCE->_isRunning) { - state = INSTANCE->_interpreter.step(100); + state = INSTANCE->_interpreter.step(); // if (!INSTANCE->_isStarted) { // // we have been cancelled @@ -288,9 +294,19 @@ Data DebugSession::skipToBreakPoint(const Data& data) { std::lock_guard<std::recursive_mutex> lock(_mutex); _skipTo = Breakpoint(data); + Data replyData; - Data replyData; - replyData.compound["status"] = Data("success", Data::VERBATIM); + if (_interpreter) { + // register ourself as a monitor + if (!_isRunning) { + _isRunning = true; + _interpreterThread = new std::thread(DebugSession::run, this); + } + + replyData.compound["status"] = Data("success", Data::VERBATIM); + } else { + replyData.compound["status"] = Data("failure", Data::VERBATIM); + } _resumeCond.notify_one(); return replyData; diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index 0e12aff..d23b7be 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -66,6 +66,7 @@ public: /** Monitoring */ virtual std::set<InterpreterMonitor*> getMonitors() = 0; + virtual InterpreterImpl* getInterpreter() = 0; }; diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index 6d047ec..fa7bf89 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -140,6 +140,10 @@ public: return _monitors; } + virtual InterpreterImpl* getInterpreter() { + return this; + } + /** DataModelCallbacks */ diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index ff2e7cb..aae4296 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -34,13 +34,13 @@ catch (...) { LOG(ERROR) << "An exception occurred when calling " #callback " on if (_state == USCXML_DESTROYED) { throw std::bad_weak_ptr(); } #define USCXML_MONITOR_CALLBACK(callbacks, function) \ -for (auto callback : callbacks) { callback->function(NULL); } +for (auto callback : callbacks) { callback->function(_callbacks->getInterpreter()); } #define USCXML_MONITOR_CALLBACK1(callbacks, function, arg1) \ -for (auto callback : callbacks) { callback->function(NULL, arg1); } +for (auto callback : callbacks) { callback->function(_callbacks->getInterpreter(), arg1); } #define USCXML_MONITOR_CALLBACK2(callbacks, function, arg1, arg2) \ -for (auto callback : callbacks) { callback->function(NULL, arg1, arg2); } +for (auto callback : callbacks) { callback->function(_callbacks->getInterpreter(), arg1, arg2); } // forward declare namespace XERCESC_NS { diff --git a/src/uscxml/interpreter/MicroStepImpl.h b/src/uscxml/interpreter/MicroStepImpl.h index cb4aec6..a9287aa 100644 --- a/src/uscxml/interpreter/MicroStepImpl.h +++ b/src/uscxml/interpreter/MicroStepImpl.h @@ -61,6 +61,7 @@ public: /** Monitoring */ virtual std::set<InterpreterMonitor*> getMonitors() = 0; + virtual InterpreterImpl* getInterpreter() = 0; }; /** diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index 044cb6c..071846c 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -386,9 +386,14 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD key = item.substr(0, equalPos); value = item.substr(equalPos + 1, item.length() - (equalPos + 1)); - char* keyCStr = evhttp_decode_uri(key.c_str()); - char* valueCStr = evhttp_decode_uri(value.c_str()); - request.data.compound["content"].compound[keyCStr] = Data(valueCStr, Data::VERBATIM); + size_t keyCStrLen = 0; + size_t valueCStrLen = 0; + char* keyCStr = evhttp_uridecode(key.c_str(), 1, &keyCStrLen); + char* valueCStr = evhttp_uridecode(value.c_str(), 1, &valueCStrLen); + std::string decKey = std::string(keyCStr, keyCStrLen); + std::string decValue = std::string(valueCStr, valueCStrLen); + + request.data.compound["content"].compound[decKey] = Data(decValue, Data::VERBATIM); free(keyCStr); free(valueCStr); key.clear(); @@ -412,6 +417,12 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD request.raw = raw.str(); +#if 0 + std::cout << "====" << std::endl; + std::cout << request.raw << std::endl; + std::cout << "====" << std::endl; +#endif + // try with the handler registered for path first bool answered = false; if (callbackData != NULL) |