diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-22 14:02:03 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-22 14:02:03 (GMT) |
commit | 1fb6bcf30f954e426f2d3002d14887574fb941dd (patch) | |
tree | 08cff7f2b879c50efe79e3c04d255075522af862 /src/uscxml/debug | |
parent | 71c334bf4e35559496feac3f3cf00b72ceb88812 (diff) | |
download | uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.zip uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.gz uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.bz2 |
Major refactoring
- Moved tests
- Changes to promela datamodel
- Implemented Trie
Diffstat (limited to 'src/uscxml/debug')
-rw-r--r-- | src/uscxml/debug/Breakpoint.cpp | 116 | ||||
-rw-r--r-- | src/uscxml/debug/Breakpoint.h | 38 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.cpp | 78 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.h | 20 | ||||
-rw-r--r-- | src/uscxml/debug/Debugger.cpp | 40 | ||||
-rw-r--r-- | src/uscxml/debug/Debugger.h | 38 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.cpp | 70 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.h | 24 |
8 files changed, 212 insertions, 212 deletions
diff --git a/src/uscxml/debug/Breakpoint.cpp b/src/uscxml/debug/Breakpoint.cpp index 0001127..54f5d75 100644 --- a/src/uscxml/debug/Breakpoint.cpp +++ b/src/uscxml/debug/Breakpoint.cpp @@ -24,7 +24,7 @@ namespace uscxml { Breakpoint::Breakpoint(const Data& data) { - enabled = true; + enabled = true; subject = UNDEF_SUBJECT; when = UNDEF_WHEN; action = UNDEF_ACTION; @@ -105,60 +105,60 @@ Data Breakpoint::toData() const { Data data; switch (subject) { - case STATE: - data.compound["subject"] = Data("state", Data::VERBATIM); - break; - case TRANSITION: - data.compound["subject"] = Data("transition", Data::VERBATIM); - break; - case STABLE: - data.compound["subject"] = Data("stable", Data::VERBATIM); - break; - case MICROSTEP: - data.compound["subject"] = Data("microstep", Data::VERBATIM); - break; - case EVENT: - data.compound["subject"] = Data("event", Data::VERBATIM); - break; - case INVOKER: - data.compound["subject"] = Data("invoker", Data::VERBATIM); - break; - case EXECUTABLE: - data.compound["subject"] = Data("executable", Data::VERBATIM); - break; - default: - break; + case STATE: + data.compound["subject"] = Data("state", Data::VERBATIM); + break; + case TRANSITION: + data.compound["subject"] = Data("transition", Data::VERBATIM); + break; + case STABLE: + data.compound["subject"] = Data("stable", Data::VERBATIM); + break; + case MICROSTEP: + data.compound["subject"] = Data("microstep", Data::VERBATIM); + break; + case EVENT: + data.compound["subject"] = Data("event", Data::VERBATIM); + break; + case INVOKER: + data.compound["subject"] = Data("invoker", Data::VERBATIM); + break; + case EXECUTABLE: + data.compound["subject"] = Data("executable", Data::VERBATIM); + break; + default: + break; } - + switch (when) { - case AFTER: - data.compound["when"] = Data("after", Data::VERBATIM); - break; - case BEFORE: - data.compound["when"] = Data("before", Data::VERBATIM); - break; - case ON: - data.compound["when"] = Data("on", Data::VERBATIM); - break; - default: - break; + case AFTER: + data.compound["when"] = Data("after", Data::VERBATIM); + break; + case BEFORE: + data.compound["when"] = Data("before", Data::VERBATIM); + break; + case ON: + data.compound["when"] = Data("on", Data::VERBATIM); + break; + default: + break; } switch (action) { - case ENTER: - data.compound["action"] = Data("enter", Data::VERBATIM); - break; - case EXIT: - data.compound["action"] = Data("exit", Data::VERBATIM); - break; - case INVOKE: - data.compound["action"] = Data("invoke", Data::VERBATIM); - break; - case UNINVOKE: - data.compound["action"] = Data("cancel", Data::VERBATIM); - break; - default: - break; + case ENTER: + data.compound["action"] = Data("enter", Data::VERBATIM); + break; + case EXIT: + data.compound["action"] = Data("exit", Data::VERBATIM); + break; + case INVOKE: + data.compound["action"] = Data("invoke", Data::VERBATIM); + break; + case UNINVOKE: + data.compound["action"] = Data("cancel", Data::VERBATIM); + break; + default: + break; } if (invokeId.length() > 0) @@ -176,7 +176,7 @@ Data Breakpoint::toData() const { if (executableXPath.length() > 0) { data.compound["executableXPath"] = Data(executableXPath, Data::VERBATIM); } - + if (element) data.compound["xpath"] = Data(DOMUtils::xPathForNode(element, "*"), Data::VERBATIM); @@ -194,20 +194,20 @@ Data Breakpoint::toData() const { return data; } - + bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const { // would we match the given breakpoint? if (subject != UNDEF_SUBJECT && - other.subject != subject) + other.subject != subject) return false; // subject does not match - + if (when != UNDEF_WHEN && - other.when != when) + other.when != when) return false; // time does not match - + if (action != UNDEF_ACTION && - other.action != action) + other.action != action) return false; // action does not match // when we have a qualifier it has to match @@ -248,7 +248,7 @@ bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const if(transTargetId.length() > 0 && transTargetId != other.transTargetId) { return false; } - + if (condition.length() > 0) { try { DataModel dm = interpreter.getDataModel(); diff --git a/src/uscxml/debug/Breakpoint.h b/src/uscxml/debug/Breakpoint.h index 157a56d..c48b841 100644 --- a/src/uscxml/debug/Breakpoint.h +++ b/src/uscxml/debug/Breakpoint.h @@ -27,61 +27,61 @@ namespace uscxml { class USCXML_API Breakpoint { public: - + enum When { - UNDEF_WHEN, AFTER, BEFORE, ON + UNDEF_WHEN, AFTER, BEFORE, ON }; - + enum Subject { - UNDEF_SUBJECT, STATE, TRANSITION, STABLE, MICROSTEP, EVENT, INVOKER, EXECUTABLE + UNDEF_SUBJECT, STATE, TRANSITION, STABLE, MICROSTEP, EVENT, INVOKER, EXECUTABLE }; - + enum Action { - UNDEF_ACTION, ENTER, EXIT, INVOKE, UNINVOKE + UNDEF_ACTION, ENTER, EXIT, INVOKE, UNINVOKE }; - + Breakpoint() { subject = UNDEF_SUBJECT; when = UNDEF_WHEN; action = UNDEF_ACTION; } Breakpoint(const Data& data); - + // would we match the given breakpoint as well? bool matches(Interpreter interpreter, const Breakpoint& other) const; - + Data toData() const; - + bool operator<(const Breakpoint& other) const { return (toData() < other.toData()); } - + operator bool() { return (subject != UNDEF_SUBJECT || - when != UNDEF_WHEN || - action != UNDEF_ACTION); + when != UNDEF_WHEN || + action != UNDEF_ACTION); } - + mutable bool enabled; - + When when; Subject subject; Action action; Arabica::DOM::Element<std::string> element; - + std::string invokeId; std::string invokeType; std::string eventName; - + std::string executableName; std::string executableXPath; - + std::string stateId; std::string transSourceId; std::string transTargetId; - + std::string condition; }; diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index e785c84..c73f53e 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -21,16 +21,16 @@ #include "uscxml/debug/Debugger.h" namespace uscxml { - + void DebugSession::checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpoints) { std::list<Breakpoint>::const_iterator qualifiedBreakpointIter = qualifiedBreakpoints.begin(); if (!_breakpointsEnabled) return; - + while(qualifiedBreakpointIter != qualifiedBreakpoints.end()) { const Breakpoint& qualifiedBreakpoint = *qualifiedBreakpointIter++; - + // check if one of the user-supplied breakpoints match bool userBreakpointMatched = false; Data replyData; @@ -44,7 +44,7 @@ void DebugSession::checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpo } continue; } - + std::set<Breakpoint>::const_iterator breakpointIter = _breakPoints.begin(); while(breakpointIter != _breakPoints.end()) { const Breakpoint& breakpoint = *breakpointIter++; @@ -52,10 +52,10 @@ void DebugSession::checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpo continue; if (breakpoint.matches(_interpreter, qualifiedBreakpoint)) { // do we have a condition? - + replyData.compound["breakpoint"] = breakpoint.toData(); replyData.compound["qualified"] = qualifiedBreakpoint.toData(); - + userBreakpointMatched = true; breakExecution(replyData); } @@ -70,7 +70,7 @@ void DebugSession::checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpo void DebugSession::breakExecution(Data replyData) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); - + Arabica::XPath::NodeSet<std::string> basicConf = _interpreter.getBasicConfiguration(); for (int i = 0; i < basicConf.size(); i++) { Arabica::DOM::Element<std::string> element = Arabica::DOM::Element<std::string>(basicConf[i]); @@ -94,7 +94,7 @@ void DebugSession::breakExecution(Data replyData) { Data DebugSession::debugPrepare(const Data& data) { Data replyData; - + if (!data.hasKey("xml") && !data.hasKey("url")) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No XML or URL given", Data::VERBATIM); @@ -102,7 +102,7 @@ Data DebugSession::debugPrepare(const Data& data) { } debugStop(data); - + _isAttached = false; if (data.hasKey("xml")) { @@ -112,7 +112,7 @@ Data DebugSession::debugPrepare(const Data& data) { } else { _interpreter = Interpreter(); } - + if (_interpreter) { // register ourself as a monitor _interpreter.addMonitor(_debugger); @@ -132,22 +132,22 @@ Data DebugSession::debugPrepare(const Data& data) { Data DebugSession::debugAttach(const Data& data) { Data replyData; _isAttached = true; - + if (!data.hasKey("attach")) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No id to attach to given", Data::VERBATIM); return replyData; } - + std::string interpreterId = data.at("attach").atom; bool interpreterFound = false; - + // find interpreter for sessionid std::map<std::string, boost::weak_ptr<InterpreterImpl> > instances = Interpreter::getInstances(); for (std::map<std::string, boost::weak_ptr<InterpreterImpl> >::iterator instIter = instances.begin(); - instIter != instances.end(); - instIter++) { - + instIter != instances.end(); + instIter++) { + boost::shared_ptr<InterpreterImpl> instance = instIter->second.lock(); if (instance && instance->getSessionId() == interpreterId) { _interpreter = instance; @@ -156,7 +156,7 @@ Data DebugSession::debugAttach(const Data& data) { break; } } - + if (!interpreterFound) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No interpreter with given id found", Data::VERBATIM); @@ -179,7 +179,7 @@ Data DebugSession::debugDetach(const Data& data) { Data DebugSession::debugStart(const Data& data) { Data replyData; - + if (_isAttached) { replyData.compound["reason"] = Data("Already started when attached", Data::VERBATIM); replyData.compound["status"] = Data("failure", Data::VERBATIM); @@ -201,7 +201,7 @@ Data DebugSession::debugStop(const Data& data) { // detach from old intepreter _debugger->detachSession(_interpreter); } - + if (_interpreter && !_isAttached) _interpreter.stop(); // unblock @@ -212,16 +212,16 @@ Data DebugSession::debugStop(const Data& data) { // calls destructor _interpreter = Interpreter(); - + return replyData; } - + Data DebugSession::debugStep(const Data& data) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); - + stepping(true); _resumeCond.notify_one(); - + Data replyData; if (_interpreter) { // register ourself as a monitor @@ -233,19 +233,19 @@ Data DebugSession::debugStep(const Data& data) { } return replyData; } - + Data DebugSession::debugResume(const Data& data) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); - + stepping(false); - + Data replyData; replyData.compound["status"] = Data("success", Data::VERBATIM); - + _resumeCond.notify_one(); return replyData; } - + Data DebugSession::debugPause(const Data& data) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); @@ -261,12 +261,12 @@ Data DebugSession::debugPause(const Data& data) { Data DebugSession::skipToBreakPoint(const Data& data) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); - + _skipTo = Breakpoint(data); - + Data replyData; replyData.compound["status"] = Data("success", Data::VERBATIM); - + _resumeCond.notify_one(); return replyData; } @@ -278,7 +278,7 @@ Data DebugSession::addBreakPoint(const Data& data) { if (_breakPoints.find(breakpoint) == _breakPoints.end()) { _breakPoints.insert(breakpoint); replyData.compound["status"] = Data("success", Data::VERBATIM); - + } else { replyData.compound["reason"] = Data("Breakpoint already exists", Data::VERBATIM); replyData.compound["status"] = Data("failure", Data::VERBATIM); @@ -316,7 +316,7 @@ Data DebugSession::enableBreakPoint(const Data& data) { } Data DebugSession::disableBreakPoint(const Data& data) { Breakpoint breakpoint(data); - + Data replyData; if (_breakPoints.find(breakpoint) != _breakPoints.end()) { _breakPoints.find(breakpoint)->enabled = false; @@ -325,7 +325,7 @@ Data DebugSession::disableBreakPoint(const Data& data) { replyData.compound["reason"] = Data("No such breakpoint", Data::VERBATIM); replyData.compound["status"] = Data("failure", Data::VERBATIM); } - + return replyData; } Data DebugSession::enableAllBreakPoints() { @@ -338,16 +338,16 @@ Data DebugSession::enableAllBreakPoints() { } Data DebugSession::disableAllBreakPoints() { Data replyData; - + _breakpointsEnabled = false; replyData.compound["status"] = Data("success", Data::VERBATIM); - + return replyData; } Data DebugSession::debugEval(const Data& data) { Data replyData; - + if (!data.hasKey("expression")) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No expression given", Data::VERBATIM); @@ -355,7 +355,7 @@ Data DebugSession::debugEval(const Data& data) { } std::string expr = data.at("expression").atom; - + if (!_interpreter) { replyData.compound["status"] = Data("failure", Data::VERBATIM); replyData.compound["reason"] = Data("No interpreter running", Data::VERBATIM); @@ -374,5 +374,5 @@ Data DebugSession::debugEval(const Data& data) { return replyData; } - + }
\ No newline at end of file diff --git a/src/uscxml/debug/DebugSession.h b/src/uscxml/debug/DebugSession.h index 12f1d93..1fb4f4d 100644 --- a/src/uscxml/debug/DebugSession.h +++ b/src/uscxml/debug/DebugSession.h @@ -27,7 +27,7 @@ namespace uscxml { class Debugger; - + class USCXML_API DebugSession : public boost::enable_shared_from_this<DebugSession> { public: DebugSession() { @@ -37,13 +37,13 @@ public: _markedForDeletion = false; _debugger = NULL; } - + void stepping(bool enable) { _isStepping = enable; } - + void checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpoints); - + Data debugPrepare(const Data& data); Data debugAttach(const Data& data); Data debugDetach(const Data& data); @@ -60,26 +60,26 @@ public: Data enableAllBreakPoints(); Data disableAllBreakPoints(); Data debugEval(const Data& data); - + void setDebugger(Debugger* debugger) { _debugger = debugger; } - + Interpreter getInterpreter() { return _interpreter; } - + void markForDeletion(bool mark) { _markedForDeletion = mark; } - + protected: void breakExecution(Data replyData); bool _isStepping; bool _isAttached; bool _breakpointsEnabled; - + tthread::condition_variable _resumeCond; tthread::recursive_mutex _runMutex; tthread::recursive_mutex _mutex; @@ -89,7 +89,7 @@ protected: Interpreter _interpreter; std::set<Breakpoint> _breakPoints; Breakpoint _skipTo; - + }; diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index f611d09..d1a8068 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -21,7 +21,7 @@ #include "uscxml/DOMUtils.h" namespace uscxml { - + void Debugger::afterCompletion(Interpreter interpreter) { boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) @@ -34,44 +34,44 @@ void Debugger::afterCompletion(Interpreter interpreter) { std::list<Breakpoint> getQualifiedStateBreakpoints(Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, Breakpoint breakpointTemplate) { std::list<Breakpoint> breakpoints; - + Breakpoint bp = breakpointTemplate; // copy base as template bp.stateId = ATTR(state, "id"); bp.element = state; bp.subject = Breakpoint::STATE; breakpoints.push_back(bp); - + return breakpoints; } std::list<Breakpoint> getQualifiedInvokeBreakpoints(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string invokeId, Breakpoint breakpointTemplate) { std::list<Breakpoint> breakpoints; - + Breakpoint bp = breakpointTemplate; // copy base as template bp.subject = Breakpoint::INVOKER; bp.element = invokeElem; bp.invokeId = invokeId; - + if (HAS_ATTR(invokeElem, "type")) { bp.invokeType = ATTR(invokeElem, "type"); } else if (HAS_ATTR(invokeElem, "typeexpr")) { bp.invokeType = interpreter.getDataModel().evalAsString(ATTR(invokeElem, "typeexpr")); } - + breakpoints.push_back(bp); - + return breakpoints; } std::list<Breakpoint> getQualifiedTransBreakpoints(Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, Breakpoint breakpointTemplate) { std::list<Breakpoint> breakpoints; - + Arabica::DOM::Element<std::string> source(interpreter.getSourceState(transition)); Arabica::XPath::NodeSet<std::string> targets = interpreter.getTargetStates(transition); for (int j = 0; j < targets.size(); j++) { Arabica::DOM::Element<std::string> target(targets[j]); - + Breakpoint bp = breakpointTemplate; // copy base as template bp.element = transition; bp.transSourceId = ATTR(source, "id"); @@ -134,14 +134,14 @@ void Debugger::beforeProcessingEvent(Interpreter interpreter, const Event& event } void Debugger::handleExecutable(Interpreter interpreter, - const Arabica::DOM::Element<std::string>& execContentElem, - Breakpoint::When when) { + const Arabica::DOM::Element<std::string>& execContentElem, + Breakpoint::When when) { if (!interpreter.isRunning()) return; boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; - + std::list<Breakpoint> breakpoints; Breakpoint breakpoint; @@ -150,7 +150,7 @@ void Debugger::handleExecutable(Interpreter interpreter, breakpoint.executableName = execContentElem.getLocalName(); breakpoint.subject = Breakpoint::EXECUTABLE; breakpoints.push_back(breakpoint); - + session->checkBreakpoints(breakpoints); } @@ -161,19 +161,19 @@ void Debugger::handleEvent(Interpreter interpreter, const Event& event, Breakpoi boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; - + std::list<Breakpoint> breakpoints; - + Breakpoint breakpoint; breakpoint.when = when; breakpoint.eventName = event.name; breakpoint.subject = Breakpoint::EVENT; breakpoints.push_back(breakpoint); - + session->checkBreakpoints(breakpoints); } - + void Debugger::handleStable(Interpreter interpreter, Breakpoint::When when) { if (!interpreter.isRunning()) return; @@ -187,7 +187,7 @@ void Debugger::handleStable(Interpreter interpreter, Breakpoint::When when) { breakpoint.when = when; breakpoint.subject = Breakpoint::STABLE; breakpoints.push_back(breakpoint); - + session->checkBreakpoints(breakpoints); } @@ -199,12 +199,12 @@ void Debugger::handleMicrostep(Interpreter interpreter, Breakpoint::When when) { return; std::list<Breakpoint> breakpoints; - + Breakpoint breakpoint; breakpoint.when = when; breakpoint.subject = Breakpoint::MICROSTEP; breakpoints.push_back(breakpoint); - + session->checkBreakpoints(breakpoints); } diff --git a/src/uscxml/debug/Debugger.h b/src/uscxml/debug/Debugger.h index 8f840b0..9adbae6 100644 --- a/src/uscxml/debug/Debugger.h +++ b/src/uscxml/debug/Debugger.h @@ -24,15 +24,15 @@ #include "uscxml/Interpreter.h" #include "uscxml/debug/Breakpoint.h" #include "uscxml/debug/DebugSession.h" - + namespace uscxml { - + class USCXML_API Debugger : public InterpreterMonitor { public: Debugger() { } virtual ~Debugger() {} - + virtual void attachSession(Interpreter interpreter, boost::shared_ptr<DebugSession> session) { tthread::lock_guard<tthread::recursive_mutex> lock(_sessionMutex); _sessionForInterpreter[interpreter] = session; @@ -42,16 +42,16 @@ public: tthread::lock_guard<tthread::recursive_mutex> lock(_sessionMutex); _sessionForInterpreter.erase(interpreter); } - + virtual boost::shared_ptr<DebugSession> getSession(Interpreter interpreter) { tthread::lock_guard<tthread::recursive_mutex> lock(_sessionMutex); if (_sessionForInterpreter.find(interpreter) != _sessionForInterpreter.end()) return _sessionForInterpreter[interpreter]; return boost::shared_ptr<DebugSession>(); } - + virtual void pushData(boost::shared_ptr<DebugSession> session, Data pushData) = 0; - + // InterpreterMonitor virtual void beforeProcessingEvent(Interpreter interpreter, const Event& event); virtual void beforeMicroStep(Interpreter interpreter); @@ -73,28 +73,28 @@ public: virtual void afterCompletion(Interpreter interpreter); protected: - + void handleTransition(Interpreter interpreter, - const Arabica::DOM::Element<std::string>& transition, - Breakpoint::When when); + const Arabica::DOM::Element<std::string>& transition, + Breakpoint::When when); void handleState(Interpreter interpreter, - const Arabica::DOM::Element<std::string>& state, - Breakpoint::When when, - Breakpoint::Action action); + const Arabica::DOM::Element<std::string>& state, + Breakpoint::When when, + Breakpoint::Action action); void handleInvoke(Interpreter interpreter, - const Arabica::DOM::Element<std::string>& invokeElem, - const std::string& invokeId, - Breakpoint::When when, - Breakpoint::Action action); + const Arabica::DOM::Element<std::string>& invokeElem, + const std::string& invokeId, + Breakpoint::When when, + Breakpoint::Action action); void handleExecutable(Interpreter interpreter, - const Arabica::DOM::Element<std::string>& execContentElem, - Breakpoint::When when); + const Arabica::DOM::Element<std::string>& execContentElem, + Breakpoint::When when); void handleStable(Interpreter interpreter, Breakpoint::When when); void handleMicrostep(Interpreter interpreter, Breakpoint::When when); void handleEvent(Interpreter interpreter, const Event& event, Breakpoint::When when); tthread::recursive_mutex _sessionMutex; - std::map<Interpreter, boost::shared_ptr<DebugSession> > _sessionForInterpreter; + std::map<Interpreter, boost::shared_ptr<DebugSession> > _sessionForInterpreter; }; } diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index a570263..a99aaf8 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -25,24 +25,24 @@ namespace uscxml { void DebuggerServlet::pushData(boost::shared_ptr<DebugSession> session, Data pushData) { std::cout << "trying to push " << pushData["replyType"].atom << std::endl; - + if (!session) { if (_sendQueues.size() > 0) // logging is not aware of its interpreter _sendQueues.begin()->second.push(pushData); } else { _sendQueues[session].push(pushData); } - + serverPushData(session); } void DebuggerServlet::serverPushData(boost::shared_ptr<DebugSession> session) { if (_sendQueues[session].isEmpty()) return; - + if (!_clientConns[session]) return; - + Data reply = _sendQueues[session].pop(); std::cout << "pushing " << reply["replyType"].atom << std::endl; returnData(_clientConns[session], reply); @@ -51,13 +51,13 @@ void DebuggerServlet::serverPushData(boost::shared_ptr<DebugSession> session) { void DebuggerServlet::returnData(const HTTPServer::Request& request, Data replyData) { HTTPServer::Reply reply(request); - + if (!replyData.hasKey("status")) { replyData.compound["status"] = Data("success", Data::VERBATIM); } - + std::cout << "<- " << replyData << std::endl; - + reply.content = Data::toJSON(replyData); reply.headers["Access-Control-Allow-Origin"] = "*"; reply.headers["Content-Type"] = "application/json"; @@ -66,8 +66,8 @@ void DebuggerServlet::returnData(const HTTPServer::Request& request, Data replyD bool DebuggerServlet::isCORS(const HTTPServer::Request& request) { return (request.data.at("type").atom == "options" && - request.data.at("header").hasKey("Origin") && - request.data.at("header").hasKey("Access-Control-Request-Method")); + request.data.at("header").hasKey("Origin") && + request.data.at("header").hasKey("Access-Control-Request-Method")); } void DebuggerServlet::handleCORS(const HTTPServer::Request& request) { @@ -81,7 +81,7 @@ void DebuggerServlet::handleCORS(const HTTPServer::Request& request) { corsReply.headers["Access-Control-Allow-Methods"] = request.data.at("header").at("Access-Control-Request-Method").atom; if (request.data.at("header").hasKey("Access-Control-Request-Headers")) corsReply.headers["Access-Control-Allow-Headers"] = request.data.at("header").at("Access-Control-Request-Headers").atom; - + // std::cout << "CORS!" << std::endl << request << std::endl; HTTPServer::reply(corsReply); } @@ -89,14 +89,14 @@ void DebuggerServlet::handleCORS(const HTTPServer::Request& request) { bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { if (!request.data.hasKey("path")) return false; // returnError(request); - + if (isCORS(request)) { handleCORS(request); return true; } - + std::cout << request.data["path"] << ": " << request.data["content"] << std::endl; - + Data replyData; // process request that don't need a session if (false) { @@ -107,7 +107,7 @@ bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { processListSessions(request); return true; } - + // get session or return error if (false) { } else if (!request.data.at("content").hasKey("session")) { @@ -121,9 +121,9 @@ bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { returnData(request, replyData); return true; } - + boost::shared_ptr<DebugSession> session = _sessionForId[request.data.at("content").at("session").atom]; - + if (false) { } else if (boost::starts_with(request.data.at("path").atom, "/debug/poll")) { // save long-standing client poll @@ -164,7 +164,7 @@ bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { } else if (boost::starts_with(request.data.at("path").atom, "/debug/eval")) { replyData = session->debugEval(request.data["content"]); } - + if (replyData) { returnData(request, replyData); return true; @@ -177,10 +177,10 @@ bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { void DebuggerServlet::processConnect(const HTTPServer::Request& request) { tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); std::string sessionId = UUID::getUUID(); - + _sessionForId[sessionId] = boost::shared_ptr<DebugSession>(new DebugSession()); _sessionForId[sessionId]->setDebugger(this); - + Data replyData; replyData.compound["session"] = Data(sessionId, Data::VERBATIM); replyData.compound["status"] = Data("success", Data::VERBATIM); @@ -211,18 +211,18 @@ void DebuggerServlet::processDisconnect(const HTTPServer::Request& request) { _sendQueues.erase(_sessionForId[sessionId]); _sessionForId.erase(sessionId); } - + returnData(request, replyData); } void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { Data replyData; - + std::map<std::string, boost::weak_ptr<InterpreterImpl> > instances = Interpreter::getInstances(); for (std::map<std::string, boost::weak_ptr<InterpreterImpl> >::iterator instIter = instances.begin(); - instIter != instances.end(); - instIter++) { - + instIter != instances.end(); + instIter++) { + boost::shared_ptr<InterpreterImpl> instance = instIter->second.lock(); if (instance) { Data sessionData; @@ -234,25 +234,25 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { replyData.compound["sessions"].array.push_back(sessionData); } } - + replyData.compound["status"] = Data("success", Data::VERBATIM); returnData(request, replyData); } void DebuggerServlet::send(google::LogSeverity severity, const char* full_filename, - const char* base_filename, int line, - const struct ::tm* tm_time, - const char* message, size_t message_len) { - + const char* base_filename, int line, + const struct ::tm* tm_time, + const char* message, size_t message_len) { + // _sendQueue is thread-safe, not sure about ToString though LogMessage msg(severity, - full_filename, - base_filename, - line, - tm_time, - std::string(message, message_len), - ToString(severity, base_filename, line, tm_time, message, message_len)); + full_filename, + base_filename, + line, + tm_time, + std::string(message, message_len), + ToString(severity, base_filename, line, tm_time, message, message_len)); msg.compound["replyType"] = Data("log", Data::VERBATIM); pushData(boost::shared_ptr<DebugSession>(), msg); } diff --git a/src/uscxml/debug/DebuggerServlet.h b/src/uscxml/debug/DebuggerServlet.h index ae5178f..ce6f082 100644 --- a/src/uscxml/debug/DebuggerServlet.h +++ b/src/uscxml/debug/DebuggerServlet.h @@ -37,10 +37,10 @@ public: class LogMessage : public Data { public: LogMessage(google::LogSeverity severity, const char* full_filename, - const char* base_filename, int line, - const struct ::tm* tm_time, - std::string message, std::string formatted) { - + const char* base_filename, int line, + const struct ::tm* tm_time, + std::string message, std::string formatted) { + compound["severity"] = severity; compound["fullFilename"] = Data(full_filename, Data::VERBATIM); compound["baseFilename"] = Data(base_filename, Data::VERBATIM); @@ -50,9 +50,9 @@ public: compound["formatted"] = Data(formatted, Data::VERBATIM); } }; - + virtual ~DebuggerServlet() {} - + // from Debugger virtual void addBreakpoint(const Breakpoint& breakpoint) {}; @@ -85,20 +85,20 @@ public: // void processAddBreakPoint(const HTTPServer::Request& request); // void processRemoveBreakPoint(const HTTPServer::Request& request); // void processPoll(const HTTPServer::Request& request); - + // Logsink virtual void send(google::LogSeverity severity, const char* full_filename, - const char* base_filename, int line, - const struct ::tm* tm_time, - const char* message, size_t message_len); + const char* base_filename, int line, + const struct ::tm* tm_time, + const char* message, size_t message_len); protected: void serverPushData(boost::shared_ptr<DebugSession>); std::string _url; std::map<boost::shared_ptr<DebugSession>, HTTPServer::Request> _clientConns; - std::map<boost::shared_ptr<DebugSession>, concurrency::BlockingQueue<Data> > _sendQueues; - std::map<std::string, boost::shared_ptr<DebugSession> > _sessionForId; + std::map<boost::shared_ptr<DebugSession>, concurrency::BlockingQueue<Data> > _sendQueues; + std::map<std::string, boost::shared_ptr<DebugSession> > _sessionForId; tthread::recursive_mutex _mutex; }; |