diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-10-07 23:13:54 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-10-07 23:13:54 (GMT) |
commit | 36b5c7614cc896d043ddeebae1cdb4e8e94afe18 (patch) | |
tree | e14ac52189363b252aa8ea10fdd66efef069d665 /apps/uscxml-browser.cpp | |
parent | 567df9318fff6d1bb570191c33ea68cd6ef88bee (diff) | |
download | uscxml-36b5c7614cc896d043ddeebae1cdb4e8e94afe18.zip uscxml-36b5c7614cc896d043ddeebae1cdb4e8e94afe18.tar.gz uscxml-36b5c7614cc896d043ddeebae1cdb4e8e94afe18.tar.bz2 |
Reduced compile times
- new commandline argument handling
- compiles on windows again
Diffstat (limited to 'apps/uscxml-browser.cpp')
-rw-r--r-- | apps/uscxml-browser.cpp | 146 |
1 files changed, 64 insertions, 82 deletions
diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index fa108f8..566f6bc 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -15,10 +15,6 @@ #include <dlfcn.h> #endif -#ifdef _WIN32 -#include "XGetopt.h" -#endif - class VerboseMonitor : public uscxml::InterpreterMonitor { void onStableConfiguration(uscxml::Interpreter interpreter) { printConfig(interpreter.getConfiguration()); @@ -108,23 +104,6 @@ void customTerminate() { } #endif -void printUsageAndExit() { - printf("uscxml-browser version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n"); - printf("Usage\n"); - printf("\tuscxml-browser"); -#ifdef BUILD_AS_PLUGINS - printf(" [-e pluginPath]"); -#endif - printf("[-v] [-pN] URL\n"); - printf("\n"); - printf("Options\n"); - printf("\t-v : be verbose\n"); - printf("\t-pN : port for HTTP server\n"); - printf("\t-d : write each configuration as a dot file\n"); - printf("\n"); - exit(1); -} - int main(int argc, char** argv) { using namespace uscxml; @@ -136,75 +115,78 @@ int main(int argc, char** argv) { std::set_terminate(customTerminate); #endif - if (argc < 2) { - printUsageAndExit(); + InterpreterOptions options = InterpreterOptions::fromCmdLine(argc, argv); + if (!options) { + InterpreterOptions::printUsageAndExit(argv[0]); } - - bool verbose = false; - bool useDot = false; - bool glogIsInitialized = false; - size_t port = 8080; + // setup logging google::LogToStderr(); - -#ifndef _WIN32 - opterr = 0; -#endif - int option; - while ((option = getopt(argc, argv, "dvl:e:p:")) != -1) { - switch(option) { - case 'l': - google::InitGoogleLogging(optarg); - glogIsInitialized = true; - break; - case 'e': - uscxml::Factory::pluginPath = optarg; - break; - case 'd': - useDot = true; - break; - case 'p': - port = strTo<size_t>(optarg); - break; - case 'v': - verbose = true; - break; - case '?': - break; - default: - printUsageAndExit(); - break; - } + google::InitGoogleLogging(argv[0]); + + // 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, sslConf); + + // instantiate and configure interpreters + std::list<Interpreter> interpreters; + std::map<std::string, InterpreterOptions*>::iterator confIter = options.interpreters.begin(); + while(confIter != options.interpreters.end()) { + + InterpreterOptions* currOptions = confIter->second; + std::string documentURL = confIter->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.useDot) { + SCXMLDotWriter* dotWriter = new SCXMLDotWriter(); + interpreter.addMonitor(dotWriter); + } + + interpreters.push_back(interpreter); - if (!glogIsInitialized) - google::InitGoogleLogging(argv[0]); - -// for (int i = 0; i < argc; i++) -// std::cout << argv[i] << std::endl; -// std::cout << optind << std::endl; - - // intialize http server on given port - HTTPServer::getInstance(port); + } else { + LOG(ERROR) << "Cannot create interpreter from " << documentURL; + } + confIter++; + } - LOG(INFO) << "Processing " << argv[optind]; - Interpreter interpreter = Interpreter::fromURI(argv[optind]); - if (interpreter) { - interpreter.setCmdLineOptions(argc, argv); - // interpreter->setCapabilities(Interpreter::CAN_NOTHING); - // interpreter->setCapabilities(Interpreter::CAN_BASIC_HTTP | Interpreter::CAN_GENERIC_HTTP); + // start interpreters + std::list<Interpreter>::iterator interpreterIter = interpreters.begin(); + while(interpreterIter != interpreters.end()) { + interpreterIter->start(); + interpreterIter++; + } - if (verbose) { - VerboseMonitor* vm = new VerboseMonitor(); - interpreter.addMonitor(vm); - } - if (useDot) { - SCXMLDotWriter* dotWriter = new SCXMLDotWriter(); - interpreter.addMonitor(dotWriter); + // call from main thread for UI events + while(interpreters.size() > 0) { + interpreterIter = interpreters.begin(); + while(interpreterIter != interpreters.end()) { + interpreterIter->runOnMainThread(25); + interpreterIter++; } - - interpreter.start(); - while(interpreter.runOnMainThread(25)); } + return EXIT_SUCCESS; }
\ No newline at end of file |