diff options
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/Interpreter.cpp | 153 | ||||
-rw-r--r-- | src/uscxml/Interpreter.h | 44 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.cpp | 48 | ||||
-rw-r--r-- | src/uscxml/debug/DebugSession.h | 1 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.cpp | 5 | ||||
-rw-r--r-- | src/uscxml/debug/DebuggerServlet.h | 6 | ||||
-rw-r--r-- | src/uscxml/interpreter/BasicContentExecutor.cpp | 2 | ||||
-rw-r--r-- | src/uscxml/messages/Data.h | 2 | ||||
-rw-r--r-- | src/uscxml/util/DOM.h | 1 |
9 files changed, 50 insertions, 212 deletions
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index d21ec6a..ff6de81 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -40,8 +40,6 @@ #include <memory> #include <mutex> -#include "getopt.h" - #include "easylogging++.h" INITIALIZE_EASYLOGGINGPP @@ -294,155 +292,4 @@ void StateTransitionMonitor::beforeMicroStep(InterpreterImpl* impl) { std::cerr << "}" << std::endl; } -void InterpreterOptions::printUsageAndExit(const char* progName) { - // remove path from program name - std::string progStr(progName); - if (progStr.find_last_of(PATH_SEPERATOR) != std::string::npos) { - progStr = progStr.substr(progStr.find_last_of(PATH_SEPERATOR) + 1, progStr.length() - (progStr.find_last_of(PATH_SEPERATOR) + 1)); - } - - printf("%s version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n", progStr.c_str()); - printf("Usage\n"); - printf("\t%s", progStr.c_str()); - printf(" [-v] [-d] [-lN]"); -#ifdef BUILD_AS_PLUGINS - printf(" [-p pluginPath]"); -#endif - printf(" [-tN]"); -#ifdef EVENT_SSL_FOUND - printf(" [-sN] [--certificate=FILE | --private-key=FILE --public-key=FILE] "); -#endif - printf(" \\\n\t\t URL1 [--disable-http] [--option1=value1 --option2=value2]"); - printf(" \\\n\t\t[URL2 [--disable-http] [--option3=value3 --option4=value4]]"); - printf(" \\\n\t\t[URLN [--disable-http] [--optionN=valueN --optionM=valueM]]"); - printf("\n"); - printf("Options\n"); -#ifdef BUILD_AS_PLUGINS - printf("\t-p : path to the uSCXML plugins (or export USCXML_PLUGIN_PATH)\n"); -#endif - printf("\t-v : be verbose\n"); - printf("\t-c : perform some sanity checks on the state-chart\n"); - printf("\t-lN : set loglevel to N\n"); - printf("\t-tN : port for HTTP server\n"); - printf("\t-sN : port for HTTPS server\n"); - printf("\t-wN : port for WebSocket server\n"); - printf("\n"); - exit(1); -} - -InterpreterOptions InterpreterOptions::fromCmdLine(int argc, char** argv) { - InterpreterOptions options; - optind = 0; - struct option longOptions[] = { - {"check", no_argument, 0, 'c'}, - {"verbose", no_argument, 0, 'v'}, - {"debug", no_argument, 0, 'd'}, - {"port", required_argument, 0, 't'}, - {"ssl-port", required_argument, 0, 's'}, - {"ws-port", required_argument, 0, 'w'}, - {"certificate", required_argument, 0, 0}, - {"private-key", required_argument, 0, 0}, - {"public-key", required_argument, 0, 0}, - {"plugin-path", required_argument, 0, 'p'}, - {"loglevel", required_argument, 0, 'l'}, - {0, 0, 0, 0} - }; - - opterr = 0; - InterpreterOptions* currOptions = &options; - - // parse global options - int optionInd = 0; - int option; - for (;;) { - option = getopt_long_only(argc, argv, "+vcdt:s:w:p:l:", longOptions, &optionInd); - if (option == -1) { - if (optind == argc) - // we are done with parsing - goto DONE_PARSING_CMD; - - std::string url = argv[optind]; - - options.interpreters.push_back(std::make_pair(url, new InterpreterOptions())); - currOptions = options.interpreters.back().second; - - argc -= optind; - argv += optind; - optind = 0; - - if (argc <= 1) - goto DONE_PARSING_CMD; - - } - switch(option) { - // cases without short option - case 0: { - if (iequals(longOptions[optionInd].name, "disable-http")) { - currOptions->withHTTP = false; - } else if (iequals(longOptions[optionInd].name, "private-key")) { - currOptions->privateKey = optarg; - } else if (iequals(longOptions[optionInd].name, "certificate")) { - currOptions->certificate = optarg; - } else if (iequals(longOptions[optionInd].name, "public-key")) { - currOptions->publicKey = optarg; - } - break; - } - // cases with short-hand options - case 'l': - currOptions->logLevel = strTo<unsigned int>(optarg); - break; - case 'p': - currOptions->pluginPath = optarg; - break; - case 'c': - currOptions->validate = true; - break; - case 't': - currOptions->httpPort = strTo<unsigned short>(optarg); - break; - case 's': - currOptions->httpsPort = strTo<unsigned short>(optarg); - break; - case 'w': - currOptions->wsPort = strTo<unsigned short>(optarg); - break; - case 'v': - currOptions->verbose = true; - break; - case '?': { - std::string param = argv[optind - 1]; - if (boost::starts_with(param, "--")) { - param = param.substr(2, param.length() - 2); - } else if (boost::starts_with(param, "-")) { - param = param.substr(1, param.length() - 1); - } else { - break; - } - boost::trim(param); - - size_t equalPos = param.find("="); - if (equalPos != std::string::npos) { - std::string key = param.substr(0, equalPos); - std::string value = param.substr(equalPos + 1, param.length() - (equalPos + 1)); - currOptions->additionalParameters[key] = value; - } else { - currOptions->additionalParameters[param] = ""; - } - break; - } - default: - break; - } - } - -DONE_PARSING_CMD: - - if (options.interpreters.size() == 0) - options.error = "No SCXML document to evaluate"; - - return options; -} - - } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 0d7573c..c3cd7c4 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -42,50 +42,6 @@ class InterpreterMonitor; class InterpreterImpl; class InterpreterIssue; -/** - * @ingroup interpreter - * Options to pass into an interpreter. - */ -class USCXML_API InterpreterOptions { -public: - InterpreterOptions() : - verbose(false), - validate(false), - withHTTP(true), - withHTTPS(true), - withWS(true), - logLevel(0), - httpPort(5080), - httpsPort(5443), - wsPort(5081) { - } - - bool verbose; - bool validate; - bool withHTTP; - bool withHTTPS; - bool withWS; - int logLevel; - unsigned short httpPort; - unsigned short httpsPort; - unsigned short wsPort; - std::string pluginPath; - std::string certificate; - std::string privateKey; - std::string publicKey; - std::vector<std::pair<std::string, InterpreterOptions*> > interpreters; - std::map<std::string, std::string> additionalParameters; - - std::string error; - - operator bool() { - return error.length() == 0; - } - - static void printUsageAndExit(const char* progName); - static InterpreterOptions fromCmdLine(int argc, char** argv); - -}; /** * @ingroup interpreter diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index ef4d469..042235e 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -21,6 +21,8 @@ #include "uscxml/debug/Debugger.h" #include "uscxml/util/Predicates.h" +#include <easylogging++.h> + namespace uscxml { void DebugSession::checkBreakpoints(const std::list<Breakpoint> qualifiedBreakpoints) { @@ -177,15 +179,39 @@ Data DebugSession::debugStart(const Data& data) { replyData.compound["reason"] = Data("No interpreter attached or loaded", Data::VERBATIM); replyData.compound["status"] = Data("failure", Data::VERBATIM); } else { - //_interpreter.start(); - assert(false); - + _isRunning = true; + _interpreterThread = new std::thread(DebugSession::run, this); replyData.compound["status"] = Data("success", Data::VERBATIM); } return replyData; } +void DebugSession::run(void* instance) { + DebugSession* INSTANCE = (DebugSession*)instance; + +#ifdef APPLE + std::string threadName; + threadName += "uscxml::"; + threadName += (INSTANCE->_interpreter.getImpl()->_name.size() > 0 ? INSTANCE->_interpreter.getImpl()->_name : "anon"); + threadName += ".debug"; + + pthread_setname_np(threadName.c_str()); +#endif + + InterpreterState state = USCXML_UNDEF; + while(state != USCXML_FINISHED && INSTANCE->_isRunning) { + state = INSTANCE->_interpreter.step(100); + + // if (!INSTANCE->_isStarted) { + // // we have been cancelled + // INSTANCE->_isActive = false; + // return; + // } + } + LOG(DEBUG) << "done"; +} + Data DebugSession::debugStop(const Data& data) { Data replyData; @@ -194,9 +220,11 @@ Data DebugSession::debugStop(const Data& data) { _debugger->detachSession(_interpreter.getImpl().get()); } - if (_interpreter && !_isAttached) - assert(false); - //_interpreter.stop(); + if (_isRunning && _interpreterThread != NULL) { + _isRunning = false; + _interpreterThread->join(); + delete(_interpreterThread); + } // unblock _resumeCond.notify_all(); @@ -218,9 +246,11 @@ Data DebugSession::debugStep(const Data& data) { Data replyData; if (_interpreter) { // register ourself as a monitor - if (!_isRunning) - //_interpreter.start(); - assert(false); + if (!_isRunning) { + _isRunning = true; + _interpreterThread = new std::thread(DebugSession::run, this); + + } replyData.compound["status"] = Data("success", Data::VERBATIM); } else { diff --git a/src/uscxml/debug/DebugSession.h b/src/uscxml/debug/DebugSession.h index a1ecaa0..c4f2564 100644 --- a/src/uscxml/debug/DebugSession.h +++ b/src/uscxml/debug/DebugSession.h @@ -90,6 +90,7 @@ protected: std::thread* _interpreterThread = NULL; bool _isRunning; + static void run(void* instance); bool _markedForDeletion; Debugger* _debugger; diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 2b035a6..25df9dd 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -87,7 +87,7 @@ void DebuggerServlet::handleCORS(const HTTPServer::Request& request) { HTTPServer::reply(corsReply); } -bool DebuggerServlet::httpRecvRequest(const HTTPServer::Request& request) { +bool DebuggerServlet::requestFromHTTP(const HTTPServer::Request& request) { if (!request.data.hasKey("path")) return false; // returnError(request); @@ -238,6 +238,9 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { returnData(request, replyData); } +void DebuggerServlet::handle(const el::LogDispatchData* data) { +} + /* void DebuggerServlet::send(google::LogSeverity severity, const char* full_filename, const char* base_filename, int line, diff --git a/src/uscxml/debug/DebuggerServlet.h b/src/uscxml/debug/DebuggerServlet.h index dc6b0ee..2ed1879 100644 --- a/src/uscxml/debug/DebuggerServlet.h +++ b/src/uscxml/debug/DebuggerServlet.h @@ -29,7 +29,7 @@ namespace uscxml { -class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet { +class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet, public el::LogDispatchCallback { public: class LogMessage : public Data { public: @@ -58,7 +58,7 @@ public: bool isCORS(const HTTPServer::Request& request); void handleCORS(const HTTPServer::Request& request); - bool httpRecvRequest(const HTTPServer::Request& request); + bool requestFromHTTP(const HTTPServer::Request& request); void setURL(const std::string& url) { _url = url; } @@ -92,6 +92,8 @@ public: const struct ::tm* tm_time, const char* message, size_t message_len); */ + void handle(const el::LogDispatchData* data); + protected: void serverPushData(std::shared_ptr<DebugSession>); diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 0f5a67f..2582bb0 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -597,7 +597,7 @@ Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element) { Data d; XERCESC_NS::DOMDocument* doc = parser.adoptDocument(); - d.adoptedDoc = std::make_shared<XERCESC_NS::DOMDocument*>(doc); + d.adoptedDoc = std::shared_ptr<XERCESC_NS::DOMDocument>(doc); d.node = doc->getDocumentElement(); return d; diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h index 73640f0..899ede9 100644 --- a/src/uscxml/messages/Data.h +++ b/src/uscxml/messages/Data.h @@ -220,7 +220,7 @@ protected: #endif XERCESC_NS::DOMNode* node; - std::shared_ptr<XERCESC_NS::DOMDocument*> adoptedDoc; + std::shared_ptr<XERCESC_NS::DOMDocument> adoptedDoc; std::map<std::string, Data> compound; std::list<Data> array; std::string atom; diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 86fa813..ae5fa60 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -62,7 +62,6 @@ public: static const XERCESC_NS::DOMElement* getNearestAncestor(const XERCESC_NS::DOMNode* node, const std::string tagName); static bool isDescendant(const XERCESC_NS::DOMNode* s1, const XERCESC_NS::DOMNode* s2); - static bool hasIntersection(const std::list<XERCESC_NS::DOMElement*>& l1, const std::list<XERCESC_NS::DOMElement*>& l2); static bool isMember(const XERCESC_NS::DOMElement* node, const std::list<XERCESC_NS::DOMElement*>& list); |