diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-21 11:34:44 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-21 11:34:44 (GMT) |
commit | dc5f5ddfa10bf91524e6f7555c263eaea069dcb0 (patch) | |
tree | 576b15e7fe75476e8ece954b52aa88871941beb5 /apps | |
parent | 641117e7400e9e5ef0fa451f732eb9009f0914cb (diff) | |
download | uscxml-dc5f5ddfa10bf91524e6f7555c263eaea069dcb0.zip uscxml-dc5f5ddfa10bf91524e6f7555c263eaea069dcb0.tar.gz uscxml-dc5f5ddfa10bf91524e6f7555c263eaea069dcb0.tar.bz2 |
try / catch blocks for applications and work on dot output
Diffstat (limited to 'apps')
-rw-r--r-- | apps/uscxml-browser.cpp | 80 | ||||
-rw-r--r-- | apps/uscxml-dot.cpp | 92 | ||||
-rw-r--r-- | apps/uscxml-transform.cpp | 63 |
3 files changed, 139 insertions, 96 deletions
diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index e431fdf..f9a06bb 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -173,52 +173,60 @@ int main(int argc, char** argv) { std::string documentURL = options.interpreters[0].first; LOG(INFO) << "Processing " << documentURL; - Interpreter interpreter = Interpreter::fromURI(documentURL); - if (interpreter) { - interpreter.setCmdLineOptions(currOptions->additionalParameters); - interpreter.setCapabilities(options.getCapabilities()); - - if (options.verbose) { - VerboseMonitor* vm = new VerboseMonitor(); - interpreter.addMonitor(vm); - } - if (options.withDebugger) { - interpreter.addMonitor(debugger); - } - interpreters.push_back(interpreter); + try { + Interpreter interpreter = Interpreter::fromURI(documentURL); + if (interpreter) { + interpreter.setCmdLineOptions(currOptions->additionalParameters); + interpreter.setCapabilities(options.getCapabilities()); - } else { - LOG(ERROR) << "Cannot create interpreter from " << documentURL; + if (options.verbose) { + VerboseMonitor* vm = new VerboseMonitor(); + interpreter.addMonitor(vm); + } + if (options.withDebugger) { + interpreter.addMonitor(debugger); + } + + interpreters.push_back(interpreter); + + } else { + LOG(ERROR) << "Cannot create interpreter from " << documentURL; + } + } catch (Event e) { + std::cout << e << std::endl; } } // start interpreters - std::list<Interpreter>::iterator interpreterIter = interpreters.begin(); - while(interpreterIter != interpreters.end()) { - interpreterIter->start(); - interpreterIter++; - } - - bool stillRunning = true; - // call from main thread for UI events - while(interpreters.size() > 0) { - interpreterIter = interpreters.begin(); + try { + std::list<Interpreter>::iterator interpreterIter = interpreters.begin(); while(interpreterIter != interpreters.end()) { - stillRunning = interpreterIter->runOnMainThread(25); - if (!stillRunning) { - interpreters.erase(interpreterIter++); - } else { - interpreterIter++; + interpreterIter->start(); + interpreterIter++; + } + + bool stillRunning = true; + // call from main thread for UI events + while(interpreters.size() > 0) { + interpreterIter = interpreters.begin(); + while(interpreterIter != interpreters.end()) { + stillRunning = interpreterIter->runOnMainThread(25); + if (!stillRunning) { + interpreters.erase(interpreterIter++); + } else { + interpreterIter++; + } } } - } - if (options.withDebugger) { - // idle and wait for CTRL+C or debugging events - while(true) - tthread::this_thread::sleep_for(tthread::chrono::seconds(1)); + if (options.withDebugger) { + // idle and wait for CTRL+C or debugging events + while(true) + tthread::this_thread::sleep_for(tthread::chrono::seconds(1)); + } + } catch (Event e) { + std::cout << e << std::endl; } - return EXIT_SUCCESS; }
\ No newline at end of file diff --git a/apps/uscxml-dot.cpp b/apps/uscxml-dot.cpp index 3324e54..56f5c57 100644 --- a/apps/uscxml-dot.cpp +++ b/apps/uscxml-dot.cpp @@ -7,6 +7,7 @@ #include "uscxml/Factory.h" #include <boost/algorithm/string.hpp> + using namespace uscxml; void printUsageAndExit(const char* progName) { @@ -19,12 +20,17 @@ void printUsageAndExit(const char* progName) { 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(" [-dN_0] URL"); - printf(" [[-dN_1] state_id1] .. [[-dN_M] state_idM]"); + printf(" [-eTYPE] [-dN] [-tN] URL"); + printf(" [[-dN] [-tN] [-eTYPE] state_id1] .. [[-dN] [-tN] [-eTYPE] state_idM]"); printf("\n"); printf("Options\n"); printf("\tURL : URL of SCXML document\n"); + printf("\t-e TYPE : type of edges to use:\n"); + printf("\t 'target' - aggregate per target node (default)\n"); + printf("\t 'event' - aggregate per event name\n"); + printf("\t 'transition' no aggregation, display each transition\n"); printf("\t-d : depth below anchor node (INF per default)\n"); + printf("\t-t : transition depth below anchor (INF per default)\n"); printf("\tstate_id : anchor node state id (topmost scxml element per default)\n"); printf("\n"); exit(1); @@ -32,9 +38,9 @@ void printUsageAndExit(const char* progName) { int currOpt = 1; -int consumeDepthOption(int argc, char** argv) { +int32_t consumeNumericOption(int argc, char** argv, const std::string& name, int32_t defaultVal) { std::string test = argv[currOpt]; - if (boost::starts_with(test, "-")) { + if (boost::starts_with(test, std::string("-") + name)) { int value = 0; if (test.size() > 2) { // no space before value @@ -52,7 +58,7 @@ int consumeDepthOption(int argc, char** argv) { return value; } - return -1; + return defaultVal; } int main(int argc, char** argv) { @@ -61,43 +67,69 @@ int main(int argc, char** argv) { google::LogToStderr(); google::InitGoogleLogging(argv[0]); - std::list<SCXMLDotWriter::StateAnchor> stateAnchors; - + if (argc < 2) printUsageAndExit(argv[0]); - try { - // see if there is an initial depth given for root - int depth = consumeDepthOption(argc, argv); - if (depth >= 0) { - SCXMLDotWriter::StateAnchor anchor; - anchor.depth = depth; - stateAnchors.push_back(anchor); + std::list<SCXMLDotWriter::StateAnchor> stateAnchors; + SCXMLDotWriter::StateAnchor currAnchor; + + int option; + while ((option = getopt(argc, argv, "d:t:")) != -1) { + switch(option) { + case 'd': currAnchor.childDepth = strTo<int32_t>(optarg); break; + case 't': currAnchor.transDepth = strTo<int32_t>(optarg); break; + case 'e': { + std::string edgeType(optarg); + if (edgeType == "target") { + currAnchor.type = SCXMLDotWriter::PORT_TARGET; + } else if (edgeType == "event") { + currAnchor.type = SCXMLDotWriter::PORT_EVENT; + } else if (edgeType == "transition") { + currAnchor.type = SCXMLDotWriter::PORT_TRANSITION; + } else { + printUsageAndExit(argv[0]); + } + break; + } + default: break; } + } + + if (currAnchor) + stateAnchors.push_back(currAnchor); + try { // current option has to be the interpreter's name - URL inputFile(argv[currOpt++]); + URL inputFile(argv[optind]); Interpreter interpreter = Interpreter::fromURI(inputFile); - - for (; currOpt < argc; currOpt++) { - SCXMLDotWriter::StateAnchor anchor; - depth = consumeDepthOption(argc, argv); - - if (depth >= 0) { - anchor.depth = depth; + optind++; + + while(optind < argc) { + // are + while ((option = getopt(argc, argv, "d:t:")) != -1) { + switch(option) { + case 'd': currAnchor.childDepth = strTo<int32_t>(optarg); break; + case 't': currAnchor.transDepth = strTo<int32_t>(optarg); break; + default: break; + } } - - if (argc > currOpt) { - std::string expr(argv[currOpt++]); - anchor.element = interpreter.getImpl()->getState(expr); + if (argc > optind) { + std::string expr(argv[optind++]); + currAnchor.element = interpreter.getImpl()->getState(expr); } else { printUsageAndExit(argv[0]); } - - stateAnchors.push_back(anchor); + + if (currAnchor) { + stateAnchors.push_back(currAnchor); + } + + currAnchor = SCXMLDotWriter::StateAnchor(); } - - SCXMLDotWriter::toDot("machine.dot", interpreter, stateAnchors); + + std::string outName = inputFile.file() + ".dot"; + SCXMLDotWriter::toDot(outName, interpreter, stateAnchors); } catch(Event e) { std::cerr << e << std::cout; diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp index d0c3524..245a89c 100644 --- a/apps/uscxml-transform.cpp +++ b/apps/uscxml-transform.cpp @@ -161,41 +161,44 @@ int main(int argc, char** argv) { HTTPServer::getInstance(30444, 30445, NULL); Interpreter interpreter; - if (inputFile.size() == 0 || inputFile == "-") { - LOG(INFO) << "Reading SCXML from STDIN"; - std::stringstream ss; - std::string line; - while (std::getline(std::cin, line)) { - ss << line; + try { + if (inputFile.size() == 0 || inputFile == "-") { + LOG(INFO) << "Reading SCXML from STDIN"; + std::stringstream ss; + std::string line; + while (std::getline(std::cin, line)) { + ss << line; + } + interpreter = Interpreter::fromXML(ss.str()); + } else { + interpreter = Interpreter::fromURI(inputFile); + } + if (!interpreter) { + LOG(ERROR) << "Cannot create interpreter from " << inputFile; + exit(EXIT_FAILURE); } - interpreter = Interpreter::fromXML(ss.str()); - } else { - interpreter = Interpreter::fromURI(inputFile); - } - if (!interpreter) { - LOG(ERROR) << "Cannot create interpreter from " << inputFile; - exit(EXIT_FAILURE); - } - - if (toPromela) { - Interpreter flatInterpreter = ChartToFSM::flatten(interpreter); - if (outputFile.size() == 0 || outputFile == "-") { - FSMToPromela::writeProgram(std::cout, flatInterpreter); - } else { - std::ofstream outStream; - outStream.open(outputFile.c_str()); - FSMToPromela::writeProgram(outStream, flatInterpreter); - outStream.close(); + if (toPromela) { + Interpreter flatInterpreter = ChartToFSM::flatten(interpreter); + + if (outputFile.size() == 0 || outputFile == "-") { + FSMToPromela::writeProgram(std::cout, flatInterpreter); + } else { + std::ofstream outStream; + outStream.open(outputFile.c_str()); + FSMToPromela::writeProgram(outStream, flatInterpreter); + outStream.close(); + } + exit(EXIT_SUCCESS); } - exit(EXIT_SUCCESS); - } - if (toFlat) { - std::cout << ChartToFSM::flatten(interpreter).getDocument(); - exit(EXIT_SUCCESS); + if (toFlat) { + std::cout << ChartToFSM::flatten(interpreter).getDocument(); + exit(EXIT_SUCCESS); + } + } catch (Event e) { + std::cout << e << std::endl; } - return EXIT_SUCCESS; }
\ No newline at end of file |