summaryrefslogtreecommitdiffstats
path: root/src/net/mcast/trial_programs/McastConfigArgParser.cpp
blob: 8849544a16f4551173c2a15aed7f10f657f40152 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
# 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 <iostream>

#include <QCoreApplication>

#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 == "-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->multicastUDPPort(udpport);
	}
	else
	{
		return false;
	}

	return true;
}