/* # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ # ----------------------------------------------------------------------------- # src/net/mcast/trial_programs/McastConfigArgParser.cpp # - Parse common Multicast Configuration CLI arguments # ----------------------------------------------------------------------------- */ #include #include #include "McastConfigArgParser.h" using namespace std; bool parseMcastConfigArg(QStringList::iterator& i, QStringList::iterator const& end, McastConfiguration* config) { QString arg = *i; if (arg == "-addr") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } config->multicastAddress(*i); } else if (arg == "-dport") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint16 dport = (quint16)i->toInt(&ok); if (!ok) { cerr << "Error: dport is not an integer" << endl; return false; } config->multicastDPort(dport); } else if (arg == "-sport") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint16 sport = (quint16)i->toInt(&ok); if (!ok) { cerr << "Error: sport is not an integer" << endl; return false; } config->multicastSPort(sport); } else if (arg == "-mtu") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint16 mtu = (quint16)i->toInt(&ok); if (!ok) { cerr << "Error: MTU is not an integer" << endl; return false; } config->multicastMTU(mtu); } else if (arg == "-rate") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint32 rate = i->toInt(&ok); if (!ok) { cerr << "Error: Rate is not an integer" << endl; return false; } config->multicastRate(rate); } else if (arg == "-winsize") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint16 winsize = (quint16)i->toInt(&ok); if (!ok) { cerr << "Error: Winsize is not an integer" << endl; return false; } config->multicastWinSize(winsize); } else if (arg == "-udp") { config->multicastUseUDP(true); } else if (arg == "-no-udp") { config->multicastUseUDP(false); } else if (arg == "-udp-port") { i++; if(i == end) { cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; return false; } bool ok; quint16 udpport = (quint16)i->toInt(&ok); if (!ok) { cerr << "Error: UDP-Port is not an integer" << endl; return false; } config->multicastUDPPortBase(udpport); } else if (arg == "-intf") { i++; if (i == end) { cerr << "Option " << arg.toLatin1().constData() << "is missing argument" << endl; return false; } config->multicastInterface(*i); } else { return false; } return true; }