diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-07-13 23:15:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-13 23:15:57 (GMT) |
commit | 4a9b4978eca21c01e45bdea56ee97285b8ca11a7 (patch) | |
tree | 40a8f92a0abd081f59a8aacc4b726dabf3c8f2f5 /src/apps/uscxml-browser.cpp | |
parent | f5198b3027a9a1d1de0aa92b2e62e13d0dc6f47d (diff) | |
parent | 04b04aa6624caf73ffe4fc33f918e7f48b27da37 (diff) | |
download | uscxml-4a9b4978eca21c01e45bdea56ee97285b8ca11a7.zip uscxml-4a9b4978eca21c01e45bdea56ee97285b8ca11a7.tar.gz uscxml-4a9b4978eca21c01e45bdea56ee97285b8ca11a7.tar.bz2 |
Merge pull request #162 from tklab-tud/sradomski
LambdaMonitors and prepared use-case examples
Diffstat (limited to 'src/apps/uscxml-browser.cpp')
-rw-r--r-- | src/apps/uscxml-browser.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/src/apps/uscxml-browser.cpp b/src/apps/uscxml-browser.cpp new file mode 100644 index 0000000..dd0633b --- /dev/null +++ b/src/apps/uscxml-browser.cpp @@ -0,0 +1,132 @@ +#include "uscxml/config.h" +#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterOptions.h" +#include "uscxml/debug/InterpreterIssue.h" +#include "uscxml/debug/DebuggerServlet.h" +#include "uscxml/interpreter/InterpreterMonitor.h" +#include "uscxml/util/DOM.h" + +#include "uscxml/interpreter/Logging.h" + +#include "uscxml/plugins/Factory.h" +#include "uscxml/server/HTTPServer.h" + + +int main(int argc, char** argv) { + using namespace uscxml; + +#if defined(HAS_SIGNAL_H) && !defined(WIN32) + signal(SIGPIPE, SIG_IGN); +#endif + + InterpreterOptions options = InterpreterOptions::fromCmdLine(argc, argv); + + if (!options) { + InterpreterOptions::printUsageAndExit(argv[0]); + } + + if (!options.validate) { + // setup HTTP server + HTTPServer::SSLConfig* sslConf = NULL; + if (options.certificate.length() > 0) { + sslConf = new HTTPServer::SSLConfig(); + sslConf->privateKey = options.certificate; + sslConf->publicKey = options.certificate; + sslConf->port = options.httpsPort; + + } else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) { + sslConf = new HTTPServer::SSLConfig(); + sslConf->privateKey = options.privateKey; + sslConf->publicKey = options.publicKey; + sslConf->port = options.httpsPort; + + } + HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf); + } + + if (options.pluginPath.length() > 0) { + Factory::setDefaultPluginPath(options.pluginPath); + } + + if (options.verbose) { + Factory::getInstance()->listComponents(); + } + + // instantiate and configure interpreters + std::list<Interpreter> interpreters; + for(size_t i = 0; i < options.interpreters.size(); i++) { + +// InterpreterOptions* currOptions = options.interpreters[0].second; + std::string documentURL = options.interpreters[i].first; + + LOGD(USCXML_INFO) << "Processing " << documentURL << std::endl; + + try { + Interpreter interpreter = Interpreter::fromURL(documentURL); + if (interpreter) { + + if (options.validate) { + std::list<InterpreterIssue> issues = interpreter.validate(); + for (std::list<InterpreterIssue>::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) { + LOGD(USCXML_DEBUG) << "" << *issueIter << std::endl; + } + if (issues.size() == 0) { + LOGD(USCXML_DEBUG) << "No issues found" << std::endl; + } + + } + + if (options.verbose) { + StateTransitionMonitor* vm = new StateTransitionMonitor(); + vm->copyToInvokers(true); + interpreter.addMonitor(vm); + } + + interpreters.push_back(interpreter); + + } else { + LOGD(USCXML_ERROR) << "Cannot create interpreter from " << documentURL << std::endl; + } + } catch (Event e) { + LOGD(USCXML_ERROR) << e << std::endl; + } + } + + if (options.validate) { + return EXIT_SUCCESS; + } + + if (options.withDebugger) { + DebuggerServlet* debugger; + debugger = new DebuggerServlet(); + debugger->copyToInvokers(true); + HTTPServer::getInstance()->registerServlet("/debug", debugger); + for (auto interpreter : interpreters) { + interpreter.addMonitor(debugger); + } + } + + // run interpreters + if (interpreters.size() > 0) { + try { + std::list<Interpreter>::iterator interpreterIter = interpreters.begin(); + while (interpreters.size() > 0) { + while(interpreterIter != interpreters.end()) { + InterpreterState state = interpreterIter->step(); + if (state == USCXML_FINISHED) { + interpreterIter = interpreters.erase(interpreterIter); + } else { + interpreterIter++; + } + } + interpreterIter = interpreters.begin(); + } + } catch (Event e) { + LOGD(USCXML_ERROR) << e << std::endl; + } + } else if (options.withDebugger) { + while(true) + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + return EXIT_SUCCESS; +} |