int main(int argc, char **argv) { QCoreApplication app(argc, argv); QCommandLineParser parser; QCoreApplication::setApplicationName("IDFS master node"); QCoreApplication::setApplicationVersion("1.0"); parser.setApplicationDescription("Where all file metadata is stored."); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption portOption(QStringList() << "p" << "port", "Host's port (default is 8001).", "port", "8001"); parser.addOption(portOption); parser.process(app); bool ok; quint16 port = parser.value(portOption).toUInt(&ok); if (!ok) { qDebug() << "Could not parse the port value, using 8001"; port = 8001; } MasterNode master; master.listen(QHostAddress::AnyIPv4, port); app.exec(); return 1; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QCoreApplication::setApplicationName("empire-gui"); // Configure parser for command line arguments QCommandLineParser parser; parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.addHelpOption(); QCommandLineOption modeOption("obs", "Start the client as observer."); parser.addOption(modeOption); QCommandLineOption addressOption("saddr", "Server address.", "port", "localhost"); parser.addOption(addressOption); QCommandLineOption portOption("sport", "Server port.", "port", "0"); parser.addOption(portOption); // Get arguments values parser.process(a); MainWindow w; // Process arguments QStringList args = parser.positionalArguments(); QString address = parser.value("saddr"); int port = parser.value("sport").toInt(); w.initialize(address, port, parser.isSet(modeOption)); w.show(); return a.exec(); }
FiveServerOptions::FiveServerOptions(QCoreApplication *app, QObject *parent) : QObject(parent) { m_parser.setApplicationDescription("Server daemon for dotFive"); m_parser.addHelpOption(); m_parser.addVersionOption(); QCommandLineOption hostOption(QStringList() << "H" << "host", tr("Run server to listen on IP <host>."), tr("host")); hostOption.setDefaultValue(five::ADDRESS_ANY); m_parser.addOption(hostOption); QCommandLineOption portOption(QStringList() << "p" << "port", tr("Run server to listen on port <port>."), tr("port")); portOption.setDefaultValue(five::PORT_DEFAULT); m_parser.addOption(portOption); QCommandLineOption timeOption(QStringList() << "t" << "timeout", tr("Set the timeout of <timeout> ms before closing connection, 0 to disable."), tr("timeout")); timeOption.setDefaultValue(five::TIMEOUT_DEFAULT); m_parser.addOption(timeOption); QCommandLineOption heartOption(QStringList() << "b" << "heartbeat", tr("Set the heartbeat sending timeout to <heartbeat> ms, 0 to disable."), tr("heartbeat")); heartOption.setDefaultValue(five::HEARTBEAT_DEFAULT); m_parser.addOption(heartOption); m_parser.process(*app); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCommandLineParser parser; parser.setApplicationDescription("agar.io private server"); parser.addHelpOption(); QCommandLineOption dbgOption(QStringList() << "d" << "debug", QCoreApplication::translate("main", "Debug output [default: off].")); parser.addOption(dbgOption); QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Port for server [default: 9000]."), QCoreApplication::translate("main", "port"), QLatin1Literal("9000")); parser.addOption(portOption); parser.process(a); bool debug = parser.isSet(dbgOption); int port = parser.value(portOption).toInt(); GameServer *server = new GameServer(port, debug); QObject::connect(server, &GameServer::closed, &a, &QCoreApplication::quit); return a.exec(); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCoreApplication::setApplicationName("HttpServer"); QCoreApplication::setApplicationVersion(QT_VERSION_STR); QCommandLineParser commandLineParser; commandLineParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); commandLineParser.setApplicationDescription(QStringLiteral("HTTP Test server")); commandLineParser.addHelpOption(); commandLineParser.addVersionOption(); QCommandLineOption portOption(QStringLiteral("p"), QStringLiteral("Port (default: ") + QString::number(defaultPort) + QLatin1Char(')'), QStringLiteral("port")); commandLineParser.addOption(portOption); commandLineParser.addPositionalArgument(QStringLiteral("[directory]"), QStringLiteral("Directory to serve.")); commandLineParser.process(a); const QStringList args = commandLineParser.positionalArguments(); if (args.size() != 1) commandLineParser.showHelp(1); const QString directory = QDir::cleanPath(args.front()); if (!QFileInfo(directory).isDir()) { std::wcerr << '"' << QDir::toNativeSeparators(directory) << "\" is not a directory.\n"; return -1; } unsigned short port = defaultPort; if (commandLineParser.isSet(portOption)) { const QString portV = commandLineParser.value(portOption); bool ok; port = portV.toUShort(&ok); if (!ok) { std::wcerr << portV << " is not a valid port number.\n"; return -1; } } std::wcout << "Serving \"" << QDir::toNativeSeparators(directory) << "\":\n\n" << QDir(directory).entryList(QDir::Files).join(QLatin1Char('\n')) << "\n\non http://localhost:" << port << '\n'; TestHTTPServer server(port); server.serveDirectory(directory); return a.exec(); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // TODO: separate to module based on Server Configurator App // with options to turn on/off components/etc QCommandLineParser parser; parser.setApplicationDescription("SemIoT gateway"); parser.addHelpOption(); // TODO: miltiple devices QCommandLineOption dbgOption(QStringList() << "d" << "debug", QCoreApplication::translate("main", "Debug output [default: off].")); parser.addOption(dbgOption); // TODO: get rid of magic default port: QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Port for gateway server [default: 57864]."), QCoreApplication::translate("main", "port"), QLatin1Literal("57864")); parser.addOption(portOption); parser.process(a); bool debug = parser.isSet(dbgOption); Q_UNUSED(debug); //TODO int port = parser.value(portOption).toInt(); // Internal part //DataServer dataServer; //DevicesConfigsLoader devicesConfigsLoader; FrontModuleManager fMM(&a); // External Part WebSocketServer wsServer(port,&a); HttpServer httpServer(&a); fMM.connectFrontModule((FrontModule*)&wsServer); fMM.connectFrontModule((FrontModule*)&httpServer); //wsServer.setDataServer(&dataServer); //httpServer.setDataServer(&dataServer); // FIXME: for all the protocols /* QObject::connect(&devicesConfigsLoader,SIGNAL(newDataReady(QString,QString)),&wsServer,SLOT(processNewData(QString,QString))); QObject::connect(&httpServer,SIGNAL(newRequestReceived(QVariant)),&devicesConfigsLoader,SIGNAL(newRequestReceived(QVariant))); QObject::connect(&httpServer,SIGNAL(addDeviceDriverFromUrl(QUrl)),&devicesConfigsLoader,SLOT(addConfig(QUrl))); */ // TODO: linux kernel driver // TODO: dbus // TODO: systemd? /* monarch::data::json::JsonLd jsonld(); monarch::rt::DynamicObject input; QFile file("infile"); file.open(QIODevice::ReadOnly); QByteArray ba(file.readAll()); monarch::rt::DynamicObject options; monarch::rt::DynamicObject output; jsonld().fromRdf(input,options,output); */ return a.exec(); }
int main(int argc, char * argv[]) { QCoreApplication a(argc, argv); // Build the command-line options QCommandLineParser parser; QCommandLineOption addressOption( QStringList() << "a" << "address", "address to bind to", "address", "127.0.0.1" ); parser.addOption(addressOption); QCommandLineOption portOption( QStringList() << "p" << "port", "port to listen on", "port", "8000" ); parser.addOption(portOption); QCommandLineOption dirOption( QStringList() << "d" << "directory", "directory to serve", "directory", QDir::homePath() ); parser.addOption(dirOption); parser.addHelpOption(); // Parse the options that were provided parser.process(a); // Obtain the values QHostAddress address = QHostAddress(parser.value(addressOption)); quint16 port = parser.value(portOption).toInt(); QString dir = parser.value(dirOption); // Create the filesystem handler and server QFilesystemHandler handler(dir); QHttpServer server(&handler); // Attempt to listen on the specified port if(!server.listen(address, port)) { qCritical("Unable to listen on the specified port."); return 1; } return a.exec(); }
int main(int argc, char** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; QCoreApplication app(argc, argv); app.setApplicationName("Multithreaded asynchronous message server"); app.setApplicationVersion("2.0"); QCommandLineParser parser; parser.setApplicationDescription("Author: Aleksey Blokhin"); parser.addHelpOption(); QCommandLineOption threadCountOption(QStringList() << "t" << "thread-count" , QObject::tr("the maximum number of threads used to process messages") , QObject::tr("count") , QString::number(QThread::idealThreadCount())); QCommandLineOption portOption(QStringList() << "p" << "port" , QObject::tr("the port to start the server") , QObject::tr("port")); QString bigEndianDefault, littleEndianDefault; if(QSysInfo::ByteOrder == QSysInfo::BigEndian) bigEndianDefault.append(' ').append(QObject::tr("[DEFAULT]")); else littleEndianDefault.append(' ').append(QObject::tr("[DEFAULT]")); QCommandLineOption bigEndianOption(QStringList() << "b" << "big-endian" , QObject::tr("use big-endian") + bigEndianDefault); QCommandLineOption littleEndianOption(QStringList() << "l" << "little-endian" , QObject::tr("use little-endian") + littleEndianDefault); parser.addOption(littleEndianOption); parser.addOption(bigEndianOption); parser.addOption(threadCountOption); parser.addOption(portOption); parser.process(app); QString threadCountStr = parser.value(threadCountOption); QString portStr = parser.value(portOption); QSysInfo::Endian endian = QSysInfo::ByteOrder; int threadCount = QThread::idealThreadCount(); int port = 10000; if(portStr.isEmpty()) { printf("Missing '-p' option.\n"); parser.showHelp(); } else { bool ok = false; port = portStr.toInt(&ok); if(!ok || port < 1 || port > 65535) { printf("Invalid port value.\n"); parser.showHelp(); } else if(!threadCountStr.isEmpty()) { threadCount = threadCountStr.toInt(&ok); if(!ok || threadCount < 1) { printf("Invalid thread count value.\n"); parser.showHelp(); } else { if(parser.isSet(bigEndianOption)) { if(parser.isSet(littleEndianOption)) { printf("You could use either -b nor -l.\n"); parser.showHelp(); } IOSocket::setEndian(QSysInfo::BigEndian); } else if(parser.isSet(littleEndianOption)) { if(parser.isSet(bigEndianOption)) { printf("You could use either -b nor -l.\n"); parser.showHelp(); } IOSocket::setEndian(QSysInfo::LittleEndian); } } } } Server::instance()->setThreadPoolSize(threadCount); ExecutionThread::instance()->start(); return Server::instance()->start(port) ? app.exec() : EXIT_FAILURE; }
cCommandLineInterface::cCommandLineInterface(QCoreApplication *qapplication) { // text from http://sourceforge.net/projects/mandelbulber/ parser.setApplicationDescription("Mandelbulber is an easy to use, " "handy application designed to help you render 3D Mandelbrot fractals called Mandelbulb " "and some other kind of 3D fractals like Mandelbox, Bulbbox, Juliabulb, Menger Sponge"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption noguiOption(QStringList() << "n" << "nogui", QCoreApplication::translate("main", "Start program without GUI.")); QCommandLineOption keyframeOption(QStringList() << "K" << "keyframe", QCoreApplication::translate("main", "Render keyframe animation")); QCommandLineOption flightOption(QStringList() << "F" << "flight", QCoreApplication::translate("main", "Render flight animation")); QCommandLineOption startOption(QStringList() << "s" << "start", QCoreApplication::translate("main", "Start rendering from frame number <N>."), QCoreApplication::translate("main", "N")); QCommandLineOption endOption(QStringList() << "e" << "end", QCoreApplication::translate("main", "Stop rendering on frame number <N>."), QCoreApplication::translate("main", "N")); QCommandLineOption overrideOption(QStringList() << "O" << "override", QCoreApplication::translate("main", "Override item '<KEY>' from settings file with new value '<value>'.\n" "Specify multiple KEY=VALUE pairs by separating with a '#' (KEY1=VALUE1#KEY2=VALUE2). Quote whole expression to avoid whitespace parsing issues\n" "Override fractal parameter in the form 'fractal<N>_KEY=VALUE' with <N> as index of fractal"), QCoreApplication::translate("main", "KEY=VALUE")); QCommandLineOption listOption(QStringList() << "L" << "list", QCoreApplication::translate("main", "List all possible parameters '<KEY>' with corresponding default value '<value>'.")); QCommandLineOption formatOption(QStringList() << "f" << "format", QCoreApplication::translate("main", "Image output format:\n" "jpg - JPEG format\n" "png - PNG format\n" "png16 - 16-bit PNG format\n" "png16alpha - 16-bit PNG with alpha channel format\n" "exr - EXR format"), QCoreApplication::translate("main", "FORMAT")); QCommandLineOption resOption(QStringList() << "r" << "res", QCoreApplication::translate("main", "Override image resolution."), QCoreApplication::translate("main", "WIDTHxHEIGHT")); QCommandLineOption fpkOption("fpk", QCoreApplication::translate("main", "Override frames per key parameter."), QCoreApplication::translate("main", "N")); QCommandLineOption serverOption(QStringList() << "S" << "server", QCoreApplication::translate("main", "Set application as a server listening for clients.")); QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set application as a client connected to server of given Host address" " (Host can be of type IPv4, IPv6 and Domain name address)."), QCoreApplication::translate("main", "N.N.N.N")); QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set network port number for Netrender (default 5555)."), QCoreApplication::translate("main", "N")); QCommandLineOption noColorOption(QStringList() << "C" << "no-cli-color", QCoreApplication::translate("main", "Start program without ANSI colors, when execution on CLI.")); QCommandLineOption outputOption(QStringList() << "o" << "output", QCoreApplication::translate("main", "Save rendered image(s) to this file / folder."), QCoreApplication::translate("main", "N")); QCommandLineOption queueOption(QStringList() << "q" << "queue", QCoreApplication::translate("main", "Render all images from common queue.")); QCommandLineOption statsOption(QStringList() << "stats", QCoreApplication::translate("main", "Show statistics while renderering in CLI mode.")); QCommandLineOption helpInputOption(QStringList() << "help-input", QCoreApplication::translate("main", "Show help about input.")); parser.addPositionalArgument("settings_file", QCoreApplication::translate("main", "file with fractal settings (program also tries\nto find file in ./mandelbulber/settings directory)\n" "When settings_file is put as a command line argument then program will start in noGUI mode" "<settings_file> can also be specified as a list, see all options with --help-input" )); parser.addOption(noguiOption); parser.addOption(outputOption); parser.addOption(keyframeOption); parser.addOption(flightOption); parser.addOption(startOption); parser.addOption(endOption); parser.addOption(overrideOption); parser.addOption(listOption); parser.addOption(formatOption); parser.addOption(resOption); parser.addOption(fpkOption); parser.addOption(serverOption); parser.addOption(hostOption); parser.addOption(portOption); parser.addOption(noColorOption); parser.addOption(queueOption); parser.addOption(statsOption); parser.addOption(helpInputOption); // Process the actual command line arguments given by the user parser.process(*qapplication); args = parser.positionalArguments(); cliData.nogui = parser.isSet(noguiOption); cliData.keyframe = parser.isSet(keyframeOption); cliData.flight = parser.isSet(flightOption); cliData.startFrameText = parser.value(startOption); cliData.endFrameText = parser.value(endOption); cliData.overrideParametersText = parser.value(overrideOption); cliData.imageFileFormat = parser.value(formatOption); cliData.resolution = parser.value(resOption); cliData.fpkText = parser.value(fpkOption); cliData.server = parser.isSet(serverOption); cliData.host = parser.value(hostOption); cliData.portText = parser.value(portOption); cliData.outputText = parser.value(outputOption); cliData.listParameters = parser.isSet(listOption); cliData.queue = parser.isSet(queueOption); cliData.showInputHelp = parser.isSet(helpInputOption); systemData.statsOnCLI = parser.isSet(statsOption); #ifdef WIN32 /* WINDOWS */ systemData.useColor = false; #else systemData.useColor = !parser.isSet(noColorOption); #endif /* WINDOWS */ if(cliData.listParameters) cliData.nogui = true; if(cliData.queue) cliData.nogui = true; cliTODO = modeBootOnly; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QCommandLineParser cmdline_parser; // cmdline_parser.addHelpOption(); // create commandline options // QCommandLineOption serverOption(QStringList() << "h" << "host", "NewtonCam server address", "host name or IP", "127.0.0.1"); QString str; str.setNum(NETPROTOCOL_DEFAULT_PORT); QCommandLineOption portOption(QStringList() << "p" << "port", "NewtonCam server port", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE); QCommandLineOption fontOption(QStringList() << "f" << "fontsize", "GUI font size", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE-2); QCommandLineOption statusfontOption(QStringList() << "s" << "statusfontsize", "GUI status font size", "numeric value", str); str.setNum(SERVERGUI_DEFAULT_FONTSIZE); QCommandLineOption logfontOption(QStringList() << "l" << "logfontsize", "GUI log window font size", "numeric value", str); QCommandLineOption xcoordOption(QStringList() << "x" << "xpos", "GUI window x-coordinate position", "numeric vlue", str); QCommandLineOption ycoordOption(QStringList() << "y" << "ypos", "GUI window x-coordinate position", "numeric vlue", str); cmdline_parser.addOption(portOption); cmdline_parser.addOption(fontOption); cmdline_parser.addOption(statusfontOption); cmdline_parser.addOption(logfontOption); cmdline_parser.addOption(xcoordOption); cmdline_parser.addOption(ycoordOption); cmdline_parser.addPositionalArgument("IP-address", "NewtonCam server address (default 127.0.0.1)"); cmdline_parser.process(a); quint16 port; bool ok; port = cmdline_parser.value(portOption).toUInt(&ok); if ( !ok ) { // QMessageBox::StandardButton bt = QMessageBox::critical(0,"Error","Invalid port value!"); exit(NEWTONGUI_ERROR_INVALID_PORT); } int fontsize = cmdline_parser.value(fontOption).toInt(&ok); if ( !ok ) { // QMessageBox::StandardButton bt = QMessageBox::critical(0,"Error","Invalid GUI fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int statusFontsize = cmdline_parser.value(statusfontOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid GUI status fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int logFontsize = cmdline_parser.value(logfontOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid GUI log window fontsize value!"); exit(NEWTONGUI_ERROR_INVALID_FONTSIZE); } int xcoord; bool isX = false; if ( !cmdline_parser.value(xcoordOption).isEmpty() ) { xcoord = cmdline_parser.value(xcoordOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid x-coordinate of GUI window!"); exit(NEWTONGUI_ERROR_INVALID_COORDINATE); } isX = true; } int ycoord; bool isY = false; if ( !cmdline_parser.value(ycoordOption).isEmpty() ) { ycoord = cmdline_parser.value(ycoordOption).toInt(&ok); if ( !ok ) { QMessageBox::critical(0,"Error","Invalid y-coordinate of GUI window!"); exit(NEWTONGUI_ERROR_INVALID_COORDINATE); } isY = true; } QHostAddress addr; QStringList pos_arg = cmdline_parser.positionalArguments(); if ( pos_arg.length() == 0 ) { str = "127.0.0.1"; addr.setAddress(str); } else { str = pos_arg[0]; QRegExp rx("\\s*\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\s*"); if ( !rx.exactMatch(str) ) { // do DNS look-up QHostInfo info = QHostInfo::fromName(str.trimmed()); if ( info.addresses().isEmpty() ) { QMessageBox::critical(0,"Error","Invalid server hostname!"); exit(NEWTONGUI_ERROR_INVALID_HOSTNAME); } addr = info.addresses().first(); } else { addr.setAddress(str); } } NewtonGui ng(fontsize); ng.SetFonts(fontsize,statusFontsize,logFontsize); QPoint gui_pos = ng.pos(); if ( isX ) gui_pos.setX(xcoord); if ( isY ) gui_pos.setY(ycoord); if ( isX || isY ) ng.move(gui_pos); ng.show(); // QObject::connect(&ng,&NewtonGui::Error,[=](int err){exit(err);}); str = QDateTime::currentDateTime().toString(" dd-MM-yyyy hh:mm:ss"); ng.LogMessage("<b> " + str + ":</b> Trying to connect to NewtonCam server at " + addr.toString() + " ..."); a.processEvents(); // to draw the main window and show start message ng.Connect(addr,port); return a.exec(); }