summaryrefslogtreecommitdiffstats
path: root/src/net/mcast/trial_programs/mcastsend.cpp
blob: f78a9ce02f44c2315c38cbb5e4c6e16e55313f50 (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
/*
# 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/mcastsend.cpp
#    - Send a file via the PVS Mcast protocol
# -----------------------------------------------------------------------------
*/

#include <iostream>

#include <QCoreApplication>
#include <QFile>
#include <QStringList>
#include <QTimer>

#include <src/net/mcast/McastSender.h>
#include "mcastsend.h"
#include "McastConfigArgParser.h"
#include "../McastConstants.h"
#include "../McastConfiguration.h"

using namespace std;

int
main(int argc, char**argv)
{
	QCoreApplication app(argc, argv);
	McastSend me;

	QTimer::singleShot(0, &me, SLOT(run()));

	return app.exec();
}

void McastSend::run()
{
	QStringList args = QCoreApplication::arguments();
	QStringList::iterator i = args.begin();
	QStringList::iterator const end = args.end();
	QString filename("");
	McastConfiguration config;

	++i;
	while(i != end)
	{
		// parse command line arguments

		QString arg = *i;

		cerr << "Arg: " << arg.toLatin1().constData() << endl;

		if (arg == "-file")
		{
			i++;
			if(i == end)
			{
				cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl;
				QCoreApplication::exit(1);
				return;
			}
			filename = *i;
		}
		else if (arg == "-help")
		{
			cerr << "Options:" << endl << endl
					<< " -file <FILE>       Send FILE to the listeners" << endl
					<< " -addr <ADDR>       Use ADDR as address specification" << endl
					<< " -dport <PORT>      Send to port PORT" << endl
					<< " -sport <PORT>		Send from port PORT" << endl
					<< " -mtu <BYTES>       Set MTU to BYTES" << endl
					<< " -rate <BYTES>      Send BYTES per second" << endl
					<< " -winsize <SECONDS> Set Window Size to SECONDS" << endl
					<< " -udp               Use UDP encapsulation" << endl
					<< " -udp-port PORT     Use UDP port PORT" << endl;
			QCoreApplication::quit();
			return;
		}
		else
		{
			if (!parseMcastConfigArg(i, end, &config))
			{
				cerr << "Unknown command line argument: " << arg.toLatin1().constData() << endl;
				QCoreApplication::exit(1);
				return;
			}
		}

		++i;
	}

	if(filename == "")
	{
		cerr << "No filename given" << endl;
		QCoreApplication::exit(1);
		return;
	}

	// now, do it.
	QFile* file = new QFile(filename);
	file->open(QIODevice::ReadOnly);

	McastSender* sender = new McastSender(file, &config, this);
	file->setParent(sender);

	connect(sender, SIGNAL(finished()), this, SLOT(finished()));

	QTimer::singleShot(0, sender, SLOT(start()));
}

void McastSend::finished()
{
	cerr << "finished." << endl;
	QCoreApplication::quit();
}